[libvirt] [PATCH 2/1] qemu: squash in for alternate implementation of "recognize memballoon"

Laine Stump laine at laine.org
Fri Jun 20 12:59:54 UTC 2014


Although the original patch in this thread is already ACKed, I decided
that in the interest of future expansion, I wanted to set up the
parser to more easily add recognition of other devices without needing
to re-check the string "-device", etc. Instead of checking for
"-device" and the device name in the same clause, this separates the
two so that other devices can be checked for without re-doing
STREQ(arg, "-device"). Parsing for new devices can just add another
"if STRPREFIX(opts, "blah")" clause, then do WANT_VALUE()).

I'm planning to squash this patch into the original patch before
pushing, but didn't want to resend the whole thing, as most of it was
corrections to test data.

---
 src/qemu/qemu_command.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e1d7e1b..447f2b2 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -10843,6 +10843,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
     /* Now the real processing loop */
     for (i = 1; progargv[i]; i++) {
         const char *arg = progargv[i];
+        bool argRecognized = true;
+
         /* Make sure we have a single - for all options to
            simplify next logic */
         if (STRPREFIX(arg, "--"))
@@ -11353,12 +11355,6 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
                 virDomainHostdevDefFree(hostdev);
                 goto error;
             }
-        } else if (STREQ(arg, "-device") && progargv[i + 1] &&
-                   STRPREFIX(progargv[i + 1], "virtio-balloon")) {
-            WANT_VALUE();
-            if (VIR_ALLOC(def->memballoon) < 0)
-                goto error;
-            def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO;
         } else if (STREQ(arg, "-soundhw")) {
             const char *start;
             WANT_VALUE();
@@ -11525,7 +11521,29 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
                    STREQ(arg, "-nodefaults") ||
                    STREQ(arg, "-nodefconfig")) {
             /* ignore, always added by libvirt */
+        } else if (STREQ(arg, "-device") && progargv[1 + 1]) {
+            const char *opts = progargv[i + 1];
+
+            /* NB: we can't do WANT_VALUE until we're sure that we
+             * recognize the device, otherwise the !argRecognized
+             * logic below will be messed up
+             */
+
+            if (STRPREFIX(opts, "virtio-balloon")) {
+                WANT_VALUE();
+                if (VIR_ALLOC(def->memballoon) < 0)
+                    goto error;
+                def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO;
+            } else {
+                /* add in new -device's here */
+
+                argRecognized = false;
+            }
         } else {
+            argRecognized = false;
+        }
+
+        if (!argRecognized) {
             char *tmp = NULL;
             /* something we can't yet parse.  Add it to the qemu namespace
              * cmdline/environment advanced options and hope for the best
-- 
1.9.3




More information about the libvir-list mailing list