Skip to contentSkip to conversation

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

PATCH In review Yang Hongyang 2 participants 46 messages Jul 15, 2015 – Jul 16, 2015

lore
Share & tools
lore
#0 lore raw

v8 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

In this series, we've rebased to the latest libxl migration v2.

This patchset is based on:
[PATCH v4 --for 4.6 COLOPre 00/25] Prerequisite patches for COLO

Only support hvm guest for now. The code is also hosted on github:
https://github.com/macrosheep/xen/tree/colo-v8

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 (7):
docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo
streams
secondary vm suspend/resume/checkpoint code
primary vm suspend/resume/checkpoint code
send store mfn and console mfn to xl before resuming secondary vm implement the cmdline for COLO
Support colo mode for qemu disk
COLO: use qemu block replication

Yang Hongyang (18):
A docs: add colo readme
libxc/migration: Specification update for DIRTY_BITMAP records libxc/migration: export read_record for common use tools/libxl: add back channel support to write stream tools/libxl: write colo_context records into the stream tools/libxl: add back channel support to read stream tools/libxl: handle colo_context 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 libxc/restore: support COLO restore
libxc/restore: send dirty bitmap to primary when checkpoint under colo libxc/save: support COLO save
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      |   38 ++
 docs/specs/libxc-migration-stream.pandoc |   24 +-
 docs/specs/libxl-migration-stream.pandoc |   22 +-
 tools/hotplug/Linux/Makefile             |    1 +
 tools/hotplug/Linux/colo-proxy-setup     |  131 ++++
 tools/libxc/include/xenguest.h           |   36 ++
 tools/libxc/xc_sr_common.c               |   50 ++
 tools/libxc/xc_sr_common.h               |   36 +-
 tools/libxc/xc_sr_restore.c              |  244 +++++--
 tools/libxc/xc_sr_save.c                 |  104 ++-
 tools/libxc/xc_sr_stream_format.h        |    1 +
 tools/libxl/Makefile                     |    4 +
 tools/libxl/libxl.c                      |   77 ++-
 tools/libxl/libxl_colo.h                 |   42 ++
 tools/libxl/libxl_colo_nic.c             |  320 ++++++++++
 tools/libxl/libxl_colo_proxy.c           |  267 ++++++++
 tools/libxl/libxl_colo_qdisk.c           |  209 ++++++
 tools/libxl/libxl_colo_restore.c         | 1024 ++++++++++++++++++++++++++++++
 tools/libxl/libxl_colo_save.c            |  709 +++++++++++++++++++++
 tools/libxl/libxl_create.c               |  153 ++++-
 tools/libxl/libxl_device.c               |   38 ++
 tools/libxl/libxl_dm.c                   |  257 +++++++-
 tools/libxl/libxl_dom_save.c             |   14 +-
 tools/libxl/libxl_internal.h             |  217 +++++--
 tools/libxl/libxl_qmp.c                  |   31 +
 tools/libxl/libxl_save_callout.c         |    7 +-
 tools/libxl/libxl_save_msgs_gen.pl       |   11 +-
 tools/libxl/libxl_sr_stream_format.h     |   11 +
 tools/libxl/libxl_stream_read.c          |   68 ++
 tools/libxl/libxl_stream_write.c         |  103 +++
 tools/libxl/libxl_types.idl              |    8 +
 tools/libxl/libxlu_disk_l.l              |    5 +
 tools/libxl/xl.c                         |    3 +
 tools/libxl/xl.h                         |    1 +
 tools/libxl/xl_cmdimpl.c                 |  101 ++-
 tools/libxl/xl_cmdtable.c                |    4 +-
 tools/python/xen/migration/libxl.py      |    9 +
 40 files changed, 4224 insertions(+), 182 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
1.9.1
#1 lore raw

PATCH v8 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
1.9.1
#2 lore raw

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

In reply to Yang Hongyang

From: Wen Congyang <[email protected]>

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 | 22 +++++++++++++++++++++-
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
docs/specs/libxl-migration-stream.pandoc +21 -1
index c24a434..5986273 100644
@@ -121,7 +121,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: COLO_CONTEXT
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_
              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -215,3 +217,21 @@ A checkpoint end record marks the end of a checkpoint in the image.
     +-------------------------------------------------+
 
 The end record contains no fields; its body_length is 0.
+
+COLO\_CONTEXT
+--------------
+
+A COLO context record contains the control information for COLO.
+
+     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
tools/libxl/libxl_sr_stream_format.h +11 -0
index 3f3c497..1dd2ac4 100644
@@ -36,6 +36,7 @@ typedef struct libxl__sr_rec_hdr
 #define REC_TYPE_XENSTORE_DATA       0x00000002U
 #define REC_TYPE_EMULATOR_CONTEXT    0x00000003U
 #define REC_TYPE_CHECKPOINT_END      0x00000004U
