From patchwork Sat Mar 5 17:52:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 85546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5EDE11007DB for ; Sun, 6 Mar 2011 05:04:29 +1100 (EST) Received: from localhost ([127.0.0.1]:57375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pvvmy-0005Zt-6s for incoming@patchwork.ozlabs.org; Sat, 05 Mar 2011 13:01:12 -0500 Received: from [140.186.70.92] (port=38567 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pvvea-0000yh-VH for qemu-devel@nongnu.org; Sat, 05 Mar 2011 12:52:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PvveZ-0003rD-1A for qemu-devel@nongnu.org; Sat, 05 Mar 2011 12:52:32 -0500 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:38120) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PvveY-0003qq-8b for qemu-devel@nongnu.org; Sat, 05 Mar 2011 12:52:30 -0500 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp04.au.ibm.com (8.14.4/8.13.1) with ESMTP id p25Hkvl1019397 for ; Sun, 6 Mar 2011 04:46:57 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p25HqSfC2498656 for ; Sun, 6 Mar 2011 04:52:28 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p25HqSi6019494 for ; Sun, 6 Mar 2011 04:52:28 +1100 Received: from skywalker.ibm.com ([9.124.94.223]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p25HqGsL019428; Sun, 6 Mar 2011 04:52:27 +1100 From: "Aneesh Kumar K.V" To: qemu-devel@nongnu.org Date: Sat, 5 Mar 2011 23:22:12 +0530 Message-Id: <1299347533-17047-7-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1299347533-17047-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1299347533-17047-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 202.81.31.146 Cc: aliguori@us.ibm.com, "Aneesh Kumar K.V" Subject: [Qemu-devel] [PATCH -V3 7/8] hw/9pfs: Add new virtfs option cache=none to skip host page cache X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org cache=none implies the file are opened in the host with O_SYNC open flag Signed-off-by: Aneesh Kumar K.V --- 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);