Skip to contentSkip to conversation

hw/9pfs: Use export_flag for indicating whether fs driver use path names.

PATCH New Aneesh Kumar K.V 1 participant 3 messages Oct 14, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 hw/9pfs: Use export_flag for indicating whether fs driver use path names.

From: "Aneesh Kumar K.V" <[email protected]>

This allows us to remove another member from the struct

---
 fsdev/file-op-9p.h         |    7 ++-----
 hw/9pfs/cofs.c             |    2 +-
 hw/9pfs/virtio-9p-device.c |    1 -
 hw/9pfs/virtio-9p-local.c  |    2 +-
 hw/9pfs/virtio-9p.c        |    6 +++---
 hw/9pfs/virtio-9p.h        |    6 +++---
 6 files changed, 10 insertions(+), 14 deletions(-)
fsdev/file-op-9p.h +2 -5
index d6705c0..272f018 100644
@@ -57,15 +57,12 @@ typedef struct extended_ops {
                       mode_t, uint64_t *);
 } extended_ops;
 
-/* FsContext flag values */
-#define PATHNAME_FSCONTEXT 0x1
-
 /* export flags */
-#define V9FS_IMMEDIATE_WRITEOUT 0x1
+#define V9FS_IMMEDIATE_WRITEOUT     0x00000001
+#define V9FS_PATHNAME_FSCONTEXT     0x00000002
 
 typedef struct FsContext
 {
-    int flags;
     char *fs_root;
     SecModel fs_sm;
     uid_t uid;
hw/9pfs/cofs.c +1 -1
index 68745ad..83f125b 100644
@@ -323,7 +323,7 @@ int v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath,
     int err;
     V9fsState *s = pdu->s;
 
-    if (s->ctx.flags & PATHNAME_FSCONTEXT) {
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
         err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
         if (err < 0) {
             err = -errno;
hw/9pfs/virtio-9p-device.c +0 -1
index 0724605..831cce9 100644
@@ -123,7 +123,6 @@ 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 -1
index 8a065d9..fd24dcd 100644
@@ -700,7 +700,7 @@ static int local_init(FsContext *ctx)
     int err;
     struct statfs stbuf;
 
-    ctx->flags |= PATHNAME_FSCONTEXT;
+    ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT;
     err = statfs(ctx->fs_root, &stbuf);
     if (!err) {
         switch (stbuf.f_type) {
hw/9pfs/virtio-9p.c +3 -3
index b0a87c8..aab3beb 100644
@@ -2493,7 +2493,7 @@ static void v9fs_remove(void *opaque)
         goto out_nofid;
     }
     /* if fs driver is not path based, return EOPNOTSUPP */
-    if (!pdu->s->ctx.flags & PATHNAME_FSCONTEXT) {
+    if (!(pdu->s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT)) {
         err = -EOPNOTSUPP;
         goto out_err;
     }
@@ -2640,7 +2640,7 @@ static void v9fs_rename(void *opaque)
     }
     BUG_ON(fidp->fid_type != P9_FID_NONE);
     /* if fs driver is not path based, return EOPNOTSUPP */
-    if (!pdu->s->ctx.flags & PATHNAME_FSCONTEXT) {
+    if (!(pdu->s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT)) {
         err = -EOPNOTSUPP;
         goto out;
     }
@@ -2713,7 +2713,7 @@ static int v9fs_complete_renameat(V9fsPDU *pdu, int32_t olddirfid,
     if (err < 0) {
         goto out;
     }
-    if (s->ctx.flags & PATHNAME_FSCONTEXT) {
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
         /* Only for path based fid  we need to do the below fixup */
         v9fs_fix_fid_paths(pdu, &olddirfidp->path, old_name,
                            &newdirfidp->path, new_name);
hw/9pfs/virtio-9p.h +3 -3
index e94041e..802f580 100644
@@ -422,21 +422,21 @@ static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
 
 static inline void v9fs_path_write_lock(V9fsState *s)
 {
-    if (s->ctx.flags & PATHNAME_FSCONTEXT) {
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
         qemu_co_rwlock_wrlock(&s->rename_lock);
     }
 }
 
 static inline void v9fs_path_read_lock(V9fsState *s)
 {
-    if (s->ctx.flags & PATHNAME_FSCONTEXT) {
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
         qemu_co_rwlock_rdlock(&s->rename_lock);
     }
 }
 
 static inline void v9fs_path_unlock(V9fsState *s)
 {
-    if (s->ctx.flags & PATHNAME_FSCONTEXT) {
+    if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
         qemu_co_rwlock_unlock(&s->rename_lock);
     }
 }
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 2/3 hw/9pfs: Rename fstype to fsdriver to make it consistent across VirtFS code

From: "Aneesh Kumar K.V" <[email protected]>

---
 fsdev/qemu-fsdev.c         |   32 ++++++++++++++++----------------
 fsdev/qemu-fsdev.h         |   18 +++++++++---------
 hw/9pfs/virtio-9p-device.c |    2 +-
 qemu-config.c              |    8 ++++----
 vl.c                       |    6 +++---
 5 files changed, 33 insertions(+), 33 deletions(-)
fsdev/qemu-fsdev.c +16 -16
index 946bad7..fcec494 100644
@@ -18,20 +18,20 @@
 #include "qemu-common.h"
 #include "qemu-config.h"
 
-static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =
-    QTAILQ_HEAD_INITIALIZER(fstype_entries);
+static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
+    QTAILQ_HEAD_INITIALIZER(fsdriver_entries);
 
-static FsTypeTable FsTypes[] = {
+static FsDriverTable FsDrivers[] = {
     { .name = "local", .ops = &local_ops},
     { .name = "handle", .ops = &handle_ops},
 };
 
 int qemu_fsdev_add(QemuOpts *opts)
 {
-    struct FsTypeListEntry *fsle;
+    struct FsDriverListEntry *fsle;
     int i;
     const char *fsdev_id = qemu_opts_id(opts);
-    const char *fstype = qemu_opt_get(opts, "fstype");
+    const char *fsdriver = qemu_opt_get(opts, "fsdriver");
     const char *path = qemu_opt_get(opts, "path");
     const char *sec_model = qemu_opt_get(opts, "security_model");
     const char *writeout = qemu_opt_get(opts, "writeout");
@@ -42,19 +42,19 @@ int qemu_fsdev_add(QemuOpts *opts)
         return -1;
     }
 
-    if (fstype) {
-        for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
-            if (strcmp(FsTypes[i].name, fstype) == 0) {
+    if (fsdriver) {
+        for (i = 0; i < ARRAY_SIZE(FsDrivers); i++) {
+            if (strcmp(FsDrivers[i].name, fsdriver) == 0) {
                 break;
             }
         }
 
-        if (i == ARRAY_SIZE(FsTypes)) {
-            fprintf(stderr, "fsdev: fstype %s not found\n", fstype);
+        if (i == ARRAY_SIZE(FsDrivers)) {
+            fprintf(stderr, "fsdev: fsdriver %s not found\n", fsdriver);
             return -1;
         }
     } else {
-        fprintf(stderr, "fsdev: No fstype specified\n");
+        fprintf(stderr, "fsdev: No fsdriver specified\n");
         return -1;
     }
 
@@ -73,23 +73,23 @@ int qemu_fsdev_add(QemuOpts *opts)
     fsle->fse.fsdev_id = g_strdup(fsdev_id);
     fsle->fse.path = g_strdup(path);
     fsle->fse.security_model = g_strdup(sec_model);
-    fsle->fse.ops = FsTypes[i].ops;
+    fsle->fse.ops = FsDrivers[i].ops;
     fsle->fse.export_flags = 0;
     if (writeout) {
         if (!strcmp(writeout, "immediate")) {
             fsle->fse.export_flags = V9FS_IMMEDIATE_WRITEOUT;
         }
     }
-    QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
+    QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
     return 0;
 }
 
-FsTypeEntry *get_fsdev_fsentry(char *id)
+FsDriverEntry *get_fsdev_fsentry(char *id)
 {
     if (id) {
-        struct FsTypeListEntry *fsle;
+        struct FsDriverListEntry *fsle;
 
-        QTAILQ_FOREACH(fsle, &fstype_entries, next) {
+        QTAILQ_FOREACH(fsle, &fsdriver_entries, next) {
             if (strcmp(fsle->fse.fsdev_id, id) == 0) {
                 return &fsle->fse;
             }
fsdev/qemu-fsdev.h +9 -9
index 3b2feb4..69baafc 100644
@@ -29,29 +29,29 @@
  * -----------------
  *  etc
  */
-typedef struct FsTypeTable {
+typedef struct FsDriverTable {
     const char *name;
     FileOperations *ops;
-} FsTypeTable;
+} FsDriverTable;
 
 /*
  * Structure to store the various fsdev's passed through command line.
  */
-typedef struct FsTypeEntry {
+typedef struct FsDriverEntry {
     char *fsdev_id;
     char *path;
     char *security_model;
     int export_flags;
     FileOperations *ops;
-} FsTypeEntry;
+} FsDriverEntry;
 
-typedef struct FsTypeListEntry {
-    FsTypeEntry fse;
-    QTAILQ_ENTRY(FsTypeListEntry) next;
-} FsTypeListEntry;
+typedef struct FsDriverListEntry {
+    FsDriverEntry fse;
+    QTAILQ_ENTRY(FsDriverListEntry) next;
+} FsDriverListEntry;
 
 int qemu_fsdev_add(QemuOpts *opts);
-FsTypeEntry *get_fsdev_fsentry(char *id);
+FsDriverEntry *get_fsdev_fsentry(char *id);
 extern FileOperations local_ops;
 extern FileOperations handle_ops;
 #endif
hw/9pfs/virtio-9p-device.c +1 -1
index 831cce9..af230b6 100644
@@ -49,7 +49,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
     V9fsState *s;
     int i, len;
     struct stat stat;
-    FsTypeEntry *fse;
+    FsDriverEntry *fse;
     V9fsPath path;
 
     s = (V9fsState *)virtio_common_init("virtio-9p",
qemu-config.c +4 -4
index 4559236..90b6b3e 100644
@@ -165,11 +165,11 @@ static QemuOptsList qemu_chardev_opts = {
 
 QemuOptsList qemu_fsdev_opts = {
     .name = "fsdev",
-    .implied_opt_name = "fstype",
+    .implied_opt_name = "fsdriver",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_fsdev_opts.head),
     .desc = {
         {
-            .name = "fstype",
+            .name = "fsdriver",
             .type = QEMU_OPT_STRING,
         }, {
             .name = "path",
@@ -187,11 +187,11 @@ QemuOptsList qemu_fsdev_opts = {
 
 QemuOptsList qemu_virtfs_opts = {
     .name = "virtfs",
-    .implied_opt_name = "fstype",
+    .implied_opt_name = "fsdriver",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_virtfs_opts.head),
     .desc = {
         {
-            .name = "fstype",
+            .name = "fsdriver",
             .type = QEMU_OPT_STRING,
         }, {
             .name = "path",
vl.c +3 -3
index 08e1a95..3b8199f 100644
@@ -2798,11 +2798,11 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
 
-                if (qemu_opt_get(opts, "fstype") == NULL ||
+                if (qemu_opt_get(opts, "fsdriver") == NULL ||
                         qemu_opt_get(opts, "mount_tag") == NULL ||
                         qemu_opt_get(opts, "path") == NULL ||
                         qemu_opt_get(opts, "security_model") == NULL) {
-                    fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/,"
+                    fprintf(stderr, "Usage: -virtfs fsdriver,path=/share_path/,"
                             "security_model=[mapped|passthrough|none],"
                             "mount_tag=tag.\n");
                     exit(1);
@@ -2820,7 +2820,7 @@ int main(int argc, char **argv, char **envp)
                 if (writeout) {
                     qemu_opt_set(fsdev, "writeout", writeout);
                 }
-                qemu_opt_set(fsdev, "fstype", qemu_opt_get(opts, "fstype"));
+                qemu_opt_set(fsdev, "fsdriver", qemu_opt_get(opts, "fsdriver"));
                 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
                 qemu_opt_set(fsdev, "security_model",
                              qemu_opt_get(opts, "security_model"));
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH 3/3 hw/9pfs: Use export flag for indicating security model

In reply to Aneesh Kumar K.V

From: "Aneesh Kumar K.V" <[email protected]>

This helps to remove some of the structure members

---
 fsdev/file-op-9p.h         |   36 ++++++++++++++----------------
 fsdev/qemu-fsdev.c         |   19 ++++++++++++++-
 fsdev/qemu-fsdev.h         |    1 -
 hw/9pfs/virtio-9p-device.c |   31 ++++++--------------------
 hw/9pfs/virtio-9p-local.c  |   52 ++++++++++++++++++++++----------------------
 5 files changed, 67 insertions(+), 72 deletions(-)
fsdev/file-op-9p.h +17 -19
index 272f018..908e2a5 100644
@@ -23,23 +23,6 @@
 #define SM_LOCAL_MODE_BITS    0600
 #define SM_LOCAL_DIR_MODE_BITS    0700
 
-typedef enum
-{
-    /*
-     * Server will try to set uid/gid.
-     * On failure ignore the error.
-     */
-    SM_NONE = 0,
-    /*
-     * uid/gid set on fileserver files
-     */
-    SM_PASSTHROUGH = 1,
-    /*
-     * uid/gid part of xattr
-     */
-    SM_MAPPED,
-} SecModel;
-
 typedef struct FsCred
 {
     uid_t   fc_uid;
@@ -60,12 +43,27 @@ typedef struct extended_ops {
 /* export flags */
 #define V9FS_IMMEDIATE_WRITEOUT     0x00000001
 #define V9FS_PATHNAME_FSCONTEXT     0x00000002
+/*
+ * uid/gid set on fileserver files
+ */
+#define V9FS_SM_PASSTHROUGH         0x00000004
+/*
+ * uid/gid part of xattr
+ */
+#define V9FS_SM_MAPPED              0x00000008
+/*
+ * Server will try to set uid/gid.
+ * On failure ignore the error.
+ */
+#define V9FS_SM_NONE                0x00000010
+
+
+#define V9FS_SEC_MASK               0x0000001C
 
 typedef struct FsContext
 {
-    char *fs_root;
-    SecModel fs_sm;
     uid_t uid;
+    char *fs_root;
     int export_flags;
     struct xattr_operations **xops;
     struct extended_ops exops;
fsdev/qemu-fsdev.c +17 -2
index fcec494..ce920d6 100644
@@ -72,14 +72,29 @@ int qemu_fsdev_add(QemuOpts *opts)
 
     fsle->fse.fsdev_id = g_strdup(fsdev_id);
     fsle->fse.path = g_strdup(path);
-    fsle->fse.security_model = g_strdup(sec_model);
     fsle->fse.ops = FsDrivers[i].ops;
     fsle->fse.export_flags = 0;
     if (writeout) {
         if (!strcmp(writeout, "immediate")) {
-            fsle->fse.export_flags = V9FS_IMMEDIATE_WRITEOUT;
+            fsle->fse.export_flags |= V9FS_IMMEDIATE_WRITEOUT;
         }
     }
+
+    if (!strcmp(sec_model, "passthrough")) {
+        fsle->fse.export_flags |= V9FS_SM_PASSTHROUGH;
+    } else if (!strcmp(sec_model, "mapped")) {
+        fsle->fse.export_flags |= V9FS_SM_MAPPED;
+    } else if (!strcmp(sec_model, "none")) {
+        fsle->fse.export_flags |= V9FS_SM_NONE;
+    } else {
+        fprintf(stderr, "Default to security_model=none. You may want"
+                " enable advanced security model using "
+                "security option:\n\t security_model=passthrough\n\t "
+                "security_model=mapped\n");
+
+        fsle->fse.export_flags |= V9FS_SM_NONE;
+    }
+
     QTAILQ_INSERT_TAIL(&fsdriver_entries, fsle, next);
     return 0;
 }
fsdev/qemu-fsdev.h +0 -1
index 69baafc..5099085 100644
@@ -40,7 +40,6 @@ typedef struct FsDriverTable {
 typedef struct FsDriverEntry {
     char *fsdev_id;
     char *path;
-    char *security_model;
     int export_flags;
     FileOperations *ops;
 } FsDriverEntry;
hw/9pfs/virtio-9p-device.c +7 -24
index af230b6..bba4c54 100644
@@ -83,35 +83,18 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
         exit(1);
     }
 
-    if (!strcmp(fse->security_model, "passthrough")) {
-        /* Files on the Fileserver set to client user credentials */
-        s->ctx.fs_sm = SM_PASSTHROUGH;
+    s->ctx.export_flags = fse->export_flags;
+    s->ctx.fs_root = g_strdup(fse->path);
+    s->ctx.exops.get_st_gen = NULL;
+
+    if (fse->export_flags & V9FS_SM_PASSTHROUGH) {
         s->ctx.xops = passthrough_xattr_ops;
-    } else if (!strcmp(fse->security_model, "mapped")) {
-        /* Files on the fileserver are set to QEMU credentials.
-         * Client user credentials are saved in extended attributes.
-         */
-        s->ctx.fs_sm = SM_MAPPED;
+    } else if (fse->export_flags & V9FS_SM_MAPPED) {
         s->ctx.xops = mapped_xattr_ops;
-    } else if (!strcmp(fse->security_model, "none")) {
-        /*
-         * Files on the fileserver are set to QEMU credentials.
-         */
-        s->ctx.fs_sm = SM_NONE;
-        s->ctx.xops = none_xattr_ops;
-    } else {
-        fprintf(stderr, "Default to security_model=none. You may want"
-                " enable advanced security model using "
-                "security option:\n\t security_model=passthrough\n\t "
-                "security_model=mapped\n");
-        s->ctx.fs_sm = SM_NONE;
+    } else if (fse->export_flags & V9FS_SM_NONE) {
         s->ctx.xops = none_xattr_ops;
     }
 
-    s->ctx.export_flags = fse->export_flags;
-    s->ctx.fs_root = g_strdup(fse->path);
-    s->ctx.exops.get_st_gen = NULL;
-
     len = strlen(conf->tag);
     if (len > MAX_TAG_LEN) {
         fprintf(stderr, "mount tag '%s' (%d bytes) is longer than "
hw/9pfs/virtio-9p-local.c +26 -26

152 lines not on this page · raw message

Signature · 1 line
1.7.5.4