Patchwork [RFC,2/7] qemu-config: Make qemu_config_parse more generic

login
register
mail settings
Submitter Kevin Wolf
Date March 15, 2010, 5:08 p.m.
Message ID <1268672915-12233-3-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/47766/
State New
Headers show

Comments

Kevin Wolf - March 15, 2010, 5:08 p.m.
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>
---
 qemu-config.c |   15 ++++++++-------
 qemu-config.h |    2 +-
 2 files changed, 9 insertions(+), 8 deletions(-)
Christoph Hellwig - March 28, 2010, 12:20 p.m.
On Mon, Mar 15, 2010 at 06:08:30PM +0100, Kevin Wolf wrote:
> 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>

Looks good,


Reviewed-by: Christoph Hellwig <hch@lst.de>

Patch

diff --git a/qemu-config.c b/qemu-config.c
index 8166b5e..e121f2a 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -290,7 +290,7 @@  QemuOptsList qemu_cpudef_opts = {
     },
 };
 
-static QemuOptsList *lists[] = {
+static QemuOptsList *vm_config_groups[] = {
     &qemu_drive_opts,
     &qemu_chardev_opts,
     &qemu_device_opts,
@@ -303,7 +303,7 @@  static QemuOptsList *lists[] = {
     NULL,
 };
 
-static QemuOptsList *find_list(const char *group)
+static QemuOptsList *find_list(QemuOptsList **lists, const char *group)
 {
     int i;
 
@@ -330,7 +330,7 @@  int qemu_set_option(const char *str)
         return -1;
     }
 
-    list = find_list(group);
+    list = find_list(vm_config_groups, group);
     if (list == NULL) {
         return -1;
     }
@@ -415,6 +415,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");
@@ -424,7 +425,7 @@  void qemu_config_write(FILE *fp)
     }
 }
 
-int qemu_config_parse(FILE *fp)
+int qemu_config_parse(FILE *fp, QemuOptsList **lists)
 {
     char line[1024], group[64], id[64], arg[64], value[1024];
     QemuOptsList *list = NULL;
@@ -441,7 +442,7 @@  int qemu_config_parse(FILE *fp)
         }
         if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
             /* group with id */
-            list = find_list(group);
+            list = find_list(lists, group);
             if (list == NULL)
                 return -1;
             opts = qemu_opts_create(list, id, 1);
@@ -449,7 +450,7 @@  int qemu_config_parse(FILE *fp)
         }
         if (sscanf(line, "[%63[^]]]", group) == 1) {
             /* group without id */
-            list = find_list(group);
+            list = find_list(lists, group);
             if (list == NULL)
                 return -1;
             opts = qemu_opts_create(list, NULL, 0);
@@ -481,7 +482,7 @@  int qemu_read_config_file(const char *filename)
         return -errno;
     }
 
-    if (qemu_config_parse(f) != 0) {
+    if (qemu_config_parse(f, vm_config_groups) != 0) {
         return -EINVAL;
     }
     fclose(f);
diff --git a/qemu-config.h b/qemu-config.h
index bbe9d41..086aa2a 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -16,7 +16,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);
+int qemu_config_parse(FILE *fp, QemuOptsList **lists);
 
 int qemu_read_config_file(const char *filename);