File 5ea2abb3-libxl-join-mig-rcv-thread.patch of Package libvirt.22293

commit 5ea2abb3bfd552175dc2dfcc295fde3fbf17fc37
Author: Jim Fehlig <jfehlig@suse.com>
Date:   Fri Aug 24 15:38:14 2018 -0600

    libxl: join with thread receiving migration data
    
    It is possible the incoming VM is not fully started when the finish
    phase of migration is executed. In libxlDomainMigrationDstFinish,
    wait for the thread receiving the VM to complete before executing
    finish phase tasks.
    
    Signed-off-by: Jim Fehlig <jfehlig@suse.com>
    ACKed-by: Michal Privoznik <mprivozn@redhat.com>

Index: libvirt-4.0.0/src/libxl/libxl_domain.h
===================================================================
--- libvirt-4.0.0.orig/src/libxl/libxl_domain.h
+++ libvirt-4.0.0/src/libxl/libxl_domain.h
@@ -65,6 +65,7 @@ struct _libxlDomainObjPrivate {
     /* console */
     virChrdevsPtr devs;
     libxl_evgen_domain_death *deathW;
+    virThreadPtr migrationDstReceiveThr;
     unsigned short migrationPort;
     char *lockState;
 
Index: libvirt-4.0.0/src/libxl/libxl_migration.c
===================================================================
--- libvirt-4.0.0.orig/src/libxl/libxl_migration.c
+++ libvirt-4.0.0/src/libxl/libxl_migration.c
@@ -298,9 +298,9 @@ libxlMigrateReceive(virNetSocketPtr sock
     libxlMigrationDstArgs *args = opaque;
     virNetSocketPtr *socks = args->socks;
     size_t nsocks = args->nsocks;
+    libxlDomainObjPrivatePtr priv = args->vm->privateData;
     virNetSocketPtr client_sock;
     int recvfd = -1;
-    virThread thread;
     size_t i;
 
     /* Accept migration connection */
@@ -319,7 +319,10 @@ libxlMigrateReceive(virNetSocketPtr sock
      * the migration data
      */
     args->recvfd = recvfd;
-    if (virThreadCreate(&thread, false,
+    VIR_FREE(priv->migrationDstReceiveThr);
+    if (VIR_ALLOC(priv->migrationDstReceiveThr) < 0)
+        goto fail;
+    if (virThreadCreate(priv->migrationDstReceiveThr, true,
                         libxlDoMigrateReceive, args) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("Failed to create thread for receiving migration data"));
@@ -558,7 +561,6 @@ libxlDomainMigrationPrepareTunnel3(virCo
     libxlDriverPrivatePtr driver = dconn->privateData;
     virDomainObjPtr vm = NULL;
     libxlMigrationDstArgs *args = NULL;
-    virThread thread;
     bool taint_hook = false;
     libxlDomainObjPrivatePtr priv = NULL;
     char *xmlout = NULL;
@@ -620,7 +622,10 @@ libxlDomainMigrationPrepareTunnel3(virCo
     args->nsocks = 0;
     mig = NULL;
 
-    if (virThreadCreate(&thread, false, libxlDoMigrateReceive, args) < 0) {
+    VIR_FREE(priv->migrationDstReceiveThr);
+    if (VIR_ALLOC(priv->migrationDstReceiveThr) < 0)
+        goto error;
+    if (virThreadCreate(priv->migrationDstReceiveThr, true, libxlDoMigrateReceive, args) < 0) {
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                        _("Failed to create thread for receiving migration data"));
         goto endjob;
@@ -1301,6 +1306,13 @@ libxlDomainMigrationFinish(virConnectPtr
     virObjectEventPtr event = NULL;
     virDomainPtr dom = NULL;
 
+    if (priv->migrationDstReceiveThr) {
+        virObjectUnlock(vm);
+        virThreadJoin(priv->migrationDstReceiveThr);
+        virObjectLock(vm);
+        VIR_FREE(priv->migrationDstReceiveThr);
+    }
+
     virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
     priv->migrationPort = 0;
 
openSUSE Build Service is sponsored by