hw/9pfs: Add new virtfs option cache=writethrough to skip host page cache
PATCH 1/2 hw/9pfs: Add new virtfs option cache=writethrough to skip host page cache
cache=writethrough implies the file are opened in the host with O_SYNC open flag
--- fsdev/file-op-9p.h | 1 + fsdev/qemu-fsdev.c | 10 ++++++++-- fsdev/qemu-fsdev.h | 2 ++ hw/9pfs/virtio-9p-device.c | 6 ++++++ hw/9pfs/virtio-9p.c | 28 ++++++++++++++++++++-------- qemu-config.c | 6 ++++++ qemu-options.hx | 17 ++++++++++++----- vl.c | 6 ++++++ 8 files changed, 61 insertions(+), 15 deletions(-)
fsdev/file-op-9p.h +1 -0
@@ -54,6 +54,7 @@ typedef struct FsContextchar *fs_root;SecModel fs_sm;uid_t uid; +int open_flags;struct xattr_operations **xops; } FsContext;
fsdev/qemu-fsdev.c +8 -2
@@ -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; - + 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)
fsdev/qemu-fsdev.h +2 -0
@@ -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;
hw/9pfs/virtio-9p-device.c +6 -0
@@ -114,6 +114,12 @@ 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 =qemu_strdup (fse->path); len =strlen (conf->tag);if (len >MAX_TAG_LEN ) {
hw/9pfs/virtio-9p.c +20 -8
@@ -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; +} +static void v9fs_string_init (V9fsString *str) { str->data =NULL ;
@@ -1540,10 +1556,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); }
@@ -1596,10 +1609,9 @@ static void v9fs_lcreate(void *opaque) }v9fs_string_sprintf (&fullname,"%s/%s" , fidp->path.data, name.data); -/* Ignore direct disk access hint until the server supports it. */ - flags &= ~O_DIRECT ; - - err =v9fs_co_open2 (pdu->s, fidp, fullname.data, gid, flags, mode); + flags =get_dotl_openflags (pdu->s, flags); + err =v9fs_co_open2 (pdu->s, fidp, fullname.data, gid, + flags |O_CREAT , mode);if (err <0 ) { goto out; }
qemu-config.c +6 -0
@@ -170,6 +170,9 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "security_model", .type = QEMU_OPT_STRING, + }, { + .name = "cache", + .type = QEMU_OPT_STRING, }, {/*End of list */ } },
@@ -192,6 +195,9 @@ QemuOptsList qemu_virtfs_opts = { }, { .name = "security_model", .type = QEMU_OPT_STRING, + }, { + .name = "cache", + .type = QEMU_OPT_STRING, }, { /*End of list */ }
qemu-options.hx +12 -5
@@ -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=writethrough]\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=writethrough]\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
vl.c +6 -0
@@ -2541,6 +2541,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) {
@@ -2570,6 +2571,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",
Signature · 1 line
1.7.4.1
PATCH 2/2 qemu-options.hx: Update virtfs command documentation
Clarify the virtfs option better
--- qemu-options.hx | 116 ++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 72 insertions(+), 44 deletions(-)
qemu-options.hx +72 -44
@@ -483,6 +483,8 @@ possible drivers and properties, use @code{-device ?} and @code{-device @var{driver},?}. ETEXI +DEFHEADING() + DEFHEADING(File system options:) DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,
@@ -492,34 +494,54 @@ DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, STEXI -The general form of a File system device option is: -@table @option - @item -fsdev @var{fstype} ,id=@var{id} [,@var{options}] @findex -fsdev -Fstype is one of: -@option{local}, -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}[,cache=@var{cache}] - -Create a file-system-"device" for local-filesystem. -@option{local} is only available on Linux. - -@option{path} specifies the path to be exported. @option{path} is required. +Define a new file system device. Valid options are +@table @option +@item local +This option create a file-system-"device" for local-filesystem. +Currently only local file system device is supported. +@item id=@var{id} +Identifier for this device +@item path=@var{path} +This option define the export path for the file system device. +Files below this path will be available for 9p client on the +guest. +@item security_model=@var{security_model} +This option define the security model to be used when exporting +the files. The supported security models are passthrough, mapped +and none. In passthrough security model, file are stored using +the same credentials as they are created on the guest. This require +qemu to run as root. In the mapped security model, some of the +file attributes like uid, gid, mode bits and link target are +stored as file attributes. Directories exported by this security +model cannot interact with other unix tools. "none" security model +is same as passthrough expect they won't report failures if +the sever fails to set file attributes like ownership. +@item cache=@var{cache} +This is an optional argument. The support value is writethrough +This means thatthe host page cache will be used to read and write +data but write notification will be sent to the guest only when +the data has been reported as written by the storage subsystem. -@option{security_model} specifies the security model to be followed. -@option{security_model} is required. +@end table -@option{cache} specifies whether to skip the host page cache. -@option{cache} is an optional argument. +-fsdev option is used along with -device driver "virtio-9p-pci" +Option for virtio-9p-pci driver are +@table @option +@item fsdev=@var{id} +This option specify the @var{id} value specified along with -fsdev option +@item mount_tag=@var{mount_tag} +This option specifies the tag name to be used by the guest +to mount this export point @end table + ETEXI +DEFHEADING() + DEFHEADING(Virtual File system pass-through options:) DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,
@@ -529,33 +551,39 @@ DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, STEXI -The general form of a Virtual File system pass-through option is: -@table @option - -@item -virtfs @var{fstype} [,@var{options}] -@findex -virtfs -Fstype is one of: -@option{local}, -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}[,cache=@var{cache}] +@findex -virtfs -Create a Virtual file-system-pass through for local-filesystem. - -@option{local} is only available on Linux. - -@option{path} specifies the path to be exported. @option{path} is required. - -@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. +The general form of a Virtual File system pass-through option is: +@table @option +@item local +This option create a file-system-"device" for local-filesystem. +Currently only local file system device is supported. +@item id=@var{id} +Identifier for this device +@item path=@var{path} +This option define the export path for the file system device. +Files below this path will be available for 9p client on the +guest. +@item mount_tag=@var{mount_tag} +This option specifies the tag name to be used by the guest +to mount this export point +@item security_model=@var{security_model} +This option define the security model to be used when exporting +the files. The supported security models are passthrough, mapped +and none. In passthrough security model, file are stored using +the same credentials as they are created on the guest. This require +qemu to run as root. In the mapped security model, some of the +file attributes like uid, gid, mode bits and link target are +stored as file attributes. Directories exported by this security +model cannot interact with other unix tools. "none" security model +is same as passthrough expect they won't report failures if +the sever fails to set file attributes like ownership. +@item cache=@var{cache} +This is an optional argument. The support value is writethrough +This means thatthe host page cache will be used to read and write +data but write notification will be sent to the guest only when +the data has been reported as written by the storage subsystem. @end table ETEXI
Signature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH 2/2] qemu-options.hx: Update virtfs command documentation
Quoted 53 lines · Aneesh Kumar K.V
Clarify the virtfs option better
Signed-off-by Aneesh Kumar K.V <[email protected]>--- qemu-options.hx | 116 ++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 72 insertions(+), 44 deletions(-)qemu-options.hx +13
-15@@ -483,6 +483,8 @@ possible drivers and properties, use @code{-device ?} and @code{-device @var{driver},?}. ETEXI +DEFHEADING() + DEFHEADING(File system options:) DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,@@ -492,34 +494,54 @@ DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, STEXI -The general form of a File system device option is: -@table @option - @item -fsdev @var{fstype} ,id=@var{id} [,@var{options}] @findex -fsdev -Fstype is one of: -@option{local}, -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}[,cache=@var{cache}] - -Create a file-system-"device" for local-filesystem. -@option{local} is only available on Linux. - -@option{path} specifies the path to be exported. @option{path} is required. +Define a new file system device. Valid options are +@table @option +@item local +This option create a file-system-"device" for local-filesystem. +Currently only local file system device is supported. +@item id=@var{id} +Identifier for this device +@item path=@var{path} +This option define the export path for the file system device. +Files below this path will be available for 9p client on the +guest.
qemu-options.hx DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, · line 520
Quoted 10 lines
qemu-options.hx +10
-0+@item security_model=@var{security_model} +This option define the security model to be used when exporting +the files. The supported security models are passthrough, mapped +and none. In passthrough security model, file are stored using +the same credentials as they are created on the guest. This require +qemu to run as root. In the mapped security model, some of the +file attributes like uid, gid, mode bits and link target are +stored as file attributes. Directories exported by this security +model cannot interact with other unix tools. "none" security model +is same as passthrough expect they won't report failures if
"expect"? "except"?
qemu-options.hx DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, · line 523
Quoted 3 lines
qemu-options.hx +3
-0+the sever fails to set file attributes like ownership. +@item cache=@var{cache} +This is an optional argument. The support value is writethrough
"The support value"? "The only supported value"?
qemu-options.hx DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, · line 524
Quoted 1 line
qemu-options.hx +1
-0+This means thatthe host page cache will be used to read and write
"thatthe" Use a spell-checker, please.
qemu-options.hx DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, · line 531
Quoted 11 lines
qemu-options.hx +5
-4+data but write notification will be sent to the guest only when +the data has been reported as written by the storage subsystem. -@option{security_model} specifies the security model to be followed. -@option{security_model} is required. +@end table -@option{cache} specifies whether to skip the host page cache. -@option{cache} is an optional argument. +-fsdev option is used along with -device driver "virtio-9p-pci" +Option for virtio-9p-pci driver are
Options (plural).
Quoted 68 lines
qemu-options.hx +30
-25+@table @option +@item fsdev=@var{id} +This option specify the @var{id} value specified along with -fsdev option +@item mount_tag=@var{mount_tag} +This option specifies the tag name to be used by the guest +to mount this export point @end table + ETEXI +DEFHEADING() + DEFHEADING(Virtual File system pass-through options:) DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,@@ -529,33 +551,39 @@ DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, STEXI -The general form of a Virtual File system pass-through option is: -@table @option - -@item -virtfs @var{fstype} [,@var{options}] -@findex -virtfs -Fstype is one of: -@option{local}, -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}[,cache=@var{cache}] +@findex -virtfs -Create a Virtual file-system-pass through for local-filesystem. - -@option{local} is only available on Linux. - -@option{path} specifies the path to be exported. @option{path} is required. - -@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. +The general form of a Virtual File system pass-through option is: +@table @option +@item local +This option create a file-system-"device" for local-filesystem. +Currently only local file system device is supported. +@item id=@var{id} +Identifier for this device +@item path=@var{path} +This option define the export path for the file system device. +Files below this path will be available for 9p client on the +guest. +@item mount_tag=@var{mount_tag} +This option specifies the tag name to be used by the guest +to mount this export point +@item security_model=@var{security_model} +This option define the security model to be used when exporting +the files. The supported security models are passthrough, mapped +and none. In passthrough security model, file are stored using +the same credentials as they are created on the guest. This require +qemu to run as root. In the mapped security model, some of the
qemu-options.hx DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs, · line 586
Quoted 10 lines
qemu-options.hx +10
-0+file attributes like uid, gid, mode bits and link target are +stored as file attributes. Directories exported by this security +model cannot interact with other unix tools. "none" security model +is same as passthrough expect they won't report failures if +the sever fails to set file attributes like ownership. +@item cache=@var{cache} +This is an optional argument. The support value is writethrough +This means thatthe host page cache will be used to read and write +data but write notification will be sent to the guest only when +the data has been reported as written by the storage subsystem.
Same typos as above.
Quoted 3 lines
qemu-options.hx +0
-0@end table ETEXI