• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision8be2094648f85acbd443ea0b5710e5988fda6741 (tree)
Time2019-06-06 18:51:19
AuthorPeter Maydell <peter.maydell@lina...>
CommiterPeter Maydell

Log Message

Migration Pull request
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEGJn/jt6/WMzuA0uC9IfvGFhy1yMFAlz3rOYACgkQ9IfvGFhy
1yNRkQ//TKkBVWhbKJ6yflOZce5VG72uoFrDl0jRZq/FvyhiXjvM27lF2/XTREhZ
0JgdAqE+LFCHrQQoGPNbSahsL+x+0haCgXUD6f2OoKVMXAd5cb0SsLo6JUucvtBE
7sBwE+AGI7iPgXjXtb2SYFhWauJaxmKATpSOdwuIjuI00il7bAfKt8CHTOoivVZr
yE4US5cFr/dI9zoHgxBLlOUjdSBc7e5RnFAOmDjFjr8qw+ix/WUqEpRzogFzfeqp
j4foeiQdiTegr56qN2LG9TUSu7dnmuyjJo72+D+4R2mxERTwlkfxxwG5/uXdxJSD
ZThqWhArvUooMykD9BRzsjfdBTaMGNKqFTIa/Ww2a2Q5OPutPZVVrRMsmAmSkipX
+ZsFjRxqrxpC+A/HcfhSJrMVqbNRz0xS40h3aOuE1pfySvFjatP1eQ+E/PwbJjf7
zifxE8Kez8ZK73RmN1BIp1kDOAgc0GtqJLEbkk7ln1PsxnS184Mpi3UAndaCVes+
r9ttDm4lKSJ7LP1/gIEJ7ivYWzk+f7D2aqTlwU3n8HIhSyr/JXxKGhm363yNOfI5
uj1MU2e788/J/tLnVULVGmfnGWLwJXzou5dGF8BMLMy7MIvNF0H1Wf5Dl1oLpqEU
k7syQ/N5OyVBUEtS5c86R0YabT711OoUA3SL6RP7OiSAjz1pxgE=
=/CLD
-----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/juanquintela/tags/migration-pull-request' into staging

Migration Pull request

# gpg: Signature made Wed 05 Jun 2019 12:52:06 BST
# gpg: using RSA key 1899FF8EDEBF58CCEE034B82F487EF185872D723
# gpg: Good signature from "Juan Quintela <quintela@redhat.com>" [full]
# gpg: aka "Juan Quintela <quintela@trasno.org>" [full]
# Primary key fingerprint: 1899 FF8E DEBF 58CC EE03 4B82 F487 EF18 5872 D723

* remotes/juanquintela/tags/migration-pull-request:

migratioin/ram: leave RAMBlock->bmap blank on allocating
migration-test: Add a test for fd protocol
migration: Fix fd protocol for incoming defer
migration/ram.c: multifd_send_state->count is not really used
migration/ram.c: MultiFDSendParams.sem_sync is not really used

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Change Summary

Incremental Difference

