]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: send allowReboot in migration cookie
authorPavel Hrdina <phrdina@redhat.com>
Fri, 13 Oct 2017 10:06:54 +0000 (12:06 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 19 Oct 2017 09:52:34 +0000 (11:52 +0200)
We need to send allowReboot in the migration cookie to ensure the same
behavior of the virDomainSetLifecycleAction() API on the destination.

Consider this scenario:

    1. On the source the domain is started with:
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>restart</on_reboot>
        <on_crash>destroy</on_crash>

    2. User calls an API to set "destroy" for <on_reboot>:
        <on_poweroff>destroy</on_poweroff>
        <on_reboot>destroy</on_reboot>
        <on_crash>destroy</on_crash>

    3. The guest is migrated to a different host

    4a. Without the allowReboot in the migration cookie the QEMU
        process on destination would be started with -no-reboot
        which would prevent using the virDomainSetLifecycleAction() API
        for the rest of the guest lifetime.

    4b. With the allowReboot in the migration cookie the QEMU process
        on destination is started without -no-reboot like it was started
        on the source host and the virDomainSetLifecycleAction() API
        continues to work.

The following patch adds a QEMU implementation of the
virDomainSetLifecycleAction() API and that implementation disallows
using the API if all actions are set to "destroy" because we add
"-no-reboot" on the QEMU command line.  Changing the lifecycle action
is in this case pointless because the QEMU process is always terminated.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_migration.c
src/qemu/qemu_migration_cookie.c
src/qemu/qemu_migration_cookie.h

index 26f65e2d9bcd2877a46dbaab1d75fce428442d88..42db316ef7351bd3fdb3a3846b3b2a7d98e09196 100644 (file)
@@ -1877,7 +1877,7 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf,
 }
 
 
-static void
+void
 qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
                                          virTristateBool allowReboot)
 {
@@ -2121,7 +2121,7 @@ qemuDomainObjPrivateXMLParseBlockjobs(qemuDomainObjPrivatePtr priv,
 }
 
 
-static int
+int
 qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
                                         virTristateBool *allowReboot)
 {
index afe979d2ed5748bddc9b240d6c0266bcf50946f2..1c99be4c28a57687d2e0ba938caab77f8e5b159e 100644 (file)
@@ -979,4 +979,12 @@ qemuDomainFixupCPUs(virDomainObjPtr vm,
 char *
 qemuDomainGetMachineName(virDomainObjPtr vm);
 
+void
+qemuDomainObjPrivateXMLFormatAllowReboot(virBufferPtr buf,
+                                         virTristateBool allowReboot);
+
+int
+qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
+                                        virTristateBool *allowReboot);
+
 #endif /* __QEMU_DOMAIN_H__ */
index b286d68061eb7d20fd1d170f5b25f799483afb4b..57544ee8370ba548906d97ae3f90eb5c560361a5 100644 (file)
@@ -2023,6 +2023,8 @@ qemuMigrationBeginPhase(virQEMUDriverPtr driver,
     if (priv->origCPU)
         cookieFlags |= QEMU_MIGRATION_COOKIE_CPU;
 
+    cookieFlags |= QEMU_MIGRATION_COOKIE_ALLOW_REBOOT;
+
     if (!(mig = qemuMigrationEatCookie(driver, vm, NULL, 0, 0)))
         goto cleanup;
 
@@ -2649,7 +2651,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
                                        QEMU_MIGRATION_COOKIE_NBD |
                                        QEMU_MIGRATION_COOKIE_MEMORY_HOTPLUG |
                                        QEMU_MIGRATION_COOKIE_CPU_HOTPLUG |
-                                       QEMU_MIGRATION_COOKIE_CPU)))
+                                       QEMU_MIGRATION_COOKIE_CPU |
+                                       QEMU_MIGRATION_COOKIE_ALLOW_REBOOT)))
         goto cleanup;
 
     if (STREQ_NULLABLE(protocol, "rdma") &&
@@ -2689,6 +2692,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
         goto stopjob;
     stopProcess = true;
 
+    priv->allowReboot = mig->allowReboot;
+
     if (!(incoming = qemuMigrationPrepareIncoming(vm, tunnel, protocol,
                                                   listenAddress, port,
                                                   dataFD[0])))
index bc6a8dc552817c8b7154c0ab7eb691e3cadf8747..28779137930f44ab22d09a52e3e0f5c8ce389973 100644 (file)
@@ -49,7 +49,8 @@ VIR_ENUM_IMPL(qemuMigrationCookieFlag,
               "statistics",
               "memory-hotplug",
               "cpu-hotplug",
-              "cpu");
+              "cpu",
+              "allowReboot");
 
 
 static void
