]> xenbits.xensource.com Git - libvirt.git/commitdiff
Add public APIs for post-copy migration
authorCristian Klein <cristiklein@gmail.com>
Mon, 1 Dec 2014 15:59:53 +0000 (16:59 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 21 Mar 2016 14:15:46 +0000 (15:15 +0100)
To use post-copy one has to start the migration with
VIR_MIGRATE_POSTCOPY flag and, while migration is in progress, call
virDomainMigrateStartPostCopy() to switch from pre-copy to post-copy.

Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
include/libvirt/libvirt-domain.h
src/driver-hypervisor.h
src/libvirt-domain.c
src/libvirt_public.syms
src/remote/remote_driver.c
src/remote/remote_protocol.x
src/remote_protocol-structs

index f97a808143f2d08d20162724b09d43a5f89d8333..7e06796c3c7357b14d3aeedbd3211e5800bbccb0 100644 (file)
@@ -678,6 +678,7 @@ typedef enum {
     VIR_MIGRATE_ABORT_ON_ERROR    = (1 << 12), /* abort migration on I/O errors happened during migration */
     VIR_MIGRATE_AUTO_CONVERGE     = (1 << 13), /* force convergence */
     VIR_MIGRATE_RDMA_PIN_ALL      = (1 << 14), /* RDMA memory pinning */
+    VIR_MIGRATE_POSTCOPY          = (1 << 15), /* enable (but do not start) post-copy migration */
 } virDomainMigrateFlags;
 
 
@@ -836,6 +837,9 @@ int virDomainMigrateGetMaxSpeed(virDomainPtr domain,
                                 unsigned long *bandwidth,
                                 unsigned int flags);
 
+int virDomainMigrateStartPostCopy(virDomainPtr domain,
+                                  unsigned int flags);
+
 char * virConnectGetDomainCapabilities(virConnectPtr conn,
                                        const char *emulatorbin,
                                        const char *arch,
index 2cbd01bb20ba18be91879d318c1c980ee2f39203..9bc321125ace26d2b4de4e9fa02506af209d8f4e 100644 (file)
@@ -637,6 +637,10 @@ typedef int
                                     unsigned long resource,
                                     const char *dom_xml);
 
+typedef int
+(*virDrvDomainMigrateStartPostCopy)(virDomainPtr domain,
+                                    unsigned int flags);
+
 typedef int
 (*virDrvConnectIsEncrypted)(virConnectPtr conn);
 
@@ -1455,6 +1459,7 @@ struct _virHypervisorDriver {
     virDrvDomainSetUserPassword domainSetUserPassword;
     virDrvConnectRegisterCloseCallback connectRegisterCloseCallback;
     virDrvConnectUnregisterCloseCallback connectUnregisterCloseCallback;
+    virDrvDomainMigrateStartPostCopy domainMigrateStartPostCopy;
 };
 
 
index ca32dc124bde28ad2a16f8e7bf7ddbea6f1085a2..caa81c0165ab812ee4284d8b32cb4499604da34f 100644 (file)
@@ -3537,6 +3537,7 @@ virDomainMigrateUnmanaged(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_POSTCOPY Enable (but do not start) post-copy
  *
  * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
  * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
@@ -3573,6 +3574,11 @@ virDomainMigrateUnmanaged(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * Enabling the VIR_MIGRATE_POSTCOPY flag tells libvirt to enable post-copy
+ * migration.  Use virDomainMigrateStartPostCopy to switch migration into
+ * the post-copy mode.  See virDomainMigrateStartPostCopy for more details
+ * about post-copy.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -3748,6 +3754,7 @@ virDomainMigrate(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_POSTCOPY Enable (but do not start) post-copy
  *
  * VIR_MIGRATE_TUNNELLED requires that VIR_MIGRATE_PEER2PEER be set.
  * Applications using the VIR_MIGRATE_PEER2PEER flag will probably
@@ -3784,6 +3791,11 @@ virDomainMigrate(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * Enabling the VIR_MIGRATE_POSTCOPY flag tells libvirt to enable post-copy
+ * migration.  Use virDomainMigrateStartPostCopy to switch migration into
+ * the post-copy mode.  See virDomainMigrateStartPostCopy for more details
+ * about post-copy.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -3968,6 +3980,11 @@ virDomainMigrate2(virDomainPtr domain,
  * can use either VIR_MIGRATE_NON_SHARED_DISK or
  * VIR_MIGRATE_NON_SHARED_INC as they are mutually exclusive.
  *
+ * Enabling the VIR_MIGRATE_POSTCOPY flag tells libvirt to enable post-copy
+ * migration.  Use virDomainMigrateStartPostCopy to switch migration into
+ * the post-copy mode.  See virDomainMigrateStartPostCopy for more details
+ * about post-copy.
+ *
  * There are many limitations on migration imposed by the underlying
  * technology - for example it may not be possible to migrate between
  * different processors even with the same architecture, or between
@@ -4208,6 +4225,7 @@ int virDomainMigrateUnmanagedCheckCompat(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_POSTCOPY Enable (but do not start) post-copy
  *
  * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
  * If the VIR_MIGRATE_PEER2PEER flag is NOT set, the duri parameter
@@ -4240,6 +4258,11 @@ int virDomainMigrateUnmanagedCheckCompat(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * Enabling the VIR_MIGRATE_POSTCOPY flag tells libvirt to enable post-copy
+ * migration.  Use virDomainMigrateStartPostCopy to switch migration into
+ * the post-copy mode.  See virDomainMigrateStartPostCopy for more details
+ * about post-copy.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -4321,6 +4344,7 @@ virDomainMigrateToURI(virDomainPtr domain,
  *                                 automatically when supported).
  *   VIR_MIGRATE_UNSAFE    Force migration even if it is considered unsafe.
  *   VIR_MIGRATE_OFFLINE Migrate offline
+ *   VIR_MIGRATE_POSTCOPY Enable (but do not start) post-copy
  *
  * The operation of this API hinges on the VIR_MIGRATE_PEER2PEER flag.
  *
@@ -4366,6 +4390,11 @@ virDomainMigrateToURI(virDomainPtr domain,
  * not support this feature and will return an error if bandwidth
  * is not 0.
  *
+ * Enabling the VIR_MIGRATE_POSTCOPY flag tells libvirt to enable post-copy
+ * migration.  Use virDomainMigrateStartPostCopy to switch migration into
+ * the post-copy mode.  See virDomainMigrateStartPostCopy for more details
+ * about post-copy.
+ *
  * To see which features are supported by the current hypervisor,
  * see virConnectGetCapabilities, /capabilities/host/migration_features.
  *
@@ -4446,6 +4475,11 @@ virDomainMigrateToURI2(virDomainPtr domain,
  * can use either VIR_MIGRATE_NON_SHARED_DISK or
  * VIR_MIGRATE_NON_SHARED_INC as they are mutually exclusive.
  *
+ * Enabling the VIR_MIGRATE_POSTCOPY flag tells libvirt to enable post-copy
+ * migration.  Use virDomainMigrateStartPostCopy to switch migration into
+ * the post-copy mode.  See virDomainMigrateStartPostCopy for more details
+ * about post-copy.
+ *
  * There are many limitations on migration imposed by the underlying
  * technology - for example it may not be possible to migrate between
  * different processors even with the same architecture, or between
@@ -8868,14 +8902,15 @@ virDomainGetJobInfo(virDomainPtr domain, virDomainJobInfoPtr info)
  *
  * When @flags contains VIR_DOMAIN_JOB_STATS_COMPLETED, the function will
  * return statistics about a recently completed job. Specifically, this
- * flag may be used to query statistics of a completed incoming migration.
- * Statistics of a completed job are automatically destroyed once read or
- * when libvirtd is restarted. Note that time information returned for
- * completed migrations may be completely irrelevant unless both source and
- * destination hosts have synchronized time (i.e., NTP daemon is running on
- * both of them). The statistics of a completed job can also be obtained by
- * listening to a VIR_DOMAIN_EVENT_ID_JOB_COMPLETED event (on the source host
- * in case of a migration job).
+ * flag may be used to query statistics of a completed incoming pre-copy
+ * migration (statistics for post-copy migration are only available on the
+ * source hsot). Statistics of a completed job are automatically destroyed
+ * once read or when libvirtd is restarted. Note that time information
+ * returned for completed migrations may be completely irrelevant unless both
+ * source and destination hosts have synchronized time (i.e., NTP daemon is
+ * running on both of them). The statistics of a completed job can also be
+ * obtained by listening to a VIR_DOMAIN_EVENT_ID_JOB_COMPLETED event (on the
+ * source host in case of a migration job).
  *
  * Returns 0 in case of success and -1 in case of failure.
  */
@@ -9164,6 +9199,96 @@ virDomainMigrateGetMaxSpeed(virDomainPtr domain,
 }
 
 
+/**
+ * virDomainMigrateStartPostCopy:
+ * @domain: a domain object
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Starts post-copy migration. This function has to be called while
+ * migration (initiated with VIR_MIGRATE_POSTCOPY flag) is in progress.
+ *
+ * Traditional pre-copy migration iteratively walks through guest memory
+ * pages and migrates those that changed since the previous iteration. The
+ * iterative phase stops when the number of dirty pages is low enough so that
+ * the virtual CPUs can be paused, all dirty pages transferred to the
+ * destination, where the virtual CPUs are unpaused, and all this can happen
+ * within a predefined downtime period. It's clear that this process may never
+ * converge if downtime is too short and/or the guest keeps changing a lot of
+ * memory pages.
+ *
+ * When migration is switched to post-copy mode, the virtual CPUs are paused
+ * immediately, only a minimum set of pages is transferred, and the CPUs are
+ * unpaused on destination. The source keeps sending all remaining memory pages
+ * to the destination while the guest is already running there. Whenever the
+ * guest tries to read a memory page which has not been migrated yet, the
+ * hypervisor has to tell the source to transfer that page in a priority
+ * channel. To minimize such page faults, it is a good idea to run at least one
+ * iteration of pre-copy migration before switching to post-copy.
+ *
+ * Post-copy migration is guaranteed to converge since each page is transferred
+ * at most once no matter how fast it changes. On the other hand once the
+ * guest is running on the destination host, the migration can no longer be
+ * rolled back because none of the hosts has complete state. If this happens,
+ * libvirt will leave the domain paused on both hosts with
+ * VIR_DOMAIN_PAUSED_POSTCOPY_FAILED reason. It's up to the upper layer to
+ * decide what to do in such case.
+ *
+ * The following domain life cycle events are emitted during post-copy
+ * migration:
+ *  VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY (on the source) -- migration entered
+ *      post-copy mode.
+ *  VIR_DOMAIN_EVENT_RESUMED_POSTCOPY (on the destination) -- the guest is
+ *      running on the destination host while some of its memory pages still
+ *      remain on the source host; neither the source nor the destination host
+ *      contain a complete guest state from this point until migration
+ *      finishes.
+ *  VIR_DOMAIN_EVENT_RESUMED_MIGRATED (on the destination),
+ *  VIR_DOMAIN_EVENT_STOPPED_MIGRATED (on the source) -- migration finished
+ *      successfully and the destination host holds a complete guest state.
+ *  VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED (on the destination) -- emitted
+ *      when migration fails in post-copy mode and it's unclear whether any
+ *      of the hosts has a complete guest state.
+ *
+ * The progress of a post-copy migration can be monitored normally using
+ * virDomainGetJobStats on the source host. Fetching statistics of a completed
+ * post-copy migration can also be done on the source host (by calling
+ * virDomainGetJobStats or listening to VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
+ * event, but (in contrast to pre-copy migration) the statistics are not
+ * available on the destination host. Thus, VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
+ * event is the only way of getting statistics of a completed post-copy
+ * migration of a transient domain (because the domain is removed after
+ * migration and there's no domain to run virDomainGetJobStats on).
+ *
+ * Returns 0 in case of success, -1 otherwise.
+ */
+int
+virDomainMigrateStartPostCopy(virDomainPtr domain,
+                              unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain);
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+    conn = domain->conn;
+
+    virCheckReadOnlyGoto(conn->flags, error);
+
+    if (conn->driver->domainMigrateStartPostCopy) {
+        if (conn->driver->domainMigrateStartPostCopy(domain, flags) < 0)
+            goto error;
+        return 0;
+    }
+
+    virReportUnsupportedError();
+ error:
+    virDispatchError(conn);
+    return -1;
+}
+
+
 /**
  * virConnectDomainEventRegisterAny:
  * @conn: pointer to the connection
index dd9419185f4564ca0307a6102d6374d91a27183e..221743a7f843f218102dadc825158c7752cd337b 100644 (file)
@@ -725,4 +725,9 @@ LIBVIRT_1.2.19 {
         virDomainRename;
 } LIBVIRT_1.2.17;
 
+LIBVIRT_1.3.3 {
+    global:
+        virDomainMigrateStartPostCopy;
+} LIBVIRT_1.2.19;
+
 # .... define new API here using predicted next version number ....
index d342227d4675de71d5ccc9f4257f5df9f7640867..be7b2f4a04f3373868b37ba334ac560a2b637e58 100644 (file)
@@ -7763,6 +7763,7 @@ static virHypervisorDriver hypervisor_driver = {
     .domainRename = remoteDomainRename, /* 1.2.19 */
     .connectRegisterCloseCallback = remoteConnectRegisterCloseCallback, /* 1.3.2 */
     .connectUnregisterCloseCallback = remoteConnectUnregisterCloseCallback, /* 1.3.2 */
+    .domainMigrateStartPostCopy = remoteDomainMigrateStartPostCopy, /* 1.3.3 */
 };
 
 static virNetworkDriver network_driver = {
index b4cb8f11096724a6b99b8304013939d9e8efcc7e..017bdbba9316256e1038803cc8aa9f46517a7523 100644 (file)
@@ -3238,6 +3238,11 @@ struct remote_domain_event_callback_job_completed_msg {
     remote_typed_param params<REMOTE_DOMAIN_JOB_STATS_MAX>;
 };
 
+struct remote_domain_migrate_start_post_copy_args {
+    remote_nonnull_domain dom;
+    unsigned int flags;
+};
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -5740,5 +5745,11 @@ enum remote_procedure {
      * @generate: both
      * @acl: none
      */
-    REMOTE_PROC_DOMAIN_EVENT_CALLBACK_JOB_COMPLETED = 363
+    REMOTE_PROC_DOMAIN_EVENT_CALLBACK_JOB_COMPLETED = 363,
+
+    /**
+     * @generate: both
+     * @acl: domain:migrate
+     */
+    REMOTE_PROC_DOMAIN_MIGRATE_START_POST_COPY = 364
 };
index 070338c40053c746347ad99a28c501dd16c96c80..9d59e0e7fab15b5884868940ec4a4893717a98b1 100644 (file)
@@ -2708,6 +2708,10 @@ struct remote_domain_event_callback_job_completed_msg {
                 remote_typed_param * params_val;
         } params;
 };
+struct remote_domain_migrate_start_post_copy_args {
+        remote_nonnull_domain      dom;
+        u_int                      flags;
+};
 enum remote_procedure {
         REMOTE_PROC_CONNECT_OPEN = 1,
         REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -3072,4 +3076,5 @@ enum remote_procedure {
         REMOTE_PROC_CONNECT_CLOSE_CALLBACK_UNREGISTER = 361,
         REMOTE_PROC_CONNECT_EVENT_CONNECTION_CLOSED = 362,
         REMOTE_PROC_DOMAIN_EVENT_CALLBACK_JOB_COMPLETED = 363,
+        REMOTE_PROC_DOMAIN_MIGRATE_START_POST_COPY = 364,
 };