Skip to content

Commit b7acd65

Browse files
zhijianli88Juan Quintela
authored andcommitted
migration: allow multifd for socket protocol only
To: <[email protected]>, <[email protected]>, <[email protected]> CC: Li Zhijian <[email protected]> Date: Sat, 31 Jul 2021 22:05:51 +0800 (5 weeks, 4 days, 17 hours ago) multifd with unsupported protocol will cause a segment fault. (gdb) bt #0 0x0000563b4a93faf8 in socket_connect (addr=0x0, errp=0x7f7f02675410) at ../util/qemu-sockets.c:1190 #1 0x0000563b4a797a03 in qio_channel_socket_connect_sync (ioc=0x563b4d16e8c0, addr=0x0, errp=0x7f7f02675410) at ../io/channel-socket.c:145 #2 0x0000563b4a797abf in qio_channel_socket_connect_worker (task=0x563b4cd86c30, opaque=0x0) at ../io/channel-socket.c:168 #3 0x0000563b4a792631 in qio_task_thread_worker (opaque=0x563b4cd86c30) at ../io/task.c:124 #4 0x0000563b4a91da69 in qemu_thread_start (args=0x563b4c44bb80) at ../util/qemu-thread-posix.c:541 qemu#5 0x00007f7fe9b5b3f9 in ?? () qemu#6 0x0000000000000000 in ?? () It's enough to check migrate_multifd_is_allowed() in multifd cleanup() and multifd setup() though there are so many other places using migrate_use_multifd(). Signed-off-by: Li Zhijian <[email protected]> Reviewed-by: Juan Quintela <[email protected]> Signed-off-by: Juan Quintela <[email protected]>
1 parent 1230a25 commit b7acd65

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

migration/migration.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,12 @@ static void qemu_start_incoming_migration(const char *uri, Error **errp)
453453
{
454454
const char *p = NULL;
455455

456+
migrate_protocol_allow_multifd(false); /* reset it anyway */
456457
qapi_event_send_migration(MIGRATION_STATUS_SETUP);
457458
if (strstart(uri, "tcp:", &p) ||
458459
strstart(uri, "unix:", NULL) ||
459460
strstart(uri, "vsock:", NULL)) {
461+
migrate_protocol_allow_multifd(true);
460462
socket_start_incoming_migration(p ? p : uri, errp);
461463
#ifdef CONFIG_RDMA
462464
} else if (strstart(uri, "rdma:", &p)) {
@@ -2280,9 +2282,11 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
22802282
}
22812283
}
22822284

2285+
migrate_protocol_allow_multifd(false);
22832286
if (strstart(uri, "tcp:", &p) ||
22842287
strstart(uri, "unix:", NULL) ||
22852288
strstart(uri, "vsock:", NULL)) {
2289+
migrate_protocol_allow_multifd(true);
22862290
socket_start_outgoing_migration(s, p ? p : uri, &local_err);
22872291
#ifdef CONFIG_RDMA
22882292
} else if (strstart(uri, "rdma:", &p)) {

migration/multifd.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void multifd_save_cleanup(void)
531531
{
532532
int i;
533533

534-
if (!migrate_use_multifd()) {
534+
if (!migrate_use_multifd() || !migrate_multifd_is_allowed()) {
535535
return;
536536
}
537537
multifd_send_terminate_threads(NULL);
@@ -868,6 +868,17 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
868868
multifd_new_send_channel_cleanup(p, sioc, local_err);
869869
}
870870

871+
static bool migrate_allow_multifd;
872+
void migrate_protocol_allow_multifd(bool allow)
873+
{
874+
migrate_allow_multifd = allow;
875+
}
876+
877+
bool migrate_multifd_is_allowed(void)
878+
{
879+
return migrate_allow_multifd;
880+
}
881+
871882
int multifd_save_setup(Error **errp)
872883
{
873884
int thread_count;
@@ -878,6 +889,11 @@ int multifd_save_setup(Error **errp)
878889
if (!migrate_use_multifd()) {
879890
return 0;
880891
}
892+
if (!migrate_multifd_is_allowed()) {
893+
error_setg(errp, "multifd is not supported by current protocol");
894+
return -1;
895+
}
896+
881897
s = migrate_get_current();
882898
thread_count = migrate_multifd_channels();
883899
multifd_send_state = g_malloc0(sizeof(*multifd_send_state));
@@ -971,7 +987,7 @@ int multifd_load_cleanup(Error **errp)
971987
{
972988
int i;
973989

974-
if (!migrate_use_multifd()) {
990+
if (!migrate_use_multifd() || !migrate_multifd_is_allowed()) {
975991
return 0;
976992
}
977993
multifd_recv_terminate_threads(NULL);
@@ -1120,6 +1136,10 @@ int multifd_load_setup(Error **errp)
11201136
if (!migrate_use_multifd()) {
11211137
return 0;
11221138
}
1139+
if (!migrate_multifd_is_allowed()) {
1140+
error_setg(errp, "multifd is not supported by current protocol");
1141+
return -1;
1142+
}
11231143
thread_count = migrate_multifd_channels();
11241144
multifd_recv_state = g_malloc0(sizeof(*multifd_recv_state));
11251145
multifd_recv_state->params = g_new0(MultiFDRecvParams, thread_count);

migration/multifd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef QEMU_MIGRATION_MULTIFD_H
1414
#define QEMU_MIGRATION_MULTIFD_H
1515

16+
bool migrate_multifd_is_allowed(void);
17+
void migrate_protocol_allow_multifd(bool allow);
1618
int multifd_save_setup(Error **errp);
1719
void multifd_save_cleanup(void);
1820
int multifd_load_setup(Error **errp);

0 commit comments

Comments
 (0)