Patchwork [4/4] v2, cpu model corrections/updates: add verbose config file handling

login
register
mail settings
Submitter john cooper
Date Sept. 15, 2010, 5:31 a.m.
Message ID <4C905A46.5030001@redhat.com>
Download mbox | patch
Permalink /patch/64775/
State New
Headers show

Comments

john cooper - Sept. 15, 2010, 5:31 a.m.
Failure by qemu to open a default config file isn't cause to
error exit -- it just quietly continues on.   After puzzling
issues with otherwise opaque config file locations and
startup handling numerous times, some help from qemu seemed
justified.

The prior version of this patch overloaded "-readconfig ?"
to enable verbose handling.  Here we add a global "-config"
flag which takes [verbose][,nodefault] as options modifying
config file handling.  Note "-nodefconfig" has been removed
and functionally replaced here by the "nodefault" flag option.

Signed-off-by: john cooper <john.cooper@redhat.com>
---

Patch

diff --git a/qemu-config.c b/qemu-config.c
index 1efdbec..805fcc6 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -534,21 +534,31 @@  out:
     return res;
 }
 
-int qemu_read_config_file(const char *filename)
+/* attempt to open and parse config file, report problems if vflag
+ */
+int qemu_read_config_file(const char *filename, int vflag)
 {
     FILE *f = fopen(filename, "r");
-    int ret;
+    int rv = 0;
+    const char *err;
 
     if (f == NULL) {
-        return -errno;
+        rv = -errno;
+        err = "open";
     }
-
-    ret = qemu_config_parse(f, vm_config_groups, filename);
-    fclose(f);
-
-    if (ret == 0) {
-        return 0;
-    } else {
-        return -EINVAL;
+    else if (qemu_config_parse(f, vm_config_groups, filename) != 0) {
+        rv = -EINVAL;
+        err = "parse";
+    }
+    else if (vflag) {
+        fprintf(stderr, "parsed config file %s\n", filename);
+    }
+    if (f) {
+        fclose(f);
+    }
+    if (rv && vflag) {
+        fprintf(stderr, "can't %s config file %s: %s\n",
+                err, filename, strerror(-rv));
     }
+    return rv;
 }
diff --git a/qemu-config.h b/qemu-config.h
index 533a049..897fbce 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -13,6 +13,6 @@  void qemu_add_globals(void);
 void qemu_config_write(FILE *fp);
 int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname);
 
-int qemu_read_config_file(const char *filename);
+int qemu_read_config_file(const char *filename, int vflag);
 
 #endif /* QEMU_CONFIG_H */
diff --git a/qemu-options.hx b/qemu-options.hx
index 453f129..038a2fa 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2219,16 +2219,19 @@  STEXI
 @findex -writeconfig
 Write device configuration to @var{file}.
 ETEXI
-DEF("nodefconfig", 0, QEMU_OPTION_nodefconfig,
-    "-nodefconfig\n"
-    "                do not load default config files at startup\n",
+DEF("config", HAS_ARG, QEMU_OPTION_config,
+    "-config [nodefault][,verbose]\n"
+    "                set global config file options.\n",
     QEMU_ARCH_ALL)
 STEXI
-@item -nodefconfig
-@findex -nodefconfig
-Normally QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and
-@var{sysconfdir}/target-@var{ARCH}.conf on startup.  The @code{-nodefconfig}
-option will prevent QEMU from loading these configuration files at startup.
+@item -config
+@findex -config
+By default QEMU loads a configuration file from @var{sysconfdir}/qemu.conf and
+@var{sysconfdir}/target-@var{ARCH}.conf on startup.
+The @code{-config nodefault} option will prevent QEMU from loading these
+configuration files at startup.
+Additionally @code{-config verbose} will provide detail to the user of
+all config file handling.
 ETEXI
 
 HXCOMM This is the last statement. Insert new options before this line!
diff --git a/vl.c b/vl.c
index fd491ba..c787f64 100644
--- a/vl.c
+++ b/vl.c
@@ -1822,6 +1822,7 @@  int main(int argc, char **argv, char **envp)
     const char *incoming = NULL;
     int show_vnc_port = 0;
     int defconfig = 1;
+    int defconfig_verbose = 0;
 
     atexit(qemu_run_exit_notifiers);
     error_set_progname(argv[0]);
@@ -1872,9 +1873,22 @@  int main(int argc, char **argv, char **envp)
 
             popt = lookup_opt(argc, argv, &optarg, &optind);
             switch (popt->index) {
-            case QEMU_OPTION_nodefconfig:
-                defconfig=0;
+            case QEMU_OPTION_config:
+                {
+                char *p, *q, *r;
+
+                for (r = p = strdup(optarg); (q = strtok(r, ",")); r = NULL)
+                    if (!strcmp(q, "nodefault")) {
+                        defconfig = 0;
+                    } else if (!strcmp(q, "verbose")) {
+                        defconfig_verbose = 1;
+                    } else {
+                        fprintf(stderr, "unknown option \"%s\"\n", q);
+                        exit(1);
+                    }
+                free(p);
                 break;
+                }
             }
         }
     }
@@ -1882,12 +1896,13 @@  int main(int argc, char **argv, char **envp)
     if (defconfig) {
         int ret;
 
-        ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf");
+        ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf",
+                                    defconfig_verbose);
         if (ret < 0 && ret != -ENOENT) {
             exit(1);
         }
 
-        ret = qemu_read_config_file(arch_config_name);
+        ret = qemu_read_config_file(arch_config_name, defconfig_verbose);
         if (ret < 0 && ret != -ENOENT) {
             exit(1);
         }
@@ -2596,15 +2611,9 @@  int main(int argc, char **argv, char **envp)
                 xen_mode = XEN_ATTACH;
                 break;
             case QEMU_OPTION_readconfig:
-                {
-                    int ret = qemu_read_config_file(optarg);
-                    if (ret < 0) {
-                        fprintf(stderr, "read config %s: %s\n", optarg,
-                            strerror(-ret));
-                        exit(1);
-                    }
-                    break;
-                }
+                if (qemu_read_config_file(optarg, defconfig_verbose) < 0)
+                    exit(1);
+                break;
             case QEMU_OPTION_writeconfig:
                 {
                     FILE *fp;