diff mbox series

[v4,15/16] migration/multifd: Register nocomp ops dynamically

Message ID 20240823173911.6712-16-farosas@suse.de
State New
Headers show
Series migration/multifd: Remove multifd_send_state->pages | expand

Commit Message

Fabiano Rosas Aug. 23, 2024, 5:39 p.m. UTC
Prior to moving the ram code into multifd-nocomp.c, change the code to
register the nocomp ops dynamically so we don't need to have the ops
structure defined in multifd.c.

While here, move the ops struct initialization to the end of the file
to make the next diff cleaner.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 migration/multifd.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Comments

Philippe Mathieu-Daudé Aug. 26, 2024, 6:32 a.m. UTC | #1
On 23/8/24 19:39, Fabiano Rosas wrote:
> Prior to moving the ram code into multifd-nocomp.c, change the code to
> register the nocomp ops dynamically so we don't need to have the ops
> structure defined in multifd.c.
> 
> While here, move the ops struct initialization to the end of the file
> to make the next diff cleaner.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>   migration/multifd.c | 32 +++++++++++++++++++-------------
>   1 file changed, 19 insertions(+), 13 deletions(-)


> +static MultiFDMethods multifd_nocomp_ops = {

As a follow up cleanup, have multifd_register_ops() take a
const MultiFDMethods*, making these arrays also const.

> +    .send_setup = multifd_nocomp_send_setup,
> +    .send_cleanup = multifd_nocomp_send_cleanup,
> +    .send_prepare = multifd_nocomp_send_prepare,
> +    .recv_setup = multifd_nocomp_recv_setup,
> +    .recv_cleanup = multifd_nocomp_recv_cleanup,
> +    .recv = multifd_nocomp_recv
> +};
> +
> +static void multifd_nocomp_register(void)
> +{
> +    multifd_register_ops(MULTIFD_COMPRESSION_NONE, &multifd_nocomp_ops);
> +}
> +
> +migration_init(multifd_nocomp_register);
Prasad Pandit Aug. 26, 2024, 11:18 a.m. UTC | #2
On Fri, 23 Aug 2024 at 23:12, Fabiano Rosas <farosas@suse.de> wrote:
> Prior to moving the ram code into multifd-nocomp.c, change the code to
> register the nocomp ops dynamically so we don't need to have the ops
> structure defined in multifd.c.
>
> While here, move the ops struct initialization to the end of the file
> to make the next diff cleaner.
>
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>  migration/multifd.c | 32 +++++++++++++++++++-------------
>  1 file changed, 19 insertions(+), 13 deletions(-)
>
> diff --git a/migration/multifd.c b/migration/multifd.c
> index 9f40bb2f16..e100836cbe 100644
> --- a/migration/multifd.c
> +++ b/migration/multifd.c
> @@ -287,22 +287,12 @@ static int multifd_nocomp_recv(MultiFDRecvParams *p, Error **errp)
>      return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp);
>  }
>
> -static MultiFDMethods multifd_nocomp_ops = {
> -    .send_setup = multifd_nocomp_send_setup,
> -    .send_cleanup = multifd_nocomp_send_cleanup,
> -    .send_prepare = multifd_nocomp_send_prepare,
> -    .recv_setup = multifd_nocomp_recv_setup,
> -    .recv_cleanup = multifd_nocomp_recv_cleanup,
> -    .recv = multifd_nocomp_recv
> -};
> -
> -static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] = {
> -    [MULTIFD_COMPRESSION_NONE] = &multifd_nocomp_ops,
> -};
> +static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] = {};
>
>  void multifd_register_ops(int method, MultiFDMethods *ops)
>  {
> -    assert(0 < method && method < MULTIFD_COMPRESSION__MAX);
> +    assert(0 <= method && method < MULTIFD_COMPRESSION__MAX);
> +    assert(!multifd_ops[method]);
>      multifd_ops[method] = ops;
>  }
>
> @@ -1701,3 +1691,19 @@ bool multifd_send_prepare_common(MultiFDSendParams *p)
>
>      return true;
>  }
> +
> +static MultiFDMethods multifd_nocomp_ops = {
> +    .send_setup = multifd_nocomp_send_setup,
> +    .send_cleanup = multifd_nocomp_send_cleanup,
> +    .send_prepare = multifd_nocomp_send_prepare,
> +    .recv_setup = multifd_nocomp_recv_setup,
> +    .recv_cleanup = multifd_nocomp_recv_cleanup,
> +    .recv = multifd_nocomp_recv
> +};
> +
> +static void multifd_nocomp_register(void)
> +{
> +    multifd_register_ops(MULTIFD_COMPRESSION_NONE, &multifd_nocomp_ops);
> +}
> +
> +migration_init(multifd_nocomp_register);

Looks okay.
Reviewed-by: Prasad Pandit <pjp@fedoraproject.org>

Thank you.
---
  - Prasad
Peter Xu Aug. 26, 2024, 4:15 p.m. UTC | #3
On Fri, Aug 23, 2024 at 02:39:10PM -0300, Fabiano Rosas wrote:
> Prior to moving the ram code into multifd-nocomp.c, change the code to
> register the nocomp ops dynamically so we don't need to have the ops
> structure defined in multifd.c.
> 
> While here, move the ops struct initialization to the end of the file
> to make the next diff cleaner.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>

Reviewed-by: Peter Xu <peterx@redhat.com>
diff mbox series

Patch

diff --git a/migration/multifd.c b/migration/multifd.c
index 9f40bb2f16..e100836cbe 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -287,22 +287,12 @@  static int multifd_nocomp_recv(MultiFDRecvParams *p, Error **errp)
     return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp);
 }
 
-static MultiFDMethods multifd_nocomp_ops = {
-    .send_setup = multifd_nocomp_send_setup,
-    .send_cleanup = multifd_nocomp_send_cleanup,
-    .send_prepare = multifd_nocomp_send_prepare,
-    .recv_setup = multifd_nocomp_recv_setup,
-    .recv_cleanup = multifd_nocomp_recv_cleanup,
-    .recv = multifd_nocomp_recv
-};
-
-static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] = {
-    [MULTIFD_COMPRESSION_NONE] = &multifd_nocomp_ops,
-};
+static MultiFDMethods *multifd_ops[MULTIFD_COMPRESSION__MAX] = {};
 
 void multifd_register_ops(int method, MultiFDMethods *ops)
 {
-    assert(0 < method && method < MULTIFD_COMPRESSION__MAX);
+    assert(0 <= method && method < MULTIFD_COMPRESSION__MAX);
+    assert(!multifd_ops[method]);
     multifd_ops[method] = ops;
 }
 
@@ -1701,3 +1691,19 @@  bool multifd_send_prepare_common(MultiFDSendParams *p)
 
     return true;
 }
+
+static MultiFDMethods multifd_nocomp_ops = {
+    .send_setup = multifd_nocomp_send_setup,
+    .send_cleanup = multifd_nocomp_send_cleanup,
+    .send_prepare = multifd_nocomp_send_prepare,
+    .recv_setup = multifd_nocomp_recv_setup,
+    .recv_cleanup = multifd_nocomp_recv_cleanup,
+    .recv = multifd_nocomp_recv
+};
+
+static void multifd_nocomp_register(void)
+{
+    multifd_register_ops(MULTIFD_COMPRESSION_NONE, &multifd_nocomp_ops);
+}
+
+migration_init(multifd_nocomp_register);