From patchwork Fri Apr 23 15:30:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 50822 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 24C9EB7D1D for ; Sat, 24 Apr 2010 01:34:15 +1000 (EST) Received: from localhost ([127.0.0.1]:32949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5KtQ-0008FB-4n for incoming@patchwork.ozlabs.org; Fri, 23 Apr 2010 11:34:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O5Kqy-0007Gn-TC for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:31:40 -0400 Received: from [140.186.70.92] (port=50179 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5Kqs-0007Fp-Vt for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:31:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O5Kqr-0005nU-Cs for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:31:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46636) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5Kqr-0005nB-4Z for qemu-devel@nongnu.org; Fri, 23 Apr 2010 11:31:33 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3NFVVlj023440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Apr 2010 11:31:31 -0400 Received: from localhost.localdomain (vpn2-9-155.ams2.redhat.com [10.36.9.155]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3NFVOC7020467; Fri, 23 Apr 2010 11:31:29 -0400 From: Kevin Wolf To: aliguori@linux.vnet.ibm.com Date: Fri, 23 Apr 2010 17:30:34 +0200 Message-Id: <1272036658-26776-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1272036658-26776-1-git-send-email-kwolf@redhat.com> References: <1272036658-26776-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 02/26] qemu-config: Make qemu_config_parse more generic 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 qemu_config_parse gets the option groups as a parameter now instead of hardcoding the VM configuration groups. This way it can be used for other configurations, too. Signed-off-by: Kevin Wolf --- qemu-config.c | 18 ++++++++++++------ qemu-config.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 8254b35..9b5fe78 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -296,7 +296,7 @@ QemuOptsList qemu_cpudef_opts = { }, }; -static QemuOptsList *lists[] = { +static QemuOptsList *vm_config_groups[] = { &qemu_drive_opts, &qemu_chardev_opts, &qemu_device_opts, @@ -309,7 +309,7 @@ static QemuOptsList *lists[] = { NULL, }; -QemuOptsList *qemu_find_opts(const char *group) +static QemuOptsList *find_list(QemuOptsList **lists, const char *group) { int i; @@ -323,6 +323,11 @@ QemuOptsList *qemu_find_opts(const char *group) return lists[i]; } +QemuOptsList *qemu_find_opts(const char *group) +{ + return find_list(vm_config_groups, group); +} + int qemu_set_option(const char *str) { char group[64], id[64], arg[64]; @@ -421,6 +426,7 @@ static int config_write_opts(QemuOpts *opts, void *opaque) void qemu_config_write(FILE *fp) { struct ConfigWriteData data = { .fp = fp }; + QemuOptsList **lists = vm_config_groups; int i; fprintf(fp, "# qemu config file\n\n"); @@ -430,7 +436,7 @@ void qemu_config_write(FILE *fp) } } -int qemu_config_parse(FILE *fp, const char *fname) +int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) { char line[1024], group[64], id[64], arg[64], value[1024]; Location loc; @@ -451,7 +457,7 @@ int qemu_config_parse(FILE *fp, const char *fname) } if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { /* group with id */ - list = qemu_find_opts(group); + list = find_list(lists, group); if (list == NULL) goto out; opts = qemu_opts_create(list, id, 1); @@ -459,7 +465,7 @@ int qemu_config_parse(FILE *fp, const char *fname) } if (sscanf(line, "[%63[^]]]", group) == 1) { /* group without id */ - list = qemu_find_opts(group); + list = find_list(lists, group); if (list == NULL) goto out; opts = qemu_opts_create(list, NULL, 0); @@ -496,7 +502,7 @@ int qemu_read_config_file(const char *filename) return -errno; } - if (qemu_config_parse(f, filename) != 0) { + if (qemu_config_parse(f, vm_config_groups, filename) != 0) { return -EINVAL; } fclose(f); diff --git a/qemu-config.h b/qemu-config.h index 07a7a27..dd299c2 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -17,7 +17,7 @@ int qemu_global_option(const char *str); void qemu_add_globals(void); void qemu_config_write(FILE *fp); -int qemu_config_parse(FILE *fp, const char *fname); +int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname); int qemu_read_config_file(const char *filename);