For multifd we currently choose exclusively between migration using compression or migration without compression. The compression method is chosen via the multifd_compression parameter (none, zlib, zstd). We've been using the 'none' value to mean the regular socket migration.
Rename the 'multifd_ops' array to 'multifd_compression_ops' and move the 'nocomp_multifd_ops' out of it. We don't need to have the non-compression methods in an array because they are not registered dynamically and cannot be compiled out like the compression code. Rename the 'nocomp' functions to 'multifd_socket' and remove the comments which are useless IMHO. Next patch moves the functions into a socket specific file. Signed-off-by: Fabiano Rosas <faro...@suse.de> --- migration/multifd-zlib.c | 2 +- migration/multifd-zstd.c | 2 +- migration/multifd.c | 109 +++++++++++---------------------------- migration/multifd.h | 3 +- 4 files changed, 34 insertions(+), 82 deletions(-) diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 37ce48621e..d89163e975 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -319,7 +319,7 @@ static MultiFDMethods multifd_zlib_ops = { static void multifd_zlib_register(void) { - multifd_register_ops(MULTIFD_COMPRESSION_ZLIB, &multifd_zlib_ops); + multifd_register_compression(MULTIFD_COMPRESSION_ZLIB, &multifd_zlib_ops); } migration_init(multifd_zlib_register); diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index b471daadcd..a90788540e 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -310,7 +310,7 @@ static MultiFDMethods multifd_zstd_ops = { static void multifd_zstd_register(void) { - multifd_register_ops(MULTIFD_COMPRESSION_ZSTD, &multifd_zstd_ops); + multifd_register_compression(MULTIFD_COMPRESSION_ZSTD, &multifd_zstd_ops); } migration_init(multifd_zstd_register); diff --git a/migration/multifd.c b/migration/multifd.c index 25cbc6dc6b..2968649500 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -45,48 +45,17 @@ typedef struct { uint64_t unused2[4]; /* Reserved for future use */ } __attribute__((packed)) MultiFDInit_t; -/* Multifd without compression */ - -/** - * nocomp_send_setup: setup send side - * - * For no compression this function does nothing. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_send_setup(MultiFDSendParams *p, Error **errp) +static int multifd_socket_send_setup(MultiFDSendParams *p, Error **errp) { return 0; } -/** - * nocomp_send_cleanup: cleanup send side - * - * For no compression this function does nothing. - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp) +static void multifd_socket_send_cleanup(MultiFDSendParams *p, Error **errp) { return; } -/** - * nocomp_send_prepare: prepare date to be able to send - * - * For no compression we just have to calculate the size of the - * packet. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) +static int multifd_socket_send_prepare(MultiFDSendParams *p, Error **errp) { MultiFDPages_t *pages = p->pages; @@ -101,43 +70,16 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) return 0; } -/** - * nocomp_recv_setup: setup receive side - * - * For no compression this function does nothing. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_recv_setup(MultiFDRecvParams *p, Error **errp) +static int multifd_socket_recv_setup(MultiFDRecvParams *p, Error **errp) { return 0; } -/** - * nocomp_recv_cleanup: setup receive side - * - * For no compression this function does nothing. - * - * @p: Params for the channel that we are using - */ -static void nocomp_recv_cleanup(MultiFDRecvParams *p) +static void multifd_socket_recv_cleanup(MultiFDRecvParams *p) { } -/** - * nocomp_recv_pages: read the data from the channel into actual pages - * - * For no compression we just need to read things into the correct place. - * - * Returns 0 for success or -1 for error - * - * @p: Params for the channel that we are using - * @errp: pointer to an error - */ -static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp) +static int multifd_socket_recv_pages(MultiFDRecvParams *p, Error **errp) { uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK; @@ -153,23 +95,34 @@ static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp) return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); } -static MultiFDMethods multifd_nocomp_ops = { - .send_setup = nocomp_send_setup, - .send_cleanup = nocomp_send_cleanup, - .send_prepare = nocomp_send_prepare, - .recv_setup = nocomp_recv_setup, - .recv_cleanup = nocomp_recv_cleanup, - .recv_pages = nocomp_recv_pages +static MultiFDMethods multifd_socket_ops = { + .send_setup = multifd_socket_send_setup, + .send_cleanup = multifd_socket_send_cleanup, + .send_prepare = multifd_socket_send_prepare, + .recv_setup = multifd_socket_recv_setup, + .recv_cleanup = multifd_socket_recv_cleanup, + .recv_pages = multifd_socket_recv_pages }; -static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] = { - [MULTIFD_COMPRESSION_NONE] = &multifd_nocomp_ops, -}; +static MultiFDMethods *multifd_compression_ops[MULTIFD_COMPRESSION__MAX] = {0}; + +static MultiFDMethods *multifd_get_ops(void) +{ + MultiFDCompression comp = migrate_multifd_compression(); + + assert(comp < MULTIFD_COMPRESSION__MAX); + + if (comp != MULTIFD_COMPRESSION_NONE) { + return multifd_compression_ops[comp]; + } + + return &multifd_socket_ops; +} -void multifd_register_ops(int method, MultiFDMethods *ops) +void multifd_register_compression(int method, MultiFDMethods *ops) { assert(0 < method && method < MULTIFD_COMPRESSION__MAX); - multifd_ops[method] = ops; + multifd_compression_ops[method] = ops; } static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) @@ -915,7 +868,7 @@ int multifd_save_setup(Error **errp) multifd_send_state->pages = multifd_pages_init(page_count); qemu_sem_init(&multifd_send_state->channels_ready, 0); qatomic_set(&multifd_send_state->exiting, 0); - multifd_send_state->ops = multifd_ops[migrate_multifd_compression()]; + multifd_send_state->ops = multifd_get_ops(); for (i = 0; i < thread_count; i++) { MultiFDSendParams *p = &multifd_send_state->params[i]; @@ -1171,7 +1124,7 @@ int multifd_load_setup(Error **errp) multifd_recv_state->params = g_new0(MultiFDRecvParams, thread_count); qatomic_set(&multifd_recv_state->count, 0); qemu_sem_init(&multifd_recv_state->sem_sync, 0); - multifd_recv_state->ops = multifd_ops[migrate_multifd_compression()]; + multifd_recv_state->ops = multifd_get_ops(); for (i = 0; i < thread_count; i++) { MultiFDRecvParams *p = &multifd_recv_state->params[i]; diff --git a/migration/multifd.h b/migration/multifd.h index 35d11f103c..4630baccd4 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -204,7 +204,6 @@ typedef struct { int (*recv_pages)(MultiFDRecvParams *p, Error **errp); } MultiFDMethods; -void multifd_register_ops(int method, MultiFDMethods *ops); +void multifd_register_compression(int method, MultiFDMethods *ops); #endif - -- 2.35.3