qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH -V3 7/8] hw/9pfs: Add new virtfs option cache=none to skip host page cache
Date: Sat,  5 Mar 2011 23:22:12 +0530	[thread overview]
Message-ID: <1299347533-17047-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com> (raw)
In-Reply-To: <1299347533-17047-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

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

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fsdev/qemu-fsdev.c  |    8 +++++++-
 fsdev/qemu-fsdev.h  |    1 +
 hw/9pfs/virtio-9p.c |   17 ++++++++++++-----
 hw/file-op-9p.h     |    1 +
 qemu-config.c       |    6 ++++++
 qemu-options.hx     |   17 ++++++++++++-----
 vl.c                |   23 +++++++++++++++++++----
 7 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index 0b33290..d803d47 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -33,6 +33,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");
@@ -71,10 +73,14 @@ int qemu_fsdev_add(QemuOpts *opts)
     fsle->fse.path = qemu_strdup(path);
     fsle->fse.security_model = qemu_strdup(sec_model);
     fsle->fse.ops = FsTypes[i].ops;
+    if (cache) {
+        fsle->fse.cache = qemu_strdup(cache);
+    } else {
+        fsle->fse.cache = NULL;
+    }
 
     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 a704043..d3a0fac 100644
--- a/fsdev/qemu-fsdev.h
+++ b/fsdev/qemu-fsdev.h
@@ -41,6 +41,7 @@ typedef struct FsTypeEntry {
     char *fsdev_id;
     char *path;
     char *security_model;
+    char *cache;
     FileOperations *ops;
 } FsTypeEntry;
 
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 293a562..75df1a1 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -70,17 +70,18 @@ static int omode_to_uflags(int8_t mode)
     return ret;
 }
 
-static int get_dotl_openflags(int oflags)
+static int get_dotl_openflags(V9fsState *s, int oflags)
 {
     int flags;
     /*
      * Since we can share the fd between multiple fids,
      * open the file in read write mode
      */
+    flags = s->ctx.open_flags;
     if ((oflags & O_ACCMODE) != O_RDONLY) {
-        flags = O_RDWR;
+        flags |= O_RDWR;
     } else {
-        flags = O_RDONLY;
+        flags |= O_RDONLY;
     }
     /*
      * If the client asked for any of the below flags we
@@ -1856,7 +1857,7 @@ static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
         v9fs_open_post_opendir(s, vs, err);
     } else {
         if (s->proto_version == V9FS_PROTO_2000L) {
-            flags = get_dotl_openflags(vs->mode);
+            flags = get_dotl_openflags(s, vs->mode);
         } else {
             flags = omode_to_uflags(vs->mode);
         }
@@ -1987,7 +1988,7 @@ static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu)
     v9fs_string_sprintf(&vs->fullname, "%s/%s", vs->fidp->fsmap.path.data,
              vs->name.data);
 
-    flags = get_dotl_openflags(flags);
+    flags = get_dotl_openflags(s, flags);
     vs->fidp->fsmap.fs.fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid,
                                           gid, flags | O_CREAT, mode);
     vs->fidp->fsmap.open_flags = flags;
@@ -3912,6 +3913,12 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
         exit(1);
     }
 
+    if (fse->cache && !strcmp(fse->cache, "none")) {
+        s->ctx.open_flags = O_SYNC;
+    } else {
+        s->ctx.open_flags = 0;
+    }
+
     s->ctx.fs_root = qemu_strdup(fse->path);
     len = strlen(conf->tag);
     if (len > MAX_TAG_LEN) {
diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index e306305..8577020 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -54,6 +54,7 @@ typedef struct FsContext
     char *fs_root;
     SecModel fs_sm;
     uid_t uid;
+    int open_flags;
     struct xattr_operations **xops;
 } FsContext;
 
diff --git a/qemu-config.c b/qemu-config.c
index 965fa46..4d87a39 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -165,6 +165,9 @@ QemuOptsList qemu_fsdev_opts = {
         }, {
             .name = "security_model",
             .type = QEMU_OPT_STRING,
+        }, {
+            .name = "cache",
+            .type = QEMU_OPT_STRING,
         },
         { /*End of list */ }
     },
@@ -187,6 +190,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 898561d..ad27bf0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -486,7 +486,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=none]\n",
     QEMU_ARCH_ALL)
 
 STEXI
@@ -502,7 +503,7 @@ The specific Fstype will determine the applicable options.
 
 Options to each backend are described below.
 
-@item -fsdev local ,id=@var{id} ,path=@var{path} ,security_model=@var{security_model}
+@item -fsdev local ,id=@var{id} ,path=@var{path} ,security_model=@var{security_model}[,cache=@var{cache}]
 
 Create a file-system-"device" for local-filesystem.
 
@@ -513,13 +514,17 @@ Create a file-system-"device" for local-filesystem.
 @option{security_model} specifies the security model to be followed.
 @option{security_model} is required.
 
+@option{cache} specifies whether to skip the host page cache.
+@option{cache} 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=none]\n",
     QEMU_ARCH_ALL)
 
 STEXI
@@ -535,7 +540,7 @@ The specific Fstype will determine the applicable options.
 
 Options to each backend are described below.
 
-@item -virtfs local ,path=@var{path} ,mount_tag=@var{mount_tag} ,security_model=@var{security_model}
+@item -virtfs local ,path=@var{path} ,mount_tag=@var{mount_tag} ,security_model=@var{security_model}[,cache=@var{cache}]
 
 Create a Virtual file-system-pass through for local-filesystem.
 
@@ -546,10 +551,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.
 
+@option{cache} specifies whether to skip the host page cache.
+@option{cache} is an optional argument.
+
 @end table
 ETEXI
 
