[libvirt PATCH 2/2] qemu: don't strip audio elements with user config present

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To support backwards live migration we must strip the default added
audio element, however, we are too aggressive in doing so. We are only
comparing a couple of attributes for equality, so risk stripping config
that was user customized. To improve this we need to a deep comparison
of the audio config.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 72 +++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 32 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index fb203bc830..ef0a08d405 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3507,17 +3507,15 @@ qemuDomainDefSuggestDefaultAudioBackend(virQEMUDriver *driver,
 }
 
 static int
-qemuDomainDefClearDefaultAudioBackend(virQEMUDriver *driver,
-                                      virDomainDef *def)
+qemuDomainDefCreateDefaultAudioBackend(virQEMUDriver *driver,
+                                       virDomainDef *def,
+                                       virDomainAudioDef **audioout)
 {
     bool addAudio;
     int audioBackend;
     int audioSDLDriver;
-    virDomainAudioDef *audio;
 
-    if (def->naudios != 1) {
-        return 0;
-    }
+    *audioout = NULL;
 
     if (qemuDomainDefSuggestDefaultAudioBackend(driver,
                                                 def,
@@ -3526,21 +3524,45 @@ qemuDomainDefClearDefaultAudioBackend(virQEMUDriver *driver,
                                                 &audioSDLDriver) < 0)
         return -1;
 
-    if (!addAudio)
-        return 0;
+    if (addAudio) {
+        virDomainAudioDef *audio = g_new0(virDomainAudioDef, 1);
+
+        audio->type = audioBackend;
+        audio->id = 1;
 
-    audio = def->audios[0];
-    if (audio->type != audioBackend)
+        if (audioBackend == VIR_DOMAIN_AUDIO_TYPE_SDL)
+            audio->backend.sdl.driver = audioSDLDriver;
+
+        *audioout = audio;
+    }
+
+    return 0;
+}
+
+
+static int
+qemuDomainDefClearDefaultAudioBackend(virQEMUDriver *driver,
+                                      virDomainDef *def)
+{
+    virDomainAudioDef *audio = NULL;
+
+    if (def->naudios != 1) {
         return 0;
+    }
 
-    if (audio->type == VIR_DOMAIN_AUDIO_TYPE_SDL &&
-        audio->backend.sdl.driver != audioSDLDriver)
+    if (qemuDomainDefCreateDefaultAudioBackend(driver, def, &audio) < 0)
+        return -1;
+
+    if (!audio)
         return 0;
 
+    if (virDomainAudioIsEqual(def->audios[0], audio)) {
+        virDomainAudioDefFree(def->audios[0]);
+        g_free(def->audios);
+        def->naudios = 0;
+        def->audios = NULL;
+    }
     virDomainAudioDefFree(audio);
-    g_free(def->audios);
-    def->naudios = 0;
-    def->audios = NULL;
 
     return 0;
 }
@@ -3549,33 +3571,19 @@ static int
 qemuDomainDefAddDefaultAudioBackend(virQEMUDriver *driver,
                                     virDomainDef *def)
 {
-    bool addAudio;
-    int audioBackend;
-    int audioSDLDriver;
+    virDomainAudioDef *audio;
 
     if (def->naudios > 0) {
         return 0;
     }
 
-    if (qemuDomainDefSuggestDefaultAudioBackend(driver,
-                                                def,
-                                                &addAudio,
-                                                &audioBackend,
-                                                &audioSDLDriver) < 0)
+    if (qemuDomainDefCreateDefaultAudioBackend(driver, def, &audio) < 0)
         return -1;
 
-    if (addAudio) {
-        virDomainAudioDef *audio = g_new0(virDomainAudioDef, 1);
-
-        audio->type = audioBackend;
-        audio->id = 1;
-
+    if (audio) {
         def->naudios = 1;
         def->audios = g_new0(virDomainAudioDef *, def->naudios);
         def->audios[0] = audio;
-
-        if (audioBackend == VIR_DOMAIN_AUDIO_TYPE_SDL)
-            audio->backend.sdl.driver = audioSDLDriver;
     }
 
     return 0;
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux