Skip to contentSkip to conversation

migration: Support gtree migration

PATCH Superseded Eric Auger 2 participants 3 messages Oct 3, 2019

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH 1/1 migration: Support gtree migration

Introduce support for GTree migration. A custom save/restore is implemented. Each item is made of a key and a data. For that reason, 2 VMSD objects are passed into the GTree VMStateField.

When putting the items, the tree is traversed in sorted order by g_tree_foreach.

On the get() path, gtrees must be allocated using the proper key compare, key destroy and value destroy. This can be done externally of automatically. If done automatically, the set of functions must be stored within the VMStateField in a new opaque pointer.

Automatic allocation is needed for complex state save/restore. For instance the virtio-iommu uses a gtree of domain and each domain has a gtree of mappings.

Special care was taken about direct key (ie. when the key is not a pointer to an object but is directly a value).

Tests are added to test save/dump of structs containing gtrees including the virtio-iommu domain/mappings scenario.

---
 include/migration/vmstate.h |  31 +++
 migration/trace-events      |   6 +
 migration/vmstate-types.c   | 133 ++++++++++++
 tests/test-vmstate.c        | 422 ++++++++++++++++++++++++++++++++++++
 4 files changed, 592 insertions(+)
include/migration/vmstate.h +31 -0
index 1fbfd099dd..4d9698eaab 100644
@@ -171,6 +171,7 @@ struct VMStateField {
     int version_id;
     int struct_version_id;
     bool (*field_exists)(void *opaque, int version_id);
+    void *data;
 };
 
 struct VMStateDescription {
@@ -224,6 +225,7 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 extern const VMStateInfo vmstate_info_tmp;
 extern const VMStateInfo vmstate_info_bitmap;
 extern const VMStateInfo vmstate_info_qtailq;
+extern const VMStateInfo vmstate_info_gtree;
 
 #define type_check_2darray(t1,t2,n,m) ((t1(*)[n][m])0 - (t2*)0)
 /*
@@ -754,6 +756,35 @@ extern const VMStateInfo vmstate_info_qtailq;
     .start        = offsetof(_type, _next),                              \
 }
 
+typedef struct GTreeInitData {
+    GCompareDataFunc key_compare_func;
+    gpointer key_compare_data;
+    GDestroyNotify key_destroy_func;
+    GDestroyNotify value_destroy_func;
+} GTreeInitData;
+
+/*
+ * For migrating a GTree.
+ * _vmsd: Start address of the 2 element array containing the key vmsd
+ *        and the data vmsd
+ * _key_type: type of the key
+ * _val_type: type of the value
+ * _data: pointer to a GTreeInitData struct
+ * if _data is NULL, the target tree must have been properly initialized
+ */
+#define VMSTATE_GTREE_V(_field, _state, _version, _vmsd,                       \
+                        _key_type, _val_type, _data)                           \
+{                                                                              \
+    .name         = (stringify(_field)),                                       \
+    .version_id   = (_version),                                                \
+    .vmsd         = (_vmsd),                                                   \
+    .info         = &vmstate_info_gtree,                                       \
+    .start        = sizeof(_key_type),                                         \
+    .size         = sizeof(_val_type),                                         \
+    .offset       = offsetof(_state, _field),                                  \
+    .data         = (_data)                                                    \
+}
+
 /* _f : field name
    _f_n : num of elements field_name
    _n : num of elements
migration/trace-events +6 -0
index 858d415d56..3e2775bd3b 100644
@@ -71,6 +71,12 @@ get_qtailq_end(const char *name, const char *reason, int val) "%s %s/%d"
 put_qtailq(const char *name, int version_id) "%s v%d"
 put_qtailq_end(const char *name, const char *reason) "%s %s"
 
+get_gtree(const char *key_name, const char *val_name, int version) "%s/%s %d"
+get_gtree_fail(const char *key_name, const char *reason, int val) "%s %s/%d"
+get_gtree_succeed(const char *key_name, const char *val_name, const char *reason, int val) "%s/%s %s/%d"
+put_gtree(const char *key_name, int key_version, const char *val_name, int val_version) "%s(%d)/%s(%d)"
+put_gtree_end(const char *key_name, const char *val_name, const char *reason) "%s/%s %s"
+
 # qemu-file.c
 qemu_file_fclose(void) ""
 
migration/vmstate-types.c +133 -0

142 lines not on this page · raw message

tests/test-vmstate.c +422 -0

440 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

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

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

  CC      tests/test-io-channel-command.o
  CC      tests/test-io-channel-buffer.o
  CC      tests/test-base64.o

/tmp/qemu-test/src/tests/test-vmstate.c:852:5: error: initializer element is not constant
vmstate_interval, /* key */
^
/tmp/qemu-test/src/tests/test-vmstate.c:852:5: error: (near initialization for 'vmstate_interval_mapping[0]')
/tmp/qemu-test/src/tests/test-vmstate.c:854:1: error: initializer element is not constant
};
^
/tmp/qemu-test/src/tests/test-vmstate.c:854:1: error: (near initialization for 'vmstate_interval_mapping[1]')
/tmp/qemu-test/src/tests/test-vmstate.c:928:1: error: initializer element is not constant
};
^
/tmp/qemu-test/src/tests/test-vmstate.c:928:1: error: (near initialization for 'vmstate_id_domain[1]')
make: *** [tests/test-vmstate.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 662, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=29beec1022b5489dac47067d0e745111', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-6cgndvkd/src/docker-src.2019-10-03-08.31.37.22540:/var/tmp/qemu:z,ro', 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=29beec1022b5489dac47067d0e745111
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-6cgndvkd/src'
make: *** [docker-run-test-quick@centos7] Error 2

real 4m2.336s
user 0m7.389s

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

#2 lore raw
In reply to Eric Auger
Patchew URL: https://patchew.org/QEMU/[email protected]/

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

Hi,

This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===

CC net/net.o
CC net/queue.o
/tmp/qemu-test/src/migration/vmstate-types.c: In function 'put_gtree_elem':
/tmp/qemu-test/src/migration/vmstate-types.c:714:26: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]

         qemu_put_be64(f, (uint64_t)key);
                          ^
/tmp/qemu-test/src/migration/vmstate-types.c: In function 'put_gtree':
/tmp/qemu-test/src/migration/vmstate-types.c:735:19: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
     GTree *tree = (GTree *)(*pval);
                   ^
/tmp/qemu-test/src/migration/vmstate-types.c: In function 'get_gtree':
/tmp/qemu-test/src/migration/vmstate-types.c:789:17: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
         *pval = (uint64_t)tree;
                 ^
/tmp/qemu-test/src/migration/vmstate-types.c:792:16: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
         tree = (GTree *)(*pval);
                ^
/tmp/qemu-test/src/migration/vmstate-types.c:797:19: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
             key = (gpointer)qemu_get_be64(f);
                   ^

cc1: all warnings being treated as errors
make: *** [/tmp/qemu-test/src/rules.mak:69: migration/vmstate-types.o] Error 1
make: *** Waiting for unfinished jobs....
Traceback (most recent call last):
File "./tests/docker/docker.py", line 662, in <module>
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', '--label', 'com.qemu.instance.uuid=c0e78400ef584686b547174a1de2761f', '-u', '1003', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/home/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-d9wvmd6u/src/docker-src.2019-10-03-08.36.16.14842:/var/tmp/qemu:z,ro', 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit status 2. filter=--filter=label=com.qemu.instance.uuid=c0e78400ef584686b547174a1de2761f
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-d9wvmd6u/src'
make: *** [docker-run-test-mingw@fedora] Error 2

real 10m59.834s
user 0m8.062s

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