From patchwork Wed Mar 16 08:31:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 87186 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 C2C16B7006 for ; Wed, 16 Mar 2011 19:32:55 +1100 (EST) Received: from localhost ([127.0.0.1]:41019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pzm9y-0002iq-2w for incoming@patchwork.ozlabs.org; Wed, 16 Mar 2011 04:32:50 -0400 Received: from [140.186.70.92] (port=35311 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pzm9O-0002hO-Nc for qemu-devel@nongnu.org; Wed, 16 Mar 2011 04:32:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pzm9N-00062f-DI for qemu-devel@nongnu.org; Wed, 16 Mar 2011 04:32:14 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:42731) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pzm9N-00062E-5z for qemu-devel@nongnu.org; Wed, 16 Mar 2011 04:32:13 -0400 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p2G8WBYi030135 for ; Wed, 16 Mar 2011 08:32:11 GMT Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p2G8WS5g2060458 for ; Wed, 16 Mar 2011 08:32:30 GMT Received: from d06av05.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p2G8W8oa011490 for ; Wed, 16 Mar 2011 02:32:08 -0600 Received: from stefanha-thinkpad.ibm.com (sig-9-145-191-4.de.ibm.com [9.145.191.4]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p2G8W7TQ011471; Wed, 16 Mar 2011 02:32:07 -0600 From: Stefan Hajnoczi To: Date: Wed, 16 Mar 2011 08:31:43 +0000 Message-Id: <1300264303-10092-1-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.2.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.163 Cc: Anthony Liguori , Venkateswararao Jujjuri , "Aneesh Kumar K.V" , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2] vl.c: Replace -virtfs string manipulation with QemuOpts 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 The -virtfs option creates an fsdev representing the pass-through file system and a guest-visible virtio-9p-pci device that can access this file system. This patch replaces the string manipulation used to build and reparse option lists with direct QemuOpts calls. Removing the string manipulation code makes it easier to maintain and less error prone. An error message is also updated to use "mount_tag" instead of "mnt_tag". Signed-off-by: Stefan Hajnoczi --- v2: * Updated error message according to JV's suggestion vl.c | 56 +++++++++++++++++++------------------------------------- 1 files changed, 19 insertions(+), 37 deletions(-) diff --git a/vl.c b/vl.c index b1a94aa..cf16e19 100644 --- a/vl.c +++ b/vl.c @@ -2411,9 +2411,8 @@ int main(int argc, char **argv, char **envp) } break; case QEMU_OPTION_virtfs: { - char *arg_fsdev = NULL; - char *arg_9p = NULL; - int len = 0; + QemuOpts *fsdev; + QemuOpts *device; olist = qemu_find_opts("virtfs"); if (!olist) { @@ -2432,45 +2431,28 @@ int main(int argc, char **argv, char **envp) qemu_opt_get(opts, "security_model") == NULL) { fprintf(stderr, "Usage: -virtfs fstype,path=/share_path/," "security_model=[mapped|passthrough|none]," - "mnt_tag=tag.\n"); + "mount_tag=tag.\n"); exit(1); } - len = strlen(",id=,path=,security_model="); - len += strlen(qemu_opt_get(opts, "fstype")); - len += strlen(qemu_opt_get(opts, "mount_tag")); - len += strlen(qemu_opt_get(opts, "path")); - len += strlen(qemu_opt_get(opts, "security_model")); - arg_fsdev = qemu_malloc((len + 1) * sizeof(*arg_fsdev)); - - snprintf(arg_fsdev, (len + 1) * sizeof(*arg_fsdev), - "%s,id=%s,path=%s,security_model=%s", - qemu_opt_get(opts, "fstype"), - qemu_opt_get(opts, "mount_tag"), - qemu_opt_get(opts, "path"), - qemu_opt_get(opts, "security_model")); - - len = strlen("virtio-9p-pci,fsdev=,mount_tag="); - len += 2*strlen(qemu_opt_get(opts, "mount_tag")); - arg_9p = qemu_malloc((len + 1) * sizeof(*arg_9p)); - - snprintf(arg_9p, (len + 1) * sizeof(*arg_9p), - "virtio-9p-pci,fsdev=%s,mount_tag=%s", - qemu_opt_get(opts, "mount_tag"), - qemu_opt_get(opts, "mount_tag")); - - if (!qemu_opts_parse(qemu_find_opts("fsdev"), arg_fsdev, 1)) { - fprintf(stderr, "parse error [fsdev]: %s\n", optarg); + fsdev = qemu_opts_create(qemu_find_opts("fsdev"), + qemu_opt_get(opts, "mount_tag"), 1); + if (!fsdev) { + fprintf(stderr, "duplicate fsdev id: %s\n", + qemu_opt_get(opts, "mount_tag")); exit(1); } - - if (!qemu_opts_parse(qemu_find_opts("device"), arg_9p, 1)) { - fprintf(stderr, "parse error [device]: %s\n", optarg); - exit(1); - } - - qemu_free(arg_fsdev); - qemu_free(arg_9p); + qemu_opt_set(fsdev, "fstype", qemu_opt_get(opts, "fstype")); + qemu_opt_set(fsdev, "path", qemu_opt_get(opts, "path")); + qemu_opt_set(fsdev, "security_model", + qemu_opt_get(opts, "security_model")); + + device = qemu_opts_create(qemu_find_opts("device"), NULL, 0); + qemu_opt_set(device, "driver", "virtio-9p-pci"); + qemu_opt_set(device, "fsdev", + qemu_opt_get(opts, "mount_tag")); + qemu_opt_set(device, "mount_tag", + qemu_opt_get(opts, "mount_tag")); break; } case QEMU_OPTION_serial: