Skip to contentSkip to conversation

migration/snapshot: External snapshot utility

RFC PATCH Superseded Andrey Gruzdev 2 participants 9 messages May 12, 2021 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover migration/snapshot: External snapshot utility

Changes v0 -> v1:
* Changed command-line format, now use blockdev specification to define vmstate image.
* Don't deal with image creation in the tool, create externally.
* Better block layer AIO handling in the load path.
* Reduced fragmentation of the image backing file by using 'writtent-slice' bitmaps in RAM blocks. Zero block write is issued to a never written slice before the actual memory page write takes place.
* Improved load performance in postcopy by using 'loaded-slice' bitmaps in RAM blocks.
* Refactored error handling/messages.
* Refactored namings.

This series is a kind of PoC for asynchronous snapshot reverting. It is about external snapshots only and doesn't involve block devices. Thus, it's mainly intended to be used with the new 'background-snapshot' migration capability and otherwise standard QEMU migration mechanism.

The major ideas behind this first version were:
* Make it compatible with 'exec:'-style migration - options can be create some separate tool or integrate into qemu-system.
* Support asynchronous revert stage by using unaltered postcopy logic at destination. To do this, we should be capable of saving RAM pages so that any particular page can be directly addressed by it's block ID and page offset. Possible solutions here seem to be:
use separate index (and storing it somewhere)
create sparse file on host FS and address pages with file offset use QCOW2 (or other) image container with inherent sparsity support
* Make image file dense on the host FS so we don't depend on copy/backup tools and how they deal with sparse files. Off course, there's some performance cost for this choice.
* Make the code which is parsing unstructered format of migration stream, at least, not very sophisticated. Also, try to have minimum dependencies on QEMU migration code, both RAM and device.
* Try to keep page save latencies small while not degrading migration bandwidth too much.

For this first version I decided not to integrate into main QEMU code but create a separate tool. The main reason is that there's not too much migration code that is target-specific and can be used in it's unmodified form. Also, it's still not very clear how to make 'qemu-system' integration in terms of command-line (or monitor/QMP?) interface extension.

For the storage format, QCOW2 as a container and large (1MB) cluster size seem to be an optimal choice. Larger cluster is beneficial for performance particularly in the case when image preallocation is disabled. Such cluster size does not result in too high internal fragmentation level (~10% of space waste in most cases) yet allows to reduce significantly the number of expensive cluster allocations.

A bit tricky part is dispatching QEMU migration stream cause it is mostly unstructered and depends on configuration parameters like 'send-configuration' and 'send-section-footer'. But, for the case with default values in migration globals it seems that implemented dispatching code works well and won't have compatibility issues in a reasonably long time frame.

I decided to keep RAM save path synchronous, anyhow it's better to use writeback cache mode for the live snapshots cause of it's interleaving page address pattern. Page coalescing buffer is used to merge contiguous pages to optimize block layer writes.

Since for snapshot loading opening image file in cached mode would not do any good, it implies that Linux native AIO and O_DIRECT mode is used in a common scenario. AIO support in RAM loading path is implemented by using a ring of preallocated fixed-sized buffers in such a way that there's always a number of outstanding block requests anytime. It also ensures in-order request completion.

How to use:

**Save:**
* > qemu-img create -f qcow2 -o size=<2_x_ram_size>,cluster_size=1M, preallocation=off,refcount_bits=8 <image-filename>
* qemu> migrate_set_capability background-snapshot on
* qemu> migrate "exec:qemu-snapshot <image-filename>,cache.direct=off,file.aio=threads"

**Load:**
* Use 'qemu-system-* -incoming defer'
* qemu> migrate_incoming "exec:qemu-snapshot --revert <image-filename>,cache.direct=on,file.aio=native"

**Load with postcopy:**
* Use 'qemu-system-* -incoming defer'
* qemu> migrate_set_capability postcopy-ram on
* qemu> migrate_incoming "exec:qemu-snapshot --revert --postcopy=60 <image-filename>,cache.direct=on,file.aio=native"

And yes, asynchronous revert works well only with SSD, not with rotational disk..

Some performance stats:
* SATA SSD drive with ~500/450 MB/s sequantial read/write and ~60K IOPS max.
* 220 MB/s average save rate (depends on workload).
* 440 MB/s average load rate in precopy.
* 260 MB/s average load rate in postcopy.

Andrey Gruzdev (7):
migration/snapshot: Introduce qemu-snapshot tool migration/snapshot: Introduce qemu_ftell2() routine migration/snapshot: Move RAM_SAVE_FLAG_xxx defines to migration/ram.h migration/snapshot: Block layer AIO support in qemu-snapshot migration/snapshot: Implementation of qemu-snapshot save path migration/snapshot: Implementation of qemu-snapshot load path migration/snapshot: Implementation of qemu-snapshot load path in
postcopy mode

 include/qemu-snapshot.h |  155 ++++
 meson.build             |    2 +
 migration/qemu-file.c   |    6 +
 migration/qemu-file.h   |    1 +
 migration/ram.c         |   16 -
 migration/ram.h         |   16 +
 qemu-snapshot-io.c      |  266 ++++++
 qemu-snapshot-vm.c      | 1881 +++++++++++++++++++++++++++++++++++++++
 qemu-snapshot.c         |  554 ++++++++++++
 9 files changed, 2881 insertions(+), 16 deletions(-)
 create mode 100644 include/qemu-snapshot.h
 create mode 100644 qemu-snapshot-io.c
 create mode 100644 qemu-snapshot-vm.c
 create mode 100644 qemu-snapshot.c
Signature · 1 line
2.27.0
#1 lore raw

RFC PATCH 1/7 migration/snapshot: Introduce qemu-snapshot tool

Execution environment, command-line argument parsing, usage/version info etc.

---
 include/qemu-snapshot.h |  59 ++++++
 meson.build             |   2 +
 qemu-snapshot-vm.c      |  57 ++++++
 qemu-snapshot.c         | 439 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 557 insertions(+)
 create mode 100644 include/qemu-snapshot.h
 create mode 100644 qemu-snapshot-vm.c
 create mode 100644 qemu-snapshot.c
include/qemu-snapshot.h new file +59 -0
new file mode 100644
index 0000000000..154e11e9a5
@@ -0,0 +1,59 @@
+/*
+ * QEMU External Snapshot Utility
+ *
+ * Copyright Virtuozzo GmbH, 2021
+ *
+ * Authors:
+ *  Andrey Gruzdev   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * later. See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_SNAPSHOT_H
+#define QEMU_SNAPSHOT_H
+
+/* Invalid offset */
+#define INVALID_OFFSET              -1
+/* Maximum byte count for qemu_get_buffer_in_place() */
+#define INPLACE_READ_MAX            (32768 - 4096)
+
+/* Backing cluster size */
+#define BDRV_CLUSTER_SIZE           (1024 * 1024)
+
+/* Minimum supported target page size */
+#define PAGE_SIZE_MIN               4096
+/*
+ * Maximum supported target page size. The limit is caused by using
+ * QEMUFile and qemu_get_buffer_in_place() on migration channel.
+ * IO_BUF_SIZE is currently 32KB.
+ */
+#define PAGE_SIZE_MAX               16384
+/* RAM slice size for snapshot saving */
+#define SLICE_SIZE                  PAGE_SIZE_MAX
+/* RAM slice size for snapshot revert */
+#define SLICE_SIZE_REVERT           (16 * PAGE_SIZE_MAX)
+
+typedef struct StateSaveCtx {
+    BlockBackend *blk;          /* Block backend */
+} StateSaveCtx;
+
+typedef struct StateLoadCtx {
+    BlockBackend *blk;          /* Block backend */
+} StateLoadCtx;
+
+extern int64_t page_size;       /* Page size */
+extern int64_t page_mask;       /* Page mask */
+extern int page_bits;           /* Page size bits */
+extern int64_t slice_size;      /* RAM slice size */
+extern int64_t slice_mask;      /* RAM slice mask */
+extern int slice_bits;          /* RAM slice size bits */
+
+void ram_init_state(void);
+void ram_destroy_state(void);
+StateSaveCtx *get_save_context(void);
+StateLoadCtx *get_load_context(void);
+int coroutine_fn save_state_main(StateSaveCtx *s);
+int coroutine_fn load_state_main(StateLoadCtx *s);
+
+#endif /* QEMU_SNAPSHOT_H */
meson.build +2 -0
index 0b41ff4118..b851671914 100644
@@ -2361,6 +2361,8 @@ if have_tools
              dependencies: [block, qemuutil], install: true)
   qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'),
                dependencies: [blockdev, qemuutil, gnutls], install: true)
+  qemu_snapshot = executable('qemu-snapshot', files('qemu-snapshot.c', 'qemu-snapshot-vm.c'),
+               dependencies: [blockdev, qemuutil, migration], install: true)
 
   subdir('storage-daemon')
   subdir('contrib/rdmacm-mux')
qemu-snapshot-vm.c new file +57 -0

57 lines not on this page · raw message

qemu-snapshot.c new file +439 -0

439 lines not on this page · raw message

Signature · 1 line
2.27.0
#2 lore raw

RFC PATCH 2/7 migration/snapshot: Introduce qemu_ftell2() routine

In reply to Andrey Gruzdev

In qemu-snapshot it is needed to retrieve current QEMUFile offset as a number of bytes read by qemu_get_byte()/qemu_get_buffer().

The existing qemu_ftell() routine would give read position as a number of bytes fetched from underlying IOChannel which is not the same.

---
 migration/qemu-file.c | 6 ++++++
 migration/qemu-file.h | 1 +
 2 files changed, 7 insertions(+)
migration/qemu-file.c +6 -0
index d6e03dbc0e..66be5e6460 100644
@@ -657,6 +657,12 @@ int64_t qemu_ftell(QEMUFile *f)
     return f->pos;
 }
 
+int64_t qemu_ftell2(QEMUFile *f)
+{
+    qemu_fflush(f);
+    return f->pos + f->buf_index - f->buf_size;
+}
+
 int qemu_file_rate_limit(QEMUFile *f)
 {
     if (f->shutdown) {
migration/qemu-file.h +1 -0
index a9b6d6ccb7..bd1a6def02 100644
@@ -124,6 +124,7 @@ void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
 int qemu_get_fd(QEMUFile *f);
 int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
+int64_t qemu_ftell2(QEMUFile *f);
 int64_t qemu_ftell_fast(QEMUFile *f);
 /*
  * put_buffer without copying the buffer.
Signature · 1 line
2.27.0
#3 lore raw

RFC PATCH 3/7 migration/snapshot: Move RAM_SAVE_FLAG_xxx defines to migration/ram.h

In reply to Andrey Gruzdev

Move RAM_SAVE_FLAG_xxx defines from migration/ram.c to migration/ram.h

---
 migration/ram.c | 16 ----------------
 migration/ram.h | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)
migration/ram.c +0 -16
index ace8ad431c..0359b63dde 100644
@@ -63,22 +63,6 @@
 /***********************************************************/
 /* ram save/restore */
 
-/* RAM_SAVE_FLAG_ZERO used to be named RAM_SAVE_FLAG_COMPRESS, it
- * worked for pages that where filled with the same char.  We switched
- * it to only search for the zero value.  And to avoid confusion with
- * RAM_SSAVE_FLAG_COMPRESS_PAGE just rename it.
- */
-
-#define RAM_SAVE_FLAG_FULL     0x01 /* Obsolete, not used anymore */
-#define RAM_SAVE_FLAG_ZERO     0x02
-#define RAM_SAVE_FLAG_MEM_SIZE 0x04
-#define RAM_SAVE_FLAG_PAGE     0x08
-#define RAM_SAVE_FLAG_EOS      0x10
-#define RAM_SAVE_FLAG_CONTINUE 0x20
-#define RAM_SAVE_FLAG_XBZRLE   0x40
-/* 0x80 is reserved in migration.h start with 0x100 next */
-#define RAM_SAVE_FLAG_COMPRESS_PAGE    0x100
-
 static inline bool is_zero_range(uint8_t *p, uint64_t size)
 {
     return buffer_is_zero(p, size);
migration/ram.h +16 -0
index 4833e9fd5b..d6498b651f 100644
@@ -33,6 +33,22 @@
 #include "exec/cpu-common.h"
 #include "io/channel.h"
 
+/* RAM_SAVE_FLAG_ZERO used to be named RAM_SAVE_FLAG_COMPRESS, it
+ * worked for pages that where filled with the same char.  We switched
+ * it to only search for the zero value.  And to avoid confusion with
+ * RAM_SSAVE_FLAG_COMPRESS_PAGE just rename it.
+ */
+
+#define RAM_SAVE_FLAG_FULL     0x01 /* Obsolete, not used anymore */
+#define RAM_SAVE_FLAG_ZERO     0x02
+#define RAM_SAVE_FLAG_MEM_SIZE 0x04
+#define RAM_SAVE_FLAG_PAGE     0x08
+#define RAM_SAVE_FLAG_EOS      0x10
+#define RAM_SAVE_FLAG_CONTINUE 0x20
+#define RAM_SAVE_FLAG_XBZRLE   0x40
+/* 0x80 is reserved in migration.h start with 0x100 next */
+#define RAM_SAVE_FLAG_COMPRESS_PAGE    0x100
+
 extern MigrationStats ram_counters;
 extern XBZRLECacheStats xbzrle_counters;
 extern CompressionStats compression_counters;
Signature · 1 line
2.27.0
#4 lore raw

RFC PATCH 4/7 migration/snapshot: Block layer AIO support in qemu-snapshot

In reply to Andrey Gruzdev

This commit enables asynchronous block layer I/O for qemu-snapshot tool. Implementation provides in-order request completion delivery to simplify migration code.

Several file utility routines are introduced as well.

---
 include/qemu-snapshot.h |  30 +++++
 meson.build             |   2 +-
 qemu-snapshot-io.c      | 266 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 297 insertions(+), 1 deletion(-)
 create mode 100644 qemu-snapshot-io.c
include/qemu-snapshot.h +30 -0
index 154e11e9a5..7b3406fd56 100644
@@ -34,6 +34,23 @@
 /* RAM slice size for snapshot revert */
 #define SLICE_SIZE_REVERT           (16 * PAGE_SIZE_MAX)
 
+typedef struct AioRing AioRing;
+
+typedef struct AioRingRequest {
+    void *opaque;               /* Opaque */
+
+    void *data;                 /* Data buffer */
+    int64_t offset;             /* Offset */
+    size_t size;                /* Size */
+} AioRingRequest;
+
+typedef struct AioRingEvent {
+    AioRingRequest *origin;     /* Originating request */
+    ssize_t status;             /* Completion status */
+} AioRingEvent;
+
+typedef ssize_t coroutine_fn (*AioRingFunc)(AioRingRequest *req);
+
 typedef struct StateSaveCtx {
     BlockBackend *blk;          /* Block backend */
 } StateSaveCtx;
@@ -56,4 +73,17 @@ StateLoadCtx *get_load_context(void);
 int coroutine_fn save_state_main(StateSaveCtx *s);
 int coroutine_fn load_state_main(StateLoadCtx *s);
 
+AioRing *coroutine_fn aio_ring_new(AioRingFunc func, unsigned ring_entries,
+        unsigned max_inflight);
+void aio_ring_free(AioRing *ring);
+void aio_ring_set_max_inflight(AioRing *ring, unsigned max_inflight);
+AioRingRequest *coroutine_fn aio_ring_get_request(AioRing *ring);
+void coroutine_fn aio_ring_submit(AioRing *ring);
+AioRingEvent *coroutine_fn aio_ring_wait_event(AioRing *ring);
+void coroutine_fn aio_ring_complete(AioRing *ring);
+
+QEMUFile *qemu_fopen_bdrv_vmstate(BlockDriverState *bs, int is_writable);
+void qemu_fsplice(QEMUFile *f_dst, QEMUFile *f_src, size_t size);
+void qemu_fsplice_tail(QEMUFile *f_dst, QEMUFile *f_src);
+
 #endif /* QEMU_SNAPSHOT_H */
meson.build +1 -1
index b851671914..c25fc518df 100644
@@ -2361,7 +2361,7 @@ if have_tools
              dependencies: [block, qemuutil], install: true)
   qemu_nbd = executable('qemu-nbd', files('qemu-nbd.c'),
                dependencies: [blockdev, qemuutil, gnutls], install: true)
-  qemu_snapshot = executable('qemu-snapshot', files('qemu-snapshot.c', 'qemu-snapshot-vm.c'),
+  qemu_snapshot = executable('qemu-snapshot', files('qemu-snapshot.c', 'qemu-snapshot-vm.c', 'qemu-snapshot-io.c'),
                dependencies: [blockdev, qemuutil, migration], install: true)
 
   subdir('storage-daemon')
qemu-snapshot-io.c new file +266 -0

266 lines not on this page · raw message

Signature · 1 line
2.27.0
#5 lore raw

RFC PATCH 5/7 migration/snapshot: Implementation of qemu-snapshot save path

In reply to Andrey Gruzdev

Includes code to parse incoming migration stream, dispatch data to section handlers and deal with complications of open-coded migration format without introducing strong dependencies on QEMU migration code.

---
 include/qemu-snapshot.h |  34 +-
 qemu-snapshot-vm.c      | 771 +++++++++++++++++++++++++++++++++++++++-
 qemu-snapshot.c         |  56 ++-
 3 files changed, 857 insertions(+), 4 deletions(-)
include/qemu-snapshot.h +33 -1
index 7b3406fd56..52519f76c4 100644
@@ -51,8 +51,40 @@ typedef struct AioRingEvent {
 
 typedef ssize_t coroutine_fn (*AioRingFunc)(AioRingRequest *req);
 
+typedef struct QIOChannelBuffer QIOChannelBuffer;
+
 typedef struct StateSaveCtx {
-    BlockBackend *blk;          /* Block backend */
+    BlockBackend *blk;              /* Block backend */
+    QEMUFile *f_fd;                 /* QEMUFile for incoming stream */
+    QEMUFile *f_vmstate;            /* QEMUFile for vmstate backing */
+
+    QIOChannelBuffer *ioc_leader;   /* Migration stream leader */
+    QIOChannelBuffer *ioc_pages;    /* Page coalescing buffer */
+
+    /* Block offset of first page in ioc_pages */
+    int64_t bdrv_offset;
+    /* Block offset of the last page in ioc_pages */
+    int64_t last_bdrv_offset;
+
+    /* Current section offset */
+    int64_t section_offset;
+    /* Offset of the section containing list of RAM blocks */
+    int64_t ram_list_offset;
+    /* Offset of the first RAM section */
+    int64_t ram_offset;
+    /* Offset of the first non-iterable device section */
+    int64_t device_offset;
+
+    /* Zero buffer to fill unwritten slices on backing */
+    void *zero_buf;
+
+    /*
+     * Since we can't rewind the state of migration stream QEMUFile, we just
+     * keep first few hundreds of bytes from the beginning of each section for
+     * the case if particular section appears to be the first non-iterable
+     * device section and we are going to call default_handler().
+     */
+    uint8_t section_header[512];
 } StateSaveCtx;
 
 typedef struct StateLoadCtx {
qemu-snapshot-vm.c +769 -2

786 lines not on this page · raw message

qemu-snapshot.c +55 -1

74 lines not on this page · raw message

Signature · 1 line
2.27.0
#6 lore raw

RFC PATCH 6/7 migration/snapshot: Implementation of qemu-snapshot load path

In reply to Andrey Gruzdev

This part implements snapshot loading in precopy mode.

---
 include/qemu-snapshot.h |  24 +-
 qemu-snapshot-vm.c      | 588 +++++++++++++++++++++++++++++++++++++++-
 qemu-snapshot.c         |  47 +++-
 3 files changed, 654 insertions(+), 5 deletions(-)
include/qemu-snapshot.h +23 -1
index 52519f76c4..aae730d70e 100644
@@ -34,6 +34,13 @@
 /* RAM slice size for snapshot revert */
 #define SLICE_SIZE_REVERT           (16 * PAGE_SIZE_MAX)
 
+/* AIO transfer size */
+#define AIO_TRANSFER_SIZE           BDRV_CLUSTER_SIZE
+/* AIO ring size */
+#define AIO_RING_SIZE               64
+/* AIO ring in-flight limit */
+#define AIO_RING_INFLIGHT           16
+
 typedef struct AioRing AioRing;
 
 typedef struct AioRingRequest {
@@ -88,7 +95,20 @@ typedef struct StateSaveCtx {
 } StateSaveCtx;
 
 typedef struct StateLoadCtx {
-    BlockBackend *blk;          /* Block backend */
+    BlockBackend *blk;              /* Block backend */
+    QEMUFile *f_fd;                 /* QEMUFile for outgoing stream */
+    QEMUFile *f_vmstate;            /* QEMUFile for vmstate backing */
+
+    QIOChannelBuffer *ioc_leader;   /* vmstate stream leader */
+
+    AioRing *aio_ring;              /* AIO ring */
+
+    /* vmstate offset of the section containing list of RAM blocks */
+    int64_t ram_list_offset;
+    /* vmstate offset of the first non-iterable device section */
+    int64_t device_offset;
+    /* vmstate EOF */
+    int64_t eof_offset;
 } StateLoadCtx;
 
 extern int64_t page_size;       /* Page size */
@@ -100,6 +120,8 @@ extern int slice_bits;          /* RAM slice size bits */
 
 void ram_init_state(void);
 void ram_destroy_state(void);
+ssize_t coroutine_fn ram_load_aio_co(AioRingRequest *req);
+
 StateSaveCtx *get_save_context(void);
 StateLoadCtx *get_load_context(void);
 int coroutine_fn save_state_main(StateSaveCtx *s);
qemu-snapshot-vm.c +585 -3

634 lines not on this page · raw message

qemu-snapshot.c +46 -1

65 lines not on this page · raw message

Signature · 1 line
2.27.0
#7 lore raw

RFC PATCH 7/7 migration/snapshot: Implementation of qemu-snapshot load path in postcopy mode

In reply to Andrey Gruzdev

The commit enables asynchronous snapshot loading using standard postcopy migration mechanism on destination VM.

The point of switchover to postcopy is trivially selected based on percentage of non-zero pages loaded in precopy.

---
 include/qemu-snapshot.h |  12 +
 qemu-snapshot-vm.c      | 485 +++++++++++++++++++++++++++++++++++++++-
 qemu-snapshot.c         |  16 ++
 3 files changed, 508 insertions(+), 5 deletions(-)
include/qemu-snapshot.h +12 -0
index aae730d70e..84a0c38e08 100644
@@ -36,10 +36,14 @@
 
 /* AIO transfer size */
 #define AIO_TRANSFER_SIZE           BDRV_CLUSTER_SIZE
+/* AIO transfer size for postcopy */
+#define AIO_TRANSFER_SIZE_LOWLAT    (BDRV_CLUSTER_SIZE / 4)
 /* AIO ring size */
 #define AIO_RING_SIZE               64
 /* AIO ring in-flight limit */
 #define AIO_RING_INFLIGHT           16
+/* AIO ring in-flight limit for postcopy */
+#define AIO_RING_INFLIGHT_LOWLAT    4
 
 typedef struct AioRing AioRing;
 
@@ -97,12 +101,20 @@ typedef struct StateSaveCtx {
 typedef struct StateLoadCtx {
     BlockBackend *blk;              /* Block backend */
     QEMUFile *f_fd;                 /* QEMUFile for outgoing stream */
+    QEMUFile *f_rp_fd;              /* QEMUFile for return path stream */
     QEMUFile *f_vmstate;            /* QEMUFile for vmstate backing */
 
     QIOChannelBuffer *ioc_leader;   /* vmstate stream leader */
 
     AioRing *aio_ring;              /* AIO ring */
 
+    bool postcopy;                  /* From command-line --postcopy */
+    int postcopy_percent;           /* From command-line --postcopy */
+    bool in_postcopy;               /* In postcopy mode */
+
+    QemuThread rp_listen_thread;    /* Return path listening thread */
+    bool has_rp_listen_thread;      /* Have listening thread */
+
     /* vmstate offset of the section containing list of RAM blocks */
     int64_t ram_list_offset;
     /* vmstate offset of the first non-iterable device section */
qemu-snapshot-vm.c +480 -5

554 lines not on this page · raw message

qemu-snapshot.c +16 -0
index 92956623f7..29d954c5d6 100644
@@ -123,6 +123,10 @@ static void destroy_load_context(void)
 {
     StateLoadCtx *s = get_load_context();
 
+    if (s->has_rp_listen_thread) {
+        qemu_thread_join(&s->rp_listen_thread);
+    }
+
     if (s->f_vmstate) {
         qemu_fclose(s->f_vmstate);
     }
@@ -226,12 +230,16 @@ static void coroutine_fn snapshot_load_co(void *opaque)
 {
     StateLoadCtx *s = get_load_context();
     QIOChannel *ioc_fd;
+    QIOChannel *ioc_rp_fd;
     uint8_t *buf;
     size_t count;
     int res = -1;
 
     init_load_context();
 
+    s->postcopy = params.postcopy;
+    s->postcopy_percent = params.postcopy_percent;
+
     /* Block backend */
     s->blk = image_open_opts(params.blk_optstr, params.blk_options,
                              params.blk_flags);
@@ -250,6 +258,14 @@ static void coroutine_fn snapshot_load_co(void *opaque)
     object_unref(OBJECT(ioc_fd));
     qemu_file_set_blocking(s->f_fd, false);
 
+    /* QEMUFile on return path fd if we are going to use postcopy */
+    if (params.postcopy) {
+        ioc_rp_fd = qio_channel_new_fd(params.rp_fd, NULL);
+        qio_channel_set_name(QIO_CHANNEL(ioc_fd), "migration-channel-rp");
+        s->f_rp_fd = qemu_fopen_channel_input(ioc_rp_fd);
+        object_unref(OBJECT(ioc_rp_fd));
+    }
+
     /* Buffer channel to store leading part of migration stream */
     s->ioc_leader = qio_channel_buffer_new(INPLACE_READ_MAX);
     qio_channel_set_name(QIO_CHANNEL(s->ioc_leader), "migration-leader-buffer");
Signature · 1 line
2.27.0
#8 lore raw
In reply to Andrey Gruzdev
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [RFC PATCH v1 0/7] migration/snapshot: External snapshot utility

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu

   3158964..3e9f48b  master     -> master
 - [tag update]      patchew/[email protected] -> patchew/[email protected]
 * [new tag]         patchew/[email protected] -> patchew/[email protected]

Switched to a new branch 'test'
87d9eb7 migration/snapshot: Implementation of qemu-snapshot load path in postcopy mode dece241 migration/snapshot: Implementation of qemu-snapshot load path cbaa5b9 migration/snapshot: Implementation of qemu-snapshot save path f9dd5c5 migration/snapshot: Block layer AIO support in qemu-snapshot ed9b73d migration/snapshot: Move RAM_SAVE_FLAG_xxx defines to migration/ram.h 92f9263 migration/snapshot: Introduce qemu_ftell2() routine
32c347a migration/snapshot: Introduce qemu-snapshot tool

=== OUTPUT BEGIN ===
1/7 Checking commit 32c347a19ef4 (migration/snapshot: Introduce qemu-snapshot tool) Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#19:
new file mode 100644

WARNING: line over 80 characters
#227: FILE: qemu-snapshot.c:63:
+ int postcopy_percent; /* Start postcopy after % of normal pages loaded */

WARNING: line over 80 characters
#274: FILE: qemu-snapshot.c:110:
+static BlockBackend *image_open_opts(const char *optstr, QDict *options, int flags)

ERROR: switch and case should be at the same indent #414: FILE: qemu-snapshot.c:250:
+ switch (c) {
+ case '?':
[...]
+ case 'h':
[...]
+ case 'V':
[...]
+ case 'T':
[...]
+ case 'r':
[...]
+ case OPTION_POSTCOPY:
[...]
+ case OPTION_PAGE_SIZE:
[...]
+ case OPTION_URI:
[...]
+ default:

ERROR: trailing whitespace
#436: FILE: qemu-snapshot.c:272:
+ $

ERROR: consider using qemu_strtol in preference to strtol #449: FILE: qemu-snapshot.c:285:
+ postcopy_percent = strtol(optarg, &r, 10);

WARNING: line over 80 characters
#450: FILE: qemu-snapshot.c:286:
+ if (*r != '\0' || postcopy_percent < 0 || postcopy_percent > 100) {

ERROR: consider using qemu_strtol in preference to strtol #468: FILE: qemu-snapshot.c:304:
+ target_page_size = strtol(optarg, &r, 0);

WARNING: line over 80 characters
#469: FILE: qemu-snapshot.c:305:
+ if (*r != '\0' || (target_page_size & (target_page_size - 1)) != 0 ||

ERROR: space required after that ',' (ctx:VxV)
#494: FILE: qemu-snapshot.c:330:

+                    fd = strtol(p, &r,10);
                                      ^

ERROR: consider using qemu_strtol in preference to strtol #494: FILE: qemu-snapshot.c:330:
+ fd = strtol(p, &r,10);

total: 6 errors, 5 warnings, 563 lines checked

Patch 1/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

2/7 Checking commit 92f92637b84c (migration/snapshot: Introduce qemu_ftell2() routine) 3/7 Checking commit ed9b73da773a (migration/snapshot: Move RAM_SAVE_FLAG_xxx defines to migration/ram.h)
WARNING: Block comments use a leading /* on a separate line
#51: FILE: migration/ram.h:36:
+/* RAM_SAVE_FLAG_ZERO used to be named RAM_SAVE_FLAG_COMPRESS, it

total: 0 errors, 1 warnings, 44 lines checked

Patch 3/7 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
4/7 Checking commit f9dd5c542600 (migration/snapshot: Block layer AIO support in qemu-snapshot) Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#81:
new file mode 100644

total: 0 errors, 1 warnings, 314 lines checked

Patch 4/7 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
5/7 Checking commit cbaa5b9bd2a6 (migration/snapshot: Implementation of qemu-snapshot save path)
WARNING: line over 80 characters
#554: FILE: qemu-snapshot-vm.c:507:
+ error_report("RAM page with unknown combination of flags 0x%x", flags);

WARNING: line over 80 characters
#648: FILE: qemu-snapshot-vm.c:601:
+ (size_t)(ssize_t) (VMSTATE_HEADER_EOF_OFFSET - eof_pos));

WARNING: line over 80 characters
#832: FILE: qemu-snapshot-vm.c:783:
+ * Normally we will never get here since the ending part of migration

total: 0 errors, 3 warnings, 901 lines checked

Patch 5/7 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
6/7 Checking commit dece2418c08d (migration/snapshot: Implementation of qemu-snapshot load path)
ERROR: trailing whitespace
#296: FILE: qemu-snapshot-vm.c:996:
+ $

ERROR: switch and case should be at the same indent #435: FILE: qemu-snapshot-vm.c:1135:
+ switch (flags) {
+ case RAM_SAVE_FLAG_MEM_SIZE:
[...]
+ case RAM_SAVE_FLAG_EOS:
[...]
+ default:

WARNING: line over 80 characters
#446: FILE: qemu-snapshot-vm.c:1146:
+ error_report("Unknown combination of RAM page flags 0x%x", flags);

WARNING: line over 80 characters
#765: FILE: qemu-snapshot.c:258:
+ s->aio_ring = aio_ring_new(ram_load_aio_co, AIO_RING_SIZE, AIO_RING_INFLIGHT);

total: 2 errors, 2 warnings, 741 lines checked

Patch 6/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

7/7 Checking commit 87d9eb785185 (migration/snapshot: Implementation of qemu-snapshot load path in postcopy mode)
WARNING: line over 80 characters
#517: FILE: qemu-snapshot-vm.c:1272:
+ send_command(s->f_fd, MIG_CMD_PACKAGED, sizeof(length), (uint8_t *) &length);

WARNING: line over 80 characters
#603: FILE: qemu-snapshot-vm.c:1836:
+ if (!res && s->postcopy && !s->in_postcopy && is_postcopy_switchover(s)) {

total: 0 errors, 2 warnings, 628 lines checked

Patch 7/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]