Skip to contentSkip to conversation

COarse-grain LOck-stepping Virtual Machines for Non-stop Service

PATCH Superseded Wen Congyang 5 participants 45 messages Dec 30, 2015 – Jan 27, 2016

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v9 cover COarse-grain LOck-stepping Virtual Machines for Non-stop Service

This patchset implemented the COLO feature for Xen. For detail/install/use of COLO feature, refer to:
http://wiki.xen.org/wiki/COLO_-_Coarse_Grain_Lock_Stepping

This patchset is based on:
1. http://lists.xenproject.org/archives/html/xen-devel/2015-12/msg02881.html
2. http://lists.xenproject.org/archives/html/xen-devel/2015-12/msg02884.html

Changlog from v8 to v9:
1. Rebased to the upstream xen
2. Fix some bugs found in the test

Changelog from v7 to v8:
1. Rebased to the latest libxl migration v2.

Changelog from v6 to v7:
1. Ported to Libxl migration v2
2. Send dirty bitmap from secondary to primary on libxc side
3. Address review comments

Changelog from v5 to v6:
1. based on migration v2(libxc)
2. split the patchset into prerequisite patchset and this main patchset.

Changelog from v4 to v5:
1. rebase to the latest xen upstream
2. disk replication: blktap2->qdisk
3. nic replication: colo-agent->colo-proxy

Changelog from v3 to v4:
1. rebase to newest xen
2. bug fix

Changlog from v2 to v3:
1. rebase to newest remus
2. add nic replication support

Changlog from v1 to v2:
1. rebase to newest remus
2. add disk replication support

Wen Congyang (25):
docs: add colo readme
docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo
streams
libxc/migration: Specification update for DIRTY_PFN_LIST records libxc/migration: export read_record for common use tools/libxl: add back channel support to write stream tools/libxl: write checkpoint_state records into the stream tools/libxl: add back channel support to read stream tools/libxl: handle checkpoint_state records in a libxl migration v2
read stream
tools/libx{l,c}: introduce should_checkpoint callback tools/libx{l,c}: add postcopy/suspend callback to restore side secondary vm suspend/resume/checkpoint code
primary vm suspend/resume/checkpoint code
libxc/restore: support COLO restore
libxc/restore: send dirty pfn list to primary when checkpoint under
colo
send store gfn and console gfn to xl before resuming secondary vm libxc/save: support COLO save
implement the cmdline for COLO
Support colo mode for qemu disk
COLO: use qemu block replication
COLO proxy: implement setup/teardown of COLO proxy module COLO proxy: preresume, postresume and checkpoint
COLO nic: implement COLO nic subkind
setup and control colo proxy on primary side
setup and control colo proxy on secondary side
cmdline switches and config vars to control colo-proxy

 docs/README.colo                         |    9 +
 docs/man/xl.conf.pod.5                   |    6 +
 docs/man/xl.pod.1                        |   11 +-
 docs/misc/xl-disk-configuration.txt      |   50 ++
 docs/specs/libxc-migration-stream.pandoc |   24 +-
 docs/specs/libxl-migration-stream.pandoc |   25 +-
 tools/hotplug/Linux/Makefile             |    1 +
 tools/hotplug/Linux/colo-proxy-setup     |  135 ++++
 tools/libxc/include/xenguest.h           |   36 +
 tools/libxc/xc_sr_common.c               |   50 ++
 tools/libxc/xc_sr_common.h               |   26 +-
 tools/libxc/xc_sr_restore.c              |  244 +++++--
 tools/libxc/xc_sr_save.c                 |  102 ++-
 tools/libxc/xc_sr_stream_format.h        |    1 +
 tools/libxl/Makefile                     |    4 +
 tools/libxl/libxl.c                      |   97 ++-
 tools/libxl/libxl_colo.h                 |   40 ++
 tools/libxl/libxl_colo_nic.c             |  321 +++++++++
 tools/libxl/libxl_colo_proxy.c           |  292 ++++++++
 tools/libxl/libxl_colo_qdisk.c           |  262 ++++++++
 tools/libxl/libxl_colo_restore.c         | 1085 ++++++++++++++++++++++++++++++
 tools/libxl/libxl_colo_save.c            |  701 +++++++++++++++++++
 tools/libxl/libxl_create.c               |   79 ++-
 tools/libxl/libxl_device.c               |   54 ++
 tools/libxl/libxl_dm.c                   |  184 ++++-
 tools/libxl/libxl_dom_save.c             |   14 +-
 tools/libxl/libxl_internal.h             |  234 +++++--
 tools/libxl/libxl_qmp.c                  |   93 +++
 tools/libxl/libxl_save_callout.c         |    7 +-
 tools/libxl/libxl_save_msgs_gen.pl       |   13 +-
 tools/libxl/libxl_sr_stream_format.h     |   11 +
 tools/libxl/libxl_stream_read.c          |   96 ++-
 tools/libxl/libxl_stream_write.c         |   86 ++-
 tools/libxl/libxl_types.idl              |   10 +
 tools/libxl/libxlu_disk_l.l              |    7 +
 tools/libxl/xl.c                         |    3 +
 tools/libxl/xl.h                         |    1 +
 tools/libxl/xl_cmdimpl.c                 |   99 ++-
 tools/libxl/xl_cmdtable.c                |    4 +-
 tools/python/xen/migration/libxc.py      |    8 +
 tools/python/xen/migration/libxl.py      |    9 +
 41 files changed, 4340 insertions(+), 194 deletions(-)
 create mode 100644 docs/README.colo
 create mode 100755 tools/hotplug/Linux/colo-proxy-setup
 create mode 100644 tools/libxl/libxl_colo.h
 create mode 100644 tools/libxl/libxl_colo_nic.c
 create mode 100644 tools/libxl/libxl_colo_proxy.c
 create mode 100644 tools/libxl/libxl_colo_qdisk.c
 create mode 100644 tools/libxl/libxl_colo_restore.c
 create mode 100644 tools/libxl/libxl_colo_save.c
Signature · 1 line
2.5.0
#1 lore raw

PATCH v9 1/25 docs: add colo readme

add colo readme, refer to
http://wiki.xen.org/wiki/COLO_-_Coarse_Grain_Lock_Stepping

---
 docs/README.colo | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 docs/README.colo
docs/README.colo new file +9 -0
new file mode 100644
index 0000000..466eb72
@@ -0,0 +1,9 @@
+COLO FT/HA (COarse-grain LOck-stepping Virtual Machines for Non-stop Service)
+project is a high availability solution. Both primary VM (PVM) and secondary VM
+(SVM) run in parallel. They receive the same request from client, and generate
+response in parallel too. If the response packets from PVM and SVM are
+identical, they are released immediately. Otherwise, a VM checkpoint (on demand)
+is conducted.
+
+See the website at http://wiki.xen.org/wiki/COLO_-_Coarse_Grain_Lock_Stepping
+for details.
Signature · 1 line
2.5.0
#2 lore raw

PATCH v9 2/25 docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

In reply to Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +23 -2
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_
              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -249,6 +251,25 @@ A checkpoint end record marks the end of a checkpoint in the image.
 The end record contains no fields; its body_length is 0.
 
 
+CHECKPOINT\_STATE
+--------------
+
+A checkpoint state record contains the control information for checkpoint.
+
+     0     1     2     3     4     5     6     7 octet
+    +------------------------+------------------------+
+    | control_id             | padding                |
+    +------------------------+------------------------+
+
+--------------------------------------------------------------------
+Field            Description
+------------     ---------------------------------------------------
+control_id       0x00000000: Secondary VM is out of sync, start a new checkpoint
+                 0x00000001: Secondary VM is suspended
+                 0x00000002: Secondary VM is ready
+                 0x00000003: Secondary VM is resumed
+--------------------------------------------------------------------
+
 Future Extensions
 =================
 
tools/libxl/libxl_sr_stream_format.h +11 -0
index 54da360..75f5190 100644
@@ -36,6 +36,7 @@ typedef struct libxl__sr_rec_hdr
 #define REC_TYPE_EMULATOR_XENSTORE_DATA 0x00000002U
 #define REC_TYPE_EMULATOR_CONTEXT       0x00000003U
 #define REC_TYPE_CHECKPOINT_END         0x00000004U
