virtio-9p: Add Read only support for 9p export.
PATCH v3 1/1 virtio-9p: Add Read only 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 to 9p export.
---
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 | 1 + fsdev/qemu-fsdev.c | 11 ++++++++++- fsdev/qemu-fsdev.h | 3 +++ hw/9pfs/virtio-9p-device.c | 5 +++++ hw/9pfs/virtio-9p.c | 41 +++++++++++++++++++++++++++++++++++++++++ qemu-config.c | 7 +++++++ vl.c | 1 + 7 files changed, 68 insertions(+), 1 deletions(-)
fsdev/file-op-9p.h +1 -0
@@ -55,6 +55,7 @@ typedef struct FsContextSecModel fs_sm;uid_t uid;struct xattr_operations **xops; +int flags; } FsContext;void cred_init (FsCred *);
fsdev/qemu-fsdev.c +10 -1
@@ -28,11 +28,12 @@ static FsTypeTable FsTypes[] = {int qemu_fsdev_add (QemuOpts *opts) {struct FsTypeListEntry *fsle; -int i; +int i, flags;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" ); +int readonly =qemu_opt_get_bool (opts,"readonly" ,0 );if (!fsdev_id) {fprintf (stderr,"fsdev: No id specified\n" );
@@ -65,12 +66,20 @@ int qemu_fsdev_add(QemuOpts *opts)return -1 ; } + flags =0 ; +if (readonly) { + flags |=MS_RDONLY ; + }else { + flags &= ~MS_RDONLY ; + } + fsle =qemu_malloc (sizeof (*fsle)); fsle->fse.fsdev_id =qemu_strdup (fsdev_id); fsle->fse.path =qemu_strdup (path); fsle->fse.security_model =qemu_strdup (sec_model); fsle->fse.ops = FsTypes[i].ops; + fsle->fse.flags = flags;QTAILQ_INSERT_TAIL (&fstype_entries, fsle, next);return 0 ;
fsdev/qemu-fsdev.h +3 -0
@@ -42,6 +42,7 @@ typedef struct FsTypeEntry {char *path;char *security_model;FileOperations *ops; +int flags; } FsTypeEntry; typedef struct FsTypeListEntry {
@@ -52,4 +53,6 @@ typedef struct FsTypeListEntry {int qemu_fsdev_add (QemuOpts *opts);FsTypeEntry *get_fsdev_fsentry (char *id);extern FileOperations local_ops; + +#define MS_RDONLY 0x01#endif
hw/9pfs/virtio-9p-device.c +5 -0
@@ -107,6 +107,11 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) s->ctx.xops = none_xattr_ops; } + s->ctx.flags =0 ; +if (fse->flags &MS_RDONLY ) { + s->ctx.flags |=MS_RDONLY ; + } +if (lstat (fse->path, &stat)) {fprintf (stderr,"share path %s does not exist\n" , fse->path);exit (1 );
hw/9pfs/virtio-9p.c +41 -0
65 lines not on this page · raw message
qemu-config.c +7 -0
@@ -170,7 +170,11 @@ QemuOptsList qemu_fsdev_opts = { }, { .name = "security_model", .type = QEMU_OPT_STRING, + }, { + .name = "readonly", + .type = QEMU_OPT_BOOL, }, + {/*End of list */ } }, };
@@ -192,6 +196,9 @@ QemuOptsList qemu_virtfs_opts = { }, { .name = "security_model", .type = QEMU_OPT_STRING, + }, { + .name = "readonly", + .type = QEMU_OPT_BOOL, }, { /*End of list */ }
vl.c +1 -0
@@ -2483,6 +2483,7 @@ int main(int argc, char **argv, char **envp)qemu_opt_set (fsdev,"security_model" ,qemu_opt_get (opts,"security_model" )); +qemu_opt_set (fsdev,"readonly" ,qemu_opt_get (opts,"readonly" )); 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.4
Quoted 13 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 to 9p export.
Signed-off-by M. Mohan Kumar <[email protected]>---
Change 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 needed
Quoted 8 lines
fsdev/file-op-9p.h | 1 + fsdev/qemu-fsdev.c | 11 ++++++++++- fsdev/qemu-fsdev.h | 3 +++hw/9pfs/virtio-9p-device.c | 5 +++++
hw/9pfs/virtio-9p.c | 41 +++++++++++++++++++++++++++++++++++++++++qemu-config.c| 7 +++++++
vl.c | 1 +7 files changed, 68 insertions(+), 1 deletions(-)