Received: from [140.186.70.92] (port=38686 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5XQH-0000Vq-8Y for qemu-devel@nongnu.org; Tue, 12 Oct 2010 01:29:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P5XQC-0003w5-Nf for qemu-devel@nongnu.org; Tue, 12 Oct 2010 01:29:13 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:34892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P5XQC-0003uC-6Y for qemu-devel@nongnu.org; Tue, 12 Oct 2010 01:29:08 -0400 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp07.au.ibm.com (8.14.4/8.13.1) with ESMTP id o9C5TRLL027544 for ; Tue, 12 Oct 2010 16:29:27 +1100 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9C5T3jB2449442 for ; Tue, 12 Oct 2010 16:29:03 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9C5T2sB003511 for ; Tue, 12 Oct 2010 16:29:02 +1100 From: Harsh Prateek Bora Date: Tue, 12 Oct 2010 10:58:50 +0530 Message-Id: <1286861330-27191-1-git-send-email-harsh@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] Introduce 9p commandline arguments sanity checks List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Harsh Prateek Bora This patch checks the validity of 9p related commandline arguments and throws error if the arguments are not appropriate. Signed-off-by: Harsh Prateek Bora --- fsdev/qemu-fsdev.c | 39 ++++++++++++++++++++++++++------------- hw/virtio-9p.c | 2 +- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 280b8f5..3f4c543 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -29,35 +29,48 @@ int qemu_fsdev_add(QemuOpts *opts) { struct FsTypeListEntry *fsle; int i; + 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"); - if (qemu_opts_id(opts) == NULL) { + if (!fsdev_id) { fprintf(stderr, "fsdev: No id specified\n"); return -1; } - for (i = 0; i < ARRAY_SIZE(FsTypes); i++) { - if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0) { - break; + if (fstype) { + for (i = 0; i < ARRAY_SIZE(FsTypes); i++) { + if (strcmp(FsTypes[i].name, fstype) == 0) { + break; + } } - } - if (i == ARRAY_SIZE(FsTypes)) { - fprintf(stderr, "fsdev: fstype %s not found\n", - qemu_opt_get(opts, "fstype")); + if (i == ARRAY_SIZE(FsTypes)) { + fprintf(stderr, "fsdev: fstype %s not found\n", fstype); + return -1; + } + } + else { + fprintf(stderr, "fsdev: No fstype specified\n"); return -1; } - if (qemu_opt_get(opts, "security_model") == NULL) { + if (!sec_model) { fprintf(stderr, "fsdev: No security_model specified.\n"); return -1; } + if (!path) { + fprintf(stderr, "fsdev: No path specified.\n"); + return -1; + } + fsle = qemu_malloc(sizeof(*fsle)); - fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts)); - fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path")); - fsle->fse.security_model = qemu_strdup(qemu_opt_get(opts, - "security_model")); + 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; QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next); diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 60f0802..0df56d7 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -3697,7 +3697,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf) if (!fse) { /* We don't have a fsdev identified by fsdev_id */ fprintf(stderr, "Virtio-9p device couldn't find fsdev " - "with the id %s\n", conf->fsdev_id); + "with the id = %s\n", conf->fsdev_id ? conf->fsdev_id : "unknown"); exit(1); } -- 1.7.1.1