+#define REC_TYPE_CHECKPOINT_STATE       0x00000005U
 
 typedef struct libxl__sr_emulator_hdr
 {
@@ -47,6 +48,16 @@ typedef struct libxl__sr_emulator_hdr
 #define EMULATOR_QEMU_TRADITIONAL    0x00000001U
 #define EMULATOR_QEMU_UPSTREAM       0x00000002U
 
+typedef struct libxl_sr_checkpoint_state
+{
+    uint32_t id;
+} libxl_sr_checkpoint_state;
+
+#define CHECKPOINT_NEW               0x00000000U
+#define CHECKPOINT_SVM_SUSPENDED     0x00000001U
+#define CHECKPOINT_SVM_READY         0x00000002U
+#define CHECKPOINT_SVM_RESUMED       0x00000003U
+
 #endif /* LIBXL__SR_STREAM_FORMAT_H */
 
 /*
tools/python/xen/migration/libxl.py +9 -0
index fc0acf6..d5f54dc 100644
@@ -37,6 +37,7 @@ REC_TYPE_libxc_context          = 0x00000001
 REC_TYPE_emulator_xenstore_data = 0x00000002
 REC_TYPE_emulator_context       = 0x00000003
 REC_TYPE_checkpoint_end         = 0x00000004
+REC_TYPE_checkpoint_state       = 0x00000005
 
 rec_type_to_str = {
     REC_TYPE_end                    : "End",
@@ -44,6 +45,7 @@ rec_type_to_str = {
     REC_TYPE_emulator_xenstore_data : "Emulator xenstore data",
     REC_TYPE_emulator_context       : "Emulator context",
     REC_TYPE_checkpoint_end         : "Checkpoint end",
+    REC_TYPE_checkpoint_state       : "Checkpoint state"
 }
 
 # emulator_* header
@@ -212,6 +214,11 @@ class VerifyLibxl(VerifyBase):
         if len(content) != 0:
             raise RecordError("Checkpoint end record with non-zero length")
 
+    def verify_record_checkpoint_state(self, content):
+        """ Checkpoint state """
+        if len(content) == 0:
+            raise RecordError("Checkpoint state record with zero length")
+
 
 record_verifiers = {
     REC_TYPE_end:
@@ -224,4 +231,6 @@ record_verifiers = {
         VerifyLibxl.verify_record_emulator_context,
     REC_TYPE_checkpoint_end:
         VerifyLibxl.verify_record_checkpoint_end,
+    REC_TYPE_checkpoint_state:
+        VerifyLibxl.verify_record_checkpoint_state,
 }
Signature · 1 line
2.5.0
#3 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 29 lines · Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +1 -1
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============

docs/specs/libxl-migration-stream.pandoc type 0x00000000: END · line 124

Quoted 7 lines
docs/specs/libxl-migration-stream.pandoc +3 -1
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_

This is in the 'mandatory' records. Should it be part of optional records?

Would this checkpoint state always present on non-COLO guest migration?

#4 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 33 lines · Konrad Rzeszutek Wilk
Quoted 32 lines · Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +1 -1
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
Quoted 8 lines

docs/specs/libxl-migration-stream.pandoc type 0x00000000: END · line 124

Quoted 4 lines
docs/specs/libxl-migration-stream.pandoc +3 -1
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_

This is in the 'mandatory' records. Should it be part of optional records?

Would this checkpoint state always present on non-COLO guest migration?

No. Will be fixed in the next version

Thanks
Wen Congyang

Quoted 5 lines

.

#5 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 34 lines · Wen Congyang
Quoted 33 lines · Konrad Rzeszutek Wilk
Quoted 32 lines · Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +1 -1
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
Quoted 8 lines
Quoted 7 lines

docs/specs/libxl-migration-stream.pandoc type 0x00000000: END · line 124

Quoted 4 lines
docs/specs/libxl-migration-stream.pandoc +3 -1
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_

This is in the 'mandatory' records. Should it be part of optional records?

Would this checkpoint state always present on non-COLO guest migration?

No. Will be fixed in the next version

It is correct that CHECKPOINT_STATE is a mandatory record.

Optional records which are free for the receiving end to ignore if they are not understood.

~Andrew

#6 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 41 lines · Andrew Cooper
Quoted 40 lines · Wen Congyang
Quoted 39 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +1 -1
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============

docs/specs/libxl-migration-stream.pandoc type 0x00000000: END · line 124

Quoted 7 lines
docs/specs/libxl-migration-stream.pandoc +3 -1
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_

This is in the 'mandatory' records. Should it be part of optional records?

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Would this checkpoint state always present on non-COLO guest migration?

No. Will be fixed in the next version

It is correct that CHECKPOINT_STATE is a mandatory record.

Optional records which are free for the receiving end to ignore if they are not understood.

What you are saying is that the receving end has to expect this (CHECKPOINT_STATE) even there is nothing in them - as the size of them is zero (becuase there are no dirty PFNs to send).

Quoted 2 lines

~Andrew

#7 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 43 lines · Konrad Rzeszutek Wilk
Quoted 42 lines · Andrew Cooper
Quoted 41 lines · Wen Congyang
Quoted 40 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +1 -1
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============

docs/specs/libxl-migration-stream.pandoc type 0x00000000: END · line 124

Quoted 7 lines
docs/specs/libxl-migration-stream.pandoc +3 -1
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_

This is in the 'mandatory' records. Should it be part of optional records?

Would this checkpoint state always present on non-COLO guest migration?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

No. Will be fixed in the next version

It is correct that CHECKPOINT_STATE is a mandatory record.

Optional records which are free for the receiving end to ignore if they are not understood.

What you are saying is that the receving end has to expect this (CHECKPOINT_STATE) even there is nothing in them - as the size of them is zero (becuase there are no dirty PFNs to send).

The sole difference between a mandatory record an an option record is the receivers behaviour.

Mandatory records may not be ignored, and constitutes a hard error. Optional records may be ignored, without error, if they are not understood.

~Andrew

#8 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 53 lines · Andrew Cooper
Quoted 43 lines · Konrad Rzeszutek Wilk
Quoted 42 lines · Andrew Cooper
Quoted 41 lines · Wen Congyang
Quoted 40 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +1 -1
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============

docs/specs/libxl-migration-stream.pandoc type 0x00000000: END · line 124

Quoted 7 lines
docs/specs/libxl-migration-stream.pandoc +3 -1
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_

This is in the 'mandatory' records. Should it be part of optional records?

Would this checkpoint state always present on non-COLO guest migration?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

No. Will be fixed in the next version

It is correct that CHECKPOINT_STATE is a mandatory record.

Optional records which are free for the receiving end to ignore if they are not understood.

What you are saying is that the receving end has to expect this (CHECKPOINT_STATE) even there is nothing in them - as the size of them is zero (becuase there are no dirty PFNs to send).

Quoted 5 lines

The sole difference between a mandatory record an an option record is the receivers behaviour.

Mandatory records may not be ignored, and constitutes a hard error. Optional records may be ignored, without error, if they are not understood.

You are still not answering my question.

Is it a hard error if the mandatory record is zero length?

Quoted 2 lines

~Andrew

#9 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 53 lines · Konrad Rzeszutek Wilk
Quoted 52 lines · Andrew Cooper
Quoted 51 lines · Konrad Rzeszutek Wilk
Quoted 41 lines · Andrew Cooper
Quoted 40 lines · Wen Congyang
Quoted 39 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Wen Congyang

It is the negotiation record for COLO.
Primary->Secondary:
control_id 0x00000000: Secondary VM is out of sync, start a new checkpoint
Secondary->Primary:

                0x00000001: Secondary VM is suspended
                0x00000002: Secondary VM is ready
                0x00000003: Secondary VM is resumed
---
 docs/specs/libxl-migration-stream.pandoc | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
docs/specs/libxl-migration-stream.pandoc +1 -1
index 2c97d86..5166d66 100644
@@ -1,6 +1,6 @@
 % LibXenLight Domain Image Format
 % Andrew Cooper <<[email protected]>>
-% Revision 1
+% Revision 2
 
 Introduction
 ============

docs/specs/libxl-migration-stream.pandoc type 0x00000000: END · line 124

Quoted 7 lines
docs/specs/libxl-migration-stream.pandoc +3 -1
@@ -119,7 +119,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: CHECKPOINT_STATE
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_

This is in the 'mandatory' records. Should it be part of optional records?

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Would this checkpoint state always present on non-COLO guest migration?

No. Will be fixed in the next version

It is correct that CHECKPOINT_STATE is a mandatory record.

Optional records which are free for the receiving end to ignore if they are not understood.

What you are saying is that the receving end has to expect this (CHECKPOINT_STATE) even there is nothing in them - as the size of them is zero (becuase there are no dirty PFNs to send).

Quoted 8 lines
Quoted 5 lines

The sole difference between a mandatory record an an option record is the receivers behaviour.

Mandatory records may not be ignored, and constitutes a hard error. Optional records may be ignored, without error, if they are not understood.

You are still not answering my question.

Is it a hard error if the mandatory record is zero length?

Not if the type specifies that a zero length record is permitted.

~Andrew

#10 lore raw

Re: [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Andrew Cooper writes ("Re: [Xen-devel] [PATCH v9 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams"):

Quoted 5 lines · Konrad Rzeszutek Wilk
Quoted 4 lines · Andrew Cooper
Quoted 3 lines

Mandatory records may not be ignored, and constitutes a hard error. Optional records may be ignored, without error, if they are not understood.

Mandatory' is a somewhat misleading term. (In a past life we called these different kinds of protocol extension harmful' and harmless'. A harmless' extension is one that is safe to ignore if the receiver does not know about the extension. A `harmful' extension will always cause a naive receiver to get a parse error.)

Quoted 5 lines
Quoted 3 lines

You are still not answering my question.

Is it a hard error if the mandatory record is zero length?

Not if the type specifies that a zero length record is permitted.

This is misleading. Obviously the behaviour of a naive receiver cannot depend on the specification document for the type, because that specification document was written after the type was invented.

Let me provide an exhaustive case analysis:

Optional or Value sent Receiver knows Receiver
Mandatory about the type? behaviour

Optional or No record of Yes Depends on type
Mandatory this type spec and semantics;
reciever may fail if information is required.

Optional or Empty Yes Depends on type
Mandatory record(s) spec and semantics;
empty record might be invalid or semantically inappropriate (eg inconsistent with other info)

Optional or Nonempty Yes Depends on type
Mandatory record(s) spec and semantics

Optional or No record of No Whatever it does
Mandatory this type normally, obviously

And these are the only cases where Optional' or Mandatory' makes a difference:

Optional Empty No Record(s) silently
record(s) discarded by receiver

Optional Nonempty No Record(s) silently
record(s) discarded by receiver

Mandatory Empty No Receiver ABORTS
record(s) entire operation

Mandatory Nonempty No Receiver ABORTS
record(s) entire operation

There is nothing special about empty records. Indeed an empty record can be used as a flag.

Ian.

#11 lore raw

PATCH v9 3/25 libxc/migration: Specification update for DIRTY_PFN_LIST records

In reply to Wen Congyang

Used by secondary to send it's dirty bitmap to primary under COLO.

---
 docs/specs/libxc-migration-stream.pandoc | 24 +++++++++++++++++++++++-
 tools/libxc/xc_sr_common.c               |  1 +
 tools/libxc/xc_sr_stream_format.h        |  1 +
 tools/python/xen/migration/libxc.py      |  8 ++++++++
 4 files changed, 33 insertions(+), 1 deletion(-)
docs/specs/libxc-migration-stream.pandoc +23 -1
index 8cd678f..ae1f1d0 100644
@@ -227,7 +227,9 @@ type         0x00000000: END
 
              0x0000000E: CHECKPOINT
 
-             0x0000000F - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x0000000F: DIRTY_PFN_LIST
+
+             0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_
              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -599,6 +601,26 @@ CHECKPOINT record or an END record.
 
 \clearpage
 
+DIRTY_PFN_LIST
+------------
+
+A dirty pfn list record is used to convey information about dirty memory
+in the VM. It is an unordered list of PFNs. Currently only applicable in
+the backchannel of a checkpointed stream.
+
+     0     1     2     3     4     5     6     7 octet
+    +-------------------------------------------------+
+    | pfn[0]                                          |
+    +-------------------------------------------------+
+    ...
+    +-------------------------------------------------+
+    | pfn[C-1]                                        |
+    +-------------------------------------------------+
+
+The count of pfns is: record->length/sizeof(uint64_t).
+
+\clearpage
+
 Layout
 ======
 
tools/libxc/xc_sr_common.c +1 -0
index 945cfa6..8150140 100644
@@ -35,6 +35,7 @@ static const char *mandatory_rec_types[] =
     [REC_TYPE_X86_PV_VCPU_MSRS]     = "x86 PV vcpu msrs",
     [REC_TYPE_VERIFY]               = "Verify",
     [REC_TYPE_CHECKPOINT]           = "Checkpoint",
+    [REC_TYPE_DIRTY_PFN_LIST]       = "Dirty pfn list",
 };
 
 const char *rec_type_to_str(uint32_t type)
tools/libxc/xc_sr_stream_format.h +1 -0
index 6d0f8fd..8b8533f 100644
@@ -75,6 +75,7 @@ struct xc_sr_rhdr
 #define REC_TYPE_X86_PV_VCPU_MSRS     0x0000000cU
 #define REC_TYPE_VERIFY               0x0000000dU
 #define REC_TYPE_CHECKPOINT           0x0000000eU
+#define REC_TYPE_DIRTY_PFN_LIST       0x0000000fU
 
 #define REC_TYPE_OPTIONAL             0x80000000U
 
tools/python/xen/migration/libxc.py +8 -0
index b0255ac..47da5e3 100644
@@ -60,6 +60,7 @@ REC_TYPE_toolstack            = 0x0000000b
 REC_TYPE_x86_pv_vcpu_msrs     = 0x0000000c
 REC_TYPE_verify               = 0x0000000d
 REC_TYPE_checkpoint           = 0x0000000e
+REC_TYPE_dirty_pfn_list       = 0x0000000f
 
 rec_type_to_str = {
     REC_TYPE_end                  : "End",
@@ -77,6 +78,7 @@ rec_type_to_str = {
     REC_TYPE_x86_pv_vcpu_msrs     : "x86 PV vcpu msrs",
     REC_TYPE_verify               : "Verify",
     REC_TYPE_checkpoint           : "Checkpoint",
+    REC_TYPE_dirty_pfn_list       : "Dirty pfn list"
 }
 
 # page_data
@@ -403,6 +405,10 @@ class VerifyLibxc(VerifyBase):
         if len(content) != 0:
             raise RecordError("Checkpoint record with non-zero length")
 
+    def verify_record_dirty_pfn_list(self, content):
+        """ dirty pfn list """
+        raise RecordError("Found dirty pfn list record in stream")
+
 
 record_verifiers = {
     REC_TYPE_end:
@@ -443,4 +449,6 @@ record_verifiers = {
         VerifyLibxc.verify_record_verify,
     REC_TYPE_checkpoint:
         VerifyLibxc.verify_record_checkpoint,
+    REC_TYPE_dirty_pfn_list:
+        VerifyLibxc.verify_record_dirty_pfn_list,
     }
Signature · 1 line
2.5.0
#12 lore raw

Re: [PATCH v9 03/25] libxc/migration: Specification update for DIRTY_PFN_LIST records

docs/specs/libxc-migration-stream.pandoc type 0x00000000: END · line 231

Quoted 2 lines
docs/specs/libxc-migration-stream.pandoc +2 -0
+             0x0000000F: DIRTY_PFN_LIST
+

Perhaps make it part of the optional and prefix it with CHECKPOINT?

Quoted 4 lines

+ 0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_

              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
#13 lore raw

Re: [PATCH v9 03/25] libxc/migration: Specification update for DIRTY_PFN_LIST records

Quoted 4 lines · Konrad Rzeszutek Wilk

docs/specs/libxc-migration-stream.pandoc type 0x00000000: END · line 231

Quoted 2 lines
docs/specs/libxc-migration-stream.pandoc +2 -0
+             0x0000000F: DIRTY_PFN_LIST
+

Perhaps make it part of the optional and prefix it with CHECKPOINT?

Will be fixed in the next version.

Thanks
Wen Congyang

Quoted 9 lines
Quoted 5 lines

+ 0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_

              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_

.

#14 lore raw

Re: [PATCH v9 03/25] libxc/migration: Specification update for DIRTY_PFN_LIST records

In reply to Konrad Rzeszutek Wilk
Quoted 4 lines · Konrad Rzeszutek Wilk

docs/specs/libxc-migration-stream.pandoc type 0x00000000: END · line 231

Quoted 2 lines
docs/specs/libxc-migration-stream.pandoc +2 -0
+             0x0000000F: DIRTY_PFN_LIST
+

Perhaps make it part of the optional and prefix it with CHECKPOINT?

IIUC, optional record can be ignored, but this record cannot be ignored.

To Andrew Cooper:
Should I mark this record as optional record?

Thanks
Wen Congyang

Quoted 9 lines
Quoted 5 lines

+ 0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_

              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_

.

#15 lore raw

Re: [PATCH v9 03/25] libxc/migration: Specification update for DIRTY_PFN_LIST records

Quoted 10 lines · Wen Congyang
Quoted 4 lines · Konrad Rzeszutek Wilk
Quoted 2 lines

+             0x0000000F: DIRTY_PFN_LIST
+

Perhaps make it part of the optional and prefix it with CHECKPOINT?

IIUC, optional record can be ignored, but this record cannot be ignored.

To Andrew Cooper:
Should I mark this record as optional record?

My understanding was that this indicated things for which support was mandatory (whereas unknown optional ones may be ignored), not that they must be present in every stream.

IOW placing this in the mandatory flags is correct, since the restorer cannot simply ignore a checkpoint flag.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw

Re: [PATCH v9 03/25] libxc/migration: Specification update for DIRTY_PFN_LIST records

Quoted 7 lines · Ian Campbell
Quoted 6 lines · Wen Congyang
Quoted 3 lines · Konrad Rzeszutek Wilk

docs/specs/libxc-migration-stream.pandoc type 0x00000000: END · line 231

Quoted 2 lines
docs/specs/libxc-migration-stream.pandoc +2 -0
+             0x0000000F: DIRTY_PFN_LIST
+

Perhaps make it part of the optional and prefix it with CHECKPOINT?

IIUC, optional record can be ignored, but this record cannot be ignored.

Quoted 8 lines
Quoted 2 lines

To Andrew Cooper:
Should I mark this record as optional record?

My understanding was that this indicated things for which support was mandatory (whereas unknown optional ones may be ignored), not that they must be present in every stream.

IOW placing this in the mandatory flags is correct, since the restorer cannot simply ignore a checkpoint flag.

Both correct on all points. This should be a mandatory record.

~Andrew

#17 lore raw

PATCH v9 4/25 libxc/migration: export read_record for common use

In reply to Wen Congyang

read_record() could be used by primary to read dirty bitmap record sent by secondary under COLO.
When used by save side, we need to pass the backchannel fd instead of ctx->fd to read_record(), so we added a fd param to it.

---
 tools/libxc/xc_sr_common.c  | 49 +++++++++++++++++++++++++++++++++++
 tools/libxc/xc_sr_common.h  | 14 ++++++++++
 tools/libxc/xc_sr_restore.c | 63 +--------------------------------------------
 3 files changed, 64 insertions(+), 62 deletions(-)
tools/libxc/xc_sr_common.c +49 -0
index 8150140..42ee074 100644
@@ -89,6 +89,55 @@ int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
     return -1;
 }
 
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)
+{
+    xc_interface *xch = ctx->xch;
+    struct xc_sr_rhdr rhdr;
+    size_t datasz;
+
+    if ( read_exact(fd, &rhdr, sizeof(rhdr)) )
+    {
+        PERROR("Failed to read Record Header from stream");
+        return -1;
+    }
+    else if ( rhdr.length > REC_LENGTH_MAX )
+    {
+        ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.type,
+              rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX);
+        return -1;
+    }
+
+    datasz = ROUNDUP(rhdr.length, REC_ALIGN_ORDER);
+
+    if ( datasz )
+    {
+        rec->data = malloc(datasz);
+
+        if ( !rec->data )
+        {
+            ERROR("Unable to allocate %zu bytes for record data (0x%08x, %s)",
+                  datasz, rhdr.type, rec_type_to_str(rhdr.type));
+            return -1;
+        }
+
+        if ( read_exact(fd, rec->data, datasz) )
+        {
+            free(rec->data);
+            rec->data = NULL;
+            PERROR("Failed to read %zu bytes of data for record (0x%08x, %s)",
+                   datasz, rhdr.type, rec_type_to_str(rhdr.type));
+            return -1;
+        }
+    }
+    else
+        rec->data = NULL;
+
+    rec->type   = rhdr.type;
+    rec->length = rhdr.length;
+
+    return 0;
+};
+
 static void __attribute__((unused)) build_assertions(void)
 {
     XC_BUILD_BUG_ON(sizeof(struct xc_sr_ihdr) != 24);
tools/libxc/xc_sr_common.h +14 -0
index bc99e9a..53d6129 100644
@@ -370,6 +370,20 @@ static inline int write_record(struct xc_sr_context *ctx,
 }
 
 /*
+ * Reads a record from the stream, and fills in the record structure.
+ *
+ * Returns 0 on success and non-0 on failure.
+ *
+ * On success, the records type and size shall be valid.
+ * - If size is 0, data shall be NULL.
+ * - If size is non-0, data shall be a buffer allocated by malloc() which must
+ *   be passed to free() by the caller.
+ *
+ * On failure, the contents of the record structure are undefined.
+ */
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);
+
+/*
  * This would ideally be private in restore.c, but is needed by
  * x86_pv_localise_page() if we receive pagetables frames ahead of the
  * contents of the frames they point at.
tools/libxc/xc_sr_restore.c +1 -62

75 lines not on this page · raw message

Signature · 1 line
2.5.0
#18 lore raw

Re: [PATCH v9 04/25] libxc/migration: export read_record for common use

Quoted 5 lines · Wen Congyang

read_record() could be used by primary to read dirty bitmap record sent by secondary under COLO.
When used by save side, we need to pass the backchannel fd instead of ctx->fd to read_record(), so we added a fd param to it.

Could you add:

No functional changes.

Quoted 186 lines
---
 tools/libxc/xc_sr_common.c  | 49 +++++++++++++++++++++++++++++++++++
 tools/libxc/xc_sr_common.h  | 14 ++++++++++
 tools/libxc/xc_sr_restore.c | 63 +--------------------------------------------
 3 files changed, 64 insertions(+), 62 deletions(-)
tools/libxc/xc_sr_common.c +49 -0
index 8150140..42ee074 100644
@@ -89,6 +89,55 @@ int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
     return -1;
 }
 
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)
+{
+    xc_interface *xch = ctx->xch;
+    struct xc_sr_rhdr rhdr;
+    size_t datasz;
+
+    if ( read_exact(fd, &rhdr, sizeof(rhdr)) )
+    {
+        PERROR("Failed to read Record Header from stream");
+        return -1;
+    }
+    else if ( rhdr.length > REC_LENGTH_MAX )
+    {
+        ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.type,
+              rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX);
+        return -1;
+    }
+
+    datasz = ROUNDUP(rhdr.length, REC_ALIGN_ORDER);
+
+    if ( datasz )
+    {
+        rec->data = malloc(datasz);
+
+        if ( !rec->data )
+        {
+            ERROR("Unable to allocate %zu bytes for record data (0x%08x, %s)",
+                  datasz, rhdr.type, rec_type_to_str(rhdr.type));
+            return -1;
+        }
+
+        if ( read_exact(fd, rec->data, datasz) )
+        {
+            free(rec->data);
+            rec->data = NULL;
+            PERROR("Failed to read %zu bytes of data for record (0x%08x, %s)",
+                   datasz, rhdr.type, rec_type_to_str(rhdr.type));
+            return -1;
+        }
+    }
+    else
+        rec->data = NULL;
+
+    rec->type   = rhdr.type;
+    rec->length = rhdr.length;
+
+    return 0;
+};
+
 static void __attribute__((unused)) build_assertions(void)
 {
     XC_BUILD_BUG_ON(sizeof(struct xc_sr_ihdr) != 24);
tools/libxc/xc_sr_common.h +14 -0
index bc99e9a..53d6129 100644
@@ -370,6 +370,20 @@ static inline int write_record(struct xc_sr_context *ctx,
 }
 
 /*
+ * Reads a record from the stream, and fills in the record structure.
+ *
+ * Returns 0 on success and non-0 on failure.
+ *
+ * On success, the records type and size shall be valid.
+ * - If size is 0, data shall be NULL.
+ * - If size is non-0, data shall be a buffer allocated by malloc() which must
+ *   be passed to free() by the caller.
+ *
+ * On failure, the contents of the record structure are undefined.
+ */
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);
+
+/*
  * This would ideally be private in restore.c, but is needed by
  * x86_pv_localise_page() if we receive pagetables frames ahead of the
  * contents of the frames they point at.
tools/libxc/xc_sr_restore.c +1 -62
index d4dc501..e543be3 100644
@@ -69,67 +69,6 @@ static int read_headers(struct xc_sr_context *ctx)
 }
 
 /*
- * Reads a record from the stream, and fills in the record structure.
- *
- * Returns 0 on success and non-0 on failure.
- *
- * On success, the records type and size shall be valid.
- * - If size is 0, data shall be NULL.
- * - If size is non-0, data shall be a buffer allocated by malloc() which must
- *   be passed to free() by the caller.
- *
- * On failure, the contents of the record structure are undefined.
- */
-static int read_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
-{
-    xc_interface *xch = ctx->xch;
-    struct xc_sr_rhdr rhdr;
-    size_t datasz;
-
-    if ( read_exact(ctx->fd, &rhdr, sizeof(rhdr)) )
-    {
-        PERROR("Failed to read Record Header from stream");
-        return -1;
-    }
-    else if ( rhdr.length > REC_LENGTH_MAX )
-    {
-        ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.type,
-              rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX);
-        return -1;
-    }
-
-    datasz = ROUNDUP(rhdr.length, REC_ALIGN_ORDER);
-
-    if ( datasz )
-    {
-        rec->data = malloc(datasz);
-
-        if ( !rec->data )
-        {
-            ERROR("Unable to allocate %zu bytes for record data (0x%08x, %s)",
-                  datasz, rhdr.type, rec_type_to_str(rhdr.type));
-            return -1;
-        }
-
-        if ( read_exact(ctx->fd, rec->data, datasz) )
-        {
-            free(rec->data);
-            rec->data = NULL;
-            PERROR("Failed to read %zu bytes of data for record (0x%08x, %s)",
-                   datasz, rhdr.type, rec_type_to_str(rhdr.type));
-            return -1;
-        }
-    }
-    else
-        rec->data = NULL;
-
-    rec->type   = rhdr.type;
-    rec->length = rhdr.length;
-
-    return 0;
-};
-
-/*
  * Is a pfn populated?
  */
 static bool pfn_is_populated(const struct xc_sr_context *ctx, xen_pfn_t pfn)