diff --git a/vl.c b/vl.c
index 14255c4..5c76ece 100644
--- a/vl.c
+++ b/vl.c
@@ -2379,6 +2379,8 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
             case QEMU_OPTION_virtfs: {
+                const char *cache;
+                char *arg_cache = NULL;
                 char *arg_fsdev = NULL;
                 char *arg_9p = NULL;
                 int len = 0;
@@ -2404,7 +2406,18 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
 
+                cache = qemu_opt_get(opts, "cache");
+                if (cache) {
+                    len = strlen(",cache=");
+                    len += strlen(cache);
+                    arg_cache = qemu_malloc(len+1);
+                    snprintf(arg_cache, (len+1), ",cache=%s", cache);
+                } else {
+                    arg_cache = (char *)"";
+                }
+
                 len = strlen(",id=,path=,security_model=");
+                len += strlen(arg_cache);
                 len += strlen(qemu_opt_get(opts, "fstype"));
                 len += strlen(qemu_opt_get(opts, "mount_tag"));
                 len += strlen(qemu_opt_get(opts, "path"));
@@ -2412,20 +2425,22 @@ int main(int argc, char **argv, char **envp)
                 arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev));
 
                 snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev),
-                         "%s,id=%s,path=%s,security_model=%s",
+                         "%s,id=%s,path=%s,security_model=%s%s",
                          qemu_opt_get(opts, "fstype"),
                          qemu_opt_get(opts, "mount_tag"),
                          qemu_opt_get(opts, "path"),
-                         qemu_opt_get(opts, "security_model"));
+                         qemu_opt_get(opts, "security_model"),
+                         arg_cache);
 
                 len = strlen("virtio-9p-pci,fsdev=,mount_tag=");
                 len += 2*strlen(qemu_opt_get(opts, "mount_tag"));
                 arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p));
 
                 snprintf(arg_9p, (len + 1) * sizeof(*arg_9p),
-                         "virtio-9p-pci,fsdev=%s,mount_tag=%s",
+                         "virtio-9p-pci,fsdev=%s,mount_tag=%s%s",
+                         qemu_opt_get(opts, "mount_tag"),
                          qemu_opt_get(opts, "mount_tag"),
-                         qemu_opt_get(opts, "mount_tag"));
+                         arg_cache);
 
                 if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) {
                     fprintf(stderr, "parse error [fsdev]: %s\n", optarg);
-- 
1.7.1

  parent reply	other threads:[~2011-03-05 17:52 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-05 17:52 [Qemu-devel] [PATCH -V3 1/8] hw/9pfs: Add V9fsfidmap in preparation for adding fd reclaim Aneesh Kumar K.V
2011-03-05 17:52 ` [Qemu-devel] [PATCH -V3 2/8] hw/9pfs: Add file descriptor reclaim support Aneesh Kumar K.V
2011-03-13 16:08   ` Stefan Hajnoczi
2011-03-13 18:57     ` Aneesh Kumar K. V
2011-03-14 10:13       ` Stefan Hajnoczi
2011-03-15  8:35         ` Aneesh Kumar K. V
2011-03-05 17:52 ` [Qemu-devel] [PATCH -V3 3/8] hw/9pfs: Use v9fs_do_close instead of close Aneesh Kumar K.V
2011-03-13 16:10   ` Stefan Hajnoczi
2011-03-13 18:58     ` Aneesh Kumar K. V
2011-03-05 17:52 ` [Qemu-devel] [PATCH -V3 4/8] hw/9pfs: Implement syncfs Aneesh Kumar K.V
2011-03-13 16:24   ` Stefan Hajnoczi
2011-03-13 18:59     ` Aneesh Kumar K. V
2011-03-05 17:52 ` [Qemu-devel] [PATCH -V3 5/8] hw/9pfs: Add open flag to fid Aneesh Kumar K.V
2011-03-13 16:38   ` Stefan Hajnoczi
2011-03-13 19:01     ` Aneesh Kumar K. V
2011-03-05 17:52 ` [Qemu-devel] [PATCH -V3 6/8] hw/9pfs: Add directory reclaim support Aneesh Kumar K.V
2011-03-13 16:42   ` Stefan Hajnoczi
2011-03-13 19:02     ` Aneesh Kumar K. V
2011-03-05 17:52 ` Aneesh Kumar K.V [this message]
2011-03-13 17:23   ` [Qemu-devel] [PATCH -V3 7/8] hw/9pfs: Add new virtfs option cache=none to skip host page cache Stefan Hajnoczi
2011-03-13 19:04     ` Aneesh Kumar K. V
2011-03-13 20:57       ` Stefan Hajnoczi
2011-03-15  8:36         ` Aneesh Kumar K. V
2011-03-14 10:20       ` Stefan Hajnoczi
2011-03-15  9:19         ` Aneesh Kumar K. V
2011-03-15 11:11           ` Stefan Hajnoczi
2011-03-15 12:30             ` Aneesh Kumar K. V
2011-03-16  8:59               ` Stefan Hajnoczi
2011-03-05 17:52 ` [Qemu-devel] [PATCH -V3 8/8] hw/9pfs: Skip file system sync if we have specified cache=none option Aneesh Kumar K.V
2011-03-13 15:46 ` [Qemu-devel] [PATCH -V3 1/8] hw/9pfs: Add V9fsfidmap in preparation for adding fd reclaim Stefan Hajnoczi
2011-03-13 19:06   ` Aneesh Kumar K. V
2011-03-13 20:53     ` Stefan Hajnoczi
2011-03-14 10:23       ` Stefan Hajnoczi
2011-03-15  9:20       ` Aneesh Kumar K. V
2011-03-15 10:38         ` Stefan Hajnoczi
2011-03-15 12:27           ` Aneesh Kumar K. V

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299347533-17047-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com \
    --to=aneesh.kumar@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).