qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH -V3 25/32] virtio-9p: Move V9fs File system spec


From: jvrao
Subject: Re: [Qemu-devel] [PATCH -V3 25/32] virtio-9p: Move V9fs File system specific options to a separate header file.
Date: Sun, 28 Mar 2010 18:09:33 -0700
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

Aneesh Kumar K.V wrote:

Missed one more point in my previous response. 
<SNIP>

> 
> -static int local_lstat(V9fsState *s, const char *path, struct stat *stbuf)
> +static int local_lstat(FsContext *s, const char *path, struct stat *stbuf)

We have been using 's' for V9fsState For FsContext it is better to use something
else (ctx?).. which makes the code easy to read and even for search/cscope.

Thanks,
JV

>  {
>      return lstat(rpath(s, path), stbuf);
>  }
> 
> -static int local_setuid(V9fsState *s, uid_t uid)
> +static int local_setuid(FsContext *s, uid_t uid)
>  {
>      struct passwd *pw;
>      gid_t groups[33];
> @@ -70,80 +70,80 @@ static int local_setuid(V9fsState *s, uid_t uid)
>      return 0;
>  }
> 
> -static ssize_t local_readlink(V9fsState *s, const char *path,
> +static ssize_t local_readlink(FsContext *s, const char *path,
>                             char *buf, size_t bufsz)
>  {
>      return readlink(rpath(s, path), buf, bufsz);
>  }
> 
> -static int local_close(V9fsState *s, int fd)
> +static int local_close(FsContext *s, int fd)
>  {
>      return close(fd);
>  }
> 
> -static int local_closedir(V9fsState *s, DIR *dir)
> +static int local_closedir(FsContext *s, DIR *dir)
>  {
>      return closedir(dir);
>  }
> 
> -static int local_open(V9fsState *s, const char *path, int flags)
> +static int local_open(FsContext *s, const char *path, int flags)
>  {
>      return open(rpath(s, path), flags);
>  }
> 
> -static DIR *local_opendir(V9fsState *s, const char *path)
> +static DIR *local_opendir(FsContext *s, const char *path)
>  {
>      return opendir(rpath(s, path));
>  }
> 
> -static void local_rewinddir(V9fsState *s, DIR *dir)
> +static void local_rewinddir(FsContext *s, DIR *dir)
>  {
>      return rewinddir(dir);
>  }
> 
> -static off_t local_telldir(V9fsState *s, DIR *dir)
> +static off_t local_telldir(FsContext *s, DIR *dir)
>  {
>      return telldir(dir);
>  }
> 
> -static struct dirent *local_readdir(V9fsState *s, DIR *dir)
> +static struct dirent *local_readdir(FsContext *s, DIR *dir)
>  {
>      return readdir(dir);
>  }
> 
> -static void local_seekdir(V9fsState *s, DIR *dir, off_t off)
> +static void local_seekdir(FsContext *s, DIR *dir, off_t off)
>  {
>      return seekdir(dir, off);
>  }
> 
> -static ssize_t local_readv(V9fsState *s, int fd, const struct iovec *iov,
> +static ssize_t local_readv(FsContext *s, int fd, const struct iovec *iov,
>                          int iovcnt)
>  {
>      return readv(fd, iov, iovcnt);
>  }
> 
> -static off_t local_lseek(V9fsState *s, int fd, off_t offset, int whence)
> +static off_t local_lseek(FsContext *s, int fd, off_t offset, int whence)
>  {
>      return lseek(fd, offset, whence);
>  }
> 
> -static ssize_t local_writev(V9fsState *s, int fd, const struct iovec *iov,
> +static ssize_t local_writev(FsContext *s, int fd, const struct iovec *iov,
>                           int iovcnt)
>  {
>      return writev(fd, iov, iovcnt);
>  }
> 
> -static int local_chmod(V9fsState *s, const char *path, mode_t mode)
> +static int local_chmod(FsContext *s, const char *path, mode_t mode)
>  {
>      return chmod(rpath(s, path), mode);
>  }
> 
> -static int local_mknod(V9fsState *s, const char *path, mode_t mode, dev_t 
> dev)
> +static int local_mknod(FsContext *s, const char *path, mode_t mode, dev_t 
> dev)
>  {
>      return mknod(rpath(s, path), mode, dev);
>  }
> 
> -static int local_mksock(V9fsState *s2, const char *path)
> +static int local_mksock(FsContext *s2, const char *path)
>  {
>      struct sockaddr_un addr;
>      int s;
> @@ -164,28 +164,28 @@ static int local_mksock(V9fsState *s2, const char *path)
>      return 0;
>  }
> 
> -static int local_mkdir(V9fsState *s, const char *path, mode_t mode)
> +static int local_mkdir(FsContext *s, const char *path, mode_t mode)
>  {
>      return mkdir(rpath(s, path), mode);
>  }
> 
> -static int local_fstat(V9fsState *s, int fd, struct stat *stbuf)
> +static int local_fstat(FsContext *s, int fd, struct stat *stbuf)
>  {
>      return fstat(fd, stbuf);
>  }
> 
> -static int local_open2(V9fsState *s, const char *path, int flags, mode_t 
> mode)
> +static int local_open2(FsContext *s, const char *path, int flags, mode_t 
> mode)
>  {
>      return open(rpath(s, path), flags, mode);
>  }
> 
> -static int local_symlink(V9fsState *s, const char *oldpath,
> +static int local_symlink(FsContext *s, const char *oldpath,
>                        const char *newpath)
>  {
>      return symlink(oldpath, rpath(s, newpath));
>  }
> 
> -static int local_link(V9fsState *s, const char *oldpath, const char *newpath)
> +static int local_link(FsContext *s, const char *oldpath, const char *newpath)
>  {
>      char *tmp = qemu_strdup(rpath(s, oldpath));
>      int err, serrno = 0;
> @@ -205,12 +205,12 @@ static int local_link(V9fsState *s, const char 
> *oldpath, const char *newpath)
>      return err;
>  }
> 
> -static int local_truncate(V9fsState *s, const char *path, off_t size)
> +static int local_truncate(FsContext *s, const char *path, off_t size)
>  {
>      return truncate(rpath(s, path), size);
>  }
> 
> -static int local_rename(V9fsState *s, const char *oldpath,
> +static int local_rename(FsContext *s, const char *oldpath,
>                       const char *newpath)
>  {
>      char *tmp;
> @@ -232,29 +232,29 @@ static int local_rename(V9fsState *s, const char 
> *oldpath,
> 
>  }
> 
> -static int local_chown(V9fsState *s, const char *path, uid_t uid, gid_t gid)
> +static int local_chown(FsContext *s, const char *path, uid_t uid, gid_t gid)
>  {
>      return chown(rpath(s, path), uid, gid);
>  }
> 
> -static int local_utime(V9fsState *s, const char *path,
> +static int local_utime(FsContext *s, const char *path,
>                      const struct utimbuf *buf)
>  {
>      return utime(rpath(s, path), buf);
>  }
> 
> -static int local_remove(V9fsState *s, const char *path)
> +static int local_remove(FsContext *s, const char *path)
>  {
>      return remove(rpath(s, path));
>  }
> 
> 
> -static int local_fsync(V9fsState *s, int fd)
> +static int local_fsync(FsContext *s, int fd)
>  {
>      return fsync(fd);
>  }
> 
> -static V9fsPosixFileOperations ops = {
> +static FileOperations ops = {
>      .lstat = local_lstat,
>      .setuid = local_setuid,
>      .readlink = local_readlink,
> @@ -285,7 +285,7 @@ static V9fsPosixFileOperations ops = {
>      .fsync = local_fsync,
>  };
> 
> -V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
> +FileOperations *virtio_9p_init_local(const char *path)
>  {
> -return &ops;
> +    return &ops;
>  }
> diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
> index e519605..d03693d 100644
> --- a/hw/virtio-9p.c
> +++ b/hw/virtio-9p.c
> @@ -22,23 +22,23 @@ int debug_9p_pdu = 1;
> 
>  extern void pprint_pdu(V9fsPDU *pdu);
> 
> -static int posix_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
> +static int v9fs_do_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
>  {
> -    return s->ops->lstat(s, path->data, stbuf);
> +    return s->ops->lstat(&s->ctx, path->data, stbuf);
>  }
> 
> -static int posix_setuid(V9fsState *s, uid_t uid)
> +static int v9fs_do_setuid(V9fsState *s, uid_t uid)
>  {
> -    return s->ops->setuid(s, uid);
> +    return s->ops->setuid(&s->ctx, uid);
>  }
> 
> -static ssize_t posix_readlink(V9fsState *s, V9fsString *path, V9fsString 
> *buf)
> +static ssize_t v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString 
> *buf)
>  {
>      ssize_t len;
> 
>      buf->data = qemu_malloc(1024);
> 
> -    len = s->ops->readlink(s, path->data, buf->data, 1024 - 1);
> +    len = s->ops->readlink(&s->ctx, path->data, buf->data, 1024 - 1);
>      if (len > -1) {
>          buf->size = len;
>          buf->data[len] = 0;
> @@ -47,134 +47,134 @@ static ssize_t posix_readlink(V9fsState *s, V9fsString 
> *path, V9fsString *buf)
>      return len;
>  }
> 
> -static int posix_close(V9fsState *s, int fd)
> +static int v9fs_do_close(V9fsState *s, int fd)
>  {
> -    return s->ops->close(s, fd);
> +    return s->ops->close(&s->ctx, fd);
>  }
> 
> -static int posix_closedir(V9fsState *s, DIR *dir)
> +static int v9fs_do_closedir(V9fsState *s, DIR *dir)
>  {
> -    return s->ops->closedir(s, dir);
> +    return s->ops->closedir(&s->ctx, dir);
>  }
> 
> -static int posix_open(V9fsState *s, V9fsString *path, int flags)
> +static int v9fs_do_open(V9fsState *s, V9fsString *path, int flags)
>  {
> -    return s->ops->open(s, path->data, flags);
> +    return s->ops->open(&s->ctx, path->data, flags);
>  }
> 
> -static DIR *posix_opendir(V9fsState *s, V9fsString *path)
> +static DIR *v9fs_do_opendir(V9fsState *s, V9fsString *path)
>  {
> -    return s->ops->opendir(s, path->data);
> +    return s->ops->opendir(&s->ctx, path->data);
>  }
> 
> -static void posix_rewinddir(V9fsState *s, DIR *dir)
> +static void v9fs_do_rewinddir(V9fsState *s, DIR *dir)
>  {
> -    return s->ops->rewinddir(s, dir);
> +    return s->ops->rewinddir(&s->ctx, dir);
>  }
> 
> -static off_t posix_telldir(V9fsState *s, DIR *dir)
> +static off_t v9fs_do_telldir(V9fsState *s, DIR *dir)
>  {
> -    return s->ops->telldir(s, dir);
> +    return s->ops->telldir(&s->ctx, dir);
>  }
> 
> -static struct dirent *posix_readdir(V9fsState *s, DIR *dir)
> +static struct dirent *v9fs_do_readdir(V9fsState *s, DIR *dir)
>  {
> -    return s->ops->readdir(s, dir);
> +    return s->ops->readdir(&s->ctx, dir);
>  }
> 
> -static void posix_seekdir(V9fsState *s, DIR *dir, off_t off)
> +static void v9fs_do_seekdir(V9fsState *s, DIR *dir, off_t off)
>  {
> -    return s->ops->seekdir(s, dir, off);
> +    return s->ops->seekdir(&s->ctx, dir, off);
>  }
> 
> -static int posix_readv(V9fsState *s, int fd, const struct iovec *iov,
> +static int v9fs_do_readv(V9fsState *s, int fd, const struct iovec *iov,
>                      int iovcnt)
>  {
> -    return s->ops->readv(s, fd, iov, iovcnt);
> +    return s->ops->readv(&s->ctx, fd, iov, iovcnt);
>  }
> 
> -static off_t posix_lseek(V9fsState *s, int fd, off_t offset, int whence)
> +static off_t v9fs_do_lseek(V9fsState *s, int fd, off_t offset, int whence)
>  {
> -    return s->ops->lseek(s, fd, offset, whence);
> +    return s->ops->lseek(&s->ctx, fd, offset, whence);
>  }
> 
> -static int posix_writev(V9fsState *s, int fd, const struct iovec *iov,
> +static int v9fs_do_writev(V9fsState *s, int fd, const struct iovec *iov,
>                         int iovcnt)
>  {
> -    return s->ops->writev(s, fd, iov, iovcnt);
> +    return s->ops->writev(&s->ctx, fd, iov, iovcnt);
>  }
> 
> -static int posix_chmod(V9fsState *s, V9fsString *path, mode_t mode)
> +static int v9fs_do_chmod(V9fsState *s, V9fsString *path, mode_t mode)
>  {
> -    return s->ops->chmod(s, path->data, mode);
> +    return s->ops->chmod(&s->ctx, path->data, mode);
>  }
> 
> -static int posix_mknod(V9fsState *s, V9fsString *path, mode_t mode, dev_t 
> dev)
> +static int v9fs_do_mknod(V9fsState *s, V9fsString *path, mode_t mode, dev_t 
> dev)
>  {
> -    return s->ops->mknod(s, path->data, mode, dev);
> +    return s->ops->mknod(&s->ctx, path->data, mode, dev);
>  }
> 
> -static int posix_mksock(V9fsState *s, V9fsString *path)
> +static int v9fs_do_mksock(V9fsState *s, V9fsString *path)
>  {
> -    return s->ops->mksock(s, path->data);
> +    return s->ops->mksock(&s->ctx, path->data);
>  }
> 
> -static int posix_mkdir(V9fsState *s, V9fsString *path, mode_t mode)
> +static int v9fs_do_mkdir(V9fsState *s, V9fsString *path, mode_t mode)
>  {
> -    return s->ops->mkdir(s, path->data, mode);
> +    return s->ops->mkdir(&s->ctx, path->data, mode);
>  }
> 
> -static int posix_fstat(V9fsState *s, int fd, struct stat *stbuf)
> +static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf)
>  {
> -    return s->ops->fstat(s, fd, stbuf);
> +    return s->ops->fstat(&s->ctx, fd, stbuf);
>  }
> 
> -static int posix_open2(V9fsState *s, V9fsString *path, int flags, mode_t 
> mode)
> +static int v9fs_do_open2(V9fsState *s, V9fsString *path, int flags, mode_t 
> mode)
>  {
> -    return s->ops->open2(s, path->data, flags, mode);
> +    return s->ops->open2(&s->ctx, path->data, flags, mode);
>  }
> 
> -static int posix_symlink(V9fsState *s, V9fsString *oldpath,
> +static int v9fs_do_symlink(V9fsState *s, V9fsString *oldpath,
>                        V9fsString *newpath)
>  {
> -    return s->ops->symlink(s, oldpath->data, newpath->data);
> +    return s->ops->symlink(&s->ctx, oldpath->data, newpath->data);
>  }
> 
> -static int posix_link(V9fsState *s, V9fsString *oldpath, V9fsString *newpath)
> +static int v9fs_do_link(V9fsState *s, V9fsString *oldpath, V9fsString 
> *newpath)
>  {
> -    return s->ops->link(s, oldpath->data, newpath->data);
> +    return s->ops->link(&s->ctx, oldpath->data, newpath->data);
>  }
> 
> -static int posix_truncate(V9fsState *s, V9fsString *path, off_t size)
> +static int v9fs_do_truncate(V9fsState *s, V9fsString *path, off_t size)
>  {
> -    return s->ops->truncate(s, path->data, size);
> +    return s->ops->truncate(&s->ctx, path->data, size);
>  }
> 
> -static int posix_rename(V9fsState *s, V9fsString *oldpath,
> +static int v9fs_do_rename(V9fsState *s, V9fsString *oldpath,
>                       V9fsString *newpath)
>  {
> -    return s->ops->rename(s, oldpath->data, newpath->data);
> +    return s->ops->rename(&s->ctx, oldpath->data, newpath->data);
>  }
> 
> -static int posix_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t gid)
> +static int v9fs_do_chown(V9fsState *s, V9fsString *path, uid_t uid, gid_t 
> gid)
>  {
> -    return s->ops->chown(s, path->data, uid, gid);
> +    return s->ops->chown(&s->ctx, path->data, uid, gid);
>  }
> 
> -static int posix_utime(V9fsState *s, V9fsString *path,
> +static int v9fs_do_utime(V9fsState *s, V9fsString *path,
>                      const struct utimbuf *buf)
>  {
> -    return s->ops->utime(s, path->data, buf);
> +    return s->ops->utime(&s->ctx, path->data, buf);
>  }
> 
> -static int posix_remove(V9fsState *s, V9fsString *path)
> +static int v9fs_do_remove(V9fsState *s, V9fsString *path)
>  {
> -    return s->ops->remove(s, path->data);
> +    return s->ops->remove(&s->ctx, path->data);
>  }
> 
> -static int posix_fsync(V9fsState *s, int fd)
> +static int v9fs_do_fsync(V9fsState *s, int fd)
>  {
> -    return s->ops->fsync(s, fd);
> +    return s->ops->fsync(&s->ctx, fd);
>  }
> 
>  static void v9fs_string_init(V9fsString *str)
> @@ -227,7 +227,7 @@ static V9fsFidState *lookup_fid(V9fsState *s, int32_t fid)
> 
>      for (f = s->fid_list; f; f = f->next) {
>          if (f->fid == fid) {
> -            posix_setuid(s, f->uid);
> +            v9fs_do_setuid(s, f->uid);
>              return f;
>          }
>      }
> @@ -271,9 +271,9 @@ static int free_fid(V9fsState *s, int32_t fid)
>      *fidpp = fidp->next;
> 
>      if (fidp->fd != -1)
> -        posix_close(s, fidp->fd);
> +        v9fs_do_close(s, fidp->fd);
>      if (fidp->dir)
> -        posix_closedir(s, fidp->dir);
> +        v9fs_do_closedir(s, fidp->dir);
>      v9fs_string_free(&fidp->path);
>      qemu_free(fidp);
> 
> @@ -325,7 +325,7 @@ static int fid_to_qid(V9fsState *s, V9fsFidState *fidp, 
> V9fsQID *qidp)
>      struct stat stbuf;
>      int err;
> 
> -    err = posix_lstat(s, &fidp->path, &stbuf);
> +    err = v9fs_do_lstat(s, &fidp->path, &stbuf);
>      if (err) {
>          return err;
>      }
> @@ -683,7 +683,7 @@ static int stat_to_v9stat(V9fsState *s, V9fsString *name,
>          v9fs_string_null(&v9stat->extension);
> 
>          if (v9stat->mode & P9_STAT_MODE_SYMLINK) {
> -            err = posix_readlink(s, name, &v9stat->extension);
> +            err = v9fs_do_readlink(s, name, &v9stat->extension);
>              if (err == -1) {
>                  err = -errno;
>                  return err;
> @@ -816,7 +816,7 @@ static void v9fs_stat(V9fsState *s, V9fsPDU *pdu)
>          goto out;
>      }
> 
> -    err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
> +    err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
>      v9fs_stat_post_lstat(s, vs, err);
>      return;
> 
> @@ -880,7 +880,7 @@ static void v9fs_walk_post_newfid_lstat(V9fsState *s, 
> V9fsWalkState *vs,
>                                              vs->wnames[vs->name_idx].data);
>          v9fs_string_copy(&vs->newfidp->path, &vs->path);
> 
> -        err = posix_lstat(s, &vs->newfidp->path, &vs->stbuf);
> +        err = v9fs_do_lstat(s, &vs->newfidp->path, &vs->stbuf);
>          v9fs_walk_post_newfid_lstat(s, vs, err);
>          return;
>      }
> @@ -909,7 +909,7 @@ static void v9fs_walk_post_oldfid_lstat(V9fsState *s, 
> V9fsWalkState *vs,
>                  vs->fidp->path.data, vs->wnames[vs->name_idx].data);
>          v9fs_string_copy(&vs->fidp->path, &vs->path);
> 
> -        err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
> +        err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
>          v9fs_walk_post_oldfid_lstat(s, vs, err);
>          return;
>      }
> @@ -967,7 +967,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
>                  vs->fidp->path.data, vs->wnames[vs->name_idx].data);
>              v9fs_string_copy(&vs->fidp->path, &vs->path);
> 
> -            err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
> +            err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
>              v9fs_walk_post_oldfid_lstat(s, vs, err);
>              return;
>          }
> @@ -988,7 +988,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
>                                  vs->wnames[vs->name_idx].data);
>              v9fs_string_copy(&vs->newfidp->path, &vs->path);
> 
> -            err = posix_lstat(s, &vs->newfidp->path, &vs->stbuf);
> +            err = v9fs_do_lstat(s, &vs->newfidp->path, &vs->stbuf);
>              v9fs_walk_post_newfid_lstat(s, vs, err);
>              return;
>          }
> @@ -1092,10 +1092,10 @@ static void v9fs_open_post_lstat(V9fsState *s, 
> V9fsOpenState *vs, int err)
>      stat_to_qid(&vs->stbuf, &vs->qid);
> 
>      if (S_ISDIR(vs->stbuf.st_mode)) {
> -        vs->fidp->dir = posix_opendir(s, &vs->fidp->path);
> +        vs->fidp->dir = v9fs_do_opendir(s, &vs->fidp->path);
>          v9fs_open_post_opendir(s, vs, err);
>      } else {
> -        vs->fidp->fd = posix_open(s, &vs->fidp->path,
> +        vs->fidp->fd = v9fs_do_open(s, &vs->fidp->path,
>                                      omode_to_uflags(vs->mode));
>          v9fs_open_post_open(s, vs, err);
>      }
> @@ -1127,7 +1127,7 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
>      BUG_ON(vs->fidp->fd != -1);
>      BUG_ON(vs->fidp->dir);
> 
> -    err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
> +    err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
> 
>      v9fs_open_post_lstat(s, vs, err);
>      return;
> @@ -1238,7 +1238,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, 
> V9fsReadState *vs,
>                              &vs->v9stat);
>      if ((vs->len != (vs->v9stat.size + 2)) ||
>              ((vs->count + vs->len) > vs->max_count)) {
> -        posix_seekdir(s, vs->fidp->dir, vs->dir_pos);
> +        v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos);
>          v9fs_read_post_seekdir(s, vs, err);
>          return;
>      }
> @@ -1246,11 +1246,11 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, 
> V9fsReadState *vs,
>      v9fs_stat_free(&vs->v9stat);
>      v9fs_string_free(&vs->name);
>      vs->dir_pos = vs->dent->d_off;
> -    vs->dent = posix_readdir(s, vs->fidp->dir);
> +    vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
>      v9fs_read_post_readdir(s, vs, err);
>      return;
>  out:
> -    posix_seekdir(s, vs->fidp->dir, vs->dir_pos);
> +    v9fs_do_seekdir(s, vs->fidp->dir, vs->dir_pos);
>      v9fs_read_post_seekdir(s, vs, err);
>      return;
> 
> @@ -1263,7 +1263,7 @@ static void v9fs_read_post_readdir(V9fsState *s, 
> V9fsReadState *vs, ssize_t err)
>          v9fs_string_init(&vs->name);
>          v9fs_string_sprintf(&vs->name, "%s/%s", vs->fidp->path.data,
>                              vs->dent->d_name);
> -        err = posix_lstat(s, &vs->name, &vs->stbuf);
> +        err = v9fs_do_lstat(s, &vs->name, &vs->stbuf);
>          v9fs_read_post_dir_lstat(s, vs, err);
>          return;
>      }
> @@ -1278,7 +1278,7 @@ static void v9fs_read_post_readdir(V9fsState *s, 
> V9fsReadState *vs, ssize_t err)
> 
>  static void v9fs_read_post_telldir(V9fsState *s, V9fsReadState *vs, ssize_t 
> err)
>  {
> -    vs->dent = posix_readdir(s, vs->fidp->dir);
> +    vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
>      v9fs_read_post_readdir(s, vs, err);
>      return;
>  }
> @@ -1286,7 +1286,7 @@ static void v9fs_read_post_telldir(V9fsState *s, 
> V9fsReadState *vs, ssize_t err)
>  static void v9fs_read_post_rewinddir(V9fsState *s, V9fsReadState *vs,
>                                         ssize_t err)
>  {
> -    vs->dir_pos = posix_telldir(s, vs->fidp->dir);
> +    vs->dir_pos = v9fs_do_telldir(s, vs->fidp->dir);
>      v9fs_read_post_telldir(s, vs, err);
>      return;
>  }
> @@ -1305,7 +1305,7 @@ static void v9fs_read_post_readv(V9fsState *s, 
> V9fsReadState *vs, ssize_t err)
>              if (0) {
>                  print_sg(vs->sg, vs->cnt);
>              }
> -            vs->len = posix_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
> +            vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
>          } while (vs->len == -1 && errno == EINTR);
>          if (vs->len == -1) {
>              err  = -errno;
> @@ -1335,7 +1335,7 @@ static void v9fs_read_post_lseek(V9fsState *s, 
> V9fsReadState *vs, ssize_t err)
>              if (0) {
>                  print_sg(vs->sg, vs->cnt);
>              }
> -            vs->len = posix_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
> +            vs->len = v9fs_do_readv(s, vs->fidp->fd, vs->sg, vs->cnt);
>          } while (vs->len == -1 && errno == EINTR);
>       if (vs->len == -1) {
>              err  = -errno;
> @@ -1373,14 +1373,14 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
>          vs->max_count = vs->count;
>          vs->count = 0;
>          if (vs->off == 0) {
> -            posix_rewinddir(s, vs->fidp->dir);
> +            v9fs_do_rewinddir(s, vs->fidp->dir);
>          }
>          v9fs_read_post_rewinddir(s, vs, err);
>          return;
>      } else if (vs->fidp->fd != -1) {
>          vs->sg = vs->iov;
>          pdu_marshal(vs->pdu, vs->offset + 4, "v", vs->sg, &vs->cnt);
> -        err = posix_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
> +        err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
>          v9fs_read_post_lseek(s, vs, err);
>          return;
>      } else {
> @@ -1436,7 +1436,7 @@ static void v9fs_write_post_writev(V9fsState *s, 
> V9fsWriteState *vs,
>          do {
>              if (0)
>                  print_sg(vs->sg, vs->cnt);
> -            vs->len =  posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
> +            vs->len =  v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
>          } while (vs->len == -1 && errno == EINTR);
>          if (vs->len == -1) {
>              err  = -errno;
> @@ -1464,7 +1464,7 @@ static void v9fs_write_post_lseek(V9fsState *s, 
> V9fsWriteState *vs, ssize_t err)
>          do {
>              if (0)
>                  print_sg(vs->sg, vs->cnt);
> -            vs->len = posix_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
> +            vs->len = v9fs_do_writev(s, vs->fidp->fd, vs->sg, vs->cnt);
>          } while (vs->len == -1 && errno == EINTR);
>       if (vs->len == -1) {
>              err  = -errno;
> @@ -1506,7 +1506,7 @@ static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
>          goto out;
>      }
> 
> -    err = posix_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
> +    err = v9fs_do_lseek(s, vs->fidp->fd, vs->off, SEEK_SET);
> 
>      v9fs_write_post_lseek(s, vs, err);
>      return;
> @@ -1572,7 +1572,7 @@ static void v9fs_create_post_dir_lstat(V9fsState *s, 
> V9fsCreateState *vs,
>          goto out;
>      }
> 
> -    vs->fidp->dir = posix_opendir(s, &vs->fullname);
> +    vs->fidp->dir = v9fs_do_opendir(s, &vs->fullname);
>      v9fs_create_post_opendir(s, vs, err);
>      return;
> 
> @@ -1587,7 +1587,7 @@ static void v9fs_create_post_mkdir(V9fsState *s, 
> V9fsCreateState *vs, int err)
>          goto out;
>      }
> 
> -    err = posix_lstat(s, &vs->fullname, &vs->stbuf);
> +    err = v9fs_do_lstat(s, &vs->fullname, &vs->stbuf);
>      v9fs_create_post_dir_lstat(s, vs, err);
>      return;
> 
> @@ -1603,7 +1603,7 @@ static void v9fs_create_post_mksock(V9fsState *s, 
> V9fsCreateState *vs,
>          goto out;
>      }
> 
> -    err = posix_chmod(s, &vs->fullname, vs->perm & 0777);
> +    err = v9fs_do_chmod(s, &vs->fullname, vs->perm & 0777);
>      v9fs_create_post_perms(s, vs, err);
>      return;
> 
> @@ -1629,7 +1629,7 @@ static void v9fs_create_post_open2(V9fsState *s, 
> V9fsCreateState *vs, int err)
>          goto out;
>      }
> 
> -    err = posix_fstat(s, vs->fidp->fd, &vs->stbuf);
> +    err = v9fs_do_fstat(s, vs->fidp->fd, &vs->stbuf);
>      v9fs_create_post_fstat(s, vs, err);
> 
>      return;
> @@ -1648,10 +1648,10 @@ static void v9fs_create_post_lstat(V9fsState *s, 
> V9fsCreateState *vs, int err)
>      }
> 
>      if (vs->perm & P9_STAT_MODE_DIR) {
> -        err = posix_mkdir(s, &vs->fullname, vs->perm & 0777);
> +        err = v9fs_do_mkdir(s, &vs->fullname, vs->perm & 0777);
>          v9fs_create_post_mkdir(s, vs, err);
>      } else if (vs->perm & P9_STAT_MODE_SYMLINK) {
> -        err = posix_symlink(s, &vs->extension, &vs->fullname);
> +        err = v9fs_do_symlink(s, &vs->extension, &vs->fullname);
>          v9fs_create_post_perms(s, vs, err);
>      } else if (vs->perm & P9_STAT_MODE_LINK) {
>          int32_t nfid = atoi(vs->extension.data);
> @@ -1660,7 +1660,7 @@ static void v9fs_create_post_lstat(V9fsState *s, 
> V9fsCreateState *vs, int err)
>              err = -errno;
>              v9fs_post_create(s, vs, err);
>          }
> -        err = posix_link(s, &nfidp->path, &vs->fullname);
> +        err = v9fs_do_link(s, &nfidp->path, &vs->fullname);
>          v9fs_create_post_perms(s, vs, err);
>      } else if (vs->perm & P9_STAT_MODE_DEVICE) {
>          char ctype;
> @@ -1686,16 +1686,16 @@ static void v9fs_create_post_lstat(V9fsState *s, 
> V9fsCreateState *vs, int err)
>          }
> 
>          nmode |= vs->perm & 0777;
> -        err = posix_mknod(s, &vs->fullname, nmode, makedev(major, minor));
> +        err = v9fs_do_mknod(s, &vs->fullname, nmode, makedev(major, minor));
>          v9fs_create_post_perms(s, vs, err);
>      } else if (vs->perm & P9_STAT_MODE_NAMED_PIPE) {
> -        err = posix_mknod(s, &vs->fullname, S_IFIFO | (vs->mode & 0777), 0);
> +        err = v9fs_do_mknod(s, &vs->fullname, S_IFIFO | (vs->mode & 0777), 
> 0);
>          v9fs_post_create(s, vs, err);
>      } else if (vs->perm & P9_STAT_MODE_SOCKET) {
> -        err = posix_mksock(s, &vs->fullname);
> +        err = v9fs_do_mksock(s, &vs->fullname);
>          v9fs_create_post_mksock(s, vs, err);
>      } else {
> -        vs->fidp->fd = posix_open2(s, &vs->fullname,
> +        vs->fidp->fd = v9fs_do_open2(s, &vs->fullname,
>                                  omode_to_uflags(vs->mode) | O_CREAT,
>                                  vs->perm & 0777);
>          v9fs_create_post_open2(s, vs, err);
> @@ -1731,7 +1731,7 @@ static void v9fs_create(V9fsState *s, V9fsPDU *pdu)
>      v9fs_string_sprintf(&vs->fullname, "%s/%s", vs->fidp->path.data,
>                                                          vs->name.data);
> 
> -    err = posix_lstat(s, &vs->fullname, &vs->stbuf);
> +    err = v9fs_do_lstat(s, &vs->fullname, &vs->stbuf);
>      v9fs_create_post_lstat(s, vs, err);
>      return;
> 
> @@ -1791,7 +1791,7 @@ static void v9fs_remove(V9fsState *s, V9fsPDU *pdu)
>          goto out;
>      }
> 
> -    err = posix_remove(s, &vs->fidp->path);
> +    err = v9fs_do_remove(s, &vs->fidp->path);
>      v9fs_remove_post_remove(s, vs, err);
>      return;
> 
> @@ -1872,7 +1872,7 @@ static void v9fs_wstat_post_rename(V9fsState *s, 
> V9fsWstatState *vs, int err)
>      }
> 
>      if (vs->v9stat.length != -1) {
> -        if (posix_truncate(s, &vs->fidp->path, vs->v9stat.length) < 0) {
> +        if (v9fs_do_truncate(s, &vs->fidp->path, vs->v9stat.length) < 0) {
>              err = -errno;
>          }
>      }
> @@ -1922,7 +1922,7 @@ static void v9fs_wstat_post_chown(V9fsState *s, 
> V9fsWstatState *vs, int err)
>          vs->nname.size = strlen(new_name);
> 
>          if (strcmp(new_name, vs->fidp->path.data) != 0) {
> -            if (posix_rename(s, &vs->fidp->path, &vs->nname)) {
> +            if (v9fs_do_rename(s, &vs->fidp->path, &vs->nname)) {
>                  err = -errno;
>              } else {
>                  /*
> @@ -1965,7 +1965,7 @@ static void v9fs_wstat_post_utime(V9fsState *s, 
> V9fsWstatState *vs, int err)
>      }
> 
>      if (vs->v9stat.n_gid != -1) {
> -        if (posix_chown(s, &vs->fidp->path, vs->v9stat.n_uid,
> +        if (v9fs_do_chown(s, &vs->fidp->path, vs->v9stat.n_uid,
>                      vs->v9stat.n_gid)) {
>              err = -errno;
>          }
> @@ -1989,7 +1989,7 @@ static void v9fs_wstat_post_chmod(V9fsState *s, 
> V9fsWstatState *vs, int err)
>          struct utimbuf tb;
>          tb.actime = 0;
>          tb.modtime = vs->v9stat.mtime;
> -        if (posix_utime(s, &vs->fidp->path, &tb)) {
> +        if (v9fs_do_utime(s, &vs->fidp->path, &tb)) {
>              err = -errno;
>          }
>      }
> @@ -2054,7 +2054,7 @@ static void v9fs_wstat_post_lstat(V9fsState *s, 
> V9fsWstatState *vs, int err)
>              goto out;
>      }
> 
> -    if (posix_chmod(s, &vs->fidp->path, v9mode_to_mode(vs->v9stat.mode,
> +    if (v9fs_do_chmod(s, &vs->fidp->path, v9mode_to_mode(vs->v9stat.mode,
>                      &vs->v9stat.extension))) {
>              err = -errno;
>       }
> @@ -2087,13 +2087,13 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu)
> 
>      /* do we need to sync the file? */
>      if (donttouch_stat(&vs->v9stat)) {
> -        err = posix_fsync(s, vs->fidp->fd);
> +        err = v9fs_do_fsync(s, vs->fidp->fd);
>          v9fs_wstat_post_fsync(s, vs, err);
>          return;
>      }
> 
>      if (vs->v9stat.mode != -1) {
> -        err = posix_lstat(s, &vs->fidp->path, &vs->stbuf);
> +        err = v9fs_do_lstat(s, &vs->fidp->path, &vs->stbuf);
>          v9fs_wstat_post_lstat(s, vs, err);
>          return;
>      }
> @@ -2243,7 +2243,8 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
> *conf)
>           fprintf(stderr, "share path %s is not a directory \n", 
> conf->share_path);
>           exit(1);
>      }
> -    s->fs_root = qemu_strdup(conf->share_path);
> +
> +    s->ctx.fs_root = qemu_strdup(conf->share_path);
>      len = strlen(conf->tag);
>      if (len > MAX_TAG_LEN)
>           len = MAX_TAG_LEN;
> @@ -2251,7 +2252,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
> *conf)
>      s->tag = qemu_malloc(len);
>      memcpy(s->tag, conf->tag, len);
>      s->tag_len = len;
> -    s->uid = -1;
> +    s->ctx.uid = -1;
> 
>      s->ops = virtio_9p_init_local(conf->share_path);
>      s->vdev.get_features = virtio_9p_get_features;
> diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
> index 81c2c59..a249b67 100644
> --- a/hw/virtio-9p.h
> +++ b/hw/virtio-9p.h
> @@ -6,6 +6,8 @@
>  #include <sys/time.h>
>  #include <utime.h>
> 
> +#include "file-op.h"
> +
>  /* The feature bitmap for virtio 9P */
>  /* The mount point is specified in a config variable */
>  #define VIRTIO_9P_MOUNT_TAG 0
> @@ -129,7 +131,6 @@ struct V9fsFidState
>      V9fsFidState *next;
>  };
> 
> -struct V9fsPosixFileOpertions ;
>  typedef struct V9fsState
>  {
>      VirtIODevice vdev;
> @@ -137,9 +138,8 @@ typedef struct V9fsState
>      V9fsPDU pdus[MAX_REQ];
>      V9fsPDU *free_pdu;
>      V9fsFidState *fid_list;
> -    struct V9fsPosixFileOpertions *ops;
> -    char *fs_root;
> -    uid_t uid;
> +    FileOperations *ops;
> +    FsContext ctx;
>      uint16_t tag_len;
>      uint8_t *tag;
>      size_t config_size;
> @@ -153,40 +153,7 @@ struct virtio_9p_config
>      uint8_t tag[0];
>  } __attribute__((packed));
> 
> -typedef struct V9fsPosixFileOpertions
> -{
> -    int (*lstat)(V9fsState *, const char *, struct stat *);
> -    ssize_t (*readlink)(V9fsState *, const char *, char *, size_t);
> -    int (*chmod)(V9fsState *, const char *, mode_t);
> -    int (*chown)(V9fsState *, const char *, uid_t, gid_t);
> -    int (*mknod)(V9fsState *, const char *, mode_t, dev_t);
> -    int (*mksock)(V9fsState *, const char *);
> -    int (*utime)(V9fsState *, const char *, const struct utimbuf *);
> -    int (*remove)(V9fsState *, const char *);
> -    int (*symlink)(V9fsState *, const char *, const char *);
> -    int (*link)(V9fsState *, const char *, const char *);
> -    int (*setuid)(V9fsState *, uid_t);
> -    int (*close)(V9fsState *, int);
> -    int (*closedir)(V9fsState *, DIR *);
> -    DIR *(*opendir)(V9fsState *, const char *);
> -    int (*open)(V9fsState *, const char *, int);
> -    int (*open2)(V9fsState *, const char *, int, mode_t);
> -    void (*rewinddir)(V9fsState *, DIR *);
> -    off_t (*telldir)(V9fsState *, DIR *);
> -    struct dirent *(*readdir)(V9fsState *, DIR *);
> -    void (*seekdir)(V9fsState *, DIR *, off_t);
> -    ssize_t (*readv)(V9fsState *, int, const struct iovec *, int);
> -    ssize_t (*writev)(V9fsState *, int, const struct iovec *, int);
> -    off_t (*lseek)(V9fsState *, int, off_t, int);
> -    int (*mkdir)(V9fsState *, const char *, mode_t);
> -    int (*fstat)(V9fsState *, int, struct stat *);
> -    int (*rename)(V9fsState *, const char *, const char *);
> -    int (*truncate)(V9fsState *, const char *, off_t);
> -    int (*fsync)(V9fsState *, int);
> -    void *opaque;
> -} V9fsPosixFileOperations;
> -
> -V9fsPosixFileOperations *virtio_9p_init_local(const char *path);
> +FileOperations *virtio_9p_init_local(const char *path);
>  extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
>                              size_t offset, size_t size, int pack);
> 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]