hw/9pfs: Move fid pathname tracking to seperate data type.
PATCH 2/5 9p: add 9P2000.L unlinkat operation
In reply to Aneesh Kumar K.Vunlinkat - Remove a directory entry
size[4] Tunlinkat tag[2] dirfid[4] name[s] flag[4] size[4] Runlinkat tag[2]
older Tremove have the below request format
size[4] Tremove tag[2] fid[4]
The remove message is used to remove a directory entry either file or directory The remove opreation is actually a directory opertation and should ideally have dirfid, if not we cannot represent the fid on server with anything other than name. We will have to derive the directory name from fid in the Tremove request.
NOTE: The operation doesn't clunk the unlink fid.
--- fsdev/file-op-9p.h | 1 + hw/9pfs/cofs.c | 16 ++++++++++++++++ hw/9pfs/virtio-9p-coth.h | 1 + hw/9pfs/virtio-9p-local.c | 16 ++++++++++++++++ hw/9pfs/virtio-9p.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/9pfs/virtio-9p.h | 2 ++ 6 files changed, 80 insertions(+), 0 deletions(-)
fsdev/file-op-9p.h +1 -0
@@ -104,6 +104,7 @@ typedef struct FileOperationsint (*name_to_path)(FsContext *,V9fsPath *,const char *,V9fsPath *);int (*renameat)(FsContext *ctx,V9fsPath *olddir,const char *old_name,V9fsPath *newdir,const char *new_name); +int (*unlinkat)(FsContext *ctx,V9fsPath *dir,const char *name,int flags);void *opaque; } FileOperations;
hw/9pfs/cofs.c +16 -0
@@ -184,6 +184,22 @@ int v9fs_co_remove(V9fsState *s, V9fsPath *path)return err; } +int v9fs_co_unlinkat (V9fsState *s,V9fsPath *path,V9fsString *name,int flags) +{ +int err; + +qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_co_run_in_worker ( + { + err = s->ops->unlinkat (&s->ctx, path, name->data, flags); +if (err <0 ) { + err = -errno; + } + }); +qemu_co_rwlock_unlock (&s->rename_lock); +return err; +} +/* Only work with path name based fid */ int v9fs_co_rename (V9fsState *s,V9fsPath *oldpath,V9fsPath *newpath) {
hw/9pfs/virtio-9p-coth.h +1 -0
@@ -77,6 +77,7 @@ extern int v9fs_co_mkdir(V9fsState *, V9fsFidState *, V9fsString *, mode_t, uid_t, gid_t, struct stat *);extern int v9fs_co_remove (V9fsState *,V9fsPath *);extern int v9fs_co_rename (V9fsState *,V9fsPath *,V9fsPath *); +extern int v9fs_co_unlinkat (V9fsState *,V9fsPath *,V9fsString *,int flags);extern int v9fs_co_renameat (V9fsState *,V9fsPath *,V9fsString *,V9fsPath *,V9fsString *);extern int v9fs_co_fstat (V9fsState *,int ,struct stat *);
hw/9pfs/virtio-9p-local.c +16 -0
@@ -631,6 +631,21 @@ static int local_renameat(FsContext *ctx, V9fsPath *olddir,return ret; } +static int local_unlinkat (FsContext *ctx,V9fsPath *dir, +const char *name,int flags) +{ +int ret; +V9fsString fullname; +char buffer[PATH_MAX ]; +v9fs_string_init (&fullname); + +v9fs_string_sprintf (&fullname,"%s/%s" , dir->data, name); + ret =remove (rpath (ctx, fullname.data, buffer)); +v9fs_string_free (&fullname); + +return ret; +} +FileOperations local_ops = { .lstat = local_lstat, .readlink = local_readlink,
@@ -664,4 +679,5 @@ FileOperations local_ops = { .lremovexattr = local_lremovexattr, .name_to_path = local_name_to_path, .renameat = local_renameat, + .unlinkat = local_unlinkat, };
hw/9pfs/virtio-9p.c +44 -0
56 lines not on this page · raw message
hw/9pfs/virtio-9p.h +2 -0
@@ -54,6 +54,8 @@ enum {P9_RMKDIR ,P9_TRENAMEAT =74 ,P9_RRENAMEAT , +P9_TUNLINKAT =76 , +P9_RUNLINKAT ,P9_TVERSION =100 ,P9_RVERSION , P9_TAUTH = 102,
Signature · 1 line
1.7.4.1
PATCH 3/5 hw/9pfs: Add init callback to fs driver
In reply to Aneesh Kumar K.VThis call back can be used to do fs driver specific initialization.
--- fsdev/file-op-9p.h | 2 ++ hw/9pfs/virtio-9p-device.c | 7 ++++++- hw/9pfs/virtio-9p-local.c | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-)
fsdev/file-op-9p.h +2 -0
@@ -19,6 +19,7 @@#include <sys/stat.h> #include <sys/uio.h> #include <sys/vfs.h> +#define SM_LOCAL_MODE_BITS 0600#define SM_LOCAL_DIR_MODE_BITS 0700
@@ -67,6 +68,7 @@ void cred_init(FsCred *); typedef struct FileOperations { + int (*init)(struct FsContext *); int (*lstat)(FsContext *, V9fsPath *, struct stat *); ssize_t (*readlink)(FsContext *, V9fsPath *, char *, size_t); int (*chmod)(FsContext *, V9fsPath *, FsCred *);
hw/9pfs/virtio-9p-device.c +6 -1
@@ -45,7 +45,7 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t *config) }VirtIODevice *virtio_9p_init (DeviceState *dev,V9fsConf *conf) - { +{V9fsState *s;int i, len;struct stat stat;
@@ -139,6 +139,11 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) s->fid_list =NULL ;qemu_co_rwlock_init (&s->rename_lock); +if (s->ops->init (&s->ctx) <0 ) { +fprintf (stderr,"Virtio-9p Failed to initialize fs-driver with id:%s" +" and export path:%s\n" , conf->fsdev_id, s->ctx.fs_root); +exit (1 ); + }if (v9fs_init_worker_threads () <0 ) {fprintf (stderr,"worker thread initialization failed\n" );exit (1 );
hw/9pfs/virtio-9p-local.c +6 -1
@@ -21,7 +21,6 @@#include <sys/un.h> #include <attr/xattr.h> -static int local_lstat (FsContext *fs_ctx,V9fsPath *fs_path,struct stat *stbuf) {int err;
@@ -646,7 +645,13 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,return ret; } +static int local_init (FsContext *ctx) +{ +return 0 ; +} +FileOperations local_ops = { + .init = local_init, .lstat = local_lstat, .readlink = local_readlink, .close = local_close,
Signature · 1 line
1.7.4.1
PATCH 1/5 hw/9pfs: Move fid pathname tracking to seperate data type.
This enables us to add handles to track fids later. The V9fsPath added is similar to V9fsString except that the size include the NULL byte also.
--- fsdev/file-op-9p.h | 45 ++++--- hw/9pfs/codir.c | 21 ++-- hw/9pfs/cofile.c | 38 +++-- hw/9pfs/cofs.c | 98 +++++++++---- hw/9pfs/coxattr.c | 17 +-- hw/9pfs/virtio-9p-coth.h | 33 +++-- hw/9pfs/virtio-9p-local.c | 189 ++++++++++++++++++++------ hw/9pfs/virtio-9p.c | 343 +++++++++++++++++++++++++-------------------- hw/9pfs/virtio-9p.h | 7 +- 9 files changed, 502 insertions(+), 289 deletions(-)
fsdev/file-op-9p.h +27 -18
@@ -58,43 +58,52 @@ typedef struct FsContextstruct xattr_operations **xops; } FsContext; +typedef struct V9fsPath { +int16_t size; +char *data; +}V9fsPath ; +void cred_init (FsCred *);typedef struct FileOperations { -int (*lstat)(FsContext *,const char *,struct stat *); -ssize_t (*readlink)(FsContext *,const char *,char *,size_t ); -int (*chmod)(FsContext *,const char *,FsCred *); -int (*chown)(FsContext *,const char *,FsCred *); -int (*mknod)(FsContext *,const char *,FsCred *); -int (*utimensat)(FsContext *,const char *,const struct timespec *); +int (*lstat)(FsContext *,V9fsPath *,struct stat *); +ssize_t (*readlink)(FsContext *,V9fsPath *,char *,size_t ); +int (*chmod)(FsContext *,V9fsPath *,FsCred *); +int (*chown)(FsContext *,V9fsPath *,FsCred *); +int (*mknod)(FsContext *,V9fsPath *,const char *,FsCred *); +int (*utimensat)(FsContext *,V9fsPath *,const struct timespec *);int (*remove)(FsContext *,const char *); -int (*symlink)(FsContext *,const char *,const char *,FsCred *); -int (*link)(FsContext *,const char *,const char *); +int (*symlink)(FsContext *,const char *,V9fsPath *, +const char *,FsCred *); +int (*link)(FsContext *,V9fsPath *,V9fsPath *,const char *);int (*setuid)(FsContext *,uid_t );int (*close)(FsContext *,int );int (*closedir)(FsContext *,DIR *); -DIR *(*opendir)(FsContext *,const char *); -int (*open)(FsContext *,const char *,int ); -int (*open2)(FsContext *,const char *,int ,FsCred *); +DIR *(*opendir)(FsContext *,V9fsPath *); +int (*open)(FsContext *,V9fsPath *,int ); +int (*open2)(FsContext *,V9fsPath *,const char *,int ,FsCred *);void (*rewinddir)(FsContext *,DIR *);off_t (*telldir)(FsContext *,DIR *);int (*readdir_r)(FsContext *,DIR *,struct dirent *,struct dirent **);void (*seekdir)(FsContext *,DIR *,off_t );ssize_t (*preadv)(FsContext *,int ,const struct iovec *,int ,off_t );ssize_t (*pwritev)(FsContext *,int ,const struct iovec *,int ,off_t ); -int (*mkdir)(FsContext *,const char *,FsCred *); +int (*mkdir)(FsContext *,V9fsPath *,const char *,FsCred *);int (*fstat)(FsContext *,int ,struct stat *);int (*rename)(FsContext *,const char *,const char *); -int (*truncate)(FsContext *,const char *,off_t ); +int (*truncate)(FsContext *,V9fsPath *,off_t );int (*fsync)(FsContext *,int ,int ); -int (*statfs)(FsContext *s,const char *path,struct statfs *stbuf); -ssize_t (*lgetxattr)(FsContext *,const char *, +int (*statfs)(FsContext *s,V9fsPath *path,struct statfs *stbuf); +ssize_t (*lgetxattr)(FsContext *,V9fsPath *,const char *,void *,size_t ); -ssize_t (*llistxattr)(FsContext *,const char *,void *,size_t ); -int (*lsetxattr)(FsContext *,const char *, +ssize_t (*llistxattr)(FsContext *,V9fsPath *,void *,size_t ); +int (*lsetxattr)(FsContext *,V9fsPath *,const char *,void *,size_t ,int ); -int (*lremovexattr)(FsContext *,const char *,const char *); +int (*lremovexattr)(FsContext *,V9fsPath *,const char *); +int (*name_to_path)(FsContext *,V9fsPath *,const char *,V9fsPath *); +int (*renameat)(FsContext *ctx,V9fsPath *olddir,const char *old_name, +V9fsPath *newdir,const char *new_name);void *opaque; }FileOperations ;
hw/9pfs/codir.c +11 -10
@@ -25,7 +25,6 @@ int v9fs_co_readdir_r(V9fsState *s, V9fsFidState *fidp, struct dirent *dent, v9fs_co_run_in_worker( { errno = 0; - /*FIXME!! need to switch to readdir_r */ err = s->ops->readdir_r(&s->ctx, fidp->fs.dir, dent, result); if (!*result && errno) { err = -errno;
@@ -71,29 +70,31 @@ int v9fs_co_mkdir(V9fsState *s, V9fsFidState *fidp, V9fsString *name, {int err;FsCred cred; -V9fsString fullname; +V9fsPath path;cred_init (&cred); cred.fc_mode = mode; cred.fc_uid = uid; cred.fc_gid = gid; -v9fs_string_init (&fullname);qemu_co_rwlock_rdlock (&s->rename_lock); -v9fs_string_sprintf (&fullname,"%s/%s" , fidp->path.data, name->data);v9fs_co_run_in_worker ( { - err = s->ops->mkdir (&s->ctx, fullname.data, &cred); + err = s->ops->mkdir (&s->ctx, &fidp->path, name->data, &cred);if (err <0 ) { err = -errno; }else { - err = s->ops->lstat (&s->ctx, fullname.data, stbuf); -if (err <0 ) { - err = -errno; +v9fs_path_init (&path); + err =v9fs_name_to_path (s, &fidp->path, name->data, &path); +if (!err) { + err = s->ops->lstat (&s->ctx, &path, stbuf); +if (err <0 ) { + err = -errno; + } } +v9fs_path_free (&path); } });qemu_co_rwlock_unlock (&s->rename_lock); -v9fs_string_free (&fullname);return err; }
@@ -104,7 +105,7 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp)qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - fidp->fs.dir = s->ops->opendir(&s->ctx, fidp->path.data); + fidp->fs.dir = s->ops->opendir(&s->ctx, &fidp->path); if (!fidp->fs.dir) { err = -errno; } else {
hw/9pfs/cofile.c +23 -15
@@ -17,14 +17,14 @@#include "qemu-coroutine.h" #include "virtio-9p-coth.h" -int v9fs_co_lstat (V9fsState *s,V9fsString *path,struct stat *stbuf) +int v9fs_co_lstat (V9fsState *s,V9fsPath *path,struct stat *stbuf) {int err;qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - err = s->ops->lstat(&s->ctx, path->data, stbuf); + err = s->ops->lstat(&s->ctx, path, stbuf); if (err < 0) { err = -errno; }
@@ -54,7 +54,7 @@ int v9fs_co_open(V9fsState *s, V9fsFidState *fidp, int flags)qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - fidp->fs.fd = s->ops->open(&s->ctx, fidp->path.data, flags); + fidp->fs.fd = s->ops->open(&s->ctx, &fidp->path, flags); if (fidp->fs.fd == -1) { err = -errno; } else {
@@ -76,33 +76,40 @@ int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, V9fsString *name, gid_t gid, {int err;FsCred cred; -V9fsString fullname; +V9fsPath path; +cred_init (&cred); cred.fc_mode = mode &07777 ; cred.fc_uid = fidp->uid; cred.fc_gid = gid; -v9fs_string_init (&fullname);/* * Hold the directory fid lock so that directory path name * don't change. Read lock is fine because this fid cannot * be used by any other operation. */ qemu_co_rwlock_rdlock (&s->rename_lock); -v9fs_string_sprintf (&fullname,"%s/%s" , fidp->path.data, name->data);v9fs_co_run_in_worker ( { - fidp->fs.fd = s->ops->open2 (&s->ctx, fullname.data, flags, &cred); + fidp->fs.fd = s->ops->open2 (&s->ctx, &fidp->path, + name->data, flags, &cred);if (fidp->fs.fd ==-1 ) { err = -errno; }else { - err = s->ops->lstat (&s->ctx, fullname.data, stbuf); -if (err <0 ) { - err = -errno; - err = s->ops->close (&s->ctx, fidp->fs.fd); +v9fs_path_init (&path); + err =v9fs_name_to_path (s, &fidp->path, name->data, &path); +if (!err) { + err = s->ops->lstat (&s->ctx, &path, stbuf); +if (err <0 ) { + err = -errno; + s->ops->close (&s->ctx, fidp->fs.fd); + }else { +v9fs_path_copy (&fidp->path, &path); + } }else { -v9fs_string_copy (&fidp->path, &fullname); + s->ops->close (&s->ctx, fidp->fs.fd); } +v9fs_path_free (&path); } });qemu_co_rwlock_unlock (&s->rename_lock);
@@ -112,7 +119,6 @@ int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, V9fsString *name, gid_t gid,v9fs_reclaim_fd (s); } } -v9fs_string_free (&fullname);return err; }
@@ -149,14 +155,16 @@ int v9fs_co_fsync(V9fsState *s, V9fsFidState *fidp, int datasync)return err; } -int v9fs_co_link (V9fsState *s,V9fsString *oldpath,V9fsString *newpath) +int v9fs_co_link (V9fsState *s,V9fsFidState *oldfid, +V9fsFidState *newdirfid,V9fsString *name) {int err;qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - err = s->ops->link(&s->ctx, oldpath->data, newpath->data); + err = s->ops->link(&s->ctx, &oldfid->path, + &newdirfid->path, name->data); if (err < 0) { err = -errno; }
hw/9pfs/cofs.c +68 -30
228 lines not on this page · raw message
hw/9pfs/coxattr.c +8 -9
@@ -17,14 +17,14 @@#include "qemu-coroutine.h" #include "virtio-9p-coth.h" -int v9fs_co_llistxattr (V9fsState *s,V9fsString *path,void *value,size_t size) +int v9fs_co_llistxattr (V9fsState *s,V9fsPath *path,void *value,size_t size) {int err;qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - err = s->ops->llistxattr(&s->ctx, path->data, value, size); + err = s->ops->llistxattr(&s->ctx, path, value, size); if (err < 0) { err = -errno; }
@@ -33,7 +33,7 @@ int v9fs_co_llistxattr(V9fsState *s, V9fsString *path, void *value, size_t size)return err; } -int v9fs_co_lgetxattr (V9fsState *s,V9fsString *path, +int v9fs_co_lgetxattr (V9fsState *s,V9fsPath *path,V9fsString *xattr_name,void *value,size_t size) {
@@ -42,7 +42,7 @@ int v9fs_co_lgetxattr(V9fsState *s, V9fsString *path,qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - err = s->ops->lgetxattr(&s->ctx, path->data, + err = s->ops->lgetxattr(&s->ctx, path, xattr_name->data, value, size); if (err < 0) {
@@ -53,7 +53,7 @@ int v9fs_co_lgetxattr(V9fsState *s, V9fsString *path,return err; } -int v9fs_co_lsetxattr (V9fsState *s,V9fsString *path, +int v9fs_co_lsetxattr (V9fsState *s,V9fsPath *path,V9fsString *xattr_name,void *value,size_t size,int flags) {
@@ -62,7 +62,7 @@ int v9fs_co_lsetxattr(V9fsState *s, V9fsString *path,qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - err = s->ops->lsetxattr(&s->ctx, path->data, + err = s->ops->lsetxattr(&s->ctx, path, xattr_name->data, value, size, flags); if (err < 0) {
@@ -73,7 +73,7 @@ int v9fs_co_lsetxattr(V9fsState *s, V9fsString *path,return err; } -int v9fs_co_lremovexattr (V9fsState *s,V9fsString *path, +int v9fs_co_lremovexattr (V9fsState *s,V9fsPath *path,V9fsString *xattr_name) {int err;
@@ -81,8 +81,7 @@ int v9fs_co_lremovexattr(V9fsState *s, V9fsString *path,qemu_co_rwlock_rdlock (&s->rename_lock); v9fs_co_run_in_worker( { - err = s->ops->lremovexattr(&s->ctx, path->data, - xattr_name->data); + err = s->ops->lremovexattr(&s->ctx, path, xattr_name->data); if (err < 0) { err = -errno; }
hw/9pfs/virtio-9p-coth.h +19 -14
@@ -56,43 +56,48 @@ typedef struct V9fsThPool {extern void co_run_in_worker_bh (void *);extern int v9fs_init_worker_threads (void ); -extern int v9fs_co_readlink (V9fsState *,V9fsString *,V9fsString *); +extern int v9fs_co_readlink (V9fsState *,V9fsPath *,V9fsString *);extern int v9fs_co_readdir_r (V9fsState *,V9fsFidState *,struct dirent *,struct dirent **result);extern off_t v9fs_co_telldir (V9fsState *,V9fsFidState *);extern void v9fs_co_seekdir (V9fsState *,V9fsFidState *,off_t );extern void v9fs_co_rewinddir (V9fsState *,V9fsFidState *); -extern int v9fs_co_statfs (V9fsState *,V9fsString *,struct statfs *); -extern int v9fs_co_lstat (V9fsState *,V9fsString *,struct stat *); -extern int v9fs_co_chmod (V9fsState *,V9fsString *,mode_t ); -extern int v9fs_co_utimensat (V9fsState *,V9fsString *,struct timespec [2 ]); -extern int v9fs_co_chown (V9fsState *,V9fsString *,uid_t ,gid_t ); -extern int v9fs_co_truncate (V9fsState *,V9fsString *,off_t ); -extern int v9fs_co_llistxattr (V9fsState *,V9fsString *,void *,size_t ); -extern int v9fs_co_lgetxattr (V9fsState *,V9fsString *, +extern int v9fs_co_statfs (V9fsState *,V9fsPath *,struct statfs *); +extern int v9fs_co_lstat (V9fsState *,V9fsPath *,struct stat *); +extern int v9fs_co_chmod (V9fsState *,V9fsPath *,mode_t ); +extern int v9fs_co_utimensat (V9fsState *,V9fsPath *,struct timespec [2 ]); +extern int v9fs_co_chown (V9fsState *,V9fsPath *,uid_t ,gid_t ); +extern int v9fs_co_truncate (V9fsState *,V9fsPath *,off_t ); +extern int v9fs_co_llistxattr (V9fsState *,V9fsPath *,void *,size_t ); +extern int v9fs_co_lgetxattr (V9fsState *,V9fsPath *,V9fsString *,void *,size_t );extern int v9fs_co_mknod (V9fsState *,V9fsFidState *,V9fsString *,uid_t ,gid_t ,dev_t ,mode_t ,struct stat *);extern int v9fs_co_mkdir (V9fsState *,V9fsFidState *,V9fsString *,mode_t ,uid_t ,gid_t ,struct stat *); -extern int v9fs_co_remove (V9fsState *,V9fsString *); -extern int v9fs_co_rename (V9fsState *,V9fsString *,V9fsString *); +extern int v9fs_co_remove (V9fsState *,V9fsPath *); +extern int v9fs_co_rename (V9fsState *,V9fsPath *,V9fsPath *); +extern int v9fs_co_renameat (V9fsState *,V9fsPath *,V9fsString *, +V9fsPath *,V9fsString *);extern int v9fs_co_fstat (V9fsState *,int ,struct stat *);extern int v9fs_co_opendir (V9fsState *,V9fsFidState *);extern int v9fs_co_open (V9fsState *,V9fsFidState *,int );extern int v9fs_co_open2 (V9fsState *,V9fsFidState *,V9fsString *,gid_t ,int ,int ,struct stat *); -extern int v9fs_co_lsetxattr (V9fsState *,V9fsString *,V9fsString *, +extern int v9fs_co_lsetxattr (V9fsState *,V9fsPath *,V9fsString *,void *,size_t ,int ); -extern int v9fs_co_lremovexattr (V9fsState *,V9fsString *,V9fsString *); +extern int v9fs_co_lremovexattr (V9fsState *,V9fsPath *,V9fsString *);extern int v9fs_co_closedir (V9fsState *,DIR *);extern int v9fs_co_close (V9fsState *,int );extern int v9fs_co_fsync (V9fsState *,V9fsFidState *,int );extern int v9fs_co_symlink (V9fsState *,V9fsFidState *,V9fsString *,const char *,gid_t ,struct stat *); -extern int v9fs_co_link (V9fsState *,V9fsString *,V9fsString *); +extern int v9fs_co_link (V9fsState *,V9fsFidState *, +V9fsFidState *,V9fsString *);extern int v9fs_co_pwritev (V9fsState *,V9fsFidState *,struct iovec *,int ,int64_t );extern int v9fs_co_preadv (V9fsState *,V9fsFidState *,struct iovec *,int ,int64_t ); +extern int v9fs_co_name_to_path (V9fsState *,V9fsPath *, +const char *,V9fsPath *);#endif
hw/9pfs/virtio-9p-local.c +149 -40
441 lines not on this page · raw message
hw/9pfs/virtio-9p.c +191 -152
624 lines not on this page · raw message
hw/9pfs/virtio-9p.h +6 -1
@@ -204,7 +204,7 @@ struct V9fsFidState {int fid_type;int32_t fid; -V9fsString path; +V9fsPath path;union {int fd;DIR *dir;
@@ -395,4 +395,9 @@ extern void v9fs_string_free(V9fsString *str);extern void v9fs_string_null (V9fsString *str);extern void v9fs_string_sprintf (V9fsString *str,const char *fmt, ...);extern void v9fs_string_copy (V9fsString *lhs,V9fsString *rhs); +extern void v9fs_path_init (V9fsPath *path); +extern void v9fs_path_free (V9fsPath *path); +extern void v9fs_path_copy (V9fsPath *lhs,V9fsPath *rhs); +extern int v9fs_name_to_path (V9fsState *s,V9fsPath *dirpath, +const char *name,V9fsPath *path);#endif
Signature · 1 line
1.7.4.1
PATCH 4/5 hw/9pfs: Add fs driver specific details to fscontext
Add a new context flag PATHNAME_FSCONTEXT and indicate whether the fs driver track fid using path names. Also add a private pointer that help us to track fs driver specific values in there
--- fsdev/file-op-9p.h | 6 ++++ hw/9pfs/codir.c | 8 +++--- hw/9pfs/cofile.c | 16 ++++++------ hw/9pfs/cofs.c | 57 ++++++++++++++++++++++++++----------------- hw/9pfs/coxattr.c | 16 ++++++------ hw/9pfs/virtio-9p-device.c | 1 + hw/9pfs/virtio-9p-local.c | 1 + hw/9pfs/virtio-9p.c | 29 ++++++++++++++++------ hw/9pfs/virtio-9p.h | 21 ++++++++++++++++ 9 files changed, 104 insertions(+), 51 deletions(-)
fsdev/file-op-9p.h +6 -0
@@ -50,13 +50,19 @@ typedef struct FsCredstruct xattr_operations ; +/* FsContext flag values */ +#define PATHNAME_FSCONTEXT 0x1 +typedef struct FsContext { +int flags;char *fs_root;SecModel fs_sm;uid_t uid;int open_flags;struct xattr_operations **xops; +/* fs driver specific data */ +void *private; }FsContext ; typedef struct V9fsPath {
hw/9pfs/codir.c +4 -4
@@ -76,7 +76,7 @@ int v9fs_co_mkdir(V9fsState *s, V9fsFidState *fidp, V9fsString *name, cred.fc_mode = mode; cred.fc_uid = uid; cred.fc_gid = gid; -qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_path_read_lock (s); v9fs_co_run_in_worker( { err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred);
@@ -94,7 +94,7 @@ int v9fs_co_mkdir(V9fsState *s, V9fsFidState *fidp, V9fsString *name,v9fs_path_free (&path); } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);return err; }
@@ -102,7 +102,7 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp) {int err; -qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_path_read_lock (s); v9fs_co_run_in_worker( { fidp->fs.dir = s->ops->opendir(&s->ctx, &fidp->path);
@@ -112,7 +112,7 @@ int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp) err =0 ; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);if (!err) { total_open_fd++;if (total_open_fd > open_fd_hw) {
hw/9pfs/cofile.c +8 -8
@@ -21,7 +21,7 @@ int v9fs_co_lstat(V9fsState *s, V9fsPath *path, struct stat *stbuf) {int err; -qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_path_read_lock (s); v9fs_co_run_in_worker( { err = s->ops->lstat(&s->ctx, path, stbuf);
@@ -29,7 +29,7 @@ int v9fs_co_lstat(V9fsState *s, V9fsPath *path, struct stat *stbuf) err = -errno; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);return err; }
@@ -51,7 +51,7 @@ int v9fs_co_open(V9fsState *s, V9fsFidState *fidp, int flags) {int err; -qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_path_read_lock (s); v9fs_co_run_in_worker( { fidp->fs.fd = s->ops->open(&s->ctx, &fidp->path, flags);
@@ -61,7 +61,7 @@ int v9fs_co_open(V9fsState *s, V9fsFidState *fidp, int flags) err =0 ; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);if (!err) { total_open_fd++;if (total_open_fd > open_fd_hw) {
@@ -88,7 +88,7 @@ int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, V9fsString *name, gid_t gid,* don't change. Read lock is fine because this fid cannot * be used by any other operation. */ -qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_path_read_lock (s); v9fs_co_run_in_worker( { fidp->fs.fd = s->ops->open2(&s->ctx, &fidp->path,
@@ -112,7 +112,7 @@ int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, V9fsString *name, gid_t gid,v9fs_path_free (&path); } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);if (!err) { total_open_fd++;if (total_open_fd > open_fd_hw) {
@@ -160,7 +160,7 @@ int v9fs_co_link(V9fsState *s, V9fsFidState *oldfid, { int err; - qemu_co_rwlock_rdlock(&s->rename_lock); + v9fs_path_read_lock(s); v9fs_co_run_in_worker( { err = s->ops->link(&s->ctx, &oldfid->path,
@@ -169,7 +169,7 @@ int v9fs_co_link(V9fsState *s, V9fsFidState *oldfid, err = -errno; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);return err; }
hw/9pfs/cofs.c +34 -23
183 lines not on this page · raw message
hw/9pfs/coxattr.c +8 -8
@@ -21,7 +21,7 @@ int v9fs_co_llistxattr(V9fsState *s, V9fsPath *path, void *value, size_t size) {int err; -qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_path_read_lock (s); v9fs_co_run_in_worker( { err = s->ops->llistxattr(&s->ctx, path, value, size);
@@ -29,7 +29,7 @@ int v9fs_co_llistxattr(V9fsState *s, V9fsPath *path, void *value, size_t size) err = -errno; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);return err; }
@@ -39,7 +39,7 @@ int v9fs_co_lgetxattr(V9fsState *s, V9fsPath *path, { int err; - qemu_co_rwlock_rdlock(&s->rename_lock); + v9fs_path_read_lock(s); v9fs_co_run_in_worker( { err = s->ops->lgetxattr(&s->ctx, path,
@@ -49,7 +49,7 @@ int v9fs_co_lgetxattr(V9fsState *s, V9fsPath *path, err = -errno; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);return err; }
@@ -59,7 +59,7 @@ int v9fs_co_lsetxattr(V9fsState *s, V9fsPath *path, { int err; - qemu_co_rwlock_rdlock(&s->rename_lock); + v9fs_path_read_lock(s); v9fs_co_run_in_worker( { err = s->ops->lsetxattr(&s->ctx, path,
@@ -69,7 +69,7 @@ int v9fs_co_lsetxattr(V9fsState *s, V9fsPath *path, err = -errno; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);return err; }
@@ -78,7 +78,7 @@ int v9fs_co_lremovexattr(V9fsState *s, V9fsPath *path, {int err; -qemu_co_rwlock_rdlock (&s->rename_lock); +v9fs_path_read_lock (s); v9fs_co_run_in_worker( { err = s->ops->lremovexattr(&s->ctx, path, xattr_name->data);
@@ -86,6 +86,6 @@ int v9fs_co_lremovexattr(V9fsState *s, V9fsPath *path, err = -errno; } }); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);return err; }
hw/9pfs/virtio-9p-device.c +1 -0
@@ -130,6 +130,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)memcpy (s->tag, conf->tag, len); s->tag_len = len; s->ctx.uid =-1 ; + s->ctx.flags =0 ; s->ops = fse->ops; s->vdev.get_features = virtio_9p_get_features;
hw/9pfs/virtio-9p-local.c +1 -0
@@ -647,6 +647,7 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,static int local_init (FsContext *ctx) { + ctx->flags |=PATHNAME_FSCONTEXT ;return 0 ; }
hw/9pfs/virtio-9p.c +21 -8
@@ -2343,6 +2343,7 @@ out_nofid:complete_pdu (s, pdu, err); } +/* Only works with path name based fid */ static void v9fs_remove (void *opaque) {int32_t fid;
@@ -2358,6 +2359,11 @@ static void v9fs_remove(void *opaque) err = -EINVAL ; goto out_nofid; } +/* if fs driver is not path based, return EOPNOTSUPP */ +if (!pdu->s->ctx.flags &PATHNAME_FSCONTEXT ) { + err = -EOPNOTSUPP ; + goto out_err; + }/* * IF the file is unlinked, we cannot reopen * the file later. So don't reclaim fd
@@ -2476,6 +2482,7 @@ out_nofid:return err; } +/* Only works with path name based fid */ static void v9fs_rename (void *opaque) {int32_t fid;
@@ -2495,10 +2502,14 @@ static void v9fs_rename(void *opaque) goto out_nofid; }BUG_ON (fidp->fid_type !=P9_FID_NONE ); - -qemu_co_rwlock_wrlock (&s->rename_lock); +/* if fs driver is not path based, return EOPNOTSUPP */ +if (!pdu->s->ctx.flags &PATHNAME_FSCONTEXT ) { + err = -EOPNOTSUPP ; + goto out; + } +v9fs_path_write_lock (s); err =v9fs_complete_rename (s, fidp, newdirfid, &name); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);if (!err) { err = offset; }
@@ -2563,9 +2574,11 @@ static int v9fs_complete_renameat(V9fsState *s, int32_t olddirfid,if (err <0 ) { goto out; } -/* Only for path based fid we need to do the below fixup */ -v9fs_fix_fid_paths (s, &olddirfidp->path, old_name, - &newdirfidp->path, new_name); +if (s->ctx.flags &PATHNAME_FSCONTEXT ) { +/* Only for path based fid we need to do the below fixup */ +v9fs_fix_fid_paths (s, &olddirfidp->path, old_name, + &newdirfidp->path, new_name); + } out:if (olddirfidp) {put_fid (s, olddirfidp);
@@ -2588,9 +2601,9 @@ static void v9fs_renameat(void *opaque)pdu_unmarshal (pdu, offset,"dsds" , &olddirfid, &old_name, &newdirfid, &new_name); -qemu_co_rwlock_wrlock (&s->rename_lock); +v9fs_path_write_lock (s); err =v9fs_complete_renameat (s, olddirfid, &old_name, newdirfid, &new_name); -qemu_co_rwlock_unlock (&s->rename_lock); +v9fs_path_unlock (s);if (!err) { err = offset; }
hw/9pfs/virtio-9p.h +21 -0
@@ -389,6 +389,27 @@ static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,return pdu_packunpack (dst, sg, sg_count, offset, size,0 ); } +static inline void v9fs_path_write_lock (V9fsState *s) +{ +if (s->ctx.flags &PATHNAME_FSCONTEXT ) { +qemu_co_rwlock_wrlock (&s->rename_lock); + } +} + +static inline void v9fs_path_read_lock (V9fsState *s) +{ +if (s->ctx.flags &PATHNAME_FSCONTEXT ) { +qemu_co_rwlock_rdlock (&s->rename_lock); + } +} + +static inline void v9fs_path_unlock (V9fsState *s) +{ +if (s->ctx.flags &PATHNAME_FSCONTEXT ) { +qemu_co_rwlock_unlock (&s->rename_lock); + } +} +extern void handle_9p_output (VirtIODevice *vdev,VirtQueue *vq);extern void virtio_9p_set_fd_limit (void );extern void v9fs_reclaim_fd (V9fsState *s);
Signature · 1 line
1.7.4.1
PATCH 5/5 hw/9pfs: Add handle based fs driver
In reply to Aneesh Kumar K.V--- Makefile.objs | 8 +- fsdev/qemu-fsdev.c | 1 + fsdev/qemu-fsdev.h | 1 + hw/9pfs/virtio-9p-handle.c | 602 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 608 insertions(+), 4 deletions(-) create mode 100644 hw/9pfs/virtio-9p-handle.c
Makefile.objs +4 -4
@@ -294,11 +294,11 @@ sound-obj-$(CONFIG_HDA) += intel-hda.o hda-audio.o adlib.o fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0 hw-obj-$(CONFIG_SOUND) += $(sound-obj-y) -9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o -9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-local.o virtio-9p-xattr.o -9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o +9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o +9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-local.o virtio-9p-xattr.o +9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o -9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o +9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-handle.o hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y)) $(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
fsdev/qemu-fsdev.c +1 -0
@@ -23,6 +23,7 @@ static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =static FsTypeTable FsTypes[] = { { .name ="local" , .ops = &local_ops}, + { .name ="handle" , .ops = &handle_ops}, };int qemu_fsdev_add (QemuOpts *opts)
fsdev/qemu-fsdev.h +1 -0
@@ -54,4 +54,5 @@ typedef struct FsTypeListEntry {int qemu_fsdev_add (QemuOpts *opts);FsTypeEntry *get_fsdev_fsentry (char *id);extern FileOperations local_ops; +extern FileOperations handle_ops;#endif
hw/9pfs/virtio-9p-handle.c new file +602 -0
602 lines not on this page · raw message
Signature · 1 line
1.7.4.1