qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 1/2] hw/9pfs: Add new virtfs option cache=writethrou


From: Aneesh Kumar K.V
Subject: [Qemu-devel] [PATCH 1/2] hw/9pfs: Add new virtfs option cache=writethrough to skip host page cache
Date: Fri, 7 Oct 2011 12:16:06 +0530

cache=writethrough implies the file are opened in the host with O_SYNC open flag

Signed-off-by: Aneesh Kumar K.V <address@hidden>
---
 fsdev/file-op-9p.h         |    1 +
 fsdev/qemu-fsdev.c         |   10 ++++++++--
 fsdev/qemu-fsdev.h         |    2 ++
 hw/9pfs/virtio-9p-device.c |    5 +++++
 hw/9pfs/virtio-9p.c        |   24 ++++++++++++++++++------
 qemu-config.c              |    6 ++++++
 qemu-options.hx            |   17 ++++++++++++-----
 vl.c                       |    6 ++++++
 8 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 8de8abf..5d088d4 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -59,6 +59,7 @@ typedef struct FsContext
     char *fs_root;
     SecModel fs_sm;
     uid_t uid;
+    int open_flags;
     struct xattr_operations **xops;
     /* fs driver specific data */
     void *private;
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index 768819f..fce016b 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -34,6 +34,8 @@ int qemu_fsdev_add(QemuOpts *opts)
     const char *fstype = qemu_opt_get(opts, "fstype");
     const char *path = qemu_opt_get(opts, "path");
     const char *sec_model = qemu_opt_get(opts, "security_model");
+    const char *cache = qemu_opt_get(opts, "cache");
+
 
     if (!fsdev_id) {
         fprintf(stderr, "fsdev: No id specified\n");
@@ -72,10 +74,14 @@ int qemu_fsdev_add(QemuOpts *opts)
     fsle->fse.path = g_strdup(path);
     fsle->fse.security_model = g_strdup(sec_model);
     fsle->fse.ops = FsTypes[i].ops;
-
+    fsle->fse.cache_model = 0;
+    if (cache) {
+        if (!strcmp(cache, "writethrough")) {
+            fsle->fse.cache_model = V9FS_WRITETHROUGH_CACHE;
+        }
+    }
     QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
     return 0;
-
 }
 
 FsTypeEntry *get_fsdev_fsentry(char *id)
diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h
index e04931a..4e53966 100644
--- a/fsdev/qemu-fsdev.h
+++ b/fsdev/qemu-fsdev.h
@@ -34,6 +34,7 @@ typedef struct FsTypeTable {
     FileOperations *ops;
 } FsTypeTable;
 
+#define V9FS_WRITETHROUGH_CACHE 0x1
 /*
  * Structure to store the various fsdev's passed through command line.
  */
@@ -41,6 +42,7 @@ typedef struct FsTypeEntry {
     char *fsdev_id;
     char *path;
     char *security_model;
+    int cache_model;
     FileOperations *ops;
 } FsTypeEntry;
 
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index e5b68da..a267f01 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -115,6 +115,11 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
         exit(1);
     }
 
+    if (fse->cache_model & V9FS_WRITETHROUGH_CACHE) {
+        s->ctx.open_flags = O_SYNC;
+    } else {
+        s->ctx.open_flags = 0;
+    }
     s->ctx.fs_root = g_strdup(fse->path);
     len = strlen(conf->tag);
     if (len > MAX_TAG_LEN) {
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c01c31a..1ca3c8e 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -80,6 +80,22 @@ void cred_init(FsCred *credp)
     credp->fc_rdev = -1;
 }
 
+static int get_dotl_openflags(V9fsState *s, int oflags)
+{
+    int flags;
+    /*
+     * Filter the client open flags
+     */
+    flags = s->ctx.open_flags;
+    flags |= oflags;
+    flags &= ~(O_NOCTTY | O_ASYNC | O_CREAT);
+    /*
+     * Ignore direct disk access hint until the server supports it.
+     */
+    flags &= ~O_DIRECT;
+    return flags;
+}
+
 void v9fs_string_init(V9fsString *str)
 {
     str->data = NULL;
@@ -1598,10 +1614,7 @@ static void v9fs_open(void *opaque)
         err = offset;
     } else {
         if (s->proto_version == V9FS_PROTO_2000L) {
-            flags = mode;
-            flags &= ~(O_NOCTTY | O_ASYNC | O_CREAT);
-            /* Ignore direct disk access hint until the server supports it. */
-            flags &= ~O_DIRECT;
+            flags = get_dotl_openflags(s, mode);
         } else {
             flags = omode_to_uflags(mode);
         }
@@ -1650,8 +1663,7 @@ static void v9fs_lcreate(void *opaque)
         goto out_nofid;
     }
 
