* [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality
@ 2011-10-19 17:16 M. Mohan Kumar
2011-10-19 17:16 ` [Qemu-devel] [PATCH 2/2] hw/9pfs: Read-only support for 9p export M. Mohan Kumar
2011-10-20 10:09 ` [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality Aneesh Kumar K.V
0 siblings, 2 replies; 3+ messages in thread
From: M. Mohan Kumar @ 2011-10-19 17:16 UTC (permalink / raw)
To: qemu-devel, Andreas Färber; +Cc: M. Mohan Kumar
From: "M. Mohan Kumar" <mohan@in.ibm.com>
Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
---
Changes from previous version:
* Changed qemu_opt_{get|set}_bool to use 'bool' data type
qemu-option.c | 43 +++++++++++++++++++++++++++++++++++++++----
qemu-option.h | 3 ++-
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/qemu-option.c b/qemu-option.c
index 105d760..1fd2755 100644
--- a/qemu-option.c
+++ b/qemu-option.c
@@ -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,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, 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;
+ 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)
{
diff --git a/qemu-option.h b/qemu-option.h
index b515813..07958e4 100644
--- a/qemu-option.h
+++ b/qemu-option.h
@@ -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);
--
1.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [PATCH 2/2] hw/9pfs: Read-only support for 9p export
2011-10-19 17:16 [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality M. Mohan Kumar
@ 2011-10-19 17:16 ` M. Mohan Kumar
2011-10-20 10:09 ` [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality Aneesh Kumar K.V
1 sibling, 0 replies; 3+ messages in thread
From: M. Mohan Kumar @ 2011-10-19 17:16 UTC (permalink / raw)
To: qemu-devel, Andreas Färber; +Cc: M. Mohan Kumar
From: "M. Mohan Kumar" <mohan@in.ibm.com>
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 <mohan@in.ibm.com>
---
Changes from previous version V4:
* Updated on top of current for-upstream branch
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 | 2 ++
fsdev/qemu-fsdev.c | 7 ++++++-
hw/9pfs/virtio-9p.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
qemu-config.c | 7 +++++++
vl.c | 2 ++
5 files changed, 68 insertions(+), 1 deletions(-)
diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index c7b4e38..ba564d4 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -60,6 +60,8 @@ typedef struct extended_ops {
#define V9FS_SEC_MASK 0x0000001C
+#define V9FS_RDONLY 0x00000020
+
typedef struct FsContext
{
uid_t uid;
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index e8dc0fd..7fd2aa7 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -36,7 +36,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");
@@ -87,6 +87,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;
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 1c67bfe..b6770e2 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -1271,6 +1271,11 @@ static void v9fs_fix_path(V9fsPath *dst, V9fsPath *src, int len)
dst->size++;
}
+static inline bool is_ro_export(int export_flags)
+{
+ return export_flags & V9FS_RDONLY;
+}
+
static void v9fs_version(void *opaque)
{
V9fsPDU *pdu = opaque;
@@ -1692,6 +1697,15 @@ static void v9fs_open(void *opaque)
} else {
flags = omode_to_uflags(mode);
}
+ if (is_ro_export(s->ctx.export_flags)) {
+ if (mode & O_WRONLY || mode & O_RDWR ||
+ mode & O_APPEND || mode & O_TRUNC) {
+ err = -EROFS;
+ goto out;
+ } else {
+ flags |= O_NOATIME;
+ }
+ }
err = v9fs_co_open(pdu, fidp, flags);
if (err < 0) {
goto out;
@@ -3311,6 +3325,39 @@ static void v9fs_op_not_supp(void *opaque)
complete_pdu(pdu->s, pdu, -EOPNOTSUPP);
}
+static void v9fs_fs_ro(void *opaque)
+{
+ V9fsPDU *pdu = opaque;
+ complete_pdu(pdu->s, pdu, -EROFS);
+}
+
+static inline bool is_read_only_op(int id)
+{
+ switch (id) {
+ case P9_TREADDIR:
+ case P9_TSTATFS:
+ case P9_TGETATTR:
+ case P9_TXATTRWALK:
+ case P9_TLOCK:
+ case P9_TGETLOCK:
+ case P9_TREADLINK:
+ case P9_TVERSION:
+ case P9_TLOPEN:
+ case P9_TATTACH:
+ case P9_TSTAT:
+ case P9_TWALK:
+ case P9_TCLUNK:
+ case P9_TFSYNC:
+ case P9_TOPEN:
+ case P9_TREAD:
+ case P9_TAUTH:
+ case P9_TFLUSH:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
{
Coroutine *co;
@@ -3322,6 +3369,10 @@ static void submit_pdu(V9fsState *s, V9fsPDU *pdu)
} else {
handler = pdu_co_handlers[pdu->id];
}
+
+ if (is_ro_export(s->ctx.export_flags) && !is_read_only_op(pdu->id)) {
+ handler = v9fs_fs_ro;
+ }
co = qemu_coroutine_create(handler);
qemu_coroutine_enter(co, pdu);
}
diff --git a/qemu-config.c b/qemu-config.c
index 90b6b3e..597d7e1 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -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 */ }
diff --git a/vl.c b/vl.c
index c9de124..cf66ef9 100644
--- a/vl.c
+++ b/vl.c
@@ -2823,6 +2823,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",
--
1.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality
2011-10-19 17:16 [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality M. Mohan Kumar
2011-10-19 17:16 ` [Qemu-devel] [PATCH 2/2] hw/9pfs: Read-only support for 9p export M. Mohan Kumar
@ 2011-10-20 10:09 ` Aneesh Kumar K.V
1 sibling, 0 replies; 3+ messages in thread
From: Aneesh Kumar K.V @ 2011-10-20 10:09 UTC (permalink / raw)
To: M. Mohan Kumar, qemu-devel, Andreas Färber
On Wed, 19 Oct 2011 22:46:32 +0530, "M. Mohan Kumar" <mohan@in.ibm.com> wrote:
> From: "M. Mohan Kumar" <mohan@in.ibm.com>
>
> Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Applied with doc update to v9fs.git
Thanks
-aneesh
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-20 10:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-19 17:16 [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality M. Mohan Kumar
2011-10-19 17:16 ` [Qemu-devel] [PATCH 2/2] hw/9pfs: Read-only support for 9p export M. Mohan Kumar
2011-10-20 10:09 ` [Qemu-devel] [PATCH 1/2] qemu: Add opt_set_bool functionality Aneesh Kumar K.V
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).