Patchwork [-V3,28/32] virtio-9p: Handle the fsdev command line options.

login
register
mail settings
Submitter Aneesh Kumar K.V
Date March 25, 2010, 4:43 p.m.
Message ID <1269535420-31206-29-git-send-email-aneesh.kumar@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/48579/
State New
Headers show

Comments

Aneesh Kumar K.V - March 25, 2010, 4:43 p.m.
From: Gautham R Shenoy <ego@in.ibm.com>

This patch handles:
- Parsing of fsdev commandline options.
- Maintaining a list of fsdev entries.
- Providing callbacks for the other subsystems to obtain FsTypeEntries
  for a given fsdev based on it's id.

This will be used later to decouple the share_path attribute from the virtio-9p
device.

Signed-off-by: Gautham R Shenoy <ego@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 Makefile.objs        |    5 +++-
 fsdev/qemu-fsdev.c   |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++
 fsdev/qemu-fsdev.h   |   53 +++++++++++++++++++++++++++++++++++++
 hw/virtio-9p-local.c |    4 +-
 vl.c                 |   18 +++++++++++++
 5 files changed, 147 insertions(+), 3 deletions(-)
 create mode 100644 fsdev/qemu-fsdev.c
 create mode 100644 fsdev/qemu-fsdev.h

Patch

diff --git a/Makefile.objs b/Makefile.objs
index 281f7a6..2adfdff 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -35,6 +35,9 @@  net-nested-$(CONFIG_SLIRP) += slirp.o
 net-nested-$(CONFIG_VDE) += vde.o
 net-obj-y += $(addprefix net/, $(net-nested-y))
 
+fsdev-nested-y = qemu-fsdev.o
+fsdev-obj-y += $(addprefix fsdev/, $(fsdev-nested-y))
+
 ######################################################################
 # libqemu_common.a: Target independent part of system emulation. The
 # long term path is to suppress *all* target specific code in case of
@@ -44,8 +47,8 @@  net-obj-y += $(addprefix net/, $(net-nested-y))
 common-obj-y = $(block-obj-y)
 common-obj-y += $(net-obj-y)
 common-obj-y += $(qobject-obj-y)
+common-obj-y += $(fsdev-obj-y)
 common-obj-y += readline.o console.o async.o qemu-error.o
