]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: replace multiple strcmps with a switch on an enum
authorLaine Stump <laine@laine.org>
Tue, 24 Sep 2013 13:38:32 +0000 (09:38 -0400)
committerLaine Stump <laine@laine.org>
Wed, 25 Sep 2013 14:37:33 +0000 (10:37 -0400)
I'm not sure why this code was written to compare the strings that it
had just retrieved from an enum->string conversion, rather than just
look at the original enum values, but this yields the same results,
and is much more efficient (especially as you add more devices).

This is a prerequisite for patches to resolve:

   https://bugzilla.redhat.com/show_bug.cgi?id=1003983

src/qemu/qemu_command.c

index 280d8d28e1539ee7b1ba67beb85ca972805df06b..3156cff97f43846ae1cd2f1f3d1b887027f2f8e9 100644 (file)
@@ -5269,13 +5269,18 @@ qemuBuildSoundDevStr(virDomainDefPtr def,
         goto error;
     }
 
-    /* Hack for weirdly unusual devices name in QEMU */
-    if (STREQ(model, "es1370"))
+    /* Hack for devices with different names in QEMU and libvirt */
+    switch (sound->model) {
+    case VIR_DOMAIN_SOUND_MODEL_ES1370:
         model = "ES1370";
-    else if (STREQ(model, "ac97"))
+        break;
+    case VIR_DOMAIN_SOUND_MODEL_AC97:
         model = "AC97";
-    else if (STREQ(model, "ich6"))
+        break;
+    case VIR_DOMAIN_SOUND_MODEL_ICH6:
         model = "intel-hda";
+        break;
+    }
 
     virBufferAsprintf(&buf, "%s,id=%s", model, sound->info.alias);
     if (qemuBuildDeviceAddressStr(&buf, def, &sound->info, qemuCaps) < 0)