From patchwork Wed Oct 13 11:08:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harsh Prateek Bora X-Patchwork-Id: 67669 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DAE02B6EE8 for ; Wed, 13 Oct 2010 22:50:46 +1100 (EST) Received: from localhost ([127.0.0.1]:52118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5zr0-0000oD-W2 for incoming@patchwork.ozlabs.org; Wed, 13 Oct 2010 07:50:43 -0400 Received: from [140.186.70.92] (port=33660 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P5zpu-000683-RF for qemu-devel@nongnu.org; Wed, 13 Oct 2010 07:49:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P5zCS-0000Ru-P2 for qemu-devel@nongnu.org; Wed, 13 Oct 2010 07:08:49 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:33760) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P5zCS-0000RG-91 for qemu-devel@nongnu.org; Wed, 13 Oct 2010 07:08:48 -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 o9DB97c5005840 for ; Wed, 13 Oct 2010 22:09:07 +1100 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o9DB8hhP2388204 for ; Wed, 13 Oct 2010 22:08:44 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o9DB8haf020055 for ; Wed, 13 Oct 2010 22:08:43 +1100 Received: from harshbora.in.ibm.com (ChanaKya.in.ibm.com [9.124.35.251]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o9DB8f3e019992; Wed, 13 Oct 2010 22:08:42 +1100 From: Harsh Prateek Bora To: qemu-devel@nongnu.org Date: Wed, 13 Oct 2010 16:38:37 +0530 Message-Id: <1286968117-4190-1-git-send-email-harsh@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Harsh Prateek Bora Subject: [Qemu-devel] [PATCH v2] Introduce 9p commandline arguments sanity checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- v2: - added check in get_fsdev_fsentry() and indenatation fixes fsdev/qemu-fsdev.c | 48 +++++++++++++++++++++++++++++++----------------- hw/virtio-9p.c | 4 ++-- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index 280b8f5..0b33290 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -29,35 +29,47 @@ 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); @@ -67,11 +79,13 @@ int qemu_fsdev_add(QemuOpts *opts) FsTypeEntry *get_fsdev_fsentry(char *id) { - struct FsTypeListEntry *fsle; + if (id) { + struct FsTypeListEntry *fsle; - QTAILQ_FOREACH(fsle, &fstype_entries, next) { - if (strcmp(fsle->fse.fsdev_id, id) == 0) { - return &fsle->fse; + QTAILQ_FOREACH(fsle, &fstype_entries, next) { + if (strcmp(fsle->fse.fsdev_id, id) == 0) { + return &fsle->fse; + } } } return NULL; diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 60f0802..0a9b2fb 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -3696,8 +3696,8 @@ 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); + fprintf(stderr, "Virtio-9p device couldn't find fsdev with the " + "id = %s\n", conf->fsdev_id ? conf->fsdev_id : "NULL"); exit(1); }