On Wed, Sep 02, 2026 at 07:15:42PM -0300, Fabiano Rosas wrote:
> The migrate_set_parameter_completion function is the last user of the
> MigrationParameter enum. Write the code using an output visitor and
> QDict instead so we can remove the enum in a future patch.
> 
> Signed-off-by: Fabiano Rosas <[email protected]>
> ---
>  migration/migration-hmp-cmds.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c
> index dff69650a0c..d0adda25090 100644
> --- a/migration/migration-hmp-cmds.c
> +++ b/migration/migration-hmp-cmds.c
> @@ -791,14 +791,19 @@ void migrate_set_capability_completion(ReadLineState 
> *rs, int nb_args,
>  void migrate_set_parameter_completion(ReadLineState *rs, int nb_args,
>                                        const char *str)
>  {
> +    g_autoptr(MigrationParameters) params = g_new0(MigrationParameters, 1);
> +    g_autoptr(QDict) d = migrate_params_to_dict(params, NULL);

When I played with this branch a bit then I found set_parameter completion
broke, then I found indeed the prior test didn't add set_parameter
completion test.. can add one too.

Here IIUC d is empty dict.  One possible fix:

--- a/migration/migration-hmp-cmds.c
+++ b/migration/migration-hmp-cmds.c
@@ -787,19 +787,19 @@ void migrate_set_capability_completion(ReadLineState *rs, 
int nb_args,
 void migrate_set_parameter_completion(ReadLineState *rs, int nb_args,
                                       const char *str)
 {
-    g_autoptr(MigrationParameters) params = g_new0(MigrationParameters, 1);    
                                                         
-    g_autoptr(QDict) d = migrate_params_to_dict(params, NULL);                 
                                                         
+    g_autoptr(QDict) d;                                                        
                                                         
     const QDictEntry *e;
     size_t len;

+    /* Temporarily borrow the global parameters */                             
                                                         
+    d = migrate_params_to_dict(&migrate_get_current()->parameters,             
                                                         
+                               &error_abort);                                  
                                                         
     len = strlen(str);
     readline_set_completion_index(rs, len);
     if (nb_args == 2) {
         for (e = qdict_first(d); e; e = qdict_next(d, e)) {
             const char *key = qdict_entry_key(e);
-            if (!g_str_has_prefix(key, "has-")) {                              
                                                         
-                readline_add_completion_of(rs, str, key);                      
                                                         
-            }                                                                  
                                                         
+            readline_add_completion_of(rs, str, key);                          
                                                         
         }
     }
 }

> +    const QDictEntry *e;
>      size_t len;
>  
>      len = strlen(str);
>      readline_set_completion_index(rs, len);
>      if (nb_args == 2) {
> -        int i;
> -        for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
> -            readline_add_completion_of(rs, str, MigrationParameter_str(i));
> +        for (e = qdict_first(d); e; e = qdict_next(d, e)) {
> +            const char *key = qdict_entry_key(e);
> +            if (!g_str_has_prefix(key, "has-")) {
> +                readline_add_completion_of(rs, str, key);
> +            }
>          }
>      }
>  }
> -- 
> 2.53.0
> 

-- 
Peter Xu


Reply via email to