Add opt_set_bool function
PATCH 1/2 Add opt_set_bool function
In addition to qemu_opt_set function, we need a function to set bool value also.
--- qemu-option.c | 35 +++++++++++++++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 36 insertions(+), 0 deletions(-)
qemu-option.c +35 -0
@@ -636,6 +636,41 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)return 0 ; } +int qemu_opt_set_bool (QemuOpts *opts,const char *name,int 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; +if (qemu_opt_parse (opt) <0 ) { +qemu_opt_del (opt); +return -1 ; + } +return 0 ; +} +int qemu_opt_foreach (QemuOpts *opts,qemu_opt_loopfunc func,void *opaque,int abort_on_failure) {
qemu-option.h +1 -0
@@ -109,6 +109,7 @@ int qemu_opt_get_bool(QemuOpts *opts, const char *name, int 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,int 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
PATCH v4 2/2 hw/9pfs: Add readonly support for 9p export
A new fsdev parameter "readonly" is introduced to control accessing 9p export. readonly=on|off can be used to specify the access type. By default rw access is given.
---
Changes from previous version V3:
* Use opt_set_bool function to set readonly option
* Change the flag from MS_READONLY to 9p specific
Change from previous version V2:
* QEMU_OPT_BOOL is used for readdonly parameter
Changes from previous version:
* Use "readonly" option instead of "access"
* Change function return type to boolean where its needed
fsdev/file-op-9p.h | 3 +- fsdev/qemu-fsdev.c | 12 +++++++++- fsdev/qemu-fsdev.h | 1 + hw/9pfs/virtio-9p-device.c | 3 ++ hw/9pfs/virtio-9p.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ qemu-config.c | 7 ++++++ vl.c | 2 + 7 files changed, 71 insertions(+), 3 deletions(-)
fsdev/file-op-9p.h +2 -1
@@ -58,7 +58,8 @@ typedef struct extended_ops { } extended_ops;/* FsContext flag values */ -#define PATHNAME_FSCONTEXT 0x1 +#define PATHNAME_FSCONTEXT 0x1 +#define P9_RDONLY_EXPORT 0x2/* cache flags */ #define V9FS_WRITETHROUGH_CACHE 0x1
fsdev/qemu-fsdev.c +10 -2
@@ -29,13 +29,13 @@ static FsTypeTable FsTypes[] = {int qemu_fsdev_add (QemuOpts *opts) {struct FsTypeListEntry *fsle; -int i; +int i, flags =0 ;const char *fsdev_id =qemu_opts_id (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" ); - +int rdonly =qemu_opt_get_bool (opts,"readonly" ,0 );if (!fsdev_id) {fprintf (stderr,"fsdev: No id specified\n" );
@@ -76,6 +76,14 @@ int qemu_fsdev_add(QemuOpts *opts) fsle->fse.cache_flags =V9FS_WRITETHROUGH_CACHE ; } } +if (rdonly) { + flags |=P9_RDONLY_EXPORT ; + }else { + flags &= ~P9_RDONLY_EXPORT ; + } + + fsle->fse.flags = flags; +QTAILQ_INSERT_TAIL (&fstype_entries, fsle, next);return 0 ; }
fsdev/qemu-fsdev.h +1 -0
@@ -44,6 +44,7 @@ typedef struct FsTypeEntry {char *security_model;int cache_flags;FileOperations *ops; +int flags; } FsTypeEntry; typedef struct FsTypeListEntry {
hw/9pfs/virtio-9p-device.c +3 -0
@@ -125,6 +125,9 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) s->tag_len = len; s->ctx.uid =-1 ; s->ctx.flags =0 ; +if (fse->flags &P9_RDONLY_EXPORT ) { + s->ctx.flags |=P9_RDONLY_EXPORT ; + } s->ops = fse->ops; s->vdev.get_features = virtio_9p_get_features;
hw/9pfs/virtio-9p.c +46 -0
70 lines not on this page · raw message
qemu-config.c +7 -0
@@ -180,7 +180,11 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "cache", .type = QEMU_OPT_STRING, + }, { + .name = "readonly", + .type = QEMU_OPT_BOOL, }, + {/*End of list */ } }, };
@@ -205,6 +209,9 @@ QemuOptsList qemu_virtfs_opts = { }, { .name = "cache", .type = QEMU_OPT_STRING, + }, { + .name = "readonly", + .type = QEMU_OPT_BOOL, }, { /*End of list */ }
vl.c +2 -0
@@ -2848,6 +2848,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
Re: [Qemu-devel] [PATCH V4 2/2] hw/9pfs: Add readonly support for 9p export
Quoted 31 lines · M. Mohan Kumar
A new fsdev parameter "readonly" is introduced to control accessing 9p export. readonly=on|off can be used to specify the access type. By default rw access is given.
Signed-off-by M. Mohan Kumar <[email protected]>---
Changes from previous version V3:
* Useopt_set_boolfunction to set readonly option
* Change the flag fromMS_READONLYto 9p specificChange from previous version V2:
*QEMU_OPT_BOOLis used for readdonly parameterChanges from previous version:
* Use "readonly" option instead of "access"
* Change function return type to boolean where its neededfsdev/file-op-9p.h | 3 +- fsdev/qemu-fsdev.c | 12 +++++++++- fsdev/qemu-fsdev.h | 1 + hw/9pfs/virtio-9p-device.c | 3 ++ hw/9pfs/virtio-9p.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ qemu-config.c | 7 ++++++ vl.c | 2 + 7 files changed, 71 insertions(+), 3 deletions(-)fsdev/file-op-9p.h +0
-0
fsdev/file-op-9p.h typedef struct extended_ops { · line 61
Quoted 5 lines
fsdev/file-op-9p.h +1
-1@@ -58,7 +58,8 @@ typedef struct extended_ops { } extended_ops;/* FsContext flag values */ -#define PATHNAME_FSCONTEXT 0x1 +#define PATHNAME_FSCONTEXT 0x1
why ?
Quoted 44 lines
fsdev/file-op-9p.h +1
-0+#define P9_RDONLY_EXPORT 0x2/* cache flags */ #define V9FS_WRITETHROUGH_CACHE 0x1fsdev/qemu-fsdev.c +10
-2@@ -29,13 +29,13 @@ static FsTypeTable FsTypes[] = {int qemu_fsdev_add (QemuOpts *opts) {struct FsTypeListEntry *fsle; -int i; +int i, flags =0 ;const char *fsdev_id =qemu_opts_id (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" ); - +int rdonly =qemu_opt_get_bool (opts,"readonly" ,0 );if (!fsdev_id) {fprintf (stderr,"fsdev: No id specified\n" );@@ -76,6 +76,14 @@ int qemu_fsdev_add(QemuOpts *opts) fsle->fse.cache_flags =V9FS_WRITETHROUGH_CACHE ; } } +if (rdonly) { + flags |=P9_RDONLY_EXPORT ; + }else { + flags &= ~P9_RDONLY_EXPORT ; + } + + fsle->fse.flags = flags; +QTAILQ_INSERT_TAIL (&fstype_entries, fsle, next);return 0 ; }fsdev/qemu-fsdev.h +0
-0
fsdev/qemu-fsdev.h typedef struct FsTypeEntry { · line 47
Quoted 4 lines
fsdev/qemu-fsdev.h +1
-0@@ -44,6 +44,7 @@ typedef struct FsTypeEntry {char *security_model;int cache_flags;FileOperations *ops; +int flags;
do we need extra flags ? Why not use cache_flags ? renaming that to export_flags ?
Quoted 35 lines
fsdev/qemu-fsdev.h +0
-0} FsTypeEntry; typedef struct FsTypeListEntry {hw/9pfs/virtio-9p-device.c +3
-0@@ -125,6 +125,9 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) s->tag_len = len; s->ctx.uid =-1 ; s->ctx.flags =0 ; +if (fse->flags &P9_RDONLY_EXPORT ) { + s->ctx.flags |=P9_RDONLY_EXPORT ; + } s->ops = fse->ops; s->vdev.get_features = virtio_9p_get_features;hw/9pfs/virtio-9p.c +5
-0@@ -1271,6 +1271,11 @@ static void v9fs_fix_path(V9fsPath *dst, V9fsPath *src, int len) dst->size++; } +static inline bool is_ro_export (FsContext *fs_ctx) +{ +return fs_ctx->flags &P9_RDONLY_EXPORT ; +} +static void v9fs_version (void *opaque) {V9fsPDU *pdu = opaque;@@ -1690,6 +1695,14 @@ static void v9fs_open(void *opaque) }else {
hw/9pfs/virtio-9p.c static void v9fs_open(void *opaque) · line 1705
Quoted 10 lines
hw/9pfs/virtio-9p.c +8
-0flags =omode_to_uflags (mode); } +if (is_ro_export (&s->ctx)) { +if (mode &O_WRONLY || mode &O_RDWR || mode &O_APPEND ) { + err = -EROFS ; + goto out; + }else { + flags |=O_NOATIME ; + } + }
What about O_TRUNC ?
hw/9pfs/virtio-9p.c static void v9fs_op_not_supp(void *opaque) · line 3316
Quoted 7 lines
hw/9pfs/virtio-9p.c +0
-0err =v9fs_co_open (pdu, fidp, flags);if (err <0 ) { goto out;@@ -3301,6 +3314,33 @@ static void v9fs_op_not_supp(void *opaque)complete_pdu (pdu->s, pdu, -EOPNOTSUPP ); }
-aneesh
Re: [Qemu-devel] [PATCH V4 2/2] hw/9pfs: Add readonly support for 9p export
Quoted 1 line · Aneesh Kumar K.V
On Wed, 12 Oct 2011 13:23:34 +0530, "M. Mohan Kumar" <[email protected]>
Quoted 33 lines · wrote:
Quoted 33 lines
A new fsdev parameter "readonly" is introduced to control accessing 9p export. readonly=on|off can be used to specify the access type. By default rw access is given.
Signed-off-by M. Mohan Kumar <[email protected]>---
Changes from previous version V3:
* Useopt_set_boolfunction to set readonly option
* Change the flag fromMS_READONLYto 9p specificChange from previous version V2:
*QEMU_OPT_BOOLis used for readdonly parameterChanges from previous version:
* Use "readonly" option instead of "access"
* Change function return type to boolean where its neededfsdev/file-op-9p.h | 3 +- fsdev/qemu-fsdev.c | 12 +++++++++- fsdev/qemu-fsdev.h | 1 + hw/9pfs/virtio-9p-device.c | 3 ++ hw/9pfs/virtio-9p.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ qemu-config.c | 7 ++++++ vl.c | 2 + 7 files changed, 71 insertions(+), 3 deletions(-)fsdev/file-op-9p.h +0
-0@@ -58,7 +58,8 @@ typedef struct extended_ops {
Quoted 8 lines
fsdev/file-op-9p.h typedef struct extended_ops {
Quoted 6 lines
fsdev/file-op-9p.h +1
-1} extended_ops;/* FsContext flag values */ -#define PATHNAME_FSCONTEXT 0x1 +#define PATHNAME_FSCONTEXT 0x1why ?
It was part of alignment change for above line
Quoted 61 lines
Quoted 61 lines
fsdev/file-op-9p.h +1
-0+#define P9_RDONLY_EXPORT 0x2/* cache flags */
#defineV9FS_WRITETHROUGH_CACHE0x1fsdev/qemu-fsdev.c +10
-2@@ -29,13 +29,13 @@ static FsTypeTable FsTypes[] = {int qemu_fsdev_add (QemuOpts *opts) {struct FsTypeListEntry *fsle; -int i; +int i, flags =0 ;const char *fsdev_id =qemu_opts_id (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" ); - +int rdonly =qemu_opt_get_bool (opts,"readonly" ,0 );if (!fsdev_id) {fprintf (stderr,"fsdev: No id specified\n" );@@ -76,6 +76,14 @@ int qemu_fsdev_add(QemuOpts *opts) fsle->fse.cache_flags =V9FS_WRITETHROUGH_CACHE ; } } +if (rdonly) { + flags |=P9_RDONLY_EXPORT ; + }else { + flags &= ~P9_RDONLY_EXPORT ; + } + + fsle->fse.flags = flags; +QTAILQ_INSERT_TAIL (&fstype_entries, fsle, next);return 0 ; }fsdev/qemu-fsdev.h +0
-0@@ -44,6 +44,7 @@ typedef struct FsTypeEntry {
Quoted 8 lines
fsdev/qemu-fsdev.h typedef struct FsTypeEntry {
Quoted 5 lines
fsdev/qemu-fsdev.h +1
-0char *security_model;int cache_flags;FileOperations *ops; +int flags;do we need extra flags ? Why not use
cache_flags? renaming that toexport_flags?
Yes, we can use same variable.
Quoted 53 lines
Quoted 53 lines
fsdev/qemu-fsdev.h +0
-0} FsTypeEntry;typedef struct FsTypeListEntry {
hw/9pfs/virtio-9p-device.c +3
-0@@ -125,6 +125,9 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) s->tag_len = len; s->ctx.uid =-1 ; s->ctx.flags =0 ; +if (fse->flags &P9_RDONLY_EXPORT ) { + s->ctx.flags |=P9_RDONLY_EXPORT ; + }s->ops = fse->ops; s->vdev.get_features = virtio_9p_get_features;hw/9pfs/virtio-9p.c +5
-0@@ -1271,6 +1271,11 @@ static void v9fs_fix_path(V9fsPath *dst, V9fsPath *src, int len) dst->size++; } +static inline bool is_ro_export (FsContext *fs_ctx) +{ +return fs_ctx->flags &P9_RDONLY_EXPORT ; +} +static void
v9fs_version(void *opaque)
{V9fsPDU *pdu = opaque;hw/9pfs/virtio-9p.c +0
-0@@ -1690,6 +1695,14 @@ static void v9fs_open(void *opaque) }else { flags =omode_to_uflags (mode); }
Quoted 10 lines
hw/9pfs/virtio-9p.c static void v9fs_open(void *opaque) · line 1705
Quoted 8 lines
hw/9pfs/virtio-9p.c +8
-0+if (is_ro_export (&s->ctx)) { +if (mode &O_WRONLY || mode &O_RDWR || mode &O_APPEND ) { + err = -EROFS ; + goto out; + }else { + flags |=O_NOATIME ; + } + }What about
O_TRUNC?
Thanks, I will include the check for O_TRUNC
Quoted 13 lines
hw/9pfs/virtio-9p.c static void v9fs_op_not_supp(void *opaque) · line 3317
Quoted 11 lines
err = v9fs_co_open(pdu, fidp, flags); if (err < 0) { goto out;hw/9pfs/virtio-9p.c +0
-0@@ -3301,6 +3314,33 @@ static void v9fs_op_not_supp(void *opaque)complete_pdu (pdu->s, pdu, -EOPNOTSUPP ); }-aneesh
Am 12.10.2011 09:53, schrieb M. Mohan Kumar:
Quoted 14 lines
In addition to
qemu_opt_setfunction, we need a function to set bool value also.Signed-off-by M. Mohan Kumar<[email protected]>--- qemu-option.c | 35 +++++++++++++++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 36 insertions(+), 0 deletions(-)qemu-option.c +0
-0
qemu-option.c int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) · line 639
Quoted 4 lines
qemu-option.c +1
-0@@ -636,6 +636,41 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value)return 0 ; } +int qemu_opt_set_bool (QemuOpts *opts,const char *name,int val)
Might it make sense to let qemu_opt_{get,set}_bool() use bool type?
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746, AG Nürnberg
Andreas,
I will repost the patch with boolean type change.
Signature · 2 lines
Regards, M. Mohan Kumar
Quoted 27 lines · Andreas Färber
Am 12.10.2011 09:53, schrieb M. Mohan Kumar:
Quoted 15 lines
In addition to
qemu_opt_setfunction, we need a function to set bool value also.Signed-off-by M. Mohan Kumar<[email protected]>---
qemu-option.c | 35 +++++++++++++++++++++++++++++++++++ qemu-option.h | 1 + 2 files changed, 36 insertions(+), 0 deletions(-)qemu-option.c +0
-0qemu-option.c int qemu_opt_set(QemuOpts *opts, const char *name, · line 642
Quoted 7 lines
qemu-option.c +1
-0@@ -636,6 +636,41 @@ int qemu_opt_set(QemuOpts *opts, const char *name, const char *value) return 0; } +int qemu_opt_set_bool (QemuOpts *opts,const char *name,int val)Might it make sense to let qemu_opt_{get,set}_bool() use bool type?
Andreas