[libvirt] [PATCH] Fix macvtap device tear down problem on virsh destroy

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

 



This patch fixes the problem with the tear down of the macvtap device
when issuing a 'virsh destroy' by moving the tear down block past the
point of killing the Qemu process. It seems necessary to loop at least
once in the case of 'virsh destory' since the device seems to be busy
for a while after the Qemu process has been killed. This also still
properly tears down the macvtap device when the VM is 'virsh shutdown'ed
or halted from inside.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>

Index: libvirt-macvtap/src/qemu/qemu_driver.c
===================================================================
--- libvirt-macvtap.orig/src/qemu/qemu_driver.c
+++ libvirt-macvtap/src/qemu/qemu_driver.c
@@ -2905,6 +2905,7 @@ static void qemudShutdownVMDaemon(struct
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virErrorPtr orig_err;
     virDomainDefPtr def;
+    int hasBusyDev;
     int i;
 
     if (!virDomainObjIsActive(vm))
@@ -2931,17 +2932,6 @@ static void qemudShutdownVMDaemon(struct
         }
     }
 
-#if WITH_MACVTAP
-    def = vm->def;
-    for (i = 0; i < def->nnets; i++) {
-        virDomainNetDefPtr net = def->nets[i];
-        if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
-            int dummy;
-            delMacvtapByMACAddress(net->mac, &dummy);
-        }
-    }
-#endif
-
     if (virKillProcess(vm->pid, 0) == 0 &&
         virKillProcess(vm->pid, SIGTERM) < 0)
         virReportSystemError(errno,
@@ -2988,6 +2978,23 @@ static void qemudShutdownVMDaemon(struct
 
     qemuDomainReAttachHostDevices(driver, vm->def);
 
+#if WITH_MACVTAP
+    def = vm->def;
+    for (i = 0; i < def->nnets; i++) {
+        virDomainNetDefPtr net = def->nets[i];
+        if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
+            while (1) {
+                delMacvtapByMACAddress(net->mac, &hasBusyDev);
+                if (hasBusyDev && retries++ < 5) {
+                    usleep(200*1000);
+                } else
+                    break;
+            }
+        }
+    }
+#endif
+
+    retries = 0;
 retry:
     if ((ret = qemuRemoveCgroup(driver, vm, 0)) < 0) {
         if (ret == -EBUSY && (retries++ < 5)) {
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[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]