qemu: Add opt_set_bool functionality
PATCH v3 2/2 hw/9pfs: Read-only support for 9p export
In reply to M. Mohan KumarA new fsdev parameter "readonly" is introduced to control accessing 9p export. "readonly" can be used to specify the access type. By default "rw" access is given to 9p export.
Signed-off-by M. Mohan Kumar <[email protected]>
--- fsdev/file-op-9p.h | 4 +++- fsdev/qemu-fsdev.c | 7 ++++++- hw/9pfs/virtio-9p.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-config.c | 7 +++++++ qemu-options.hx | 14 ++++++++++---- vl.c | 2 ++ 6 files changed, 78 insertions(+), 6 deletions(-)
fsdev/file-op-9p.h +3 -1
@@ -56,10 +56,12 @@ typedef struct extended_ops {* On failure ignore the error. */ #define V9FS_SM_NONE 0x00000010 - +#define V9FS_RDONLY 0x00000020#define V9FS_SEC_MASK 0x0000001C + + typedef struct FsContext { uid_t uid;
fsdev/qemu-fsdev.c +6 -1
@@ -35,7 +35,7 @@ int qemu_fsdev_add(QemuOpts *opts)const char *path =qemu_opt_get (opts,"path" );const char *sec_model =qemu_opt_get (opts,"security_model" );const char *writeout =qemu_opt_get (opts,"writeout" ); - +bool ro =qemu_opt_get_bool (opts,"readonly" ,0 );if (!fsdev_id) {fprintf (stderr,"fsdev: No id specified\n" );
@@ -86,6 +86,11 @@ int qemu_fsdev_add(QemuOpts *opts) fsle->fse.export_flags |=V9FS_IMMEDIATE_WRITEOUT ; } } +if (ro) { + fsle->fse.export_flags |=V9FS_RDONLY ; + }else { + fsle->fse.export_flags &= ~V9FS_RDONLY ; + }if (strcmp (fsdriver,"local" )) { goto done;
hw/9pfs/virtio-9p.c +50 -0
74 lines not on this page · raw message
qemu-config.c +7 -0
@@ -180,7 +180,11 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "writeout", .type = QEMU_OPT_STRING, + }, { + .name = "readonly", + .type = QEMU_OPT_BOOL, }, + {/*End of list */ } }, };
@@ -205,6 +209,9 @@ QemuOptsList qemu_virtfs_opts = { }, { .name = "writeout", .type = QEMU_OPT_STRING, + }, { + .name = "readonly", + .type = QEMU_OPT_BOOL, }, { /*End of list */ }
qemu-options.hx +10 -4
@@ -528,12 +528,12 @@ DEFHEADING(File system options:) DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev, "-fsdev fsdriver,id=id,path=path,[security_model={mapped|passthrough|none}]\n" - " [,writeout=immediate]\n", + " [,writeout=immediate][,readonly]\n", QEMU_ARCH_ALL) STEXI -@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}] +@item -fsdev @var{fsdriver},id=@var{id},path=@var{path},[security_model=@var{security_model}][,writeout=@var{writeout}][,readonly] @findex -fsdev Define a new file system device. Valid options are: @table @option
@@ -563,6 +563,9 @@ This is an optional argument. The only supported value is "immediate". This means that 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. +@item readonly +Enables exporting 9p share as a readonly mount for guests. By default +read-write access is given. @end table -fsdev option is used along with -device driver "virtio-9p-pci".
@@ -583,12 +586,12 @@ 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" - " [,writeout=immediate]\n", + " [,writeout=immediate][,readonly]\n", QEMU_ARCH_ALL) STEXI -@item -virtfs @var{fsdriver},path=@var{path},mount_tag=@var{mount_tag},security_model=@var{security_model}[,writeout=@var{writeout}] +@item -virtfs @var{fsdriver},path=@var{path},mount_tag=@var{mount_tag},security_model=@var{security_model}[,writeout=@var{writeout}][,readonly] @findex -virtfs The general form of a Virtual File system pass-through options are:
@@ -619,6 +622,9 @@ This is an optional argument. The only supported value is "immediate". This means that 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. +@item readonly +Enables exporting 9p share as a readonly mount for guests. By default +read-write access is given. @end table ETEXI
vl.c +2 -0
@@ -2827,6 +2827,8 @@ int main(int argc, char **argv, char **envp)qemu_opt_set (fsdev,"security_model" ,qemu_opt_get (opts,"security_model" )); +qemu_opt_set_bool (fsdev,"readonly" , +qemu_opt_get_bool (opts,"readonly" ,0 )); device =qemu_opts_create (qemu_find_opts ("device" ),NULL ,0 );qemu_opt_set (device,"driver" ,"virtio-9p-pci" ); qemu_opt_set(device, "fsdev",
Signature · 1 line
1.7.6
PATCH v3 1/2 qemu: Add opt_set_bool functionality
Signed-off-by M. Mohan Kumar <[email protected]>
---
Changes from previous version V2:
* qemu_opt_set_bool does not need to call qemu_opt_parse, because it supports only setting boolean types
Changes from previous version:
* Changed qemu_opt_{get|set}_bool to use 'bool' data type
qemu-option.c | 39 +++++++++++++++++++++++++++++++++++---- qemu-option.h | 3 ++- 2 files changed, 37 insertions(+), 5 deletions(-)
qemu-option.c +35 -4
@@ -168,7 +168,7 @@ QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,return NULL ; } -static int parse_option_bool (const char *name,const char *value,int *ret) +static int parse_option_bool (const char *name,const char *value,bool *ret) {if (value !=NULL ) {if (!strcmp (value,"on" )) {
@@ -258,7 +258,7 @@ static int parse_option_size(const char *name, const char *value, uint64_t *ret)int set_option_parameter (QEMUOptionParameter *list,const char *name,const char *value) { -int flag; +bool flag;// Find a matching parameter list =get_option_parameter (list, name);
@@ -508,7 +508,7 @@ struct QemuOpt {const QemuOptDesc *desc;union { -int boolean; +bool boolean;uint64_t uint; } value;
@@ -542,7 +542,7 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)return opt ? opt->str :NULL ; } -int qemu_opt_get_bool (QemuOpts *opts,const char *name,int defval) +bool qemu_opt_get_bool (QemuOpts *opts,const char *name,bool defval) {QemuOpt *opt =qemu_opt_find (opts, name);
@@ -636,6 +636,37 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)return 0 ; } +int qemu_opt_set_bool (QemuOpts *opts,const char *name,bool val) +{ +QemuOpt *opt; +const QemuOptDesc *desc = opts->list->desc; +int i; + +for (i =0 ; desc[i].name !=NULL ; i++) { +if (strcmp (desc[i].name, name) ==0 ) { +break ; + } + } +if (desc[i].name ==NULL ) { +if (i ==0 ) { +/* empty list -> allow any */ ; + }else { +qerror_report (QERR_INVALID_PARAMETER , name); +return -1 ; + } + } + + opt =g_malloc0 (sizeof (*opt)); + opt->name =g_strdup (name); + opt->opts = opts; +QTAILQ_INSERT_TAIL (&opts->head, opt, next); +if (desc[i].name !=NULL ) { + opt->desc = desc+i; + } + opt->value.boolean = !!val; +return 0 ; +} +int qemu_opt_foreach (QemuOpts *opts,qemu_opt_loopfunc func,void *opaque,int abort_on_failure) {
qemu-option.h +2 -1
@@ -105,10 +105,11 @@ struct QemuOptsList { };const char *qemu_opt_get (QemuOpts *opts,const char *name); -int qemu_opt_get_bool (QemuOpts *opts,const char *name,int defval); +bool qemu_opt_get_bool (QemuOpts *opts,const char *name,bool defval);uint64_t qemu_opt_get_number (QemuOpts *opts,const char *name,uint64_t defval);uint64_t qemu_opt_get_size (QemuOpts *opts,const char *name,uint64_t defval);int qemu_opt_set (QemuOpts *opts,const char *name,const char *value); +int qemu_opt_set_bool (QemuOpts *opts,const char *name,bool val);typedef int (*qemu_opt_loopfunc )(const char *name,const char *value,void *opaque);int qemu_opt_foreach (QemuOpts *opts,qemu_opt_loopfunc func,void *opaque,int abort_on_failure);
Signature · 1 line
1.7.6