+#define REC_TYPE_COLO_CONTEXT        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_colo_context
+{
+    uint32_t id;
+} libxl_sr_colo_context;
+
+#define COLO_NEW_CHECKPOINT          0x00000000U
+#define COLO_SVM_SUSPENDED           0x00000001U
+#define COLO_SVM_READY               0x00000002U
+#define COLO_SVM_RESUMED             0x00000003U
+
 #endif /* LIBXL__SR_STREAM_FORMAT_H */
 
 /*
tools/python/xen/migration/libxl.py +9 -0
index 415502e..57031c6 100644
@@ -37,6 +37,7 @@ REC_TYPE_libxc_context    = 0x00000001
 REC_TYPE_xenstore_data    = 0x00000002
 REC_TYPE_emulator_context = 0x00000003
 REC_TYPE_checkpoint_end   = 0x00000004
+REC_TYPE_colo_context     = 0x00000005
 
 rec_type_to_str = {
     REC_TYPE_end              : "End",
@@ -44,6 +45,7 @@ rec_type_to_str = {
     REC_TYPE_xenstore_data    : "Xenstore data",
     REC_TYPE_emulator_context : "Emulator context",
     REC_TYPE_checkpoint_end   : "Checkpoint end",
+    REC_TYPE_colo_context     : "COLO context"
 }
 
 # emulator_context
@@ -184,6 +186,11 @@ class VerifyLibxl(VerifyBase):
         if len(content) != 0:
             raise RecordError("Checkpoint end record with non-zero length")
 
+    def verify_record_colo_context(self, content):
+        """ COLO context """
+        if len(content) == 0:
+            raise RecordError("COLO context record with zero length")
+
 
 record_verifiers = {
     REC_TYPE_end:
@@ -196,4 +203,6 @@ record_verifiers = {
         VerifyLibxl.verify_record_emulator_context,
     REC_TYPE_checkpoint_end:
         VerifyLibxl.verify_record_checkpoint_end,
+    REC_TYPE_colo_context:
+        VerifyLibxl.verify_record_colo_context,
 }
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH v8 --for 4.6 COLO 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 45 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

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 | 22 +++++++++++++++++++++-
 tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
 tools/python/xen/migration/libxl.py      |  9 +++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)
docs/specs/libxl-migration-stream.pandoc +11 -1
index c24a434..5986273 100644
@@ -121,7 +121,9 @@ type         0x00000000: END
 
              0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: COLO_CONTEXT
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_
              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -215,3 +217,21 @@ A checkpoint end record marks the end of a checkpoint in the image.
     +-------------------------------------------------+
 
 The end record contains no fields; its body_length is 0.
+
+COLO\_CONTEXT
+--------------
+
+A COLO context record contains the control information for COLO.
+
+     0     1     2     3     4     5     6     7 octet
+    +------------------------+------------------------+

docs/specs/libxl-migration-stream.pandoc A checkpoint end record marks the end of a checkpoint in the image. · line 237

Quoted 10 lines
docs/specs/libxl-migration-stream.pandoc +10 -0
+    | 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

This style of table in pandoc need to be terminated with a line of -------, just like the head of the table.

Also, I wonder at the name "COLO_CONTEXT". CONTEXT implies an associated blob of data, but this is not the case here. Here, it is more of a status update, with expected actions on some states.

~Andrew

#4 lore raw

Re: [PATCH v8 --for 4.6 COLO 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 51 lines · Andrew Cooper
Quoted 50 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

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 | 22 +++++++++++++++++++++-
  tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
  tools/python/xen/migration/libxl.py      |  9 +++++++++
  3 files changed, 41 insertions(+), 1 deletion(-)
docs/specs/libxl-migration-stream.pandoc +16 -1
index c24a434..5986273 100644
@@ -121,7 +121,9 @@ type         0x00000000: END
 
               0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: COLO_CONTEXT
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_
               records.
 
               0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -215,3 +217,21 @@ A checkpoint end record marks the end of a checkpoint in the image.
      +-------------------------------------------------+
 
  The end record contains no fields; its body_length is 0.
+
+COLO\_CONTEXT
+--------------
+
+A COLO context record contains the control information for COLO.
+
+     0     1     2     3     4     5     6     7 octet
+    +------------------------+------------------------+
+    | control_id             | padding                |
+    +------------------------+------------------------+
+
+--------------------------------------------------------------------
+Field            Description
Quoted 8 lines

docs/specs/libxl-migration-stream.pandoc A checkpoint end record marks the end of a checkpoint in the image. · line 237

Quoted 5 lines
docs/specs/libxl-migration-stream.pandoc +5 -0
+------------     ---------------------------------------------------
+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

This style of table in pandoc need to be terminated with a line of -------, just like the head of the table.

Ok

Quoted 4 lines

Also, I wonder at the name "COLO_CONTEXT". CONTEXT implies an associated blob of data, but this is not the case here. Here, it is more of a status update, with expected actions on some states.

True, could you suggest a better name? sorry for my bad English...

Quoted 4 lines

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#5 lore raw

Re: [PATCH v8 --for 4.6 COLO 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 67 lines · Yang Hongyang
Quoted 55 lines · Andrew Cooper
Quoted 54 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

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 | 22 +++++++++++++++++++++-
  tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
  tools/python/xen/migration/libxl.py      |  9 +++++++++
  3 files changed, 41 insertions(+), 1 deletion(-)
docs/specs/libxl-migration-stream.pandoc +3 -1
index c24a434..5986273 100644
@@ -121,7 +121,9 @@ type         0x00000000: END
 
               0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: COLO_CONTEXT
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_
               records.
 
               0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -215,3 +217,21 @@ A checkpoint end record marks the end of a

checkpoint in the image.

      +-------------------------------------------------+

The end record contains no fields; its body_length is 0.

docs/specs/libxl-migration-stream.pandoc +14 -0
+
+COLO\_CONTEXT
+--------------
+
+A COLO context record contains the control information for COLO.
+
+     0     1     2     3     4     5     6     7 octet
+    +------------------------+------------------------+
+    | control_id             | padding                |
+    +------------------------+------------------------+
+
+--------------------------------------------------------------------
+Field            Description
+------------     ---------------------------------------------------
Quoted 8 lines

docs/specs/libxl-migration-stream.pandoc A checkpoint end record marks the end of a checkpoint in the image. · line 237

Quoted 5 lines

+control_id 0x00000000: Secondary VM is out of sync, start a
new checkpoint

docs/specs/libxl-migration-stream.pandoc +3 -0
+                 0x00000001: Secondary VM is suspended
+                 0x00000002: Secondary VM is ready
+                 0x00000003: Secondary VM is resumed

This style of table in pandoc need to be terminated with a line of -------, just like the head of the table.

Quoted 8 lines

Ok

Quoted 4 lines

Also, I wonder at the name "COLO_CONTEXT". CONTEXT implies an associated blob of data, but this is not the case here. Here, it is more of a status update, with expected actions on some states.

True, could you suggest a better name? sorry for my bad English...

In hindsight, I would also avoid putting COLO in the name.

How about CHECKPOINT_SECONDARY_STATE ?

You also want to note that this record should currently only be found in the libxl backchannel.

~Andrew

#6 lore raw

Re: [PATCH v8 --for 4.6 COLO 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 70 lines · Andrew Cooper
Quoted 69 lines · Yang Hongyang
Quoted 54 lines · Andrew Cooper
Quoted 53 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

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 | 22 +++++++++++++++++++++-
  tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
  tools/python/xen/migration/libxl.py      |  9 +++++++++
  3 files changed, 41 insertions(+), 1 deletion(-)
docs/specs/libxl-migration-stream.pandoc +3 -1
index c24a434..5986273 100644
@@ -121,7 +121,9 @@ type         0x00000000: END
 
               0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: COLO_CONTEXT
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_
               records.
 
               0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -215,3 +217,21 @@ A checkpoint end record marks the end of a

checkpoint in the image.

      +-------------------------------------------------+

The end record contains no fields; its body_length is 0.

docs/specs/libxl-migration-stream.pandoc +13 -0
+
+COLO\_CONTEXT
+--------------
+
+A COLO context record contains the control information for COLO.
+
+     0     1     2     3     4     5     6     7 octet
+    +------------------------+------------------------+
+    | control_id             | padding                |
+    +------------------------+------------------------+
+
+--------------------------------------------------------------------
+Field            Description
Quoted 8 lines

docs/specs/libxl-migration-stream.pandoc A checkpoint end record marks the end of a checkpoint in the image. · line 237

Quoted 6 lines
+------------     ---------------------------------------------------
+control_id       0x00000000: Secondary VM is out of sync, start a

new checkpoint

docs/specs/libxl-migration-stream.pandoc +3 -0
+                 0x00000001: Secondary VM is suspended
+                 0x00000002: Secondary VM is ready
+                 0x00000003: Secondary VM is resumed

This style of table in pandoc need to be terminated with a line of -------, just like the head of the table.

Ok

Quoted 3 lines

Also, I wonder at the name "COLO_CONTEXT". CONTEXT implies an associated blob of data, but this is not the case here. Here, it is more of a status update, with expected actions on some states.

Quoted 7 lines
Quoted 1 line

True, could you suggest a better name? sorry for my bad English...

In hindsight, I would also avoid putting COLO in the name.

How about CHECKPOINT_SECONDARY_STATE ?

You also want to note that this record should currently only be found in the libxl backchannel.

Sorry - ignore this final sentence. I have just read another of your replies.

~Andrew

#7 lore raw

Re: [PATCH v8 --for 4.6 COLO 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

In reply to Andrew Cooper
Quoted 75 lines · Andrew Cooper
Quoted 74 lines · Yang Hongyang
Quoted 55 lines · Andrew Cooper
Quoted 54 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

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 | 22 +++++++++++++++++++++-
   tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
   tools/python/xen/migration/libxl.py      |  9 +++++++++
   3 files changed, 41 insertions(+), 1 deletion(-)
docs/specs/libxl-migration-stream.pandoc +3 -1
index c24a434..5986273 100644
@@ -121,7 +121,9 @@ type         0x00000000: END
 
                0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x00000005: COLO_CONTEXT
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future _mandatory_
                records.
 
                0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -215,3 +217,21 @@ A checkpoint end record marks the end of a

checkpoint in the image.

       +-------------------------------------------------+

The end record contains no fields; its body_length is 0.

docs/specs/libxl-migration-stream.pandoc +14 -0
+
+COLO\_CONTEXT
+--------------
+
+A COLO context record contains the control information for COLO.
+
+     0     1     2     3     4     5     6     7 octet
+    +------------------------+------------------------+
+    | control_id             | padding                |
+    +------------------------+------------------------+
+
+--------------------------------------------------------------------
+Field            Description
+------------     ---------------------------------------------------
Quoted 8 lines

docs/specs/libxl-migration-stream.pandoc A checkpoint end record marks the end of a checkpoint in the image. · line 237

Quoted 5 lines

+control_id 0x00000000: Secondary VM is out of sync, start a
new checkpoint

docs/specs/libxl-migration-stream.pandoc +3 -0
+                 0x00000001: Secondary VM is suspended
+                 0x00000002: Secondary VM is ready
+                 0x00000003: Secondary VM is resumed

This style of table in pandoc need to be terminated with a line of -------, just like the head of the table.

Ok

Quoted 4 lines

Also, I wonder at the name "COLO_CONTEXT". CONTEXT implies an associated blob of data, but this is not the case here. Here, it is more of a status update, with expected actions on some states.

Quoted 5 lines
Quoted 1 line

True, could you suggest a better name? sorry for my bad English...

In hindsight, I would also avoid putting COLO in the name.

How about CHECKPOINT_SECONDARY_STATE ?

From my another mail, I explained the COLO_CONTEXT, do you still suggest CHECKPOINT_SECONDARY_STATE? IMO, it's more like a sync command?

Quoted 7 lines

You also want to note that this record should currently only be found in the libxl backchannel.

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#8 lore raw

Re: [PATCH v8 --for 4.6 COLO 02/25] docs/libxl: Introduce COLO_CONTEXT to support migration v2 colo streams

Quoted 84 lines · Yang Hongyang
Quoted 81 lines · Andrew Cooper
Quoted 79 lines · Yang Hongyang
Quoted 59 lines · Andrew Cooper
Quoted 58 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

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 | 22
+++++++++++++++++++++-
   tools/libxl/libxl_sr_stream_format.h     | 11 +++++++++++
   tools/python/xen/migration/libxl.py      |  9 +++++++++
   3 files changed, 41 insertions(+), 1 deletion(-)
docs/specs/libxl-migration-stream.pandoc +0 -1
index c24a434..5986273 100644
@@ -121,7 +121,9 @@ type         0x00000000: END
 
                0x00000004: CHECKPOINT_END
 
-             0x00000005 - 0x7FFFFFFF: Reserved for future

_mandatory_

docs/specs/libxl-migration-stream.pandoc +3 -0
+             0x00000005: COLO_CONTEXT
+
+             0x00000006 - 0x7FFFFFFF: Reserved for future

_mandatory_

                records.

                0x80000000 - 0xFFFFFFFF: Reserved for future

_optional_

docs/specs/libxl-migration-stream.pandoc +0 -0
@@ -215,3 +217,21 @@ A checkpoint end record marks the end of a

checkpoint in the image.

       +-------------------------------------------------+

The end record contains no fields; its body_length is 0.

docs/specs/libxl-migration-stream.pandoc +14 -0
+
+COLO\_CONTEXT
+--------------
+
+A COLO context record contains the control information for COLO.
+
+     0     1     2     3     4     5     6     7 octet
+    +------------------------+------------------------+
+    | control_id             | padding                |
+    +------------------------+------------------------+
+
+--------------------------------------------------------------------
+Field            Description
+------------     ---------------------------------------------------
Quoted 8 lines

docs/specs/libxl-migration-stream.pandoc A checkpoint end record marks the end of a checkpoint in the image. · line 237

Quoted 5 lines

+control_id 0x00000000: Secondary VM is out of sync, start a
new checkpoint

docs/specs/libxl-migration-stream.pandoc +3 -0
+                 0x00000001: Secondary VM is suspended
+                 0x00000002: Secondary VM is ready
+                 0x00000003: Secondary VM is resumed

This style of table in pandoc need to be terminated with a line of -------, just like the head of the table.

Ok

Quoted 4 lines

Also, I wonder at the name "COLO_CONTEXT". CONTEXT implies an associated blob of data, but this is not the case here. Here, it is more of a status update, with expected actions on some states.

True, could you suggest a better name? sorry for my bad English...

Quoted 7 lines
Quoted 3 lines

In hindsight, I would also avoid putting COLO in the name.

How about CHECKPOINT_SECONDARY_STATE ?

From my another mail, I explained the COLO_CONTEXT, do you still suggest CHECKPOINT_SECONDARY_STATE? IMO, it's more like a sync command?

Right, but what it contains is information concerning the current state of the secondary VM.

The real question is how you see this record being extended with further control_id's in the future.

(naming stuff is hard :( )

~Andrew

#9 lore raw

PATCH v8 3/25 libxc/migration: Specification update for DIRTY_BITMAP records

In reply to Yang Hongyang

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 +
 3 files changed, 25 insertions(+), 1 deletion(-)
docs/specs/libxc-migration-stream.pandoc +23 -1
index 68fa513..480d357 100644
@@ -227,7 +227,9 @@ type         0x00000000: END
 
              0x0000000E: CHECKPOINT
 
-             0x0000000F - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x0000000F: DIRTY_BITMAP
+
+             0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_
              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -601,6 +603,26 @@ CHECKPOINT record or an END record.
 
 \clearpage
 
+DIRTY_BITMAP
+------------
+
+A dirty_bitmap record is used for secondary to send it's dirty bitmap
+to primary while doing a checkpoint under COLO. This record only exists
+in back channel.
+
+     0     1     2     3     4     5     6     7 octet
+    +-------------------------------------------------+
+    | pfn[0]                                          |
+    +-------------------------------------------------+
+    ...
+    +-------------------------------------------------+
+    | pfn[C-1]                                        |
+    +-------------------------------------------------+
+
+The count of the pfn is: record->length/sizeof(uint64_t).
+
+\clearpage
+
 Layout
 ======
 
tools/libxc/xc_sr_common.c +1 -0
index 945cfa6..becc0f4 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_BITMAP]         = "Dirty bitmap",
 };
 
 const char *rec_type_to_str(uint32_t type)
tools/libxc/xc_sr_stream_format.h +1 -0
index 6d0f8fd..43a0209 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_BITMAP         0x0000000fU
 
 #define REC_TYPE_OPTIONAL             0x80000000U
 
Signature · 1 line
1.9.1
#10 lore raw

Re: [PATCH v8 --for 4.6 COLO 03/25] libxc/migration: Specification update for DIRTY_BITMAP records

Quoted 25 lines · Yang Hongyang

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 +
 3 files changed, 25 insertions(+), 1 deletion(-)
docs/specs/libxc-migration-stream.pandoc +3 -1
index 68fa513..480d357 100644
@@ -227,7 +227,9 @@ type         0x00000000: END
 
              0x0000000E: CHECKPOINT
 
-             0x0000000F - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x0000000F: DIRTY_BITMAP
+
+             0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_
              records.
 
              0x80000000 - 0xFFFFFFFF: Reserved for future _optional_

docs/specs/libxc-migration-stream.pandoc CHECKPOINT record or an END record. · line 607

Quoted 5 lines
docs/specs/libxc-migration-stream.pandoc +2 -0
@@ -601,6 +603,26 @@ CHECKPOINT record or an END record.
 
 \clearpage
 
+DIRTY_BITMAP
+------------

I would name this DIRTY_PFN_LIST or similar, as the content of data isn't actually a bitmap.

docs/specs/libxc-migration-stream.pandoc CHECKPOINT record or an END record. · line 611

Quoted 4 lines
docs/specs/libxc-migration-stream.pandoc +4 -0
+
+A dirty_bitmap record is used for secondary to send it's dirty bitmap
+to primary while doing a checkpoint under COLO. This record only exists
+in back channel.

This section should purely be a description of the content. i.e.

"A DIRTY\_xxx record is used to convey information about dirty memory in the VM. It is an unordered list of PFNs."

docs/specs/libxc-migration-stream.pandoc CHECKPOINT record or an END record. · line 622

Quoted 11 lines
docs/specs/libxc-migration-stream.pandoc +11 -0
+
+     0     1     2     3     4     5     6     7 octet
+    +-------------------------------------------------+
+    | pfn[0]                                          |
+    +-------------------------------------------------+
+    ...
+    +-------------------------------------------------+
+    | pfn[C-1]                                        |
+    +-------------------------------------------------+
+
+The count of the pfn is: record->length/sizeof(uint64_t).

"The count of pfns is", although I would like to hope that this is obvious from the diagram.

Down here, there should be more description of record circumstances, e.g. currently only applicable in the backchannel of a checkpointed stream.

Also please put some validation logic for this in
tools/python/xen/migration/libxc.py

~Andrew

#11 lore raw

Re: [PATCH v8 --for 4.6 COLO 03/25] libxc/migration: Specification update for DIRTY_BITMAP records

Quoted 27 lines · Andrew Cooper
Quoted 26 lines · Yang Hongyang

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 +
  3 files changed, 25 insertions(+), 1 deletion(-)
docs/specs/libxc-migration-stream.pandoc +3 -1
index 68fa513..480d357 100644
@@ -227,7 +227,9 @@ type         0x00000000: END
 
               0x0000000E: CHECKPOINT
 
-             0x0000000F - 0x7FFFFFFF: Reserved for future _mandatory_
+             0x0000000F: DIRTY_BITMAP
+
+             0x00000010 - 0x7FFFFFFF: Reserved for future _mandatory_
               records.
 
               0x80000000 - 0xFFFFFFFF: Reserved for future _optional_
@@ -601,6 +603,26 @@ CHECKPOINT record or an END record.
 
Quoted 7 lines

docs/specs/libxc-migration-stream.pandoc CHECKPOINT record or an END record. · line 607

Quoted 4 lines
docs/specs/libxc-migration-stream.pandoc +2 -0
  \clearpage
 
+DIRTY_BITMAP
+------------

I would name this DIRTY_PFN_LIST or similar, as the content of data isn't actually a bitmap.

This sounds better, thanks!

Quoted 10 lines

docs/specs/libxc-migration-stream.pandoc CHECKPOINT record or an END record. · line 611

Quoted 5 lines
docs/specs/libxc-migration-stream.pandoc +4 -0
+
+A dirty_bitmap record is used for secondary to send it's dirty bitmap
+to primary while doing a checkpoint under COLO. This record only exists
+in back channel.

This section should purely be a description of the content. i.e.

"A DIRTY\_xxx record is used to convey information about dirty memory in the VM. It is an unordered list of PFNs."

Ok.

Quoted 16 lines

docs/specs/libxc-migration-stream.pandoc CHECKPOINT record or an END record. · line 622

Quoted 12 lines
docs/specs/libxc-migration-stream.pandoc +11 -0
+
+     0     1     2     3     4     5     6     7 octet
+    +-------------------------------------------------+
+    | pfn[0]                                          |
+    +-------------------------------------------------+
+    ...
+    +-------------------------------------------------+
+    | pfn[C-1]                                        |
+    +-------------------------------------------------+
+
+The count of the pfn is: record->length/sizeof(uint64_t).

"The count of pfns is", although I would like to hope that this is obvious from the diagram.

Quoted 5 lines

Down here, there should be more description of record circumstances, e.g. currently only applicable in the backchannel of a checkpointed stream.

Also please put some validation logic for this in
tools/python/xen/migration/libxc.py

Will do, thank you.

Quoted 4 lines

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#12 lore raw

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

In reply to Yang Hongyang

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 becc0f4..0ee607c 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 28755ac..632160e 100644
@@ -356,6 +356,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
1.9.1
Reviewed-by on v8 4/25
#13 lore raw

Re: [PATCH v8 --for 4.6 COLO 04/25] libxc/migration: export read_record for common use

Quoted 8 lines · Yang Hongyang

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.

#14 lore raw

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

In reply to Yang Hongyang

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 | 16 ++++++++++++++++
 3 files changed, 18 insertions(+)
tools/libxl/libxl_dom_save.c +1 -0
index 9b7159f..25813ce 100644
@@ -445,6 +445,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 9c81d8d..a83d6a5 100644
@@ -2989,6 +2989,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 +16 -0
index 16f667a..df55277 100644
@@ -47,6 +47,13 @@
  *  - Toolstack record
  *  - if (hvm), Qemu 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. */
