From 7657232e256cb33b47b2592a49b7a4dc778f49b0 Mon Sep 17 00:00:00 2001
From: Kevin Wolf <kwolf@redhat.com>
Date: Tue, 4 May 2010 13:11:31 -0300
Subject: [PATCH 02/20] qemu-config: Make qemu_config_parse more generic

RH-Author: Kevin Wolf <kwolf@redhat.com>
Message-id: <1272978696-18996-3-git-send-email-kwolf@redhat.com>
Patchwork-id: 8987
O-Subject: [RHEL-6 qemu-kvm PATCH 2/7] qemu-config: Make qemu_config_parse more
	generic
Bugzilla: 588756
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Christoph Hellwig <chellwig@redhat.com>

Bugzilla: 588756

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 <kwolf@redhat.com>
(cherry picked from commit 490b648e5b8987d4d497c222e0941a8b129a5eb6)

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-config.c |   18 ++++++++++++------
 qemu-config.h |    2 +-
 2 files changed, 13 insertions(+), 7 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 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 53c7c20..f2efc08 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -300,7 +300,7 @@ QemuOptsList qemu_cpudef_opts = {
     },
 };
 
-static QemuOptsList *lists[] = {
+static QemuOptsList *vm_config_groups[] = {
     &qemu_drive_opts,
     &qemu_chardev_opts,
     &qemu_device_opts,
@@ -316,7 +316,7 @@ static QemuOptsList *lists[] = {
     NULL,
 };
 
-QemuOptsList *qemu_find_opts(const char *group)
+static QemuOptsList *find_list(QemuOptsList **lists, const char *group)
 {
     int i;
 
@@ -330,6 +330,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];
@@ -428,6 +433,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");
@@ -437,7 +443,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;
@@ -458,7 +464,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);
@@ -466,7 +472,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);
@@ -503,7 +509,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 a387e49..eb804a2 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -18,7 +18,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);
 
-- 
1.7.0.3