-
 common-obj-y += tcg-runtime.o host-utils.o
 common-obj-y += irq.o ioport.o input.o
 common-obj-$(CONFIG_PTIMER) += ptimer.o
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
new file mode 100644
index 0000000..cf1629a
--- /dev/null
+++ b/fsdev/qemu-fsdev.c
@@ -0,0 +1,70 @@ 
+/*
+ * Virtio 9p
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Gautham R Shenoy <ego@in.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+#include <stdio.h>
+#include <string.h>
+#include "qemu-fsdev.h"
+#include "qemu-queue.h"
+#include "osdep.h"
+#include "qemu-common.h"
+
+static QTAILQ_HEAD(FsTypeEntry_head, FsTypeListEntry) fstype_entries =
+    QTAILQ_HEAD_INITIALIZER(fstype_entries);
+
+extern FileOperations local_ops;
+static FsTypeTable FsTypes[] = {
+    { .name ="local", .ops = &local_ops},
+};
+
+int qemu_fsdev_add(QemuOpts *opts)
+{
+    struct FsTypeListEntry *fsle;
+    int i;
+
+    if (qemu_opts_id(opts) == NULL) {
+        fprintf(stderr, "fsdev: No id specified\n");
+        return -1;
+    }
+
+     for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
+        if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0)
+            break;
+    }
+
+    if (i == ARRAY_SIZE(FsTypes)) {
+        fprintf(stderr, "fsdev: fstype %s not found\n",
+                    qemu_opt_get(opts, "fstype"));
+        return -1;
+    }
+
+    fsle =qemu_malloc(sizeof(*fsle));
+
+    fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts));
+    fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path"));
+    fsle->fse.ops = FsTypes[i].ops;
+
+    QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
+    return 0;
+
+}
+
+FsTypeEntry * get_fsdev_fsentry(char *id)
+{
+    struct FsTypeListEntry *fsle;
+
+    QTAILQ_FOREACH(fsle, &fstype_entries, next) {
+        if (strcmp(fsle->fse.fsdev_id, id) == 0) {
+            return &fsle->fse;
+        }
+    }
+    return NULL;
+}
diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h
new file mode 100644
index 0000000..db280bb
--- /dev/null
+++ b/fsdev/qemu-fsdev.h
@@ -0,0 +1,53 @@ 
+/*
+ * Virtio 9p
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Gautham R Shenoy <ego@in.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+#ifndef QEMU_FSDEV_H
+#define QEMU_FSDEV_H
+#include "qemu-option.h"
+#include "hw/file-op.h"
+
+
+/*
+ * A table to store the various file systems and their callback operations.
+ * -----------------
+ * fstype | ops
+ * -----------------
+ *  local | local_ops
+ *  .     |
+ *  .     |
+ *  .     |
+ *  .     |
+ * -----------------
+ *  etc
+ */
+typedef struct FsTypeTable {
+    const char *name;
+    FileOperations *ops;
+} FsTypeTable;
+
+/*
+ * Structure to store the various fsdev's passed through command line.
+ */
+typedef struct FsTypeEntry {
+    char *fsdev_id;
+    char *path;
+    FileOperations *ops;
+} FsTypeEntry;
+
+typedef struct FsTypeListEntry {
+    FsTypeEntry fse;
+    QTAILQ_ENTRY(FsTypeListEntry) next;
+} FsTypeListEntry;
+
+extern int qemu_fsdev_add(QemuOpts *opts);
+extern FsTypeEntry *get_fsdev_fsentry(char *id);
+#endif
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 690ba3f..aae82d2 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -254,7 +254,7 @@  static int local_fsync(FsContext *s, int fd)
     return fsync(fd);
 }
 
-static FileOperations ops = {
+FileOperations local_ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
     .readlink = local_readlink,
@@ -287,5 +287,5 @@  static FileOperations ops = {
 
 FileOperations *virtio_9p_init_local(const char *path)
 {
-    return &ops;
+    return &local_ops;
 }
diff --git a/vl.c b/vl.c
index d69250c..0228045 100644
--- a/vl.c
+++ b/vl.c
@@ -150,6 +150,7 @@  int main(int argc, char **argv)
 #include "qemu-option.h"
 #include "qemu-config.h"
 #include "qemu-objects.h"
+#include "fsdev/qemu-fsdev.h"
 
 #include "disas.h"
 
@@ -3461,6 +3462,14 @@  static int chardev_init_func(QemuOpts *opts, void *opaque)
     return 0;
 }
 
+static int fsdev_init_func(QemuOpts *opts, void *opaque)
+{
+    int ret;
+    ret = qemu_fsdev_add(opts);
+
+    return ret;
+}
+
 static int mon_init_func(QemuOpts *opts, void *opaque)
 {
     CharDriverState *chr;
@@ -4256,6 +4265,13 @@  int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_fsdev:
+                opts = qemu_opts_parse(&qemu_fsdev_opts, optarg, 1);
+                if (!opts) {
+                    fprintf(stderr, "parse error: %s\n", optarg);
+                    exit(1);
+                }
+                break;
             case QEMU_OPTION_serial:
                 add_device_config(DEV_SERIAL, optarg);
                 default_serial = 0;
@@ -4625,6 +4641,8 @@  int main(int argc, char **argv, char **envp)
 
     if (qemu_opts_foreach(&qemu_chardev_opts, chardev_init_func, NULL, 1) != 0)
         exit(1);
+    if (qemu_opts_foreach(&qemu_fsdev_opts, fsdev_init_func, NULL, 1) != 0)
+        exit(1);
 
 #ifndef _WIN32
     if (daemonize) {