--- a/migration/fd.c
+++ b/migration/fd.c
@@ -52,12 +52,14 @@ static gboolean fd_accept_incoming_migration(QIOChannel *ioc,
5252 return G_SOURCE_REMOVE;
5353 }
5454
55-void fd_start_incoming_migration(const char *infd, Error **errp)
55+void fd_start_incoming_migration(const char *fdname, Error **errp)
5656 {
5757 QIOChannel *ioc;
58- int fd;
58+ int fd = monitor_fd_param(cur_mon, fdname, errp);
59+ if (fd == -1) {
60+ return;
61+ }
5962
60- fd = strtol(infd, NULL, 0);
6163 trace_migration_fd_incoming(fd);
6264
6365 ioc = qio_channel_new_fd(fd, errp);
--- a/migration/fd.h
+++ b/migration/fd.h
@@ -16,7 +16,7 @@
1616
1717 #ifndef QEMU_MIGRATION_FD_H
1818 #define QEMU_MIGRATION_FD_H
19-void fd_start_incoming_migration(const char *path, Error **errp);
19+void fd_start_incoming_migration(const char *fdname, Error **errp);
2020
2121 void fd_start_outgoing_migration(MigrationState *s, const char *fdname,
2222 Error **errp);
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -661,8 +661,6 @@ typedef struct {
661661 uint64_t num_packets;
662662 /* pages sent through this channel */
663663 uint64_t num_pages;
664- /* syncs main thread and channels */
665- QemuSemaphore sem_sync;
666664 } MultiFDSendParams;
667665
668666 typedef struct {
@@ -894,8 +892,6 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
894892
895893 struct {
896894 MultiFDSendParams *params;
897- /* number of created threads */
898- int count;
899895 /* array of pages to sent */
900896 MultiFDPages_t *pages;
901897 /* syncs main thread and channels */
@@ -1027,7 +1023,6 @@ void multifd_save_cleanup(void)
10271023 p->c = NULL;
10281024 qemu_mutex_destroy(&p->mutex);
10291025 qemu_sem_destroy(&p->sem);
1030- qemu_sem_destroy(&p->sem_sync);
10311026 g_free(p->name);
10321027 p->name = NULL;
10331028 multifd_pages_clear(p->pages);
@@ -1174,8 +1169,6 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
11741169 p->running = true;
11751170 qemu_thread_create(&p->thread, p->name, multifd_send_thread, p,
11761171 QEMU_THREAD_JOINABLE);
1177-
1178- atomic_inc(&multifd_send_state->count);
11791172 }
11801173 }
11811174
@@ -1191,7 +1184,6 @@ int multifd_save_setup(void)
11911184 thread_count = migrate_multifd_channels();
11921185 multifd_send_state = g_malloc0(sizeof(*multifd_send_state));
11931186 multifd_send_state->params = g_new0(MultiFDSendParams, thread_count);
1194- atomic_set(&multifd_send_state->count, 0);
11951187 multifd_send_state->pages = multifd_pages_init(page_count);
11961188 qemu_sem_init(&multifd_send_state->sem_sync, 0);
11971189 qemu_sem_init(&multifd_send_state->channels_ready, 0);
@@ -1201,7 +1193,6 @@ int multifd_save_setup(void)
12011193
12021194 qemu_mutex_init(&p->mutex);
12031195 qemu_sem_init(&p->sem, 0);
1204- qemu_sem_init(&p->sem_sync, 0);
12051196 p->quit = false;
12061197 p->pending_job = 0;
12071198 p->id = i;
@@ -3182,11 +3173,11 @@ static int ram_state_init(RAMState **rsp)
31823173 QSIMPLEQ_INIT(&(*rsp)->src_page_requests);
31833174
31843175 /*
3185- * Count the total number of pages used by ram blocks not including any
3186- * gaps due to alignment or unplugs.
3176+ * This must match with the initial values of dirty bitmap.
3177+ * Currently we initialize the dirty bitmap to all zeros so
3178+ * here the total dirty page count is zero.
31873179 */
3188- (*rsp)->migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
3189-
3180+ (*rsp)->migration_dirty_pages = 0;
31903181 ram_state_reset(*rsp);
31913182
31923183 return 0;
@@ -3201,8 +3192,16 @@ static void ram_list_init_bitmaps(void)
32013192 if (ram_bytes_total()) {
32023193 RAMBLOCK_FOREACH_NOT_IGNORED(block) {
32033194 pages = block->max_length >> TARGET_PAGE_BITS;
3195+ /*
3196+ * The initial dirty bitmap for migration must be set with all
3197+ * ones to make sure we'll migrate every guest RAM page to
3198+ * destination.
3199+ * Here we didn't set RAMBlock.bmap simply because it is already
3200+ * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in
3201+ * ram_block_add, and that's where we'll sync the dirty bitmaps.
3202+ * Here setting RAMBlock.bmap would be fine too but not necessary.
3203+ */
32043204 block->bmap = bitmap_new(pages);
3205- bitmap_set(block->bmap, 0, pages);
32063205 if (migrate_postcopy_ram()) {
32073206 block->unsentmap = bitmap_new(pages);
32083207 bitmap_set(block->unsentmap, 0, pages);
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -32,6 +32,7 @@
3232
3333 #define MAX_IRQ 256
3434 #define SOCKET_TIMEOUT 50
35+#define SOCKET_MAX_FDS 16
3536
3637 QTestState *global_qtest;
3738
@@ -391,6 +392,40 @@ static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
391392 va_end(ap);
392393 }
393394
395+/* Sends a message and file descriptors to the socket.
396+ * It's needed for qmp-commands like getfd/add-fd */
397+static void socket_send_fds(int socket_fd, int *fds, size_t fds_num,
398+ const char *buf, size_t buf_size)
399+{
400+ ssize_t ret;
401+ struct msghdr msg = { 0 };
402+ char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 };
403+ size_t fdsize = sizeof(int) * fds_num;
404+ struct cmsghdr *cmsg;
405+ struct iovec iov = { .iov_base = (char *)buf, .iov_len = buf_size };
406+
407+ msg.msg_iov = &iov;
408+ msg.msg_iovlen = 1;
409+
410+ if (fds && fds_num > 0) {
411+ g_assert_cmpuint(fds_num, <, SOCKET_MAX_FDS);
412+
413+ msg.msg_control = control;
414+ msg.msg_controllen = CMSG_SPACE(fdsize);
415+
416+ cmsg = CMSG_FIRSTHDR(&msg);
417+ cmsg->cmsg_len = CMSG_LEN(fdsize);
418+ cmsg->cmsg_level = SOL_SOCKET;
419+ cmsg->cmsg_type = SCM_RIGHTS;
420+ memcpy(CMSG_DATA(cmsg), fds, fdsize);
421+ }
422+
423+ do {
424+ ret = sendmsg(socket_fd, &msg, 0);
425+ } while (ret < 0 && errno == EINTR);
426+ g_assert_cmpint(ret, >, 0);
427+}
428+
394429 static GString *qtest_recv_line(QTestState *s)
395430 {
396431 GString *line;
@@ -545,7 +580,8 @@ QDict *qtest_qmp_receive(QTestState *s)
545580 * in the case that they choose to discard all replies up until
546581 * a particular EVENT is received.
547582 */
548-void qmp_fd_vsend(int fd, const char *fmt, va_list ap)
583+void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
584+ const char *fmt, va_list ap)
549585 {
550586 QObject *qobj;
551587
@@ -569,25 +605,49 @@ void qmp_fd_vsend(int fd, const char *fmt, va_list ap)
569605 fprintf(stderr, "%s", str);
570606 }
571607 /* Send QMP request */
572- socket_send(fd, str, qstring_get_length(qstr));
608+ if (fds && fds_num > 0) {
609+ socket_send_fds(fd, fds, fds_num, str, qstring_get_length(qstr));
610+ } else {
611+ socket_send(fd, str, qstring_get_length(qstr));
612+ }
573613
574614 qobject_unref(qstr);
575615 qobject_unref(qobj);
576616 }
577617 }
578618
619+void qmp_fd_vsend(int fd, const char *fmt, va_list ap)
620+{
621+ qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
622+}
623+
624+void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
625+ const char *fmt, va_list ap)
626+{
627+ qmp_fd_vsend_fds(s->qmp_fd, fds, fds_num, fmt, ap);
628+}
629+
579630 void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
580631 {
581- qmp_fd_vsend(s->qmp_fd, fmt, ap);
632+ qmp_fd_vsend_fds(s->qmp_fd, NULL, 0, fmt, ap);
582633 }
583634
584635 QDict *qmp_fdv(int fd, const char *fmt, va_list ap)
585636 {
586- qmp_fd_vsend(fd, fmt, ap);
637+ qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
587638
588639 return qmp_fd_receive(fd);
589640 }
590641
642+QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
643+ const char *fmt, va_list ap)
644+{
645+ qtest_qmp_vsend_fds(s, fds, fds_num, fmt, ap);
646+
647+ /* Receive reply */
648+ return qtest_qmp_receive(s);
649+}
650+
591651 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
592652 {
593653 qtest_qmp_vsend(s, fmt, ap);
@@ -616,6 +676,18 @@ void qmp_fd_send(int fd, const char *fmt, ...)
616676 va_end(ap);
617677 }
618678
679+QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
680+ const char *fmt, ...)
681+{
682+ va_list ap;
683+ QDict *response;
684+
685+ va_start(ap, fmt);
686+ response = qtest_vqmp_fds(s, fds, fds_num, fmt, ap);
687+ va_end(ap);
688+ return response;
689+}
690+
619691 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
620692 {
621693 va_list ap;
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -85,6 +85,21 @@ QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
8585 void qtest_quit(QTestState *s);
8686
8787 /**
88+ * qtest_qmp_fds:
89+ * @s: #QTestState instance to operate on.
90+ * @fds: array of file descriptors
91+ * @fds_num: number of elements in @fds
92+ * @fmt...: QMP message to send to qemu, formatted like
93+ * qobject_from_jsonf_nofail(). See parse_escape() for what's
94+ * supported after '%'.
95+ *
96+ * Sends a QMP message to QEMU with fds and returns the response.
97+ */
98+QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
99+ const char *fmt, ...)
100+ GCC_FMT_ATTR(4, 5);
101+
102+/**
88103 * qtest_qmp:
89104 * @s: #QTestState instance to operate on.
90105 * @fmt...: QMP message to send to qemu, formatted like
@@ -120,7 +135,23 @@ void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
120135 GCC_FMT_ATTR(2, 3);
121136
122137 /**
123- * qtest_qmpv:
138+ * qtest_vqmp_fds:
139+ * @s: #QTestState instance to operate on.
140+ * @fds: array of file descriptors
141+ * @fds_num: number of elements in @fds
142+ * @fmt: QMP message to send to QEMU, formatted like
143+ * qobject_from_jsonf_nofail(). See parse_escape() for what's
144+ * supported after '%'.
145+ * @ap: QMP message arguments
146+ *
147+ * Sends a QMP message to QEMU with fds and returns the response.
148+ */
149+QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
150+ const char *fmt, va_list ap)
151+ GCC_FMT_ATTR(4, 0);
152+
153+/**
154+ * qtest_vqmp:
124155 * @s: #QTestState instance to operate on.
125156 * @fmt: QMP message to send to QEMU, formatted like
126157 * qobject_from_jsonf_nofail(). See parse_escape() for what's
@@ -133,6 +164,22 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
133164 GCC_FMT_ATTR(2, 0);
134165
135166 /**
167+ * qtest_qmp_vsend_fds:
168+ * @s: #QTestState instance to operate on.
169+ * @fds: array of file descriptors
170+ * @fds_num: number of elements in @fds
171+ * @fmt: QMP message to send to QEMU, formatted like
172+ * qobject_from_jsonf_nofail(). See parse_escape() for what's
173+ * supported after '%'.
174+ * @ap: QMP message arguments
175+ *
176+ * Sends a QMP message to QEMU and leaves the response in the stream.
177+ */
178+void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
179+ const char *fmt, va_list ap)
180+ GCC_FMT_ATTR(4, 0);
181+
182+/**
136183 * qtest_qmp_vsend:
137184 * @s: #QTestState instance to operate on.
138185 * @fmt: QMP message to send to QEMU, formatted like
@@ -888,6 +935,8 @@ static inline int64_t clock_step(int64_t step)
888935 }
889936
890937 QDict *qmp_fd_receive(int fd);
938+void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
939+ const char *fmt, va_list ap) GCC_FMT_ATTR(4, 0);
891940 void qmp_fd_vsend(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
892941 void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
893942 void qmp_fd_send_raw(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -177,6 +177,21 @@ static void stop_cb(void *opaque, const char *name, QDict *data)
177177 /*
178178 * Events can get in the way of responses we are actually waiting for.
179179 */
180+GCC_FMT_ATTR(3, 4)
181+static QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...)
182+{
183+ va_list ap;
184+
185+ va_start(ap, command);
186+ qtest_qmp_vsend_fds(who, &fd, 1, command, ap);
187+ va_end(ap);
188+
189+ return qtest_qmp_receive_success(who, stop_cb, NULL);
190+}
191+
192+/*
193+ * Events can get in the way of responses we are actually waiting for.
194+ */
180195 GCC_FMT_ATTR(2, 3)
181196 static QDict *wait_command(QTestState *who, const char *command, ...)
182197 {
@@ -480,6 +495,7 @@ static void migrate(QTestState *who, const char *uri, const char *fmt, ...)
480495 qdict_put_str(args, "uri", uri);
481496
482497 rsp = qmp("{ 'execute': 'migrate', 'arguments': %p}", args);
498+
483499 g_assert(qdict_haskey(rsp, "return"));
484500 qobject_unref(rsp);
485501 }
@@ -1027,6 +1043,90 @@ static void test_precopy_tcp(void)
10271043 g_free(uri);
10281044 }
10291045
1046+static void test_migrate_fd_proto(void)
1047+{
1048+ QTestState *from, *to;
1049+ int ret;
1050+ int pair[2];
1051+ QDict *rsp;
1052+ const char *error_desc;
1053+
1054+ if (test_migrate_start(&from, &to, "defer", false, false)) {
1055+ return;
1056+ }
1057+
1058+ /*
1059+ * We want to pick a speed slow enough that the test completes
1060+ * quickly, but that it doesn't complete precopy even on a slow
1061+ * machine, so also set the downtime.
1062+ */
1063+ /* 1 ms should make it not converge */
1064+ migrate_set_parameter(from, "downtime-limit", 1);
1065+ /* 1GB/s */
1066+ migrate_set_parameter(from, "max-bandwidth", 1000000000);
1067+
1068+ /* Wait for the first serial output from the source */
1069+ wait_for_serial("src_serial");
1070+
1071+ /* Create two connected sockets for migration */
1072+ ret = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair);
1073+ g_assert_cmpint(ret, ==, 0);
1074+
1075+ /* Send the 1st socket to the target */
1076+ rsp = wait_command_fd(to, pair[0],
1077+ "{ 'execute': 'getfd',"
1078+ " 'arguments': { 'fdname': 'fd-mig' }}");
1079+ qobject_unref(rsp);
1080+ close(pair[0]);
1081+
1082+ /* Start incoming migration from the 1st socket */
1083+ rsp = wait_command(to, "{ 'execute': 'migrate-incoming',"
1084+ " 'arguments': { 'uri': 'fd:fd-mig' }}");
1085+ qobject_unref(rsp);
1086+
1087+ /* Send the 2nd socket to the target */
1088+ rsp = wait_command_fd(from, pair[1],
1089+ "{ 'execute': 'getfd',"
1090+ " 'arguments': { 'fdname': 'fd-mig' }}");
1091+ qobject_unref(rsp);
1092+ close(pair[1]);
1093+
1094+ /* Start migration to the 2nd socket*/
1095+ migrate(from, "fd:fd-mig", "{}");
1096+
1097+ wait_for_migration_pass(from);
1098+
1099+ /* 300ms should converge */
1100+ migrate_set_parameter(from, "downtime-limit", 300);
1101+
1102+ if (!got_stop) {
1103+ qtest_qmp_eventwait(from, "STOP");
1104+ }
1105+ qtest_qmp_eventwait(to, "RESUME");
1106+
1107+ /* Test closing fds */
1108+ /* We assume, that QEMU removes named fd from its list,
1109+ * so this should fail */
1110+ rsp = qtest_qmp(from, "{ 'execute': 'closefd',"
1111+ " 'arguments': { 'fdname': 'fd-mig' }}");
1112+ g_assert_true(qdict_haskey(rsp, "error"));
1113+ error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
1114+ g_assert_cmpstr(error_desc, ==, "File descriptor named 'fd-mig' not found");
1115+ qobject_unref(rsp);
1116+
1117+ rsp = qtest_qmp(to, "{ 'execute': 'closefd',"
1118+ " 'arguments': { 'fdname': 'fd-mig' }}");
1119+ g_assert_true(qdict_haskey(rsp, "error"));
1120+ error_desc = qdict_get_str(qdict_get_qdict(rsp, "error"), "desc");
1121+ g_assert_cmpstr(error_desc, ==, "File descriptor named 'fd-mig' not found");
1122+ qobject_unref(rsp);
1123+
1124+ /* Complete migration */
1125+ wait_for_serial("dest_serial");
1126+ wait_for_migration_complete(from);
1127+ test_migrate_end(from, to, true);
1128+}
1129+
10301130 int main(int argc, char **argv)
10311131 {
10321132 char template[] = "/tmp/migration-test-XXXXXX";
@@ -1081,6 +1181,7 @@ int main(int argc, char **argv)
10811181 qtest_add_func("/migration/precopy/tcp", test_precopy_tcp);
10821182 /* qtest_add_func("/migration/ignore_shared", test_ignore_shared); */
10831183 qtest_add_func("/migration/xbzrle/unix", test_xbzrle_unix);
1184+ qtest_add_func("/migration/fd_proto", test_migrate_fd_proto);
10841185
10851186 ret = g_test_run();
10861187