@@ -537,6 +538,18 @@ qemuMigrationCookieAddCPU(qemuMigrationCookiePtr mig,
 }
 
 
+static void
+qemuMigrationCookieAddAllowReboot(qemuMigrationCookiePtr mig,
+                                  virDomainObjPtr vm)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+
+    mig->allowReboot = priv->allowReboot;
+
+    mig->flags |= QEMU_MIGRATION_COOKIE_ALLOW_REBOOT;
+}
+
+
 static void
 qemuMigrationCookieGraphicsXMLFormat(virBufferPtr buf,
                                      qemuMigrationCookieGraphicsPtr grap)
@@ -777,6 +790,9 @@ qemuMigrationCookieXMLFormat(virQEMUDriverPtr driver,
     if (mig->flags & QEMU_MIGRATION_COOKIE_CPU && mig->cpu)
         virCPUDefFormatBufFull(buf, mig->cpu, NULL);
 
+    if (mig->flags & QEMU_MIGRATION_COOKIE_ALLOW_REBOOT)
+        qemuDomainObjPrivateXMLFormatAllowReboot(buf, mig->allowReboot);
+
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</qemu-migration>\n");
     return 0;
@@ -1225,6 +1241,10 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr mig,
         virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &mig->cpu) < 0)
         goto error;
 
+    if (flags & QEMU_MIGRATION_COOKIE_ALLOW_REBOOT &&
+        qemuDomainObjPrivateXMLParseAllowReboot(ctxt, &mig->allowReboot) < 0)
+        goto error;
+
     virObjectUnref(caps);
     return 0;
 
@@ -1305,6 +1325,9 @@ qemuMigrationBakeCookie(qemuMigrationCookiePtr mig,
         qemuMigrationCookieAddCPU(mig, dom) < 0)
         return -1;
 
+    if (flags & QEMU_MIGRATION_COOKIE_ALLOW_REBOOT)
+        qemuMigrationCookieAddAllowReboot(mig, dom);
+
     if (!(*cookieout = qemuMigrationCookieXMLFormatStr(driver, mig)))
         return -1;
 
index e5f3d75a95813c2a93bd1f315be39075d1b13b08..4a25511a9a2f9ff35c0b8a2fd0f496f12023f08d 100644 (file)
@@ -29,6 +29,7 @@ typedef enum {
     QEMU_MIGRATION_COOKIE_FLAG_MEMORY_HOTPLUG,
     QEMU_MIGRATION_COOKIE_FLAG_CPU_HOTPLUG,
     QEMU_MIGRATION_COOKIE_FLAG_CPU,
+    QEMU_MIGRATION_COOKIE_FLAG_ALLOW_REBOOT,
 
     QEMU_MIGRATION_COOKIE_FLAG_LAST
 } qemuMigrationCookieFlags;
@@ -45,6 +46,7 @@ typedef enum {
     QEMU_MIGRATION_COOKIE_MEMORY_HOTPLUG = (1 << QEMU_MIGRATION_COOKIE_FLAG_MEMORY_HOTPLUG),
     QEMU_MIGRATION_COOKIE_CPU_HOTPLUG = (1 << QEMU_MIGRATION_COOKIE_FLAG_CPU_HOTPLUG),
     QEMU_MIGRATION_COOKIE_CPU = (1 << QEMU_MIGRATION_COOKIE_FLAG_CPU),
+    QEMU_MIGRATION_COOKIE_ALLOW_REBOOT = (1 << QEMU_MIGRATION_COOKIE_FLAG_ALLOW_REBOOT),
 } qemuMigrationCookieFeatures;
 
 typedef struct _qemuMigrationCookieGraphics qemuMigrationCookieGraphics;
@@ -127,6 +129,9 @@ struct _qemuMigrationCookie {
 
     /* If flags & QEMU_MIGRATION_COOKIE_CPU */
     virCPUDefPtr cpu;
+
+    /* If flags & QEMU_MIGRATION_COOKIE_ALLOW_REBOOT */
+    virTristateBool allowReboot;
 };