-    /* Ignore direct disk access hint until the server supports it. */
-    flags &= ~O_DIRECT;
+    flags = get_dotl_openflags(pdu->s, flags);
     err = v9fs_co_open2(pdu, fidp, &name, gid,
                         flags | O_CREAT, mode, &stbuf);
     if (err < 0) {
diff --git a/qemu-config.c b/qemu-config.c
index 7a7854f..b2ab0b2 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -177,6 +177,9 @@ QemuOptsList qemu_fsdev_opts = {
         }, {
             .name = "security_model",
             .type = QEMU_OPT_STRING,
+        }, {
+            .name = "cache",
+            .type = QEMU_OPT_STRING,
         },
         { /*End of list */ }
     },
@@ -199,6 +202,9 @@ QemuOptsList qemu_virtfs_opts = {
         }, {
             .name = "security_model",
             .type = QEMU_OPT_STRING,
+        }, {
+            .name = "cache",
+            .type = QEMU_OPT_STRING,
         },
 
         { /*End of list */ }
diff --git a/qemu-options.hx b/qemu-options.hx
index dfbabd0..38f0aef 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -525,7 +525,8 @@ ETEXI
 DEFHEADING(File system options:)
 
 DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,
-    "-fsdev local,id=id,path=path,security_model=[mapped|passthrough|none]\n",
+    "-fsdev local,id=id,path=path,security_model=[mapped|passthrough|none]\n"
+    "       [,cache=writethrough]\n",
     QEMU_ARCH_ALL)
 
 STEXI
@@ -541,7 +542,7 @@ The specific Fstype will determine the applicable options.
 
 Options to each backend are described below.
 
address@hidden -fsdev local ,address@hidden ,address@hidden ,address@hidden
address@hidden -fsdev local ,address@hidden ,address@hidden 
,address@hidden,address@hidden
 
 Create a file-system-"device" for local-filesystem.
 
@@ -552,13 +553,17 @@ Create a file-system-"device" for local-filesystem.
 @option{security_model} specifies the security model to be followed.
 @option{security_model} is required.
 
address@hidden specifies whether to skip the host page cache.
address@hidden is an optional argument.
+
 @end table
 ETEXI
 
 DEFHEADING(Virtual File system pass-through options:)
 
 DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,
-    "-virtfs 
local,path=path,mount_tag=tag,security_model=[mapped|passthrough|none]\n",
+    "-virtfs 
local,path=path,mount_tag=tag,security_model=[mapped|passthrough|none]\n"
+    "        [,cache=writethrough]\n",
     QEMU_ARCH_ALL)
 
 STEXI
@@ -574,7 +579,7 @@ The specific Fstype will determine the applicable options.
 
 Options to each backend are described below.
 
address@hidden -virtfs local ,address@hidden ,address@hidden ,address@hidden
address@hidden -virtfs local ,address@hidden ,address@hidden 
,address@hidden,address@hidden
 
 Create a Virtual file-system-pass through for local-filesystem.
 
@@ -585,10 +590,12 @@ Create a Virtual file-system-pass through for 
local-filesystem.
 @option{security_model} specifies the security model to be followed.
 @option{security_model} is required.
 
-
 @option{mount_tag} specifies the tag with which the exported file is mounted.
 @option{mount_tag} is required.
 
address@hidden specifies whether to skip the host page cache.
address@hidden is an optional argument.
+
 @end table
 ETEXI
 
diff --git a/vl.c b/vl.c
index bd4a5ce..6760e39 100644
--- a/vl.c
+++ b/vl.c
@@ -2794,6 +2794,7 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_virtfs: {
                 QemuOpts *fsdev;
                 QemuOpts *device;
+                const char *cache;
 
                 olist = qemu_find_opts("virtfs");
                 if (!olist) {
@@ -2823,6 +2824,11 @@ int main(int argc, char **argv, char **envp)
                             qemu_opt_get(opts, "mount_tag"));
                     exit(1);
                 }
+
+                cache = qemu_opt_get(opts, "cache");
+                if (cache) {
+                    qemu_opt_set(fsdev, "cache", cache);
+                }
                 qemu_opt_set(fsdev, "fstype", qemu_opt_get(opts, "fstype"));
                 qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path"));
                 qemu_opt_set(fsdev, "security_model",
-- 
1.7.4.1




reply via email to

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