@@ -646,7 +585,7 @@ static int restore(struct xc_sr_context *ctx)
 
     do
     {
-        rc = read_record(ctx, &rec);
+        rc = read_record(ctx, ctx->fd, &rec);
         if ( rc )
         {
             if ( ctx->restore.buffer_all_records )
Signature · 9 lines
2.5.0




_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#19 lore raw

Re: [PATCH v9 04/25] libxc/migration: export read_record for common use

Quoted 10 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Wen Congyang

read_record() could be used by primary to read dirty bitmap record sent by secondary under COLO.
When used by save side, we need to pass the backchannel fd instead of ctx->fd to read_record(), so we added a fd param to it.

Could you add:

No functional changes.

OK, will fix it in the next version.

Thanks
Wen Congyang

Quoted 191 lines
Quoted 187 lines
---
 tools/libxc/xc_sr_common.c  | 49 +++++++++++++++++++++++++++++++++++
 tools/libxc/xc_sr_common.h  | 14 ++++++++++
 tools/libxc/xc_sr_restore.c | 63 +--------------------------------------------
 3 files changed, 64 insertions(+), 62 deletions(-)
tools/libxc/xc_sr_common.c +49 -0
index 8150140..42ee074 100644
@@ -89,6 +89,55 @@ int write_split_record(struct xc_sr_context *ctx, struct xc_sr_record *rec,
     return -1;
 }
 
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec)
+{
+    xc_interface *xch = ctx->xch;
+    struct xc_sr_rhdr rhdr;
+    size_t datasz;
+
+    if ( read_exact(fd, &rhdr, sizeof(rhdr)) )
+    {
+        PERROR("Failed to read Record Header from stream");
+        return -1;
+    }
+    else if ( rhdr.length > REC_LENGTH_MAX )
+    {
+        ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.type,
+              rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX);
+        return -1;
+    }
+
+    datasz = ROUNDUP(rhdr.length, REC_ALIGN_ORDER);
+
+    if ( datasz )
+    {
+        rec->data = malloc(datasz);
+
+        if ( !rec->data )
+        {
+            ERROR("Unable to allocate %zu bytes for record data (0x%08x, %s)",
+                  datasz, rhdr.type, rec_type_to_str(rhdr.type));
+            return -1;
+        }
+
+        if ( read_exact(fd, rec->data, datasz) )
+        {
+            free(rec->data);
+            rec->data = NULL;
+            PERROR("Failed to read %zu bytes of data for record (0x%08x, %s)",
+                   datasz, rhdr.type, rec_type_to_str(rhdr.type));
+            return -1;
+        }
+    }
+    else
+        rec->data = NULL;
+
+    rec->type   = rhdr.type;
+    rec->length = rhdr.length;
+
+    return 0;
+};
+
 static void __attribute__((unused)) build_assertions(void)
 {
     XC_BUILD_BUG_ON(sizeof(struct xc_sr_ihdr) != 24);
tools/libxc/xc_sr_common.h +14 -0
index bc99e9a..53d6129 100644
@@ -370,6 +370,20 @@ static inline int write_record(struct xc_sr_context *ctx,
 }
 
 /*
+ * Reads a record from the stream, and fills in the record structure.
+ *
+ * Returns 0 on success and non-0 on failure.
+ *
+ * On success, the records type and size shall be valid.
+ * - If size is 0, data shall be NULL.
+ * - If size is non-0, data shall be a buffer allocated by malloc() which must
+ *   be passed to free() by the caller.
+ *
+ * On failure, the contents of the record structure are undefined.
+ */
+int read_record(struct xc_sr_context *ctx, int fd, struct xc_sr_record *rec);
+
+/*
  * This would ideally be private in restore.c, but is needed by
  * x86_pv_localise_page() if we receive pagetables frames ahead of the
  * contents of the frames they point at.
tools/libxc/xc_sr_restore.c +1 -62
index d4dc501..e543be3 100644
@@ -69,67 +69,6 @@ static int read_headers(struct xc_sr_context *ctx)
 }
 
 /*
- * Reads a record from the stream, and fills in the record structure.
- *
- * Returns 0 on success and non-0 on failure.
- *
- * On success, the records type and size shall be valid.
- * - If size is 0, data shall be NULL.
- * - If size is non-0, data shall be a buffer allocated by malloc() which must
- *   be passed to free() by the caller.
- *
- * On failure, the contents of the record structure are undefined.
- */
-static int read_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
-{
-    xc_interface *xch = ctx->xch;
-    struct xc_sr_rhdr rhdr;
-    size_t datasz;
-
-    if ( read_exact(ctx->fd, &rhdr, sizeof(rhdr)) )
-    {
-        PERROR("Failed to read Record Header from stream");
-        return -1;
-    }
-    else if ( rhdr.length > REC_LENGTH_MAX )
-    {
-        ERROR("Record (0x%08x, %s) length %#x exceeds max (%#x)", rhdr.type,
-              rec_type_to_str(rhdr.type), rhdr.length, REC_LENGTH_MAX);
-        return -1;
-    }
-
-    datasz = ROUNDUP(rhdr.length, REC_ALIGN_ORDER);
-
-    if ( datasz )
-    {
-        rec->data = malloc(datasz);
-
-        if ( !rec->data )
-        {
-            ERROR("Unable to allocate %zu bytes for record data (0x%08x, %s)",
-                  datasz, rhdr.type, rec_type_to_str(rhdr.type));
-            return -1;
-        }
-
-        if ( read_exact(ctx->fd, rec->data, datasz) )
-        {
-            free(rec->data);
-            rec->data = NULL;
-            PERROR("Failed to read %zu bytes of data for record (0x%08x, %s)",
-                   datasz, rhdr.type, rec_type_to_str(rhdr.type));
-            return -1;
-        }
-    }
-    else
-        rec->data = NULL;
-
-    rec->type   = rhdr.type;
-    rec->length = rhdr.length;
-
-    return 0;
-};
-
-/*
  * Is a pfn populated?
  */
 static bool pfn_is_populated(const struct xc_sr_context *ctx, xen_pfn_t pfn)
@@ -646,7 +585,7 @@ static int restore(struct xc_sr_context *ctx)
 
     do
     {
-        rc = read_record(ctx, &rec);
+        rc = read_record(ctx, ctx->fd, &rec);
         if ( rc )
         {
             if ( ctx->restore.buffer_all_records )
Signature · 9 lines
2.5.0




_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

.

#20 lore raw

PATCH v9 5/25 tools/libxl: add back channel support to write stream

In reply to Wen Congyang

Add back channel support to write stream. If the write stream is a back channel stream, this means the write stream is used by Secondary to send some records back.

---
 tools/libxl/libxl_dom_save.c     |  1 +
 tools/libxl/libxl_internal.h     |  1 +
 tools/libxl/libxl_stream_write.c | 26 ++++++++++++++++++++------
 3 files changed, 22 insertions(+), 6 deletions(-)
tools/libxl/libxl_dom_save.c +1 -0
index 86026ac..5fd9db2 100644
@@ -409,6 +409,7 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)
     dss->sws.ao  = dss->ao;
     dss->sws.dss = dss;
     dss->sws.fd  = dss->fd;
+    dss->sws.back_channel = false;
     dss->sws.completion_callback = stream_done;
 
     libxl__stream_write_start(egc, &dss->sws);
tools/libxl/libxl_internal.h +1 -0
index b6929a9..b473748 100644
@@ -3040,6 +3040,7 @@ struct libxl__stream_write_state {
     libxl__ao *ao;
     libxl__domain_save_state *dss;
     int fd;
+    bool back_channel;
     void (*completion_callback)(libxl__egc *egc,
                                 libxl__stream_write_state *sws,
                                 int rc);
tools/libxl/libxl_stream_write.c +20 -6
index 852546f..538a1c6 100644
@@ -49,6 +49,13 @@
  *  - if (hvm)
  *      - Emulator context record
  *  - Checkpoint end record
+ *
+ * For back channel stream:
+ * - libxl__stream_write_start()
+ *    - Set up the stream to running state
+ *
+ * - Add a new API to write the record. When the record is written
+ *   out, call stream->checkpoint_callback() to return.
  */
 
 /* Success/error/cleanup handling. */
@@ -225,6 +232,15 @@ void libxl__stream_write_start(libxl__egc *egc,
 
     stream->running = true;
 
+    dc->ao        = ao;
+    dc->readfd    = -1;
+    dc->copywhat  = "save v2 stream";
+    dc->writefd   = stream->fd;
+    dc->maxsz     = -1;
+
+    if (stream->back_channel)
+        return;
+
     if (dss->type == LIBXL_DOMAIN_TYPE_HVM) {
         stream->device_model_version =
             libxl__device_model_version_running(gc, dss->domid);
@@ -249,12 +265,7 @@ void libxl__stream_write_start(libxl__egc *egc,
         stream->emu_sub_hdr.index = 0;
     }
 
-    dc->ao        = ao;
-    dc->readfd    = -1;
     dc->writewhat = "stream header";
-    dc->copywhat  = "save v2 stream";
-    dc->writefd   = stream->fd;
-    dc->maxsz     = -1;
     dc->callback  = stream_header_done;
 
     rc = libxl__datacopier_start(dc);
@@ -279,6 +290,7 @@ void libxl__stream_write_start_checkpoint(libxl__egc *egc,
 {
     assert(stream->running);
     assert(!stream->in_checkpoint);
+    assert(!stream->back_channel);
     stream->in_checkpoint = true;
 
     write_emulator_xenstore_record(egc, stream);
@@ -584,7 +596,9 @@ static void stream_done(libxl__egc *egc,
         libxl__carefd_close(stream->emu_carefd);
     free(stream->emu_body);
 
-    check_all_finished(egc, stream, rc);
+    if (!stream->back_channel)
+        /* back channel stream doesn't have save helper */
+        check_all_finished(egc, stream, rc);
 }
 
 static void checkpoint_done(libxl__egc *egc,
Signature · 1 line
2.5.0
#21 lore raw

PATCH v9 6/25 tools/libxl: write checkpoint_state records into the stream

In reply to Wen Congyang

write checkpoint_state records into the stream, used by both primary and secondary to send colo context.

---
 tools/libxl/libxl_internal.h     |  5 ++++
 tools/libxl/libxl_stream_write.c | 60 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 64 insertions(+), 1 deletion(-)
tools/libxl/libxl_internal.h +5 -0
index b473748..3cf297f 100644
@@ -3052,6 +3052,7 @@ struct libxl__stream_write_state {
     bool running;
     bool in_checkpoint;
     bool sync_teardown;  /* Only used to coordinate shutdown on error path. */
+    bool in_checkpoint_state;
     libxl__save_helper_state shs;
 
     /* Main stream-writing data. */
@@ -3075,6 +3076,10 @@ _hidden void libxl__stream_write_start(libxl__egc *egc,
 _hidden void
 libxl__stream_write_start_checkpoint(libxl__egc *egc,
                                      libxl__stream_write_state *stream);
+_hidden void
+libxl__stream_write_checkpoint_state(libxl__egc *egc,
+                                     libxl__stream_write_state *stream,
+                                     libxl_sr_checkpoint_state *srcs);
 _hidden void libxl__stream_write_abort(libxl__egc *egc,
                                        libxl__stream_write_state *stream,
                                        int rc);
tools/libxl/libxl_stream_write.c +59 -1

84 lines not on this page · raw message

Signature · 1 line
2.5.0
#22 lore raw

PATCH v9 7/25 tools/libxl: add back channel support to read stream

In reply to Wen Congyang

This is used by primay to read records sent by secondary.

---
 tools/libxl/libxl_create.c      |  1 +
 tools/libxl/libxl_internal.h    |  1 +
 tools/libxl/libxl_stream_read.c | 27 +++++++++++++++++++++++----
 3 files changed, 25 insertions(+), 4 deletions(-)
tools/libxl/libxl_create.c +1 -0
index 8087bcc..c2eeb9d 100644
@@ -1012,6 +1012,7 @@ static void domcreate_bootloader_done(libxl__egc *egc,
     dcs->srs.dcs = dcs;
     dcs->srs.fd = restore_fd;
     dcs->srs.legacy = (dcs->restore_params.stream_version == 1);
+    dcs->srs.back_channel = false;
     dcs->srs.completion_callback = domcreate_stream_done;
 
     if (restore_fd >= 0) {
tools/libxl/libxl_internal.h +1 -0
index 3cf297f..ea2cfb8 100644
@@ -3418,6 +3418,7 @@ struct libxl__stream_read_state {
     libxl__domain_create_state *dcs;
     int fd;
     bool legacy;
+    bool back_channel;
     void (*completion_callback)(libxl__egc *egc,
                                 libxl__stream_read_state *srs,
                                 int rc);
tools/libxl/libxl_stream_read.c +23 -4
index 6ad2a27..6437639 100644
@@ -104,6 +104,15 @@
  * Depending on the contents of the stream, there are likely to be several
  * parallel tasks being managed.  check_all_finished() is used to join all
  * tasks in both success and error cases.
+ *
+ * For back channel stream:
+ * - libxl__stream_read_start()
+ *    - Set up the stream to running state
+ *
+ * - libxl__stream_read_continue()
+ *     - Set up reading the next record from a started stream.
+ *       Add some codes to process_record() to handle the record.
+ *       Then call stream->checkpoint_callback() to return.
  */
 
 /* Success/error/cleanup handling. */
@@ -207,6 +216,17 @@ void libxl__stream_read_start(libxl__egc *egc,
     stream->running = true;
     stream->phase   = SRS_PHASE_NORMAL;
 
+    dc->ao       = stream->ao;
+    dc->copywhat = "restore v2 stream";
+    dc->writefd  = -1;
+
+    if (stream->back_channel) {
+        assert(!stream->legacy);
+
+        dc->readfd = stream->fd;
+        return;
+    }
+
     if (stream->legacy) {
         /* Convert the legacy stream. */
         libxl__conversion_helper_state *chs = &stream->chs;
@@ -229,10 +249,7 @@ void libxl__stream_read_start(libxl__egc *egc,
     }
     /* stream->fd is now a v2 stream. */
 
-    dc->ao       = stream->ao;
-    dc->copywhat = "restore v2 stream";
     dc->readfd   = stream->fd;
-    dc->writefd  = -1;
 
     /* Start reading the stream header. */
     rc = setup_read(stream, "stream header",
@@ -748,7 +765,9 @@ static void stream_done(libxl__egc *egc,
     LIBXL_STAILQ_FOREACH_SAFE(rec, &stream->record_queue, entry, trec)
         free_record(rec);
 
-    check_all_finished(egc, stream, rc);
+    if (!stream->back_channel)
+        /* back channel stream doesn't have restore helper */
+        check_all_finished(egc, stream, rc);
 }
 
 void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void,
Signature · 1 line
2.5.0
#23 lore raw

PATCH v9 8/25 tools/libxl: handle checkpoint_state records in a libxl migration v2 read stream

In reply to Wen Congyang

Read a checkpoint_state and call stream->checkpoint_callback to handle it.

---
 tools/libxl/libxl_internal.h    |  3 +++
 tools/libxl/libxl_stream_read.c | 57 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 1 deletion(-)
tools/libxl/libxl_internal.h +3 -0
index ea2cfb8..5f9722b 100644
@@ -3430,6 +3430,7 @@ struct libxl__stream_read_state {
     bool running;
     bool in_checkpoint;
     bool sync_teardown; /* Only used to coordinate shutdown on error path. */
+    bool in_checkpoint_state;
     libxl__save_helper_state shs;
     libxl__conversion_helper_state chs;
 
@@ -3457,6 +3458,8 @@ _hidden void libxl__stream_read_start(libxl__egc *egc,
                                       libxl__stream_read_state *stream);
 _hidden void libxl__stream_read_start_checkpoint(libxl__egc *egc,
                                                  libxl__stream_read_state *stream);
+_hidden void libxl__stream_read_checkpoint_state(libxl__egc *egc,
+                                                 libxl__stream_read_state *stream);
 _hidden void libxl__stream_read_abort(libxl__egc *egc,
                                       libxl__stream_read_state *stream, int rc);
 static inline bool
tools/libxl/libxl_stream_read.c +56 -1

93 lines not on this page · raw message

Signature · 1 line
2.5.0
#24 lore raw

PATCH v9 9/25 tools/libx{l, c}: introduce should_checkpoint callback

In reply to Wen Congyang

Under COLO, we are doing checkpoint on demand, if this callback returns 1, we will take another checkpoint. 0 indicates unexpected error.

---
 tools/libxc/include/xenguest.h     | 18 ++++++++++++++++++
 tools/libxl/libxl_save_msgs_gen.pl |  7 ++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
tools/libxc/include/xenguest.h +18 -0
index bd133af..88d6e13 100644
@@ -62,6 +62,15 @@ struct save_callbacks {
      * 1: take another checkpoint */
     int (*checkpoint)(void* data);
 
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*should_checkpoint)(void* data);
+
     /* Enable qemu-dm logging dirty pages to xen */
     int (*switch_qemu_logdirty)(int domid, unsigned enable, void *data); /* HVM only */
 
@@ -93,6 +102,15 @@ struct restore_callbacks {
 #define XGR_CHECKPOINT_FAILOVER 2 /* Failover and resume VM */
     int (*checkpoint)(void* data);
 
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully
+     * 1: take another checkpoint
+     */
+    int (*should_checkpoint)(void* data);
+
     /* to be provided as the last argument to each callback function */
     void* data;
 };
tools/libxl/libxl_save_msgs_gen.pl +4 -3
index d6d2967..9107a86 100755
@@ -26,11 +26,12 @@ our @msgs = (
     [  3, 'scxA',   "suspend", [] ],
     [  4, 'scxA',   "postcopy", [] ],
     [  5, 'srcxA',  "checkpoint", [] ],
-    [  6, 'scxA',   "switch_qemu_logdirty",  [qw(int domid
+    [  6, 'srcxA',  "should_checkpoint", [] ],
+    [  7, 'scxA',   "switch_qemu_logdirty",  [qw(int domid
                                               unsigned enable)] ],
-    [  7, 'r',      "restore_results",       ['unsigned long', 'store_mfn',
+    [  8, 'r',      "restore_results",       ['unsigned long', 'store_mfn',
                                               'unsigned long', 'console_mfn'] ],
-    [  8, 'srW',    "complete",              [qw(int retval
+    [  9, 'srW',    "complete",              [qw(int retval
                                                  int errnoval)] ],
 );
 
Signature · 1 line
2.5.0
#25 lore raw

Re: [PATCH v9 09/25] tools/libx{l, c}: introduce should_checkpoint callback

Quoted 2 lines · Wen Congyang

Under COLO, we are doing checkpoint on demand, if this callback returns 1, we will take another checkpoint.

So 1 means OK.

Quoted 1 line

0 indicates unexpected error.

Why not return an error?

Quoted 13 lines
---
 tools/libxc/include/xenguest.h     | 18 ++++++++++++++++++
 tools/libxl/libxl_save_msgs_gen.pl |  7 ++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
tools/libxc/include/xenguest.h +0 -0
index bd133af..88d6e13 100644

tools/libxc/include/xenguest.h struct save_callbacks { · line 69

Quoted 8 lines
tools/libxc/include/xenguest.h +5 -0
@@ -62,6 +62,15 @@ struct save_callbacks {
      * 1: take another checkpoint */
     int (*checkpoint)(void* data);
 
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully

checkpointing terminated gracefully

Why not return -EXX instead ?

Quoted 1 line
tools/libxc/include/xenguest.h +1 -0
+     * 1: take another checkpoint
#26 lore raw

Re: [PATCH v9 09/25] tools/libx{l, c}: introduce should_checkpoint callback

Quoted 33 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Wen Congyang

Under COLO, we are doing checkpoint on demand, if this callback returns 1, we will take another checkpoint.

So 1 means OK.

Quoted 1 line

0 indicates unexpected error.

Why not return an error?

Quoted 13 lines
---
 tools/libxc/include/xenguest.h     | 18 ++++++++++++++++++
 tools/libxl/libxl_save_msgs_gen.pl |  7 ++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
tools/libxc/include/xenguest.h +0 -0
index bd133af..88d6e13 100644

tools/libxc/include/xenguest.h struct save_callbacks { · line 69

Quoted 8 lines
tools/libxc/include/xenguest.h +5 -0
@@ -62,6 +62,15 @@ struct save_callbacks {
      * 1: take another checkpoint */
     int (*checkpoint)(void* data);
 
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully

checkpointing terminated gracefully

Quoted 3 lines

Why not return -EXX instead ?

Quoted 1 line
tools/libxc/include/xenguest.h +1 -0
+     * 1: take another checkpoint

Also perhaps the function instead of 'should_checkpoint' should just be called 'checkpoint' or 'do_checkpoint' ?

#27 lore raw

Re: [PATCH v9 09/25] tools/libx{l, c}: introduce should_checkpoint callback

Quoted 34 lines · Konrad Rzeszutek Wilk
Quoted 33 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Wen Congyang

Under COLO, we are doing checkpoint on demand, if this callback returns 1, we will take another checkpoint.

So 1 means OK.

Quoted 1 line

0 indicates unexpected error.

Why not return an error?

Quoted 13 lines
---
 tools/libxc/include/xenguest.h     | 18 ++++++++++++++++++
 tools/libxl/libxl_save_msgs_gen.pl |  7 ++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
tools/libxc/include/xenguest.h +0 -0
index bd133af..88d6e13 100644

tools/libxc/include/xenguest.h struct save_callbacks { · line 69

Quoted 8 lines
tools/libxc/include/xenguest.h +5 -0
@@ -62,6 +62,15 @@ struct save_callbacks {
      * 1: take another checkpoint */
     int (*checkpoint)(void* data);
 
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully

checkpointing terminated gracefully

Quoted 6 lines
Quoted 3 lines

Why not return -EXX instead ?

Quoted 1 line
tools/libxc/include/xenguest.h +1 -0
+     * 1: take another checkpoint

Also perhaps the function instead of 'should_checkpoint' should just be called 'checkpoint' or 'do_checkpoint' ?

I will check it. IIRC, should_checkpoint() only wait for a new checkpoint. If so, I think we can call it wait_checkpoint().

Thanks
Wen Congyang

Quoted 4 lines

.

#28 lore raw

Re: [PATCH v9 09/25] tools/libx{l, c}: introduce should_checkpoint callback

In reply to Konrad Rzeszutek Wilk
Quoted 33 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Wen Congyang

Under COLO, we are doing checkpoint on demand, if this callback returns 1, we will take another checkpoint.

So 1 means OK.

Quoted 1 line

0 indicates unexpected error.

Why not return an error?

Quoted 13 lines
---
 tools/libxc/include/xenguest.h     | 18 ++++++++++++++++++
 tools/libxl/libxl_save_msgs_gen.pl |  7 ++++---
 2 files changed, 22 insertions(+), 3 deletions(-)
tools/libxc/include/xenguest.h +0 -0
index bd133af..88d6e13 100644

tools/libxc/include/xenguest.h struct save_callbacks { · line 69

Quoted 8 lines
tools/libxc/include/xenguest.h +5 -0
@@ -62,6 +62,15 @@ struct save_callbacks {
      * 1: take another checkpoint */
     int (*checkpoint)(void* data);
 
+    /*
+     * Called after the checkpoint callback.
+     *
+     * returns:
+     * 0: terminate checkpointing gracefully

checkpointing terminated gracefully

Quoted 1 line

Why not return -EXX instead ?

Other callbacks also use 0 to indicate an error.

Thanks
Wen Congyang

Quoted 6 lines

tools/libxc/include/xenguest.h struct save_callbacks { · line 70

Quoted 2 lines
tools/libxc/include/xenguest.h +1 -0
+     * 1: take another checkpoint

.

#29 lore raw

PATCH v9 10/25 tools/libx{l, c}: add postcopy/suspend callback to restore side

In reply to Wen Congyang

Secondary(restore side) is running under COLO, we also need postcopy/suspend callbacks.

---
 tools/libxc/include/xenguest.h     | 10 ++++++++++
 tools/libxl/libxl_save_msgs_gen.pl |  4 ++--
 2 files changed, 12 insertions(+), 2 deletions(-)
tools/libxc/include/xenguest.h +10 -0
index 88d6e13..7c74977 100644
@@ -95,6 +95,16 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
 
 /* callbacks provided by xc_domain_restore */
 struct restore_callbacks {
+    /* Called after a new checkpoint to suspend the guest.
+     */
+    int (*suspend)(void* data);
+
+    /* Called after the secondary vm is ready to resume.
+     * Callback function resumes the guest & the device model,
+     * returns to xc_domain_restore.
+     */
+    int (*postcopy)(void* data);
+
     /* A checkpoint record has been found in the stream.
      * returns: */
 #define XGR_CHECKPOINT_ERROR    0 /* Terminate processing */
tools/libxl/libxl_save_msgs_gen.pl +2 -2
index 9107a86..7c9859b 100755
@@ -23,8 +23,8 @@ our @msgs = (
                                                  STRING doing_what),
                                                 'unsigned long', 'done',
                                                 'unsigned long', 'total'] ],
-    [  3, 'scxA',   "suspend", [] ],
-    [  4, 'scxA',   "postcopy", [] ],
+    [  3, 'srcxA',  "suspend", [] ],
+    [  4, 'srcxA',  "postcopy", [] ],
     [  5, 'srcxA',  "checkpoint", [] ],
     [  6, 'srcxA',  "should_checkpoint", [] ],
     [  7, 'scxA',   "switch_qemu_logdirty",  [qw(int domid
Signature · 1 line
2.5.0
#30 lore raw

PATCH v9 11/25 secondary vm suspend/resume/checkpoint code

In reply to Wen Congyang

Secondary vm is running in colo mode. So we will do
the following things again and again:
1. Resume secondary vm
a. Send CHECKPOINT_SVM_READY to master.
b. If it is not the first resume, call libxl__checkpoint_devices_preresume(). c. If it is the first resume(resume right after live migration),
- call libxl__xc_domain_restore_done() to build the secondary vm.
- enable secondary vm's logdirty.
- call libxl__domain_resume() to resume secondary vm.
- call libxl__checkpoint_devices_setup() to setup checkpoint devices.
d. Send CHECKPOINT_SVM_RESUMED to master.
2. Wait a new checkpoint
a. Call libxl__checkpoint_devices_commit().
b. Read CHECKPOINT_NEW from master.
3. Suspend secondary vm
a. Suspend secondary vm.
b. Call libxl__checkpoint_devices_postsuspend().
c. Send CHECKPOINT_SVM_SUSPENDED to master.

---
 tools/libxl/Makefile             |    1 +
 tools/libxl/libxl_colo.h         |   24 +
 tools/libxl/libxl_colo_restore.c | 1041 ++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_create.c       |   37 ++
 tools/libxl/libxl_internal.h     |   19 +
 tools/libxl/libxl_save_callout.c |    7 +-
 tools/libxl/libxl_stream_read.c  |   12 +
 7 files changed, 1140 insertions(+), 1 deletion(-)
 create mode 100644 tools/libxl/libxl_colo.h
 create mode 100644 tools/libxl/libxl_colo_restore.c
tools/libxl/Makefile +1 -0
index d075a30..19a95a9 100644
@@ -63,6 +63,7 @@ LIBXL_OBJS-y += libxl_no_convert_callout.o
 endif
 
 LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o
+LIBXL_OBJS-y += libxl_colo_restore.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
tools/libxl/libxl_colo.h new file +24 -0
new file mode 100644
index 0000000..8bea1a2
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2014 FUJITSU LIMITED
+ * Author: Wen Congyang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#ifndef LIBXL_COLO_H
+#define LIBXL_COLO_H
+
+extern void libxl__colo_restore_setup(libxl__egc *egc,
+                                      libxl__colo_restore_state *crs);
+extern void libxl__colo_restore_teardown(libxl__egc *egc, void *dcs_void,
+                                         int ret, int retval, int errnoval);
+
+#endif
tools/libxl/libxl_colo_restore.c new file +1041 -0

1,041 lines not on this page · raw message

tools/libxl/libxl_create.c +37 -0
index c2eeb9d..62aa7c9 100644
@@ -19,6 +19,7 @@
 
 #include "libxl_internal.h"
 #include "libxl_arch.h"
+#include "libxl_colo.h"
 
 #include <xc_dom.h>
 #include <xenguest.h>
@@ -960,6 +961,23 @@ static void domcreate_console_available(libxl__egc *egc,
                                         dcs->aop_console_how.for_event));
 }
 
+static void libxl__colo_restore_setup_done(libxl__egc *egc,
+                                           libxl__colo_restore_state *crs,
+                                           int rc)
+{
+    libxl__domain_create_state *dcs = CONTAINER_OF(crs, *dcs, crs);
+
+    EGC_GC;
+
+    if (rc) {
+        LOG(ERROR, "colo restore setup fails: %d", rc);
+        domcreate_stream_done(egc, &dcs->srs, rc);
+        return;
+    }
+
+    libxl__stream_read_start(egc, &dcs->srs);
+}
+
 static void domcreate_bootloader_done(libxl__egc *egc,
                                       libxl__bootloader_state *bl,
                                       int rc)
@@ -975,6 +993,8 @@ static void domcreate_bootloader_done(libxl__egc *egc,
     libxl__srm_restore_autogen_callbacks *const callbacks =
         &dcs->srs.shs.callbacks.restore.a;
     const int checkpointed_stream = dcs->restore_params.checkpointed_stream;
+    libxl__colo_restore_state *const crs = &dcs->crs;
+    libxl_domain_build_info *const info = &d_config->b_info;
 
     if (rc) {
         domcreate_rebuild_done(egc, dcs, rc);
@@ -1004,6 +1024,13 @@ static void domcreate_bootloader_done(libxl__egc *egc,
     /* Restore */
     callbacks->checkpoint = libxl__remus_domain_restore_checkpoint_callback;
 
+    /* COLO only supports HVM now */
+    if (info->type != LIBXL_DOMAIN_TYPE_HVM &&
+        checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
     rc = libxl__build_pre(gc, domid, d_config, state);
     if (rc)
         goto out;
@@ -1017,6 +1044,16 @@ static void domcreate_bootloader_done(libxl__egc *egc,
 
     if (restore_fd >= 0) {
         switch (checkpointed_stream) {
+        case LIBXL_CHECKPOINTED_STREAM_COLO:
+            /* colo restore setup */
+            crs->ao = ao;
+            crs->domid = domid;
+            crs->send_fd = dcs->send_fd;
+            crs->recv_fd = restore_fd;
+            crs->hvm = (info->type == LIBXL_DOMAIN_TYPE_HVM);
+            crs->callback = libxl__colo_restore_setup_done;
+            libxl__colo_restore_setup(egc, crs);
+            break;
         case LIBXL_CHECKPOINTED_STREAM_REMUS:
             libxl__remus_restore_setup(egc, dcs);
             /* fall through */
tools/libxl/libxl_internal.h +19 -0
index 5f9722b..79b0c6d 100644
@@ -3468,6 +3468,23 @@ libxl__stream_read_inuse(const libxl__stream_read_state *stream)
     return stream->running;
 }
 
+/* colo related structure */
+typedef struct libxl__colo_restore_state libxl__colo_restore_state;
+typedef void libxl__colo_callback(libxl__egc *,
+                                  libxl__colo_restore_state *, int rc);
+struct libxl__colo_restore_state {
+    /* must set by caller of libxl__colo_(setup|teardown) */
+    libxl__ao *ao;
+    uint32_t domid;
+    int send_fd;
+    int recv_fd;
+    int hvm;
+    libxl__colo_callback *callback;
+
+    /* private, colo restore checkpoint state */
+    libxl__domain_create_cb *saved_cb;
+    void *crcs;
+};
 
 struct libxl__domain_create_state {
     /* filled in by user */
@@ -3484,6 +3501,8 @@ struct libxl__domain_create_state {
     /* private to domain_create */
     int guest_domid;
     libxl__domain_build_state build_state;
+    libxl__colo_restore_state crs;
+    libxl__checkpoint_devices_state cds;
     libxl__bootloader_state bl;
     libxl__stub_dm_spawn_state dmss;
         /* If we're not doing stubdom, we use only dmss.dm,
tools/libxl/libxl_save_callout.c +6 -1
index 631e3e2..5a250c7 100644
@@ -15,6 +15,7 @@
 #include "libxl_osdeps.h"
 
 #include "libxl_internal.h"
+#include "libxl_colo.h"
 
 /* stream_fd is as from the caller (eventually, the application).
  * It may be 0, 1 or 2, in which case we need to dup it elsewhere.
@@ -68,7 +69,11 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,
     shs->ao = ao;
     shs->domid = domid;
     shs->recv_callback = libxl__srm_callout_received_restore;
-    shs->completion_callback = libxl__xc_domain_restore_done;
+    if (dcs->restore_params.checkpointed_stream ==
+                                                LIBXL_CHECKPOINTED_STREAM_COLO)
+        shs->completion_callback = libxl__colo_restore_teardown;
+    else
+        shs->completion_callback = libxl__xc_domain_restore_done;
     shs->caller_state = dcs;
     shs->need_results = 1;
 
tools/libxl/libxl_stream_read.c +12 -0
index e6421bc..eaae72b 100644
@@ -832,6 +832,18 @@ void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void,
      */
     if (libxl__stream_read_inuse(stream)) {
         switch (checkpointed_stream) {
+        case LIBXL_CHECKPOINTED_STREAM_COLO:
+            if (stream->completion_callback) {
+                /*
+                 * restore, just build the secondary vm, don't close
+                 * the stream
+                 */
+                stream->completion_callback(egc, stream, 0);
+            } else {
+                /* failover, just close the stream */
+                stream_complete(egc, stream, 0);
+            }
+            break;
         case LIBXL_CHECKPOINTED_STREAM_REMUS:
             /* failover */
             stream_complete(egc, stream, 0);
Signature · 1 line
2.5.0
#31 lore raw

PATCH v9 12/25 primary vm suspend/resume/checkpoint code

In reply to Wen Congyang

We will do the following things again and again:
1. Suspend primary vm
a. Suspend primary vm
b. do postsuspend
c. Read CHECKPOINT_SVM_SUSPENDED sent by secondary
2. Resume primary vm
a. Read CHECKPOINT_SVM_READY from slave
b. Do presume
c. Resume primary vm
d. Read CHECKPOINT_SVM_RESUMED from slave
3. Wait a new checkpoint
a. Wait a new checkpoint(not implemented) b. Send CHECKPOINT_NEW to slave

---
 tools/libxl/Makefile          |   2 +-
 tools/libxl/libxl.c           |   6 +-
 tools/libxl/libxl_colo.h      |  10 +
 tools/libxl/libxl_colo_save.c | 552 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_dom_save.c  |  13 +-
 tools/libxl/libxl_internal.h  | 168 +++++++------
 tools/libxl/libxl_types.idl   |   1 +
 7 files changed, 672 insertions(+), 80 deletions(-)
 create mode 100644 tools/libxl/libxl_colo_save.c
tools/libxl/Makefile +1 -1
index 19a95a9..b11cf34 100644
@@ -63,7 +63,7 @@ LIBXL_OBJS-y += libxl_no_convert_callout.o
 endif
 
 LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o
-LIBXL_OBJS-y += libxl_colo_restore.o
+LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
tools/libxl/libxl.c +5 -1
index 481824d..7d227d7 100644
@@ -17,6 +17,7 @@
 #include "libxl_osdeps.h"
 
 #include "libxl_internal.h"
+#include "libxl_colo.h"
 
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 #define BACKEND_STRING_SIZE 5
@@ -882,7 +883,10 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     assert(info);
 
     /* Point of no return */
-    libxl__remus_setup(egc, &dss->rs);
+    if (libxl_defbool_val(info->colo))
+        libxl__colo_save_setup(egc, &dss->css);
+    else
+        libxl__remus_setup(egc, &dss->rs);
     return AO_INPROGRESS;
 
  out:
tools/libxl/libxl_colo.h +10 -0
index 8bea1a2..39515c4 100644
@@ -21,4 +21,14 @@ extern void libxl__colo_restore_setup(libxl__egc *egc,
 extern void libxl__colo_restore_teardown(libxl__egc *egc, void *dcs_void,
                                          int ret, int retval, int errnoval);
 
+extern void libxl__colo_save_domain_suspend_callback(void *data);
+extern void libxl__colo_save_domain_checkpoint_callback(void *data);
+extern void libxl__colo_save_domain_resume_callback(void *data);
+extern void libxl__colo_save_domain_should_checkpoint_callback(void *data);
+extern void libxl__colo_save_setup(libxl__egc *egc,
+                                   libxl__colo_save_state *css);
+extern void libxl__colo_save_teardown(libxl__egc *egc,
+                                      libxl__colo_save_state *css,
+                                      int rc);
+
 #endif
tools/libxl/libxl_colo_save.c new file +552 -0

552 lines not on this page · raw message

tools/libxl/libxl_dom_save.c +11 -2
index 5fd9db2..776306f 100644
@@ -16,6 +16,7 @@
 #include "libxl_osdeps.h" /* must come before any other headers */
 
 #include "libxl_internal.h"
+#include "libxl_colo.h"
 
 #include <xen/errno.h>
 
@@ -401,6 +402,11 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)
         callbacks->suspend = libxl__remus_domain_suspend_callback;
         callbacks->postcopy = libxl__remus_domain_resume_callback;
         callbacks->checkpoint = libxl__remus_domain_save_checkpoint_callback;
+    } else if (dss->checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO) {
+        callbacks->suspend = libxl__colo_save_domain_suspend_callback;
+        callbacks->postcopy = libxl__colo_save_domain_resume_callback;
+        callbacks->checkpoint = libxl__colo_save_domain_checkpoint_callback;
+        callbacks->should_checkpoint = libxl__colo_save_domain_should_checkpoint_callback;
     } else
         callbacks->suspend = libxl__domain_suspend_callback;
 
@@ -442,12 +448,15 @@ static void domain_save_done(libxl__egc *egc,
 
     if (dss->remus) {
         /*
-         * With Remus, if we reach this point, it means either
+         * With Remus/COLO, if we reach this point, it means either
          * backup died or some network error occurred preventing us
          * from sending checkpoints. Teardown the network buffers and
          * release netlink resources.  This is an async op.
          */
-        libxl__remus_teardown(egc, &dss->rs, rc);
+        if (libxl_defbool_val(dss->remus->colo))
+            libxl__colo_save_teardown(egc, &dss->css, rc);
+        else
+            libxl__remus_teardown(egc, &dss->rs, rc);
         return;
     }
 
tools/libxl/libxl_internal.h +92 -76

204 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index db001ad..7c46bc2 100644
@@ -762,6 +762,7 @@ libxl_domain_remus_info = Struct("domain_remus_info",[
     ("netbuf",       libxl_defbool),
     ("netbufscript", string),
     ("diskbuf",      libxl_defbool),
+    ("colo",         libxl_defbool)
     ])
 
 libxl_event_type = Enumeration("event_type", [
Signature · 1 line
2.5.0
#32 lore raw

PATCH v9 13/25 libxc/restore: support COLO restore

In reply to Wen Congyang

call the callbacks resume/checkpoint/suspend while secondary vm status is consistent with primary.

---
 tools/libxc/xc_sr_common.h  |  6 +++--
 tools/libxc/xc_sr_restore.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 2 deletions(-)
tools/libxc/xc_sr_common.h +4 -2
index 53d6129..e768a6d 100644
@@ -175,10 +175,12 @@ struct xc_sr_context
      * migration stream
      * 0: Plain VM
      * 1: Remus
+     * 2: COLO
      */
     enum {
         MIG_STREAM_NONE, /* plain stream */
         MIG_STREAM_REMUS,
+        MIG_STREAM_COLO,
     } migration_stream;
 
     union /* Common save or restore data. */
@@ -223,13 +225,13 @@ struct xc_sr_context
             uint32_t guest_page_size;
 
             /* Plain VM, or checkpoints over time. */
-            bool checkpointed;
+            int checkpointed;
 
             /* Currently buffering records between a checkpoint */
             bool buffer_all_records;
 
 /*
- * With Remus, we buffer the records sent by the primary at checkpoint,
+ * With Remus/COLO, we buffer the records sent by the primary at checkpoint,
  * in case the primary will fail, we can recover from the last
  * checkpoint state.
  * This should be enough for most of the cases because primary only send
tools/libxc/xc_sr_restore.c +60 -0

78 lines not on this page · raw message

Signature · 1 line
2.5.0
#33 lore raw

PATCH v9 14/25 libxc/restore: send dirty pfn list to primary when checkpoint under colo

In reply to Wen Congyang

Send dirty pfn list to primary when checkpoint under colo.

---
 tools/libxc/xc_sr_common.h  |   4 ++
 tools/libxc/xc_sr_restore.c | 120 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 123 insertions(+), 1 deletion(-)
tools/libxc/xc_sr_common.h +4 -0
index e768a6d..1c661cb 100644
@@ -217,6 +217,10 @@ struct xc_sr_context
             struct xc_sr_restore_ops ops;
             struct restore_callbacks *callbacks;
 
+            int send_fd;
+            unsigned long p2m_size;
+            xc_hypercall_buffer_t dirty_bitmap_hbuf;
+
             /* From Image Header. */
             uint32_t format_version;
 
tools/libxc/xc_sr_restore.c +119 -1

166 lines not on this page · raw message

Signature · 1 line
2.5.0
#34 lore raw

PATCH v9 15/25 send store gfn and console gfn to xl before resuming secondary vm

In reply to Wen Congyang

We will call libxl__xc_domain_restore_done() to rebuild secondary vm. But we need store gfn and console gfn when rebuilding secondary vm. So make restore_results a function pointer in callback struct and struct {save,restore}_callbacks, and use this callback to send store gfn and console gfn to xl.

---
 tools/libxc/include/xenguest.h     | 8 ++++++++
 tools/libxc/xc_sr_restore.c        | 7 +++++--
 tools/libxl/libxl_colo_restore.c   | 5 -----
 tools/libxl/libxl_create.c         | 2 ++
 tools/libxl/libxl_save_msgs_gen.pl | 4 ++--
 5 files changed, 17 insertions(+), 9 deletions(-)
tools/libxc/include/xenguest.h +8 -0
index 7c74977..df36147 100644
@@ -121,6 +121,14 @@ struct restore_callbacks {
      */
     int (*should_checkpoint)(void* data);
 
+    /*
+     * callback to send store gfn and console gfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(xen_pfn_t store_gfn, xen_pfn_t console_gfn,
+                            void *data);
+
     /* to be provided as the last argument to each callback function */
     void* data;
 };
tools/libxc/xc_sr_restore.c +5 -2
index 83df539..6c480d3 100644
@@ -565,7 +565,9 @@ static int handle_checkpoint(struct xc_sr_context *ctx)
         if ( rc )
             goto err;
 
-        /* TODO: call restore_results */
+        ctx->restore.callbacks->restore_results(ctx->restore.xenstore_gfn,
+                                                ctx->restore.console_gfn,
+                                                ctx->restore.callbacks->data);
 
         /* Resume secondary vm */
         ret = ctx->restore.callbacks->postcopy(ctx->restore.callbacks->data);
@@ -848,7 +850,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
         /* this is COLO restore */
         assert(callbacks->suspend &&
                callbacks->postcopy &&
-               callbacks->should_checkpoint);
+               callbacks->should_checkpoint &&
+               callbacks->restore_results);
     }
 
     DPRINTF("fd %d, dom %u, hvm %u, pae %u, superpages %d"
tools/libxl/libxl_colo_restore.c +0 -5
index 4f25f27..f23ef8f 100644
@@ -139,11 +139,6 @@ static void colo_resume_vm(libxl__egc *egc,
         return;
     }
 
-    /*
-     * TODO: get store gfn and console gfn
-     *  We should call the callback restore_results in
-     *  xc_domain_restore() before resuming the guest.
-     */
     libxl__xc_domain_restore_done(egc, dcs, 0, 0, 0);
 
     return;
tools/libxl/libxl_create.c +2 -0
index 62aa7c9..b495741 100644
@@ -1042,6 +1042,8 @@ static void domcreate_bootloader_done(libxl__egc *egc,
     dcs->srs.back_channel = false;
     dcs->srs.completion_callback = domcreate_stream_done;
 
+    callbacks->restore_results = libxl__srm_callout_callback_restore_results;
+
     if (restore_fd >= 0) {
         switch (checkpointed_stream) {
         case LIBXL_CHECKPOINTED_STREAM_COLO:
tools/libxl/libxl_save_msgs_gen.pl +2 -2
index 7c9859b..aea07b4 100755
@@ -29,8 +29,8 @@ our @msgs = (
     [  6, 'srcxA',  "should_checkpoint", [] ],
     [  7, 'scxA',   "switch_qemu_logdirty",  [qw(int domid
                                               unsigned enable)] ],
-    [  8, 'r',      "restore_results",       ['unsigned long', 'store_mfn',
-                                              'unsigned long', 'console_mfn'] ],
+    [  8, 'rcx',    "restore_results",       ['unsigned long', 'store_gfn',
+                                              'unsigned long', 'console_gfn'] ],
     [  9, 'srW',    "complete",              [qw(int retval
                                                  int errnoval)] ],
 );
Signature · 1 line
2.5.0
#35 lore raw

PATCH v9 16/25 libxc/save: support COLO save

In reply to Wen Congyang

After suspend primary vm, get dirty bitmap on secondary vm, and send pages both dirty on primary/secondary to secondary.

---
 tools/libxc/xc_sr_common.h |   2 +
 tools/libxc/xc_sr_save.c   | 102 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 101 insertions(+), 3 deletions(-)
tools/libxc/xc_sr_common.h +2 -0
index 1c661cb..76e2cdc 100644
@@ -187,6 +187,8 @@ struct xc_sr_context
     {
         struct /* Save data. */
         {
+            int recv_fd;
+
             struct xc_sr_save_ops ops;
             struct save_callbacks *callbacks;
 
tools/libxc/xc_sr_save.c +99 -3

134 lines not on this page · raw message

Signature · 1 line
2.5.0
#36 lore raw

PATCH v9 17/25 implement the cmdline for COLO

In reply to Wen Congyang

Add a new option -c to the command 'xl remus'. If you want to use COLO HA instead of Remus HA, please use -c option.

Update man pages to reflect the addition of a new option to 'xl remus' command.

Also add a new option -c to the internal command 'xl migrate-receive'.

---
 docs/man/xl.pod.1         | 12 +++++++--
 tools/libxl/libxl.c       | 23 ++++++++++++++++--
 tools/libxl/xl_cmdimpl.c  | 62 ++++++++++++++++++++++++++++++++++++-----------
 tools/libxl/xl_cmdtable.c |  4 ++-
 4 files changed, 82 insertions(+), 19 deletions(-)
docs/man/xl.pod.1 +10 -2
index 4279c7c..1c6dd87 100644
@@ -447,12 +447,15 @@ Print huge (!) amount of debug during the migration process.
 
 =item B<remus> [I<OPTIONS>] I<domain-id> I<host>
 
-Enable Remus HA for domain. By default B<xl> relies on ssh as a transport
-mechanism between the two hosts.
+Enable Remus HA or COLO HA for domain. By default B<xl> relies on ssh as a
+transport mechanism between the two hosts.
 
 N.B: Remus support in xl is still in experimental (proof-of-concept) phase.
      Disk replication support is limited to DRBD disks.
 
+     COLO support in xl is still in experimental (proof-of-concept) phase.
+     There is no support for network or disk at the moment.
+
 B<OPTIONS>
 
 =over 4
@@ -498,6 +501,11 @@ Disable network output buffering. Requires enabling unsafe mode.
 
 Disable disk replication. Requires enabling unsafe mode.
 
+=item B<-c>
+
+Enable COLO HA. This conflicts with B<-i> and B<-b>, and memory
+checkpoint compression must be disabled.
+
 =back
 
 =item B<pause> I<domain-id>
tools/libxl/libxl.c +21 -2
index 7d227d7..ca6bca1 100644
@@ -851,12 +851,28 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
         goto out;
     }
 
+    /* The caller must set this defbool */
+    if (libxl_defbool_is_default(info->colo)) {
+        LOG(ERROR, "colo mode must be enabled/disabled");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
     libxl_defbool_setdefault(&info->allow_unsafe, false);
     libxl_defbool_setdefault(&info->blackhole, false);
-    libxl_defbool_setdefault(&info->compression, true);
+    libxl_defbool_setdefault(&info->compression,
+                             !libxl_defbool_val(info->colo));
     libxl_defbool_setdefault(&info->netbuf, true);
     libxl_defbool_setdefault(&info->diskbuf, true);
 
+    if (libxl_defbool_val(info->colo)) {
+        if (libxl_defbool_val(info->compression)) {
+            LOG(ERROR, "cannot use memory checkpoint compression in COLO mode");
+            rc = ERROR_FAIL;
+            goto out;
+        }
+    }
+
     if (!libxl_defbool_val(info->allow_unsafe) &&
         (libxl_defbool_val(info->blackhole) ||
          !libxl_defbool_val(info->netbuf) ||
@@ -878,7 +894,10 @@ int libxl_domain_remus_start(libxl_ctx *ctx, libxl_domain_remus_info *info,
     dss->live = 1;
     dss->debug = 0;
     dss->remus = info;
-    dss->checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_REMUS;
+    if (libxl_defbool_val(info->colo))
+        dss->checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_COLO;
+    else
+        dss->checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_REMUS;
 
     assert(info);
 
tools/libxl/xl_cmdimpl.c +48 -14

144 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +3 -1
index fdc1ac6..b6b630c 100644
@@ -499,7 +499,9 @@ struct cmd_spec cmd_table[] = {
       "-b                      Replicate memory checkpoints to /dev/null (blackhole).\n"
       "                        Works only in unsafe mode.\n"
       "-n                      Disable network output buffering. Works only in unsafe mode.\n"
-      "-d                      Disable disk replication. Works only in unsafe mode."
+      "-d                      Disable disk replication. Works only in unsafe mode.\n"
+      "-c                      Enable COLO HA. It is conflict with -i and -b, and memory\n"
+      "                        checkpoint must be disabled"
     },
 #endif
     { "devd",
Signature · 1 line
2.5.0
#37 lore raw

PATCH v9 18/25 Support colo mode for qemu disk

In reply to Wen Congyang

Usage: disk = ['...,colo,colo-host=xxx,colo-port=xxx,colo-export=xxx,active-disk=xxx,hidden-disk=xxx...'] For QEMU block replication details:
http://wiki.qemu.org/Features/BlockReplication

---
 docs/man/xl.pod.1                   |   2 +-
 docs/misc/xl-disk-configuration.txt |  50 ++++++++++
 tools/libxl/libxl.c                 |  62 +++++++++++-
 tools/libxl/libxl_create.c          |  25 ++++-
 tools/libxl/libxl_device.c          |  54 +++++++++++
 tools/libxl/libxl_dm.c              | 184 ++++++++++++++++++++++++++++++++++--
 tools/libxl/libxl_types.idl         |   7 ++
 tools/libxl/libxlu_disk_l.l         |   7 ++
 8 files changed, 382 insertions(+), 9 deletions(-)
docs/man/xl.pod.1 +1 -1
index 1c6dd87..4f1901d 100644
@@ -454,7 +454,7 @@ N.B: Remus support in xl is still in experimental (proof-of-concept) phase.
      Disk replication support is limited to DRBD disks.
 
      COLO support in xl is still in experimental (proof-of-concept) phase.
-     There is no support for network or disk at the moment.
+     There is no support for network at the moment.
 
 B<OPTIONS>
 
docs/misc/xl-disk-configuration.txt +50 -0

56 lines not on this page · raw message

tools/libxl/libxl.c +61 -1

86 lines not on this page · raw message

tools/libxl/libxl_create.c +24 -1
index b495741..7cb3c6a 100644
@@ -1782,12 +1782,29 @@ static void domain_create_cb(libxl__egc *egc,
 
     libxl__ao_complete(egc, ao, rc);
 }
-    
+
+static void set_disk_colo_restore(libxl_domain_config *d_config)
+{
+    int i;
+
+    for (i = 0; i < d_config->num_disks; i++)
+        libxl_defbool_set(&d_config->disks[i].colo_restore_enable, true);
+}
+
+static void unset_disk_colo_restore(libxl_domain_config *d_config)
+{
+    int i;
+
+    for (i = 0; i < d_config->num_disks; i++)
+        libxl_defbool_set(&d_config->disks[i].colo_restore_enable, false);
+}
+
 int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
                             uint32_t *domid,
                             const libxl_asyncop_how *ao_how,
                             const libxl_asyncprogress_how *aop_console_how)
 {
+    unset_disk_colo_restore(d_config);
     return do_domain_create(ctx, d_config, domid, -1, -1, NULL,
                             ao_how, aop_console_how);
 }
@@ -1798,6 +1815,12 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
                                 const libxl_asyncop_how *ao_how,
                                 const libxl_asyncprogress_how *aop_console_how)
 {
+    if (params->checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO) {
+        set_disk_colo_restore(d_config);
+    } else {
+        unset_disk_colo_restore(d_config);
+    }
+
     return do_domain_create(ctx, d_config, domid, restore_fd, send_fd, params,
                             ao_how, aop_console_how);
 }
tools/libxl/libxl_device.c +54 -0

78 lines not on this page · raw message

tools/libxl/libxl_dm.c +178 -6

212 lines not on this page · raw message

tools/libxl/libxl_types.idl +7 -0
index 7c46bc2..38f37f2 100644
@@ -574,6 +574,13 @@ libxl_device_disk = Struct("device_disk", [
     ("is_cdrom", integer),
     ("direct_io_safe", bool),
     ("discard_enable", libxl_defbool),
+    ("colo_enable", libxl_defbool),
+    ("colo_restore_enable", libxl_defbool),
+    ("colo_host", string),
+    ("colo_port", string),
+    ("colo_export", string),
+    ("active_disk", string),
+    ("hidden_disk", string)
     ])
 
 libxl_device_nic = Struct("device_nic", [
tools/libxl/libxlu_disk_l.l +7 -0
index 1a5deb5..58da943 100644
@@ -176,6 +176,13 @@ script=[^,]*,?	{ STRIP(','); SAVESTRING("script", script, FROMEQUALS); }
 direct-io-safe,? { DPC->disk->direct_io_safe = 1; }
 discard,?	{ libxl_defbool_set(&DPC->disk->discard_enable, true); }
 no-discard,?	{ libxl_defbool_set(&DPC->disk->discard_enable, false); }
+colo,?		{ libxl_defbool_set(&DPC->disk->colo_enable, true); }
+no-colo,?	{ libxl_defbool_set(&DPC->disk->colo_enable, false); }
+colo-host=[^,]*,?	{ STRIP(','); SAVESTRING("colo-host", colo_host, FROMEQUALS); }
+colo-port=[^,]*,?	{ STRIP(','); SAVESTRING("colo-port", colo_port, FROMEQUALS); }
+colo-export=[^,]*,?	{ STRIP(','); SAVESTRING("colo-export", colo_export, FROMEQUALS); }
+active-disk=[^,]*,?	{ STRIP(','); SAVESTRING("active-disk", active_disk, FROMEQUALS); }
+hidden-disk=[^,]*,?	{ STRIP(','); SAVESTRING("hidden-disk", hidden_disk, FROMEQUALS); }
 
  /* the target magic parameter, eats the rest of the string */
 
Signature · 1 line
2.5.0
#38 lore raw

PATCH v9 19/25 COLO: use qemu block replication

In reply to Wen Congyang

Use qemu block replication as our block replication solution. Note that guest must be paused before starting COLO, otherwise, the disk won't be consistent between primary and secondary.

for commit message,

---
 tools/libxl/Makefile             |   1 +
 tools/libxl/libxl_colo_qdisk.c   | 262 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_colo_restore.c |  31 ++++-
 tools/libxl/libxl_colo_save.c    |  45 ++++++-
 tools/libxl/libxl_internal.h     |  34 +++++
 tools/libxl/libxl_qmp.c          |  93 ++++++++++++++
 6 files changed, 462 insertions(+), 4 deletions(-)
 create mode 100644 tools/libxl/libxl_colo_qdisk.c
tools/libxl/Makefile +1 -0
index b11cf34..a4156c1 100644
@@ -64,6 +64,7 @@ endif
 
 LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o
 LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o
+LIBXL_OBJS-y += libxl_colo_qdisk.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
tools/libxl/libxl_colo_qdisk.c new file +262 -0

262 lines not on this page · raw message

tools/libxl/libxl_colo_restore.c +29 -2
index f23ef8f..e5cfbe5 100644
@@ -50,7 +50,10 @@ static void libxl__colo_restore_domain_checkpoint_callback(void *data);
 static void libxl__colo_restore_domain_should_checkpoint_callback(void *data);
 static void libxl__colo_restore_domain_suspend_callback(void *data);
 
+extern const libxl__checkpoint_device_instance_ops colo_restore_device_qdisk;
+
 static const libxl__checkpoint_device_instance_ops *colo_restore_ops[] = {
+    &colo_restore_device_qdisk,
     NULL,
 };
 
@@ -150,7 +153,11 @@ static int init_device_subkind(libxl__checkpoint_devices_state *cds)
     int rc;
     STATE_AO_GC(cds->ao);
 
+    rc = init_subkind_qdisk(cds);
+    if (rc)  goto out;
+
     rc = 0;
+out:
     return rc;
 }
 
@@ -158,6 +165,8 @@ static void cleanup_device_subkind(libxl__checkpoint_devices_state *cds)
 {
     /* cleanup device subkind-specific state in the libxl ctx */
     STATE_AO_GC(cds->ao);
+
+    cleanup_subkind_qdisk(cds);
 }
 
 
@@ -217,6 +226,8 @@ void libxl__colo_restore_setup(libxl__egc *egc,
     GCNEW(crcs);
     crs->crcs = crcs;
     crcs->crs = crs;
+    crs->qdisk_setuped = false;
+    crs->qdisk_used = false;
 
     /* setup dsps */
     crcs->dsps.ao = ao;
@@ -585,6 +596,22 @@ static void colo_restore_preresume_cb(libxl__egc *egc,
         goto out;
     }
 
+    if (crs->qdisk_used && !crs->qdisk_setuped) {
+         if (colo_qdisk_start(egc, crs->domid, false)) {
+             LOG(ERROR, "starting block replication fails");
+             goto out;
+         }
+         crs->qdisk_setuped = true;
+    }
+
+    if (crs->qdisk_setuped) {
+        rc = colo_qdisk_preresume(CTX, crs->domid);
+        if (rc) {
+            LOG(ERROR, "colo_qdisk_preresume() fails");
+            goto out;
+        }
+    }
+
     colo_restore_resume_vm(egc, crcs);
 
     return;
@@ -742,8 +769,8 @@ static void colo_setup_checkpoint_devices(libxl__egc *egc,
 
     STATE_AO_GC(crs->ao);
 
-    /* TODO: disk/nic support */
-    cds->device_kind_flags = 0;
+    /* TODO: nic support */
+    cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD);
     cds->callback = colo_restore_setup_cds_done;
     cds->ao = ao;
     cds->domid = crs->domid;
tools/libxl/libxl_colo_save.c +43 -2

84 lines not on this page · raw message

tools/libxl/libxl_internal.h +34 -0
index 54903af..ddf4980 100644
@@ -1767,6 +1767,25 @@ _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enabl
 _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk);
 /* Add a virtual CPU */
 _hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index);
+/* Start NBD server */
+_hidden int libxl__qmp_nbd_server_start(libxl__gc *gc, int domid,
+                                        const char *host, const char *port);
+/* Add a disk to NBD server */
+_hidden int libxl__qmp_nbd_server_add(libxl__gc *gc, int domid, const char *disk);
+/* Start block replication */
+_hidden int libxl__qmp_block_start_replication(libxl__gc *gc, int domid, bool primary);
+/* Do block checkpoint */
+_hidden int libxl__qmp_block_do_checkpoint(libxl__gc *gc, int domid);
+/* Stop block replication */
+_hidden int libxl__qmp_block_stop_replication(libxl__gc *gc, int domid,
+                                              bool primary);
+/* Stop NBD server */
+_hidden int libxl__qmp_nbd_server_stop(libxl__gc *gc, int domid);
+/* Add or remove a child to/from quorum */
+_hidden int libxl__qmp_x_blockdev_change(libxl__gc *gc, int domid, const char *parant,
+                                         const char *child, const char *node);
+/* run a hmp command in qmp mode */
+_hidden int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line);
 /* close and free the QMP handler */
 _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);
 /* remove the socket file, if the file has already been removed,
@@ -2878,6 +2897,10 @@ int init_subkind_nic(libxl__checkpoint_devices_state *cds);
 void cleanup_subkind_nic(libxl__checkpoint_devices_state *cds);
 int init_subkind_drbd_disk(libxl__checkpoint_devices_state *cds);
 void cleanup_subkind_drbd_disk(libxl__checkpoint_devices_state *cds);
+int init_subkind_qdisk(libxl__checkpoint_devices_state *cds);
+void cleanup_subkind_qdisk(libxl__checkpoint_devices_state *cds);
+int colo_qdisk_preresume(libxl_ctx *ctx, domid_t domid);
+int colo_qdisk_start(libxl__egc *egc, domid_t domid, bool primary);
 
 typedef void libxl__checkpoint_callback(libxl__egc *,
                                         libxl__checkpoint_devices_state *,
@@ -3095,6 +3118,11 @@ struct libxl__colo_save_state {
     libxl__stream_read_state srs;
     void (*callback)(libxl__egc *, libxl__colo_save_state *, int);
     bool svm_running;
+    bool paused;
+
+    /* private, used by qdisk block replication */
+    bool qdisk_used;
+    bool qdisk_setuped;
 };
 
 /*----- Domain suspend (save) state structure -----*/
@@ -3500,6 +3528,12 @@ struct libxl__colo_restore_state {
     /* private, colo restore checkpoint state */
     libxl__domain_create_cb *saved_cb;
     void *crcs;
+
+    /* private, used by qdisk block replication */
+    bool qdisk_used;
+    bool qdisk_setuped;
+    const char *host;
+    const char *port;
 };
 
 struct libxl__domain_create_state {
tools/libxl/libxl_qmp.c +93 -0

99 lines not on this page · raw message

Signature · 1 line
2.5.0
#39 lore raw

PATCH v9 20/25 COLO proxy: implement setup/teardown of COLO proxy module

In reply to Wen Congyang

setup/teardown of COLO proxy module.
we use netlink to communicate with proxy module.
About colo-proxy module:
https://lkml.org/lkml/2015/6/18/32
How to use:
http://wiki.xen.org/wiki/COLO_-_Coarse_Grain_Lock_Stepping

---
 tools/libxl/Makefile           |   1 +
 tools/libxl/libxl_colo.h       |   2 +
 tools/libxl/libxl_colo_proxy.c | 230 +++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h   |  15 +++
 4 files changed, 248 insertions(+)
 create mode 100644 tools/libxl/libxl_colo_proxy.c
tools/libxl/Makefile +1 -0
index a4156c1..8c7e5c0 100644
@@ -65,6 +65,7 @@ endif
 LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o
 LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o
 LIBXL_OBJS-y += libxl_colo_qdisk.o
+LIBXL_OBJS-y += libxl_colo_proxy.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
tools/libxl/libxl_colo.h +2 -0
index 39515c4..2604b0f 100644
@@ -31,4 +31,6 @@ extern void libxl__colo_save_teardown(libxl__egc *egc,
                                       libxl__colo_save_state *css,
                                       int rc);
 
+extern int colo_proxy_setup(libxl__colo_proxy_state *cps);
+extern void colo_proxy_teardown(libxl__colo_proxy_state *cps);
 #endif
tools/libxl/libxl_colo_proxy.c new file +230 -0

230 lines not on this page · raw message

tools/libxl/libxl_internal.h +15 -0
index ddf4980..abaa98c 100644
@@ -3109,6 +3109,15 @@ libxl__stream_read_inuse(const libxl__stream_read_state *stream)
 }
 
 /*----- colo related state structure -----*/
+typedef struct libxl__colo_proxy_state libxl__colo_proxy_state;
+struct libxl__colo_proxy_state {
+    /* set by caller of colo_proxy_setup */
+    libxl__ao *ao;
+
+    int sock_fd;
+    int index;
+};
+
 typedef struct libxl__colo_save_state libxl__colo_save_state;
 struct libxl__colo_save_state {
     int send_fd;
@@ -3123,6 +3132,9 @@ struct libxl__colo_save_state {
     /* private, used by qdisk block replication */
     bool qdisk_used;
     bool qdisk_setuped;
+
+    /* private, used by colo-proxy */
+    libxl__colo_proxy_state cps;
 };
 
 /*----- Domain suspend (save) state structure -----*/
@@ -3534,6 +3546,9 @@ struct libxl__colo_restore_state {
     bool qdisk_setuped;
     const char *host;
     const char *port;
+
+    /* private, used by colo-proxy */
+    libxl__colo_proxy_state cps;
 };
 
 struct libxl__domain_create_state {
Signature · 1 line
2.5.0
#40 lore raw

PATCH v9 21/25 COLO proxy: preresume, postresume and checkpoint

In reply to Wen Congyang

preresume, postresume and checkpoint

---
 tools/libxl/libxl_colo.h       |  4 +++
 tools/libxl/libxl_colo_proxy.c | 62 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
tools/libxl/libxl_colo.h +4 -0
index 2604b0f..ea17faa 100644
@@ -33,4 +33,8 @@ extern void libxl__colo_save_teardown(libxl__egc *egc,
 
 extern int colo_proxy_setup(libxl__colo_proxy_state *cps);
 extern void colo_proxy_teardown(libxl__colo_proxy_state *cps);
+extern void colo_proxy_preresume(libxl__colo_proxy_state *cps);
+extern void colo_proxy_postresume(libxl__colo_proxy_state *cps);
+extern int colo_proxy_checkpoint(libxl__colo_proxy_state *cps,
+                                 unsigned int timeout_us);
 #endif
tools/libxl/libxl_colo_proxy.c +62 -0

65 lines not on this page · raw message

Signature · 1 line
2.5.0
#41 lore raw

PATCH v9 22/25 COLO nic: implement COLO nic subkind

In reply to Wen Congyang

implement COLO nic subkind.

---
 tools/hotplug/Linux/Makefile         |   1 +
 tools/hotplug/Linux/colo-proxy-setup | 135 +++++++++++++++
 tools/libxl/Makefile                 |   1 +
 tools/libxl/libxl_colo_nic.c         | 321 +++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h         |   5 +
 tools/libxl/libxl_types.idl          |   1 +
 6 files changed, 464 insertions(+)
 create mode 100755 tools/hotplug/Linux/colo-proxy-setup
 create mode 100644 tools/libxl/libxl_colo_nic.c
tools/hotplug/Linux/Makefile +1 -0
index 6e10118..9bb852b 100644
@@ -28,6 +28,7 @@ XEN_SCRIPTS += block-iscsi
 XEN_SCRIPTS += block-tap
 XEN_SCRIPTS += block-drbd-probe
 XEN_SCRIPTS += $(XEN_SCRIPTS-y)
+XEN_SCRIPTS += colo-proxy-setup
 
 SUBDIRS-$(CONFIG_SYSTEMD) += systemd
 
tools/hotplug/Linux/colo-proxy-setup new file +135 -0

135 lines not on this page · raw message

tools/libxl/Makefile +1 -0
index 8c7e5c0..407794e 100644
@@ -66,6 +66,7 @@ LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o
 LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o
 LIBXL_OBJS-y += libxl_colo_qdisk.o
 LIBXL_OBJS-y += libxl_colo_proxy.o
+LIBXL_OBJS-y += libxl_colo_nic.o
 
 LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o
 LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o
tools/libxl/libxl_colo_nic.c new file +321 -0

321 lines not on this page · raw message

tools/libxl/libxl_internal.h +5 -0
index abaa98c..06e1ccc 100644
@@ -2901,6 +2901,8 @@ int init_subkind_qdisk(libxl__checkpoint_devices_state *cds);
 void cleanup_subkind_qdisk(libxl__checkpoint_devices_state *cds);
 int colo_qdisk_preresume(libxl_ctx *ctx, domid_t domid);
 int colo_qdisk_start(libxl__egc *egc, domid_t domid, bool primary);
+int init_subkind_colo_nic(libxl__checkpoint_devices_state *cds);
+void cleanup_subkind_colo_nic(libxl__checkpoint_devices_state *cds);
 
 typedef void libxl__checkpoint_callback(libxl__egc *,
                                         libxl__checkpoint_devices_state *,
@@ -3122,6 +3124,7 @@ typedef struct libxl__colo_save_state libxl__colo_save_state;
 struct libxl__colo_save_state {
     int send_fd;
     int recv_fd;
+    char *colo_proxy_script;
 
     /* private */
     libxl__stream_read_state srs;
@@ -3536,6 +3539,7 @@ struct libxl__colo_restore_state {
     int recv_fd;
     int hvm;
     libxl__colo_callback *callback;
+    char *colo_proxy_script;
 
     /* private, colo restore checkpoint state */
     libxl__domain_create_cb *saved_cb;
@@ -3565,6 +3569,7 @@ struct libxl__domain_create_state {
     libxl_asyncprogress_how aop_console_how;
     /* private to domain_create */
     int guest_domid;
+    const char *colo_proxy_script;
     libxl__domain_build_state build_state;
     libxl__colo_restore_state crs;
     libxl__checkpoint_devices_state cds;
tools/libxl/libxl_types.idl +1 -0
index 38f37f2..1981f8b 100644
@@ -598,6 +598,7 @@ libxl_device_nic = Struct("device_nic", [
     ("rate_bytes_per_interval", uint64),
     ("rate_interval_usecs", uint32),
     ("gatewaydev", string),
+    ("forwarddev", string)
     ])
 
 libxl_device_pci = Struct("device_pci", [
Signature · 1 line
2.5.0
#42 lore raw

PATCH v9 23/25 setup and control colo proxy on primary side

In reply to Wen Congyang

setup and control colo proxy on primary side

---
 tools/libxl/libxl_colo_save.c | 124 +++++++++++++++++++++++++++++++++++++++---
 tools/libxl/libxl_internal.h  |   1 +
 2 files changed, 117 insertions(+), 8 deletions(-)
tools/libxl/libxl_colo_save.c +116 -8
index 78fcc60..e3d4f91 100644
@@ -19,9 +19,11 @@
 #include "libxl_internal.h"
 #include "libxl_colo.h"
 
+extern const libxl__checkpoint_device_instance_ops colo_save_device_nic;
 extern const libxl__checkpoint_device_instance_ops colo_save_device_qdisk;
 
 static const libxl__checkpoint_device_instance_ops *colo_ops[] = {
+    &colo_save_device_nic,
     &colo_save_device_qdisk,
     NULL,
 };
@@ -33,9 +35,15 @@ static int init_device_subkind(libxl__checkpoint_devices_state *cds)
     int rc;
     STATE_AO_GC(cds->ao);
 
-    rc = init_subkind_qdisk(cds);
+    rc = init_subkind_colo_nic(cds);
     if (rc) goto out;
 
+    rc = init_subkind_qdisk(cds);
+    if (rc) {
+        cleanup_subkind_colo_nic(cds);
+        goto out;
+    }
+
     rc = 0;
 out:
     return rc;
@@ -46,6 +54,7 @@ static void cleanup_device_subkind(libxl__checkpoint_devices_state *cds)
     /* cleanup device subkind-specific state in the libxl ctx */
     STATE_AO_GC(cds->ao);
 
+    cleanup_subkind_colo_nic(cds);
     cleanup_subkind_qdisk(cds);
 }
 
@@ -77,9 +86,16 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
     css->paused = true;
     css->qdisk_setuped = false;
     css->qdisk_used = false;
+    libxl__ev_child_init(&css->child);
 
-    /* TODO: nic support */
-    cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD);
+    if (dss->remus->netbufscript)
+        css->colo_proxy_script = libxl__strdup(gc, dss->remus->netbufscript);
+    else
+        css->colo_proxy_script = GCSPRINTF("%s/colo-proxy-setup",
+                                           libxl__xen_script_dir_path());
+
+    cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VIF) |
+                             (1 << LIBXL__DEVICE_KIND_VBD);
     cds->ops = colo_ops;
     cds->callback = colo_save_setup_done;
     cds->ao = ao;
@@ -90,6 +106,12 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
     css->srs.fd = css->recv_fd;
     css->srs.back_channel = true;
     libxl__stream_read_start(egc, &css->srs);
+    css->cps.ao = ao;
+    if (colo_proxy_setup(&css->cps)) {
+        LOG(ERROR, "COLO: failed to setup colo proxy for guest with domid %u",
+            cds->domid);
+        goto out;
+    }
 
     if (init_device_subkind(cds))
         goto out;
@@ -167,6 +189,7 @@ static void colo_teardown_done(libxl__egc *egc,
     libxl__domain_save_state *dss = CONTAINER_OF(css, *dss, css);
 
     cleanup_device_subkind(cds);
+    colo_proxy_teardown(&css->cps);
     dss->callback(egc, dss, rc);
 }
 
@@ -361,6 +384,8 @@ static void colo_read_svm_ready_done(libxl__egc *egc,
         goto out;
     }
 
+    colo_proxy_preresume(&css->cps);
+
     css->svm_running = true;
     dss->cds.callback = colo_preresume_cb;
     libxl__checkpoint_devices_preresume(egc, &dss->cds);
@@ -446,6 +471,8 @@ static void colo_read_svm_resumed_done(libxl__egc *egc,
         goto out;
     }
 
+    colo_proxy_postresume(&css->cps);
+
     ok = 1;
 
 out:
@@ -454,6 +481,91 @@ out:
 
 
 /* ===================== colo: wait new checkpoint ===================== */
+
+static void colo_start_new_checkpoint(libxl__egc *egc,
+                                      libxl__checkpoint_devices_state *cds,
+                                      int rc);
+static void colo_proxy_async_wait_for_checkpoint(libxl__colo_save_state *css);
+static void colo_proxy_async_call_done(libxl__egc *egc,
+                                       libxl__ev_child *child,
+                                       int pid,
+                                       int status);
+
+static void colo_proxy_async_call(libxl__egc *egc,
+                                  libxl__colo_save_state *css,
+                                  void func(libxl__colo_save_state *),
+                                  libxl__ev_child_callback callback)
+{
+    libxl__domain_save_state *dss = CONTAINER_OF(css, *dss, css);
+    int pid = -1, rc;
+
+    STATE_AO_GC(dss->cds.ao);
+
+    /* Fork and call */
+    pid = libxl__ev_child_fork(gc, &css->child, callback);
+    if (pid == -1) {
+        LOG(ERROR, "unable to fork");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (!pid) {
+        /* child */
+        func(css);
+        /* notreached */
+        abort();
+    }
+
+    return;
+
+out:
+    callback(egc, &css->child, -1, 1);
+}
+
+static void colo_proxy_wait_for_checkpoint(libxl__egc *egc,
+                                           libxl__colo_save_state *css)
+{
+    colo_proxy_async_call(egc, css,
+                          colo_proxy_async_wait_for_checkpoint,
+                          colo_proxy_async_call_done);
+}
+
+static void colo_proxy_async_wait_for_checkpoint(libxl__colo_save_state *css)
+{
+    int req;
+
+    req = colo_proxy_checkpoint(&css->cps, 5000000);
+    if (req < 0) {
+        /* some error happens */
+        _exit(1);
+    } else if (!req) {
+        /* no checkpoint is needed, do a checkpint every 5s */
+        _exit(0);
+    } else {
+        /* net packets is not consistent, we need to start a checkpoint */
+        _exit(0);
+    }
+}
+
+static void colo_proxy_async_call_done(libxl__egc *egc,
+                                       libxl__ev_child *child,
+                                       int pid,
+                                       int status)
+{
+    libxl__colo_save_state *css = CONTAINER_OF(child, *css, child);
+    libxl__domain_save_state *dss = CONTAINER_OF(css, *dss, css);
+
+    EGC_GC;
+
+    if (status) {
+        LOG(ERROR, "failed to wait for new checkpoint");
+        colo_start_new_checkpoint(egc, &dss->cds, ERROR_FAIL);
+        return;
+    }
+
+    colo_start_new_checkpoint(egc, &dss->cds, 0);
+}
+
 /*
  * Do the following things:
  * 1. do commit
@@ -463,9 +575,6 @@ out:
 static void colo_device_commit_cb(libxl__egc *egc,
                                   libxl__checkpoint_devices_state *cds,
                                   int rc);
-static void colo_start_new_checkpoint(libxl__egc *egc,
-                                      libxl__checkpoint_devices_state *cds,
-                                      int rc);
 
 void libxl__colo_save_domain_should_checkpoint_callback(void *data)
 {
@@ -495,8 +604,7 @@ static void colo_device_commit_cb(libxl__egc *egc,
         goto out;
     }
 
-    /* TODO: wait a new checkpoint */
-    colo_start_new_checkpoint(egc, cds, 0);
+    colo_proxy_wait_for_checkpoint(egc, css);
     return;
 
 out:
tools/libxl/libxl_internal.h +1 -0
index 06e1ccc..c94e2e9 100644
@@ -3138,6 +3138,7 @@ struct libxl__colo_save_state {
 
     /* private, used by colo-proxy */
     libxl__colo_proxy_state cps;
+    libxl__ev_child child;
 };
 
 /*----- Domain suspend (save) state structure -----*/
Signature · 1 line
2.5.0
#43 lore raw

PATCH v9 24/25 setup and control colo proxy on secondary side

In reply to Wen Congyang

setup and control colo proxy on secondary side

---
 tools/libxl/libxl_colo_restore.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
tools/libxl/libxl_colo_restore.c +25 -3
index e5cfbe5..e9126ef 100644
@@ -50,9 +50,11 @@ static void libxl__colo_restore_domain_checkpoint_callback(void *data);
 static void libxl__colo_restore_domain_should_checkpoint_callback(void *data);
 static void libxl__colo_restore_domain_suspend_callback(void *data);
 
+extern const libxl__checkpoint_device_instance_ops colo_restore_device_nic;
 extern const libxl__checkpoint_device_instance_ops colo_restore_device_qdisk;
 
 static const libxl__checkpoint_device_instance_ops *colo_restore_ops[] = {
+    &colo_restore_device_nic,
     &colo_restore_device_qdisk,
     NULL,
 };
@@ -153,8 +155,14 @@ static int init_device_subkind(libxl__checkpoint_devices_state *cds)
     int rc;
     STATE_AO_GC(cds->ao);
 
+    rc = init_subkind_colo_nic(cds);
+    if (rc) goto out;
+
     rc = init_subkind_qdisk(cds);
-    if (rc)  goto out;
+    if (rc) {
+        cleanup_subkind_colo_nic(cds);
+        goto out;
+    }
 
     rc = 0;
 out:
@@ -166,6 +174,7 @@ static void cleanup_device_subkind(libxl__checkpoint_devices_state *cds)
     /* cleanup device subkind-specific state in the libxl ctx */
     STATE_AO_GC(cds->ao);
 
+    cleanup_subkind_colo_nic(cds);
     cleanup_subkind_qdisk(cds);
 }
 
@@ -345,6 +354,8 @@ static void colo_restore_teardown_devices_done(libxl__egc *egc,
     if (crcs->teardown_devices)
         cleanup_device_subkind(cds);
 
+    colo_proxy_teardown(&crs->cps);
+
     rc = crcs->saved_rc;
     if (!rc) {
         crcs->callback = do_failover_done;
@@ -612,6 +623,8 @@ static void colo_restore_preresume_cb(libxl__egc *egc,
         }
     }
 
+    colo_proxy_preresume(&crs->cps);
+
     colo_restore_resume_vm(egc, crcs);
 
     return;
@@ -648,6 +661,8 @@ static void colo_resume_vm_done(libxl__egc *egc,
 
     crcs->status = LIBXL_COLO_RESUMED;
 
+    colo_proxy_postresume(&crs->cps);
+
     /* avoid calling stream->completion_callback() more than once */
     if (crs->saved_cb) {
         dcs->callback = crs->saved_cb;
@@ -769,13 +784,20 @@ static void colo_setup_checkpoint_devices(libxl__egc *egc,
 
     STATE_AO_GC(crs->ao);
 
-    /* TODO: nic support */
-    cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD);
+    cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VIF) |
+                             (1 << LIBXL__DEVICE_KIND_VBD);
     cds->callback = colo_restore_setup_cds_done;
     cds->ao = ao;
     cds->domid = crs->domid;
     cds->ops = colo_restore_ops;
 
+    crs->cps.ao = ao;
+    if (colo_proxy_setup(&crs->cps)) {
+        LOG(ERROR, "COLO: failed to setup colo proxy for guest with domid %u",
+            cds->domid);
+        goto out;
+    }
+
     if (init_device_subkind(cds))
         goto out;
 
Signature · 1 line
2.5.0
#44 lore raw

PATCH v9 25/25 cmdline switches and config vars to control colo-proxy

In reply to Wen Congyang

Add cmdline switches to 'xl migrate-receive' command to specify a domain-specific hotplug script to setup COLO proxy.

Add a new config var 'colo.default.agentscript' to xl.conf, that allows the user to override the default global script used to setup COLO proxy.

---
 docs/man/xl.conf.pod.5      |  6 ++++++
 docs/man/xl.pod.1           |  1 -
 tools/libxl/libxl.c         |  6 ++++++
 tools/libxl/libxl_create.c  | 14 ++++++++++++--
 tools/libxl/libxl_types.idl |  1 +
 tools/libxl/xl.c            |  3 +++
 tools/libxl/xl.h            |  1 +
 tools/libxl/xl_cmdimpl.c    | 47 ++++++++++++++++++++++++++++++++++-----------
 8 files changed, 65 insertions(+), 14 deletions(-)
docs/man/xl.conf.pod.5 +6 -0
index 8ae19bb..8f7fd28 100644
@@ -111,6 +111,12 @@ Configures the default script used by Remus to setup network buffering.
 
 Default: C</etc/xen/scripts/remus-netbuf-setup>
 
+=item B<colo.default.proxyscript="PATH">
+
+Configures the default script used by COLO to setup colo-proxy.
+
+Default: C</etc/xen/scripts/colo-proxy-setup>
+
 =item B<output_format="json|sxp">
 
 Configures the default output format used by xl when printing "machine
docs/man/xl.pod.1 +0 -1
index 4f1901d..edeafcf 100644
@@ -454,7 +454,6 @@ N.B: Remus support in xl is still in experimental (proof-of-concept) phase.
      Disk replication support is limited to DRBD disks.
 
      COLO support in xl is still in experimental (proof-of-concept) phase.
-     There is no support for network at the moment.
 
 B<OPTIONS>
 
tools/libxl/libxl.c +6 -0
index e770723..56e86d8 100644
@@ -3398,6 +3398,11 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(back, nic->ifname);
     }
 
+    if (nic->forwarddev) {
+        flexarray_append(back, "forwarddev");
+        flexarray_append(back, nic->forwarddev);
+    }
+
     flexarray_append(back, "mac");
     flexarray_append(back,GCSPRINTF(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
     if (nic->ip) {
@@ -3520,6 +3525,7 @@ static int libxl__device_nic_from_xs_be(libxl__gc *gc,
     nic->ip = READ_BACKEND(NOGC, "ip");
     nic->bridge = READ_BACKEND(NOGC, "bridge");
     nic->script = READ_BACKEND(NOGC, "script");
+    nic->forwarddev = READ_BACKEND(NOGC, "forwarddev");
 
     /* vif_ioemu nics use the same xenstore entries as vif interfaces */
     tmp = READ_BACKEND(gc, "type");
tools/libxl/libxl_create.c +12 -2
index 7cb3c6a..4ba87df 100644
@@ -1054,6 +1054,11 @@ static void domcreate_bootloader_done(libxl__egc *egc,
             crs->recv_fd = restore_fd;
             crs->hvm = (info->type == LIBXL_DOMAIN_TYPE_HVM);
             crs->callback = libxl__colo_restore_setup_done;
+            if (dcs->colo_proxy_script)
+                crs->colo_proxy_script = libxl__strdup(gc, dcs->colo_proxy_script);
+            else
+                crs->colo_proxy_script = GCSPRINTF("%s/colo-proxy-setup",
+                                                   libxl__xen_script_dir_path());
             libxl__colo_restore_setup(egc, crs);
             break;
         case LIBXL_CHECKPOINTED_STREAM_REMUS:
@@ -1596,6 +1601,7 @@ static void domain_create_cb(libxl__egc *egc,
 static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
                             uint32_t *domid, int restore_fd, int send_fd,
                             const libxl_domain_restore_params *params,
+                            const char *colo_proxy_script,
                             const libxl_asyncop_how *ao_how,
                             const libxl_asyncprogress_how *aop_console_how)
 {
@@ -1619,6 +1625,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
     }
     cdcs->dcs.callback = domain_create_cb;
     cdcs->dcs.domid_soft_reset = INVALID_DOMID;
+    cdcs->dcs.colo_proxy_script = colo_proxy_script;
     libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how);
     cdcs->domid_out = domid;
 
@@ -1805,7 +1812,7 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
                             const libxl_asyncprogress_how *aop_console_how)
 {
     unset_disk_colo_restore(d_config);
-    return do_domain_create(ctx, d_config, domid, -1, -1, NULL,
+    return do_domain_create(ctx, d_config, domid, -1, -1, NULL, NULL,
                             ao_how, aop_console_how);
 }
 
@@ -1815,14 +1822,17 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
                                 const libxl_asyncop_how *ao_how,
                                 const libxl_asyncprogress_how *aop_console_how)
 {
+    char *colo_proxy_script = NULL;
+
     if (params->checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO) {
+        colo_proxy_script = params->colo_proxy_script;
         set_disk_colo_restore(d_config);
     } else {
         unset_disk_colo_restore(d_config);
     }
 
     return do_domain_create(ctx, d_config, domid, restore_fd, send_fd, params,
-                            ao_how, aop_console_how);
+                            colo_proxy_script, ao_how, aop_console_how);
 }
 
 int libxl_domain_soft_reset(libxl_ctx *ctx,
tools/libxl/libxl_types.idl +1 -0
index 1981f8b..835a946 100644
@@ -384,6 +384,7 @@ libxl_domain_create_info = Struct("domain_create_info",[
 libxl_domain_restore_params = Struct("domain_restore_params", [
     ("checkpointed_stream", integer),
     ("stream_version", uint32, {'init_val': '1'}),
+    ("colo_proxy_script", string),
     ])
 
 libxl_domain_sched_params = Struct("domain_sched_params",[
tools/libxl/xl.c +3 -0
index dfae84a..a272258 100644
@@ -45,6 +45,7 @@ char *default_bridge = NULL;
 char *default_gatewaydev = NULL;
 char *default_vifbackend = NULL;
 char *default_remus_netbufscript = NULL;
+char *default_colo_proxy_script = NULL;
 enum output_format default_output_format = OUTPUT_FORMAT_JSON;
 int claim_mode = 1;
 bool progress_use_cr = 0;
@@ -179,6 +180,8 @@ static void parse_global_config(const char *configfile,
 
     xlu_cfg_replace_string (config, "remus.default.netbufscript",
         &default_remus_netbufscript, 0);
+    xlu_cfg_replace_string (config, "colo.default.proxyscript",
+        &default_colo_proxy_script, 0);
 
     xlu_cfg_destroy(config);
 }
tools/libxl/xl.h +1 -0
index bdab125..709c3fd 100644
@@ -189,6 +189,7 @@ extern char *default_bridge;
 extern char *default_gatewaydev;
 extern char *default_vifbackend;
 extern char *default_remus_netbufscript;
+extern char *default_colo_proxy_script;
 extern char *blkdev_start;
 
 enum output_format {
tools/libxl/xl_cmdimpl.c +36 -11

114 lines not on this page · raw message

Signature · 1 line
2.5.0