@@ -178,6 +185,9 @@ void libxl__stream_write_start(libxl__egc *egc,
 
     stream->running = true;
 
+    if (stream->back_channel)
+        return;
+
     dc->ao        = ao;
     dc->readfd    = -1;
     dc->writewhat = "save/migration stream";
@@ -207,6 +217,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_toolstack_record(egc, stream);
@@ -500,6 +511,11 @@ static void stream_done(libxl__egc *egc,
     assert(stream->running);
     stream->running = false;
 
+    if (stream->back_channel) {
+        stream->completion_callback(egc, stream, stream->rc);
+        return;
+    }
+
     if (stream->emu_carefd)
         libxl__carefd_close(stream->emu_carefd);
     free(stream->emu_body);
Signature · 1 line
1.9.1
#15 lore raw

Re: [PATCH v8 --for 4.6 COLO 05/25] tools/libxl: add back channel support to write stream

Quoted 54 lines · Yang Hongyang

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 | 16 ++++++++++++++++
 3 files changed, 18 insertions(+)
tools/libxl/libxl_dom_save.c +1 -0
index 9b7159f..25813ce 100644
@@ -445,6 +445,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 9c81d8d..a83d6a5 100644
@@ -2989,6 +2989,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 +7 -0
index 16f667a..df55277 100644
@@ -47,6 +47,13 @@
  *  - Toolstack record
  *  - if (hvm), Qemu 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. */

tools/libxl/libxl_stream_write.c void libxl__stream_write_start(libxl__egc *egc, · line 190

Quoted 6 lines
tools/libxl/libxl_stream_write.c +3 -0
@@ -178,6 +185,9 @@ void libxl__stream_write_start(libxl__egc *egc,
 
     stream->running = true;
 
+    if (stream->back_channel)
+        return;
+

Some of the setup below should not be skipped.

While it makes the diff bigger, the end result would be more logical as

dc->ao = ao;
dc->readfd = -1;
dc->writefd = stream->fd;
dc->maxsz = -1;

if (!stream->back_channel) {
    /* Write the stream header. */
    dc->writewhat = "save/migration stream";
    dc->callback = stream_header_done;

    rc = ibxl__datacopier_start(dc);
    ....
}

To split the object setup from the action of sending the stream header, which are currently mixed.

What happened to the backchannel negotiation header?

~Andrew

Quoted 23 lines
tools/libxl/libxl_stream_write.c +6 -0
     dc->ao        = ao;
     dc->readfd    = -1;
     dc->writewhat = "save/migration stream";
@@ -207,6 +217,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_toolstack_record(egc, stream);
@@ -500,6 +511,11 @@ static void stream_done(libxl__egc *egc,
     assert(stream->running);
     stream->running = false;
 
+    if (stream->back_channel) {
+        stream->completion_callback(egc, stream, stream->rc);
+        return;
+    }
+
     if (stream->emu_carefd)
         libxl__carefd_close(stream->emu_carefd);
     free(stream->emu_body);
#16 lore raw

Re: [PATCH v8 --for 4.6 COLO 05/25] tools/libxl: add back channel support to write stream

Quoted 80 lines · Andrew Cooper
Quoted 54 lines · Yang Hongyang

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 | 16 ++++++++++++++++
  3 files changed, 18 insertions(+)
tools/libxl/libxl_dom_save.c +1 -0
index 9b7159f..25813ce 100644
@@ -445,6 +445,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 9c81d8d..a83d6a5 100644
@@ -2989,6 +2989,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 +7 -0
index 16f667a..df55277 100644
@@ -47,6 +47,13 @@
   *  - Toolstack record
   *  - if (hvm), Qemu 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. */

tools/libxl/libxl_stream_write.c void libxl__stream_write_start(libxl__egc *egc, · line 190

Quoted 6 lines
tools/libxl/libxl_stream_write.c +3 -0
@@ -178,6 +185,9 @@ void libxl__stream_write_start(libxl__egc *egc,
 
      stream->running = true;
 
+    if (stream->back_channel)
+        return;
+

Some of the setup below should not be skipped.

While it makes the diff bigger, the end result would be more logical as

dc->ao = ao;
dc->readfd = -1;
dc->writefd = stream->fd;
dc->maxsz = -1;

if (!stream->back_channel) {
     /* Write the stream header. */
     dc->writewhat = "save/migration stream";
     dc->callback = stream_header_done;

     rc = ibxl__datacopier_start(dc);
     ....
}
Quoted 4 lines

To split the object setup from the action of sending the stream header, which are currently mixed.

What happened to the backchannel negotiation header?

There's no negotiation header currently...If it is a broken back channel, COLO will fail.

Quoted 29 lines

~Andrew

Quoted 13 lines
tools/libxl/libxl_stream_write.c +1 -0
      dc->ao        = ao;
      dc->readfd    = -1;
      dc->writewhat = "save/migration stream";
@@ -207,6 +217,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_toolstack_record(egc, stream);
@@ -500,6 +511,11 @@ static void stream_done(libxl__egc *egc,
      assert(stream->running);

tools/libxl/libxl_stream_write.c static void stream_done(libxl__egc *egc, · line 521

Quoted 10 lines
tools/libxl/libxl_stream_write.c +5 -0
      stream->running = false;
 
+    if (stream->back_channel) {
+        stream->completion_callback(egc, stream, stream->rc);
+        return;
+    }
+
      if (stream->emu_carefd)
          libxl__carefd_close(stream->emu_carefd);
      free(stream->emu_body);

.

Signature · 2 lines
Thanks,
Yang.
#17 lore raw

PATCH v8 6/25 tools/libxl: write colo_context records into the stream

In reply to Yang Hongyang

write colo_context 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 | 87 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)
tools/libxl/libxl_internal.h +5 -0
index a83d6a5..2634836 100644
@@ -3000,6 +3000,7 @@ struct libxl__stream_write_state {
     int rc;
     bool running;
     bool in_checkpoint;
+    bool in_colo_context;
     libxl__save_helper_state shs;
 
     /* Main stream-writing data. */
@@ -3019,6 +3020,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_colo_context(libxl__egc *egc,
+                                 libxl__stream_write_state *stream,
+                                 libxl_sr_colo_context *colo_context);
 _hidden void libxl__stream_write_abort(libxl__egc *egc,
                                        libxl__stream_write_state *stream,
                                        int rc);
tools/libxl/libxl_stream_write.c +87 -0

105 lines not on this page · raw message

Signature · 1 line
1.9.1
#18 lore raw

Re: [PATCH v8 --for 4.6 COLO 06/25] tools/libxl: write colo_context records into the stream

Quoted 55 lines · Yang Hongyang

write colo_context 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 | 87 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)
tools/libxl/libxl_internal.h +5 -0
index a83d6a5..2634836 100644
@@ -3000,6 +3000,7 @@ struct libxl__stream_write_state {
     int rc;
     bool running;
     bool in_checkpoint;
+    bool in_colo_context;
     libxl__save_helper_state shs;
 
     /* Main stream-writing data. */
@@ -3019,6 +3020,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_colo_context(libxl__egc *egc,
+                                 libxl__stream_write_state *stream,
+                                 libxl_sr_colo_context *colo_context);
 _hidden void libxl__stream_write_abort(libxl__egc *egc,
                                        libxl__stream_write_state *stream,
                                        int rc);
tools/libxl/libxl_stream_write.c +10 -0
index df55277..e7a32c4 100644
@@ -96,6 +96,16 @@ static void write_checkpoint_end_record(libxl__egc *egc,
 static void checkpoint_end_record_done(libxl__egc *egc,
                                        libxl__stream_write_state *stream);
 
+/* COLO context */
+static void write_colo_context(libxl__egc *egc,
+                               libxl__stream_write_state *stream,
+                               libxl_sr_colo_context *colo_context);
+static void write_colo_context_done(libxl__egc *egc,
+                                    libxl__datacopier_state *dc,
+                                    int rc, int onwrite, int errnoval);
+static void colo_context_done(libxl__egc *egc,
+                              libxl__stream_write_state *stream, int rc);
+
 /*----- Helpers -----*/
 
 static void write_done(libxl__egc *egc,

tools/libxl/libxl_stream_write.c static void stream_complete(libxl__egc *egc, · line 516

Quoted 7 lines
tools/libxl/libxl_stream_write.c +4 -0
@@ -500,6 +510,11 @@ static void stream_complete(libxl__egc *egc,
         return;
     }
 
+    if (stream->in_colo_context) {
+        colo_context_done(egc, stream, rc);
+        return;
+    }

Please follow the same style as stream->in_checkpoint, asserting(rc) and explaining how the error comes back around.

Quoted 9 lines
tools/libxl/libxl_stream_write.c +2 -0
+
     if (!stream->rc)
         stream->rc = rc;
     stream_done(egc, stream);
@@ -555,6 +570,78 @@ static void check_all_finished(libxl__egc *egc,
     stream->completion_callback(egc, stream, stream->rc);
 }
 
+/*----- COLO context -----*/

tools/libxl/libxl_stream_write.c static void check_all_finished(libxl__egc *egc, · line 583

Quoted 10 lines
tools/libxl/libxl_stream_write.c +10 -0
+void libxl__stream_write_colo_context(libxl__egc *egc,
+                                      libxl__stream_write_state *stream,
+                                      libxl_sr_colo_context *colo_context)
+{
+    assert(stream->running);
+    assert(!stream->in_checkpoint);
+    assert(!stream->in_colo_context);
+    stream->in_colo_context = true;
+
+    write_colo_context(egc, stream, colo_context);

Use setup_write() here, which will remove most of the rest of this patch, and cover all your error handling for your.

You want a small pair of functions such as the write_checkpoint_end() pair. See write_toolstack_record() for an example using setup_write() with a body.

Also, to preempt Ian Jacksons review, use FILLZERO() over "= { ... }"

~Andrew

#19 lore raw

Re: [PATCH v8 --for 4.6 COLO 06/25] tools/libxl: write colo_context records into the stream

Quoted 75 lines · Andrew Cooper
Quoted 55 lines · Yang Hongyang

write colo_context 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 | 87 ++++++++++++++++++++++++++++++++++++++++
  2 files changed, 92 insertions(+)
tools/libxl/libxl_internal.h +5 -0
index a83d6a5..2634836 100644
@@ -3000,6 +3000,7 @@ struct libxl__stream_write_state {
      int rc;
      bool running;
      bool in_checkpoint;
+    bool in_colo_context;
      libxl__save_helper_state shs;
 
      /* Main stream-writing data. */
@@ -3019,6 +3020,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_colo_context(libxl__egc *egc,
+                                 libxl__stream_write_state *stream,
+                                 libxl_sr_colo_context *colo_context);
  _hidden void libxl__stream_write_abort(libxl__egc *egc,
                                         libxl__stream_write_state *stream,
                                         int rc);
tools/libxl/libxl_stream_write.c +10 -0
index df55277..e7a32c4 100644
@@ -96,6 +96,16 @@ static void write_checkpoint_end_record(libxl__egc *egc,
  static void checkpoint_end_record_done(libxl__egc *egc,
                                         libxl__stream_write_state *stream);
 
+/* COLO context */
+static void write_colo_context(libxl__egc *egc,
+                               libxl__stream_write_state *stream,
+                               libxl_sr_colo_context *colo_context);
+static void write_colo_context_done(libxl__egc *egc,
+                                    libxl__datacopier_state *dc,
+                                    int rc, int onwrite, int errnoval);
+static void colo_context_done(libxl__egc *egc,
+                              libxl__stream_write_state *stream, int rc);
+
  /*----- Helpers -----*/
 
  static void write_done(libxl__egc *egc,

tools/libxl/libxl_stream_write.c static void stream_complete(libxl__egc *egc, · line 516

Quoted 7 lines
tools/libxl/libxl_stream_write.c +4 -0
@@ -500,6 +510,11 @@ static void stream_complete(libxl__egc *egc,
          return;
      }
 
+    if (stream->in_colo_context) {
+        colo_context_done(egc, stream, rc);
+        return;
+    }

Please follow the same style as stream->in_checkpoint, asserting(rc) and explaining how the error comes back around.

Quoted 8 lines
tools/libxl/libxl_stream_write.c +1 -0
+
      if (!stream->rc)
          stream->rc = rc;
      stream_done(egc, stream);
@@ -555,6 +570,78 @@ static void check_all_finished(libxl__egc *egc,
      stream->completion_callback(egc, stream, stream->rc);
  }
 
Quoted 14 lines

tools/libxl/libxl_stream_write.c static void check_all_finished(libxl__egc *egc, · line 583

Quoted 11 lines
tools/libxl/libxl_stream_write.c +11 -0
+/*----- COLO context -----*/
+void libxl__stream_write_colo_context(libxl__egc *egc,
+                                      libxl__stream_write_state *stream,
+                                      libxl_sr_colo_context *colo_context)
+{
+    assert(stream->running);
+    assert(!stream->in_checkpoint);
+    assert(!stream->in_colo_context);
+    stream->in_colo_context = true;
+
+    write_colo_context(egc, stream, colo_context);

Use setup_write() here, which will remove most of the rest of this patch, and cover all your error handling for your.

setup_write() was introduced from your v4 series I think? so I missed that part when rebasing...

Quoted 6 lines

You want a small pair of functions such as the write_checkpoint_end() pair. See write_toolstack_record() for an example using setup_write() with a body.

Also, to preempt Ian Jacksons review, use FILLZERO() over "= { ... }"

Ok, thank you for the kindly explaination, will address this in the next version.

Quoted 4 lines

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#20 lore raw

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

In reply to Yang Hongyang

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 | 17 +++++++++++++++++
 3 files changed, 19 insertions(+)
tools/libxl/libxl_create.c +1 -0
index 1d4b13b..1af7103 100644
@@ -978,6 +978,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;
 
     libxl__stream_read_start(egc, &dcs->srs);
tools/libxl/libxl_internal.h +1 -0
index 2634836..05cee04 100644
@@ -3358,6 +3358,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 +17 -0
index 2d17403..b924f05 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. */
@@ -200,6 +209,9 @@ void libxl__stream_read_start(libxl__egc *egc,
     stream->running = true;
     stream->phase   = SRS_PHASE_NORMAL;
 
+    if (stream->back_channel)
+        return;
+
     if (stream->legacy) {
         /* Convert the legacy stream. */
         libxl__conversion_helper_state *chs = &stream->chs;
@@ -700,6 +712,11 @@ static void stream_done(libxl__egc *egc,
     assert(!stream->in_checkpoint);
     stream->running = false;
 
+    if (stream->back_channel) {
+        stream->completion_callback(egc, stream, stream->rc);
+        return;
+    }
+
     if (stream->incoming_record)
         free_record(stream->incoming_record);
 
Signature · 1 line
1.9.1
#21 lore raw

Re: [PATCH v8 --for 4.6 COLO 07/25] tools/libxl: add back channel support to read stream

Quoted 64 lines · Yang Hongyang

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 | 17 +++++++++++++++++
 3 files changed, 19 insertions(+)
tools/libxl/libxl_create.c +1 -0
index 1d4b13b..1af7103 100644
@@ -978,6 +978,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;
 
     libxl__stream_read_start(egc, &dcs->srs);
tools/libxl/libxl_internal.h +1 -0
index 2634836..05cee04 100644
@@ -3358,6 +3358,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 +12 -0
index 2d17403..b924f05 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. */
@@ -200,6 +209,9 @@ void libxl__stream_read_start(libxl__egc *egc,
     stream->running = true;
     stream->phase   = SRS_PHASE_NORMAL;
 
+    if (stream->back_channel)
+        return;
+
     if (stream->legacy) {
         /* Convert the legacy stream. */
         libxl__conversion_helper_state *chs = &stream->chs;

tools/libxl/libxl_stream_read.c static void stream_done(libxl__egc *egc, · line 719

Quoted 8 lines
tools/libxl/libxl_stream_read.c +5 -0
@@ -700,6 +712,11 @@ static void stream_done(libxl__egc *egc,
     assert(!stream->in_checkpoint);
     stream->running = false;
 
+    if (stream->back_channel) {
+        stream->completion_callback(egc, stream, stream->rc);
+        return;
+    }
+

This should be in stream_complete() not stream_done(). stream_done() is strictly called once, and cleans stuff up.

~Andrew

#22 lore raw

Re: [PATCH v8 --for 4.6 COLO 07/25] tools/libxl: add back channel support to read stream

Quoted 68 lines · Andrew Cooper
Quoted 67 lines · Yang Hongyang

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 | 17 +++++++++++++++++
  3 files changed, 19 insertions(+)
tools/libxl/libxl_create.c +1 -0
index 1d4b13b..1af7103 100644
@@ -978,6 +978,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;
 
      libxl__stream_read_start(egc, &dcs->srs);
tools/libxl/libxl_internal.h +1 -0
index 2634836..05cee04 100644
@@ -3358,6 +3358,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 +12 -0
index 2d17403..b924f05 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. */
@@ -200,6 +209,9 @@ void libxl__stream_read_start(libxl__egc *egc,
      stream->running = true;
      stream->phase   = SRS_PHASE_NORMAL;
 
+    if (stream->back_channel)
+        return;
+
      if (stream->legacy) {
          /* Convert the legacy stream. */
          libxl__conversion_helper_state *chs = &stream->chs;
@@ -700,6 +712,11 @@ static void stream_done(libxl__egc *egc,
      assert(!stream->in_checkpoint);
      stream->running = false;
 
Quoted 8 lines

tools/libxl/libxl_stream_read.c static void stream_done(libxl__egc *egc, · line 719

Quoted 5 lines
tools/libxl/libxl_stream_read.c +5 -0
+    if (stream->back_channel) {
+        stream->completion_callback(egc, stream, stream->rc);
+        return;
+    }
+

This should be in stream_complete() not stream_done(). stream_done() is strictly called once, and cleans stuff up.

Ok, will look into the code closely.

Quoted 4 lines

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#23 lore raw

PATCH v8 8/25 tools/libxl: handle colo_context records in a libxl migration v2 read stream

In reply to Yang Hongyang

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

---
 tools/libxl/libxl_internal.h    |  3 +++
 tools/libxl/libxl_stream_read.c | 51 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)
tools/libxl/libxl_internal.h +3 -0
index 05cee04..1be2a4a 100644
@@ -3369,6 +3369,7 @@ struct libxl__stream_read_state {
     int rc;
     bool running;
     bool in_checkpoint;
+    bool in_colo_context;
     libxl__save_helper_state shs;
     libxl__conversion_helper_state chs;
 
@@ -3396,6 +3397,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_colo_context(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 +51 -0

75 lines not on this page · raw message

Signature · 1 line
1.9.1
#24 lore raw

Re: [PATCH v8 --for 4.6 COLO 08/25] tools/libxl: handle colo_context records in a libxl migration v2 read stream

Quoted 77 lines · Yang Hongyang

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

---
 tools/libxl/libxl_internal.h    |  3 +++
 tools/libxl/libxl_stream_read.c | 51 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)
tools/libxl/libxl_internal.h +3 -0
index 05cee04..1be2a4a 100644
@@ -3369,6 +3369,7 @@ struct libxl__stream_read_state {
     int rc;
     bool running;
     bool in_checkpoint;
+    bool in_colo_context;
     libxl__save_helper_state shs;
     libxl__conversion_helper_state chs;
 
@@ -3396,6 +3397,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_colo_context(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 +21 -0
index b924f05..ab47251 100644
@@ -152,6 +152,13 @@ static void write_emulator_done(libxl__egc *egc,
                                 libxl__datacopier_state *dc,
                                 int rc, int onwrite, int errnoval);
 
+/* Handlers for colo context mini-loop */
+static void handle_colo_context(libxl__egc *egc,
+                                libxl__stream_read_state *stream,
+                                libxl__sr_record_buf *rec);
+static void colo_context_done(libxl__egc *egc,
+                              libxl__stream_read_state *stream, int rc);
+
 /*----- Helpers -----*/
 
 /* Helper to set up reading some data from the stream. */
@@ -569,6 +576,15 @@ static bool process_record(libxl__egc *egc,
         checkpoint_done(egc, stream, 0);
         break;
 
+    case REC_TYPE_COLO_CONTEXT:
+        if (!stream->in_colo_context) {
+            LOG(ERROR, "Unexpected COLO_CONTEXT record in stream");
+            rc = ERROR_FAIL;
+            goto err;
+        }
+        handle_colo_context(egc, stream, rec);
+        break;
+
     default:
         LOG(ERROR, "Unrecognised record 0x%08x", rec->hdr.type);
         rc = ERROR_FAIL;
@@ -678,6 +694,11 @@ static void stream_complete(libxl__egc *egc,
         return;
     }
 
+    if (stream->in_colo_context) {
+        colo_context_done(egc, stream, rc);
+        return;
+    }
+
     if (!stream->rc)
         stream->rc = rc;
     stream_done(egc, stream);

tools/libxl/libxl_stream_read.c static void check_all_finished(libxl__egc *egc, · line 821

Quoted 7 lines
tools/libxl/libxl_stream_read.c +4 -0
@@ -794,6 +815,36 @@ static void check_all_finished(libxl__egc *egc,
     stream->completion_callback(egc, stream, stream->rc);
 }
 
+/*----- COLO context handlers -----*/
+
+void libxl__stream_read_colo_context(libxl__egc *egc,
+                                     libxl__stream_read_state *stream)

A name like this makes the erroneous assumption that a COLO\_CONTEXT record is what is going to be found next in the stream.

Where and when is a COLO\_CONTEXT record expected, and is it only in the backchannel?

Quoted 6 lines
tools/libxl/libxl_stream_read.c +6 -0
+{
+    assert(stream->running);
+    assert(!stream->in_checkpoint);
+    assert(!stream->in_colo_context);
+    stream->in_colo_context = true;
+

tools/libxl/libxl_stream_read.c static void check_all_finished(libxl__egc *egc, · line 837

Quoted 10 lines
tools/libxl/libxl_stream_read.c +10 -0
+    setup_read_record(egc, stream);
+}
+
+static void handle_colo_context(libxl__egc *egc,
+                                libxl__stream_read_state *stream,
+                                libxl__sr_record_buf *rec)
+{
+    libxl_sr_colo_context *colo_context = rec->body;
+
+    colo_context_done(egc, stream, colo_context->id);

A handler this trivial should just be done in the switch statement in process_record(). No need for its own function for a single forward call.

~Andrew

#25 lore raw

Re: [PATCH v8 --for 4.6 COLO 08/25] tools/libxl: handle colo_context records in a libxl migration v2 read stream

Quoted 1 line · Andrew Cooper

On 15/07/15 10:18, Yang Hongyang wrote:

[...]

Quoted 16 lines

tools/libxl/libxl_stream_read.c static void check_all_finished(libxl__egc *egc, · line 821

Quoted 12 lines
tools/libxl/libxl_stream_read.c +5 -0
+
      if (!stream->rc)
          stream->rc = rc;
      stream_done(egc, stream);
@@ -794,6 +815,36 @@ static void check_all_finished(libxl__egc *egc,
      stream->completion_callback(egc, stream, stream->rc);
  }
 
+/*----- COLO context handlers -----*/
+
+void libxl__stream_read_colo_context(libxl__egc *egc,
+                                     libxl__stream_read_state *stream)

A name like this makes the erroneous assumption that a COLO\_CONTEXT record is what is going to be found next in the stream.

Quoted 2 lines

Where and when is a COLO\_CONTEXT record expected, and is it only in the backchannel?

A COLO CONTEXT is actually a set of control command (I'm not sure command here is a suitable description) which used to sync the checkpoint steps between primary and secondary. So it is not only in the back channel.

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

First boot:
When doing COLO, primary must be start with -p, then start COLO, the first step is live migration, after migration, when secondary is ready, we will resume both side.

control_id Primary Secondary
start with -p
live migrate
Receive&load state

  0x00000002                              @
                  Resume                  Resume
  0x00000003                              @

Start Comparing Packets

At checkpoint:

control_id Primary Secondary
0x00000000 @
Suspend
0x00000001 @
Suspend
Send state Receive state
Flush Network Load state
Resume Resume
0x00000003 @
Start Comparing Packets

NOTE:
1) '@' who sends the message
2) Every sync-point is synchronized by two sides with only one handshake(single direction) for low-latency.
If more strict synchronization is required, a opposite direction sync-point should be added.
3) Since sync-points are single direction, the remote side may go forward a lot when this side just receives the sync-point.

Quoted 12 lines
Quoted 12 lines
tools/libxl/libxl_stream_read.c +11 -0
+{
+    assert(stream->running);
+    assert(!stream->in_checkpoint);
+    assert(!stream->in_colo_context);
+    stream->in_colo_context = true;
+
+    setup_read_record(egc, stream);
+}
+
+static void handle_colo_context(libxl__egc *egc,
+                                libxl__stream_read_state *stream,
Quoted 8 lines

tools/libxl/libxl_stream_read.c static void check_all_finished(libxl__egc *egc, · line 837

Quoted 5 lines
tools/libxl/libxl_stream_read.c +5 -0
+                                libxl__sr_record_buf *rec)
+{
+    libxl_sr_colo_context *colo_context = rec->body;
+
+    colo_context_done(egc, stream, colo_context->id);

A handler this trivial should just be done in the switch statement in process_record(). No need for its own function for a single forward call.

Ok

Quoted 4 lines

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#26 lore raw

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

In reply to Yang Hongyang

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 4056955..fa06d9b 100644
@@ -63,6 +63,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 */
 
@@ -112,6 +121,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
1.9.1
#27 lore raw

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

In reply to Yang Hongyang

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 fa06d9b..1e7e1bb 100644
@@ -114,6 +114,16 @@ struct restore_callbacks {
     int (*toolstack_restore)(uint32_t domid, const uint8_t *buf,
             uint32_t size, void* data);
 
+    /* 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
1.9.1
#28 lore raw

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

In reply to Yang Hongyang

From: Wen Congyang <[email protected]>

Secondary vm is running in colo mode. So we will do
the following things again and again:
1. Resume secondary vm
a. Send LIBXL_COLO_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 LIBXL_COLO_SVM_RESUMED to master.
2. Wait a new checkpoint
a. Call libxl__checkpoint_devices_commit().
b. Read LIBXL_COLO_NEW_CHECKPOINT from master.
3. Suspend secondary vm
a. Suspend secondary vm.
b. Call libxl__checkpoint_devices_postsuspend().
c. Send LIBXL_COLO_SVM_SUSPENDED to master.

---
 tools/libxl/Makefile             |   1 +
 tools/libxl/libxl_colo.h         |  27 ++
 tools/libxl/libxl_colo_restore.c | 991 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_create.c       | 111 ++++-
 tools/libxl/libxl_internal.h     |  19 +
 tools/libxl/libxl_save_callout.c |   7 +-
 6 files changed, 1154 insertions(+), 2 deletions(-)
 create mode 100644 tools/libxl/libxl_colo.h
 create mode 100644 tools/libxl/libxl_colo_restore.c
tools/libxl/Makefile +1 -0
index 3cb3ae9..97b3753 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 +27 -0
new file mode 100644
index 0000000..54dc835
@@ -0,0 +1,27 @@
+/*
+ * 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_done(libxl__egc *egc, void *dcs_void,
+                                     int ret, int retval, int errnoval);
+extern void libxl__colo_restore_setup(libxl__egc *egc,
+                                      libxl__colo_restore_state *crs);
+extern void libxl__colo_restore_teardown(libxl__egc *egc,
+                                         libxl__colo_restore_state *crs,
+                                         int rc);
+
+#endif
tools/libxl/libxl_colo_restore.c new file +991 -0

991 lines not on this page · raw message

tools/libxl/libxl_create.c +110 -1

141 lines not on this page · raw message

tools/libxl/libxl_internal.h +19 -0
index 1be2a4a..597866d 100644
@@ -3407,6 +3407,24 @@ 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;
+    libxl__checkpoint_devices_state cds;
+};
 
 struct libxl__domain_create_state {
     /* filled in by user */
@@ -3421,6 +3439,7 @@ struct libxl__domain_create_state {
     /* private to domain_create */
     int guest_domid;
     libxl__domain_build_state build_state;
+    libxl__colo_restore_state crs;
     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 f8c6cf0..e9f3b2d 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_done;
+    else
+        shs->completion_callback = libxl__xc_domain_restore_done;
     shs->caller_state = dcs;
     shs->need_results = 1;
     shs->toolstack_data_file = 0;
Signature · 1 line
1.9.1
#29 lore raw

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

In reply to Yang Hongyang

From: Wen Congyang <[email protected]>

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

---
 tools/libxl/Makefile          |   2 +-
 tools/libxl/libxl.c           |   6 +-
 tools/libxl/libxl_colo.h      |  10 +
 tools/libxl/libxl_colo_save.c | 569 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_dom_save.c  |  13 +-
 tools/libxl/libxl_internal.h  | 167 +++++++------
 tools/libxl/libxl_types.idl   |   1 +
 7 files changed, 689 insertions(+), 79 deletions(-)
 create mode 100644 tools/libxl/libxl_colo_save.c
tools/libxl/Makefile +1 -1
index 97b3753..71bf7a2 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 5502709..c040909 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
@@ -845,7 +846,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 54dc835..49a430b 100644
@@ -24,4 +24,14 @@ extern void libxl__colo_restore_teardown(libxl__egc *egc,
                                          libxl__colo_restore_state *crs,
                                          int rc);
 
+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 +569 -0

569 lines not on this page · raw message

tools/libxl/libxl_dom_save.c +11 -2
index 25813ce..851dd24 100644
@@ -16,6 +16,7 @@
 #include "libxl_osdeps.h" /* must come before any other headers */
 
 #include "libxl_internal.h"
+#include "libxl_colo.h"
 
 struct libxl__physmap_info {
     uint64_t phys_offset;
@@ -437,6 +438,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;
 
@@ -573,12 +579,15 @@ static void domain_save_done(libxl__egc *egc,
     }
 
     /*
-     * 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);
 }
 
 /*========================= Domain restore ============================*/
tools/libxl/libxl_internal.h +92 -75

203 lines not on this page · raw message

tools/libxl/libxl_types.idl +1 -0
index 1d676ef..19bd2c1 100644
@@ -721,6 +721,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
1.9.1
#30 lore raw

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

In reply to Yang Hongyang

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

---
 tools/libxc/xc_sr_common.h  | 16 ++++++++++--
 tools/libxc/xc_sr_restore.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 2 deletions(-)
tools/libxc/xc_sr_common.h +14 -2
index 632160e..c5603ff 100644
@@ -167,6 +167,18 @@ struct xc_sr_context
 
     xc_dominfo_t dominfo;
 
+    /*
+     * migration stream
+     * 0: Plain VM
+     * 1: Remus
+     * 2: COLO
+     */
+    enum {
+        MIG_STREAM_PLAIN,
+        MIG_STREAM_REMUS,
+        MIG_STREAM_COLO,
+    } migration_stream;
+
     union /* Common save or restore data. */
     {
         struct /* Save data. */
@@ -209,13 +221,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
1.9.1
#31 lore raw

PATCH v8 14/25 libxc/restore: send dirty bitmap to primary when checkpoint under colo

In reply to Yang Hongyang

Send dirty bitmap 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 c5603ff..7fc2021 100644
@@ -213,6 +213,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
1.9.1
#32 lore raw

PATCH v8 15/25 send store mfn and console mfn to xl before resuming secondary vm

In reply to Yang Hongyang

From: Wen Congyang <[email protected]>

We will call libxl__xc_domain_restore_done() to rebuild secondary vm. But we need store mfn and console mfn 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 mfn and console mfn 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 | 2 +-
 5 files changed, 16 insertions(+), 8 deletions(-)
tools/libxc/include/xenguest.h +8 -0
index 1e7e1bb..d7bdfb5 100644
@@ -140,6 +140,14 @@ struct restore_callbacks {
      */
     int (*should_checkpoint)(void* data);
 
+    /*
+     * callback to send store mfn and console mfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(unsigned long store_mfn, unsigned long console_mfn,
+                            void *data);
+
     /* to be provided as the last argument to each callback function */
     void* data;
 };
tools/libxc/xc_sr_restore.c +5 -2
index 8b13d8d..fe81acb 100644
@@ -563,7 +563,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);
@@ -846,7 +848,8 @@ int xc_domain_restore2(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);
     }
 
     IPRINTF("In experimental %s", __func__);
tools/libxl/libxl_colo_restore.c +0 -5
index 5cda0b2..99f06ab 100644
@@ -137,11 +137,6 @@ static void colo_resume_vm(libxl__egc *egc,
         return;
     }
 
-    /*
-     * TODO: get store mfn and console mfn
-     *  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 bf4b55d..34e9362 100644
@@ -1080,6 +1080,8 @@ static void domcreate_bootloader_done(libxl__egc *egc,
     dcs->srs.completion_callback = domcreate_stream_done;
 
     /* colo restore setup */
+    callbacks->restore_results = libxl__srm_callout_callback_restore_results;
+
     if (checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_COLO) {
         crs->ao = ao;
         crs->domid = domid;
tools/libxl/libxl_save_msgs_gen.pl +1 -1
index 7c9859b..e8943b9 100755
@@ -29,7 +29,7 @@ our @msgs = (
     [  6, 'srcxA',  "should_checkpoint", [] ],
     [  7, 'scxA',   "switch_qemu_logdirty",  [qw(int domid
                                               unsigned enable)] ],
-    [  8, 'r',      "restore_results",       ['unsigned long', 'store_mfn',
+    [  8, 'rcx',    "restore_results",       ['unsigned long', 'store_mfn',
                                               'unsigned long', 'console_mfn'] ],
     [  9, 'srW',    "complete",              [qw(int retval
                                                  int errnoval)] ],
Signature · 1 line
1.9.1
#33 lore raw

Re: [PATCH v8 --for 4.6 COLO 15/25] send store mfn and console mfn to xl before resuming secondary vm

Quoted 24 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

We will call libxl__xc_domain_restore_done() to rebuild secondary vm. But we need store mfn and console mfn 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 mfn and console mfn 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 | 2 +-
 5 files changed, 16 insertions(+), 8 deletions(-)
tools/libxc/include/xenguest.h +0 -0
index 1e7e1bb..d7bdfb5 100644

tools/libxc/include/xenguest.h struct restore_callbacks { · line 149

Quoted 10 lines
tools/libxc/include/xenguest.h +7 -0
@@ -140,6 +140,14 @@ struct restore_callbacks {
      */
     int (*should_checkpoint)(void* data);
 
+    /*
+     * callback to send store mfn and console mfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(unsigned long store_mfn, unsigned long console_mfn,
+                            void *data);

These need to be xen_pfn_t to be usable in arm. Also, they are gfn's, not mfn's

A whole lot of terminology in this area is wrong. The top of xen/include/xen/mm.h is the authoritative description of terms, starting from c/s e758ed1

~Andrew

#34 lore raw

Re: [PATCH v8 --for 4.6 COLO 15/25] send store mfn and console mfn to xl before resuming secondary vm

Quoted 39 lines · Andrew Cooper
Quoted 24 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

We will call libxl__xc_domain_restore_done() to rebuild secondary vm. But we need store mfn and console mfn 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 mfn and console mfn 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 | 2 +-
  5 files changed, 16 insertions(+), 8 deletions(-)
tools/libxc/include/xenguest.h +0 -0
index 1e7e1bb..d7bdfb5 100644

tools/libxc/include/xenguest.h struct restore_callbacks { · line 149

Quoted 10 lines
tools/libxc/include/xenguest.h +7 -0
@@ -140,6 +140,14 @@ struct restore_callbacks {
       */
      int (*should_checkpoint)(void* data);
 
+    /*
+     * callback to send store mfn and console mfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(unsigned long store_mfn, unsigned long console_mfn,
+                            void *data);

These need to be xen_pfn_t to be usable in arm. Also, they are gfn's, not mfn's

Quoted 3 lines

A whole lot of terminology in this area is wrong. The top of xen/include/xen/mm.h is the authoritative description of terms, starting from c/s e758ed1

the existing restore_results seems unchanged, still unsigned long? see tools/libxl/libxl_save_helper.c helper_stub_restore_results

Quoted 4 lines

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#35 lore raw

Re: [PATCH v8 --for 4.6 COLO 15/25] send store mfn and console mfn to xl before resuming secondary vm

Quoted 45 lines · Yang Hongyang
Quoted 42 lines · Andrew Cooper
Quoted 27 lines · Yang Hongyang

From: Wen Congyang <[email protected]>

We will call libxl__xc_domain_restore_done() to rebuild secondary vm. But
we need store mfn and console mfn 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 mfn and console mfn 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 | 2 +-
  5 files changed, 16 insertions(+), 8 deletions(-)
tools/libxc/include/xenguest.h +0 -0
index 1e7e1bb..d7bdfb5 100644
@@ -140,6 +140,14 @@ struct restore_callbacks {
       */

tools/libxc/include/xenguest.h struct restore_callbacks { · line 150

Quoted 10 lines
tools/libxc/include/xenguest.h +7 -0
      int (*should_checkpoint)(void* data);
 
+    /*
+     * callback to send store mfn and console mfn to xl
+     * if we want to resume vm before xc_domain_save()
+     * exits.
+     */
+    void (*restore_results)(unsigned long store_mfn, unsigned long
 console_mfn,
+                            void *data);

These need to be xen_pfn_t to be usable in arm. Also, they are gfn's, not mfn's

Quoted 6 lines
Quoted 3 lines

A whole lot of terminology in this area is wrong. The top of xen/include/xen/mm.h is the authoritative description of terms, starting from c/s e758ed1

the existing restore_results seems unchanged, still unsigned long? see tools/libxl/libxl_save_helper.c helper_stub_restore_results

I have this

http://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen.git;a=commitdiff;h=2f91b4d39fd0bbbd3e2b0d3f451250d154505f9d

in my cleanup series, which I can extend all the way up the helper_stub_restore_results() chain.

~Andrew

#36 lore raw

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

In reply to Yang Hongyang

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   | 104 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 102 insertions(+), 4 deletions(-)
tools/libxc/xc_sr_common.h +2 -0
index 7fc2021..5f2d99b 100644
@@ -183,6 +183,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 +100 -4

135 lines not on this page · raw message

Signature · 1 line
1.9.1
#37 lore raw

PATCH v8 17/25 implement the cmdline for COLO

In reply to Yang Hongyang

From: Wen Congyang <[email protected]>

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  | 61 ++++++++++++++++++++++++++++++++++++-----------
 tools/libxl/xl_cmdtable.c |  4 +++-
 4 files changed, 81 insertions(+), 19 deletions(-)
docs/man/xl.pod.1 +10 -2
index f22c3f3..2cd34bb 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 c040909..791f364 100644
@@ -814,12 +814,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) ||
@@ -841,7 +857,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 +47 -14

140 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +3 -1
index 54dbecc..7e65a11 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
1.9.1
#38 lore raw

PATCH v8 18/25 Support colo mode for qemu disk

In reply to Yang Hongyang

From: Wen Congyang <[email protected]>

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

---
 docs/man/xl.pod.1                   |   2 +-
 docs/misc/xl-disk-configuration.txt |  38 ++++++
 tools/libxl/libxl.c                 |  42 +++++-
 tools/libxl/libxl_create.c          |  25 +++-
 tools/libxl/libxl_device.c          |  38 ++++++
 tools/libxl/libxl_dm.c              | 257 +++++++++++++++++++++++++++++++++++-
 tools/libxl/libxl_types.idl         |   5 +
 tools/libxl/libxlu_disk_l.l         |   5 +
 8 files changed, 403 insertions(+), 9 deletions(-)
docs/man/xl.pod.1 +1 -1
index 2cd34bb..1effce7 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 +38 -0
index 6a2118d..e366e8d 100644
@@ -234,6 +234,44 @@ were intentionally created non-sparse to avoid fragmentation of the
 file.
 
 
+===============
+COLO PARAMETERS
+===============
+
+
+colo
+----
+
+Enable COLO HA for disk. For better understanding block replication on
+QEMU, please refer to:
+http://wiki.qemu.org/Features/BlockReplication
+
+
+colo-params=host:port:exportname=<name>
+---------------------------------------
+
+Description:           Secondary host's address and port information,
+                       We will run a nbd server on secondary host,
+                       exportname is the nbd server's disk export name.
+Mandatory:             Yes when COLO enabled
+
+
+active-disk
+-----------
+
+Description:           This is used by secondary. Secondary guest's write
+                       will be buffered in this disk.
+Mandatory:             Yes when COLO enabled
+
+
+hidden-disk
+-----------
+
+Description:           This is used by secondary. It buffers the original
+                       content that is modified by the primary VM.
+Mandatory:             Yes when COLO enabled
+
+
 ============================================
 DEPRECATED PARAMETERS, PREFIXES AND SYNTAXES
 ============================================
tools/libxl/libxl.c +41 -1

66 lines not on this page · raw message

tools/libxl/libxl_create.c +24 -1
index 34e9362..d99d5ef 100644
@@ -1647,12 +1647,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);
 }
@@ -1663,6 +1680,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 +38 -0
index 2493972..5fcd45b 100644
@@ -196,6 +196,10 @@ static int disk_try_backend(disk_try_backend_args *a,
             goto bad_format;
         }
 
+        if (libxl_defbool_val(a->disk->colo_enable) ||
+            a->disk->active_disk || a->disk->hidden_disk)
+            goto bad_colo;
+
         if (a->disk->backend_domid != LIBXL_TOOLSTACK_DOMID) {
             LOG(DEBUG, "Disk vdev=%s, is using a storage driver domain, "
                        "skipping physical device check", a->disk->vdev);
@@ -218,6 +222,10 @@ static int disk_try_backend(disk_try_backend_args *a,
     case LIBXL_DISK_BACKEND_TAP:
         if (a->disk->script) goto bad_script;
 
+        if (libxl_defbool_val(a->disk->colo_enable) ||
+            a->disk->active_disk || a->disk->hidden_disk)
+            goto bad_colo;
+
         if (a->disk->is_cdrom) {
             LOG(DEBUG, "Disk vdev=%s, backend tap unsuitable for cdroms",
                        a->disk->vdev);
@@ -236,6 +244,16 @@ static int disk_try_backend(disk_try_backend_args *a,
 
     case LIBXL_DISK_BACKEND_QDISK:
         if (a->disk->script) goto bad_script;
+        if (libxl_defbool_val(a->disk->colo_enable)) {
+            if (!a->disk->colo_params)
+                goto bad_colo_params;
+
+            if (!a->disk->active_disk)
+                goto bad_active_disk;
+
+            if (!a->disk->hidden_disk)
+                goto bad_hidden_disk;
+        }
         return backend;
 
     default:
@@ -256,6 +274,26 @@ static int disk_try_backend(disk_try_backend_args *a,
     LOG(DEBUG, "Disk vdev=%s, backend %s not compatible with script=...",
         a->disk->vdev, libxl_disk_backend_to_string(backend));
     return 0;
+
+ bad_colo:
+    LOG(DEBUG, "Disk vdev=%s, backend %s not compatible with colo",
+        a->disk->vdev, libxl_disk_backend_to_string(backend));
+    return 0;
+
+ bad_colo_params:
+    LOG(DEBUG, "Disk vdev=%s, backend %s needs colo-params=... for colo",
+        a->disk->vdev, libxl_disk_backend_to_string(backend));
+    return 0;
+
+ bad_active_disk:
+    LOG(DEBUG, "Disk vdev=%s, backend %s needs active-disk=... for colo",
+        a->disk->vdev, libxl_disk_backend_to_string(backend));
+    return 0;
+
+ bad_hidden_disk:
+    LOG(DEBUG, "Disk vdev=%s, backend %s needs hidden-disk=... for colo",
+        a->disk->vdev, libxl_disk_backend_to_string(backend));
+    return 0;
 }
 
 int libxl__device_disk_set_backend(libxl__gc *gc, libxl_device_disk *disk) {
tools/libxl/libxl_dm.c +251 -6

284 lines not on this page · raw message

tools/libxl/libxl_types.idl +5 -0
index 19bd2c1..5eb9a38 100644
@@ -542,6 +542,11 @@ 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_params", string),
+    ("active_disk", string),
+    ("hidden_disk", string)
     ])
 
 libxl_device_nic = Struct("device_nic", [
tools/libxl/libxlu_disk_l.l +5 -0
index 1a5deb5..566aa1e 100644
@@ -176,6 +176,11 @@ 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-params=[^,]*,?	{ STRIP(','); SAVESTRING("colo-params", colo_params, 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
1.9.1
#39 lore raw

PATCH v8 19/25 COLO: use qemu block replication

In reply to Yang Hongyang

From: Wen Congyang <[email protected]>

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   | 209 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_colo_restore.c |  20 +++-
 tools/libxl/libxl_colo_save.c    |  36 ++++++-
 tools/libxl/libxl_internal.h     |  18 ++++
 tools/libxl/libxl_qmp.c          |  31 ++++++
 6 files changed, 311 insertions(+), 4 deletions(-)
 create mode 100644 tools/libxl/libxl_colo_qdisk.c
tools/libxl/Makefile +1 -0
index 71bf7a2..e91ae79 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 +209 -0

209 lines not on this page · raw message

tools/libxl/libxl_colo_restore.c +18 -2
index 99f06ab..96ea0b9 100644
@@ -49,7 +49,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,
 };
 
@@ -148,7 +151,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;
 }
 
@@ -156,6 +163,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);
 }
 
 
@@ -215,6 +224,7 @@ void libxl__colo_restore_setup(libxl__egc *egc,
     GCNEW(crcs);
     crs->crcs = crcs;
     crcs->crs = crs;
+    crs->qdisk_setuped = false;
 
     /* setup dsps */
     crcs->dsps.ao = ao;
@@ -519,6 +529,12 @@ static void colo_restore_preresume_cb(libxl__egc *egc,
         goto out;
     }
 
+    rc = colo_qdisk_preresume(CTX, crs->domid);
+    if (rc) {
+        LOG(ERROR, "colo_qdisk_preresume() fails");
+        goto out;
+    }
+
     colo_restore_resume_vm(egc, crcs);
 
     return;
@@ -674,8 +690,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 +34 -2
index f0ab565..1245da7 100644
@@ -19,7 +19,10 @@
 #include "libxl_internal.h"
 #include "libxl_colo.h"
 
+extern const libxl__checkpoint_device_instance_ops colo_save_device_qdisk;
+
 static const libxl__checkpoint_device_instance_ops *colo_ops[] = {
+    &colo_save_device_qdisk,
     NULL,
 };
 
@@ -30,7 +33,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;
 }
 
@@ -38,6 +45,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);
 }
 
 /* ================= colo: setup save environment ================= */
@@ -65,9 +74,11 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
     css->send_fd = dss->fd;
     css->recv_fd = dss->recv_fd;
     css->svm_running = false;
+    css->paused = true;
+    css->qdisk_setuped = false;
 
-    /* TODO: disk/nic support */
-    cds->device_kind_flags = 0;
+    /* TODO: nic support */
+    cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD);
     cds->ops = colo_ops;
     cds->callback = colo_save_setup_done;
     cds->ao = ao;
@@ -391,12 +402,33 @@ static void colo_preresume_cb(libxl__egc *egc,
         goto out;
     }
 
+    if (!css->paused) {
+        rc = colo_qdisk_preresume(CTX, dss->domid);
+        if (rc) {
+            LOG(ERROR, "colo_qdisk_preresume() fails");
+            goto out;
+        }
+    }
+
     /* Resumes the domain and the device model */
     if (libxl__domain_resume(gc, dss->domid, /* Fast Suspend */1)) {
         LOG(ERROR, "cannot resume primary vm");
         goto out;
     }
 
+    /*
+     * The guest should be paused before doing colo because there is
+     * no disk migration.
+     */
+    if (css->paused) {
+        rc = libxl_domain_unpause(CTX, dss->domid);
+        if (rc) {
+            LOG(ERROR, "cannot unpause primary vm");
+            goto out;
+        }
+        css->paused = false;
+    }
+
     /* read COLO_SVM_RESUMED */
     css->callback = colo_read_svm_resumed_done;
     css->srs.checkpoint_callback = colo_common_read_stream_done;
tools/libxl/libxl_internal.h +18 -0
index c429852..898e42c 100644
@@ -1710,6 +1710,14 @@ _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 block replication */
+_hidden int libxl__qmp_block_start_replication(libxl__gc *gc, int domid,
+                                               bool primary, const char *addr);
+/* 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);
 /* 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,
@@ -2825,6 +2833,9 @@ 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);
 
 typedef void libxl__checkpoint_callback(libxl__egc *,
                                         libxl__checkpoint_devices_state *,
@@ -3044,6 +3055,10 @@ 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_setuped;
 };
 
 /*----- Domain suspend (save) state structure -----*/
@@ -3441,6 +3456,9 @@ struct libxl__colo_restore_state {
     libxl__domain_create_cb *saved_cb;
     void *crcs;
     libxl__checkpoint_devices_state cds;
+
+    /* private, used by qdisk block replication */
+    bool qdisk_setuped;
 };
 
 struct libxl__domain_create_state {
tools/libxl/libxl_qmp.c +31 -0
index 080cb9f..a8e7a8f 100644
@@ -977,6 +977,37 @@ int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx)
     return qmp_run_command(gc, domid, "cpu-add", args, NULL, NULL);
 }
 
+int libxl__qmp_block_start_replication(libxl__gc *gc, int domid,
+                                       bool primary, const char *addr)
+{
+    libxl__json_object *args = NULL;
+
+    qmp_parameters_add_bool(gc, &args, "enable", true);
+    qmp_parameters_add_bool(gc, &args, "primary", primary);
+    if (!primary)
+        qmp_parameters_add_string(gc, &args, "addr", addr);
+
+    return qmp_run_command(gc, domid, "xen-set-block-replication", args,
+                           NULL, NULL);
+}
+
+int libxl__qmp_block_do_checkpoint(libxl__gc *gc, int domid)
+{
+    return qmp_run_command(gc, domid, "xen-do-block-checkpoint", NULL,
+                           NULL, NULL);
+}
+
+int libxl__qmp_block_stop_replication(libxl__gc *gc, int domid, bool primary)
+{
+    libxl__json_object *args = NULL;
+
+    qmp_parameters_add_bool(gc, &args, "enable", false);
+    qmp_parameters_add_bool(gc, &args, "primary", primary);
+
+    return qmp_run_command(gc, domid, "xen-set-block-replication", args,
+                           NULL, NULL);
+}
+
 int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
                                const libxl_domain_config *guest_config)
 {
Signature · 1 line
1.9.1
#40 lore raw

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

In reply to Yang Hongyang

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 | 210 +++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h   |  12 +++
 4 files changed, 225 insertions(+)
 create mode 100644 tools/libxl/libxl_colo_proxy.c
tools/libxl/Makefile +1 -0
index e91ae79..d7a3540 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 49a430b..46ca4cf 100644
@@ -34,4 +34,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 +210 -0

210 lines not on this page · raw message

tools/libxl/libxl_internal.h +12 -0
index 898e42c..23305f2 100644
@@ -3045,6 +3045,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 {
     libxl__checkpoint_devices_state cds;
@@ -3059,6 +3068,9 @@ struct libxl__colo_save_state {
 
     /* private, used by qdisk block replication */
     bool qdisk_setuped;
+
+    /* private, used by colo-proxy */
+    libxl__colo_proxy_state cps;
 };
 
 /*----- Domain suspend (save) state structure -----*/
Signature · 1 line
1.9.1
#41 lore raw

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

In reply to Yang Hongyang

preresume, postresume and checkpoint

---
 tools/libxl/libxl_colo.h       |  3 +++
 tools/libxl/libxl_colo_proxy.c | 57 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
tools/libxl/libxl_colo.h +3 -0
index 46ca4cf..4e5f02a 100644
@@ -36,4 +36,7 @@ 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);
 #endif
tools/libxl/libxl_colo_proxy.c +57 -0

60 lines not on this page · raw message

Signature · 1 line
1.9.1
#42 lore raw

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

In reply to Yang Hongyang

implement COLO nic subkind.

---
 tools/hotplug/Linux/Makefile         |   1 +
 tools/hotplug/Linux/colo-proxy-setup | 131 ++++++++++++++
 tools/libxl/Makefile                 |   1 +
 tools/libxl/libxl_colo_nic.c         | 320 +++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h         |   5 +
 tools/libxl/libxl_types.idl          |   1 +
 6 files changed, 459 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 bc8ee5e..71b6475 100644
@@ -26,6 +26,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 +131 -0

131 lines not on this page · raw message

tools/libxl/Makefile +1 -0
index d7a3540..2a180fb 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 +320 -0

320 lines not on this page · raw message

tools/libxl/libxl_internal.h +5 -0
index 23305f2..65fac32 100644
@@ -2836,6 +2836,8 @@ 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 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 *,
@@ -3059,6 +3061,7 @@ struct libxl__colo_save_state {
     libxl__checkpoint_devices_state cds;
     int send_fd;
     int recv_fd;
+    char *colo_proxy_script;
 
     /* private */
     libxl__stream_read_state srs;
@@ -3463,6 +3466,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;
@@ -3485,6 +3489,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__bootloader_state bl;
tools/libxl/libxl_types.idl +1 -0
index 5eb9a38..d835d50 100644
@@ -564,6 +564,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
1.9.1
#43 lore raw

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

In reply to Yang Hongyang

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 1245da7..50a880b 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);
 }
 
@@ -76,9 +85,16 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css)
     css->svm_running = false;
     css->paused = true;
     css->qdisk_setuped = 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;
@@ -88,6 +104,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;
@@ -162,6 +184,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);
 }
 
@@ -378,6 +401,8 @@ static void colo_read_svm_ready_done(libxl__egc *egc,
         goto out;
     }
 
+    colo_proxy_preresume(&css->cps);
+
     css->svm_running = true;
     css->cds.callback = colo_preresume_cb;
     libxl__checkpoint_devices_preresume(egc, &css->cds);
@@ -454,6 +479,8 @@ static void colo_read_svm_resumed_done(libxl__egc *egc,
         goto out;
     }
 
+    colo_proxy_postresume(&css->cps);
+
     ok = 1;
 
 out:
@@ -462,6 +489,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)
+{
+    int pid = -1, rc;
+
+    STATE_AO_GC(css->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;
+
+again:
+    req = colo_proxy_checkpoint(&css->cps);
+    if (req < 0) {
+        /* some error happens */
+        _exit(1);
+    } else if (!req) {
+        /* no checkpoint is needed, wait for 1ms and the check again */
+        usleep(1000);
+        goto again;
+    } 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);
+
+    EGC_GC;
+
+    if (status) {
+        LOG(ERROR, "failed to wait for new checkpoint");
+        colo_start_new_checkpoint(egc, &css->cds, ERROR_FAIL);
+        return;
+    }
+
+    colo_start_new_checkpoint(egc, &css->cds, 0);
+}
+
 /*
  * Do the following things:
  * 1. do commit
@@ -471,9 +583,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)
 {
@@ -503,8 +612,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 65fac32..d12297d 100644
@@ -3074,6 +3074,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
1.9.1
#44 lore raw

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

In reply to Yang Hongyang

setup and control colo proxy on secondary side

---
 tools/libxl/libxl_colo_restore.c | 28 +++++++++++++++++++++++++---
 tools/libxl/libxl_internal.h     |  3 +++
 2 files changed, 28 insertions(+), 3 deletions(-)
tools/libxl/libxl_colo_restore.c +25 -3
index 96ea0b9..da546f9 100644
@@ -49,9 +49,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,
 };
@@ -151,8 +153,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:
@@ -164,6 +172,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);
 }
 
@@ -351,6 +360,8 @@ static void colo_restore_teardown_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;
@@ -535,6 +546,8 @@ static void colo_restore_preresume_cb(libxl__egc *egc,
         goto out;
     }
 
+    colo_proxy_preresume(&crs->cps);
+
     colo_restore_resume_vm(egc, crcs);
 
     return;
@@ -571,6 +584,8 @@ static void colo_resume_vm_done(libxl__egc *egc,
 
     crcs->status = LIBXL_COLO_RESUMED;
 
+    colo_proxy_postresume(&crs->cps);
+
     /* avoid calling libxl__xc_domain_restore_done() more than once */
     if (crs->saved_cb) {
         dcs->callback = crs->saved_cb;
@@ -690,13 +705,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;
 
tools/libxl/libxl_internal.h +3 -0
index d12297d..33a93a1 100644
@@ -3476,6 +3476,9 @@ struct libxl__colo_restore_state {
 
     /* private, used by qdisk block replication */
     bool qdisk_setuped;
+
+    /* private, used by colo proxy */
+    libxl__colo_proxy_state cps;
 };
 
 struct libxl__domain_create_state {
Signature · 1 line
1.9.1
#45 lore raw

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

In reply to Yang Hongyang

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    | 50 ++++++++++++++++++++++++++++++++++-----------
 8 files changed, 67 insertions(+), 15 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 1effce7..a7ac32f 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 c6cc5aa..75372ea 100644
@@ -3305,6 +3305,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,libxl__sprintf(gc,
                                     LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
@@ -3428,6 +3433,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 d99d5ef..7de2e89 100644
@@ -1089,6 +1089,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);
     } else
         libxl__stream_read_start(egc, &dcs->srs);
@@ -1612,6 +1617,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)
 {
@@ -1628,6 +1634,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config,
     if (restore_fd > -1)
         cdcs->dcs.restore_params = *params;
     cdcs->dcs.callback = domain_create_cb;
+    cdcs->dcs.colo_proxy_script = colo_proxy_script;
     libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how);
     cdcs->domid_out = domid;
 
@@ -1670,7 +1677,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);
 }
 
@@ -1680,14 +1687,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);
 }
 
 /*
tools/libxl/libxl_types.idl +1 -0
index d835d50..6e7e358 100644
@@ -362,6 +362,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 f014306..f44f04f 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 13bccba..aa17dd5 100644
@@ -182,6 +182,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 +38 -12

117 lines not on this page · raw message

Signature · 1 line
1.9.1