Skip to contentSkip to conversation

Miscellaneous command completion patches

PATCH Applied Hani Benhabiles 3 participants 12 messages May 7, 2014 – May 15, 2014 Networking

lore
Share & tools
lore
#1 lore raw

PATCH 1/6 monitor: Convert sendkey to use command_completion.

In reply to Hani Benhabiles
---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 32 +++++++++++++++++++++++---------
 3 files changed, 25 insertions(+), 9 deletions(-)
hmp-commands.hx +1 -0
index 8971f1b..b4b23c8 100644
@@ -556,6 +556,7 @@ ETEXI
         .params     = "keys [hold_ms]",
         .help       = "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)",
         .mhandler.cmd = hmp_send_key,
+        .command_completion = sendkey_completion,
     },
 
 STEXI
hmp.h +1 -0
index 20ef454..12e21e7 100644
@@ -97,5 +97,6 @@ void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_del_completion(ReadLineState *rs, int nb_args, const char *str);
+void sendkey_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +23 -9
index 2d3fb3f..7ef251c 100644
@@ -4359,6 +4359,28 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
     qapi_free_ObjectPropertyInfoList(start);
 }
 
+void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    int i;
+    char *sep;
+    size_t len;
+
+    if (nb_args != 2) {
+        return;
+    }
+    sep = strrchr(str, '-');
+    if (sep) {
+        str = sep + 1;
+    }
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    for (i = 0; i < Q_KEY_CODE_MAX; i++) {
+        if (!strncmp(str, QKeyCode_lookup[i], len)) {
+            readline_add_completion(rs, QKeyCode_lookup[i]);
+        }
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
@@ -4427,15 +4449,7 @@ static void monitor_find_completion_by_table(Monitor *mon,
             break;
         case 's':
         case 'S':
-            if (!strcmp(cmd->name, "sendkey")) {
-                char *sep = strrchr(str, '-');
-                if (sep)
-                    str = sep + 1;
-                readline_set_completion_index(mon->rs, strlen(str));
-                for (i = 0; i < Q_KEY_CODE_MAX; i++) {
-                    cmd_completion(mon, str, QKeyCode_lookup[i]);
-                }
-            } else if (!strcmp(cmd->name, "help|?")) {
+            if (!strcmp(cmd->name, "help|?")) {
                 monitor_find_completion_by_table(mon, cmd_table,
                                                  &args[1], nb_args - 1);
             }
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH 2/6 monitor: Add chardev-remove command completion.

In reply to Hani Benhabiles
---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 23 +++++++++++++++++++++++
 3 files changed, 25 insertions(+)
hmp-commands.hx +1 -0
index b4b23c8..ba88e2a 100644
@@ -1639,6 +1639,7 @@ ETEXI
         .params     = "id",
         .help       = "remove chardev",
         .mhandler.cmd = hmp_chardev_remove,
+        .command_completion = chardev_remove_completion,
     },
 
 STEXI
hmp.h +1 -0
index 12e21e7..affc2b6 100644
@@ -98,5 +98,6 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void sendkey_completion(ReadLineState *rs, int nb_args, const char *str);
+void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +23 -0
index 7ef251c..6316a29 100644
@@ -4322,6 +4322,29 @@ static void device_del_bus_completion(ReadLineState *rs,  BusState *bus,
     }
 }
 
+void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    size_t len;
+    ChardevInfoList *list, *start;
+
+    if (nb_args != 2) {
+        return;
+    }
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+
+    start = list = qmp_query_chardev(NULL);
+    while (list) {
+        ChardevInfo *chr = list->value;
+
+        if (!strncmp(chr->label, str, len)) {
+            readline_add_completion(rs, chr->label);
+        }
+        list = list->next;
+    }
+    qapi_free_ChardevInfoList(start);
+}
+
 void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     size_t len;
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH 3/6 monitor: Add chardev-add backend argument completion.

In reply to Hani Benhabiles
---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 23 +++++++++++++++++++++++
 3 files changed, 25 insertions(+)
hmp-commands.hx +1 -0
index ba88e2a..93fa534 100644
@@ -1623,6 +1623,7 @@ ETEXI
         .params     = "args",
         .help       = "add chardev",
         .mhandler.cmd = hmp_chardev_add,
+        .command_completion = chardev_add_completion,
     },
 
 STEXI
hmp.h +1 -0
index affc2b6..f8e16a8 100644
@@ -99,5 +99,6 @@ void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void sendkey_completion(ReadLineState *rs, int nb_args, const char *str);
 void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
+void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +23 -0
index 6316a29..dacff19 100644
@@ -4252,6 +4252,29 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
+void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    size_t len;
+    ChardevBackendInfoList *list, *start;
+
+    if (nb_args != 2) {
+        return;
+    }
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+
+    start = list = qmp_query_chardev_backends(NULL);
+    while (list) {
+        const char *chr_name = list->value->name;
+
+        if (!strncmp(chr_name, str, len)) {
+            readline_add_completion(rs, chr_name);
+        }
+        list = list->next;
+    }
+    qapi_free_ChardevBackendInfoList(start);
+}
+
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     GSList *list, *elt;
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH 4/6 monitor: Add set_link arguments completion.

In reply to Hani Benhabiles

Make it possible to query all net clients without specifying an ID when calling qemu_find_net_clients_except().

This also adds the add_completion_option() function which is to be used for other commands completions as well.

---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 34 ++++++++++++++++++++++++++++++++++
 net/net.c       |  2 +-
 4 files changed, 37 insertions(+), 1 deletion(-)
hmp-commands.hx +1 -0
index 93fa534..3e7b29c 100644
@@ -1340,6 +1340,7 @@ ETEXI
         .params     = "name on|off",
         .help       = "change the link status of a network adapter",
         .mhandler.cmd = hmp_set_link,
+        .command_completion = set_link_completion,
     },
 
 STEXI
hmp.h +1 -0
index f8e16a8..91c9c85 100644
@@ -100,5 +100,6 @@ void device_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void sendkey_completion(ReadLineState *rs, int nb_args, const char *str);
 void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
 void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
+void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +34 -0
index dacff19..5ead568 100644
@@ -4252,6 +4252,17 @@ static const char *next_arg_type(const char *typestr)
     return (p != NULL ? ++p : typestr);
 }
 
+static void add_completion_option(ReadLineState *rs, const char *str,
+                                  const char *option)
+{
+    if (!str || !option) {
+        return;
+    }
+    if (!strncmp(option, str, strlen(str))) {
+        readline_add_completion(rs, option);
+    }
+}
+
 void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     size_t len;
@@ -4427,6 +4438,29 @@ void sendkey_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    size_t len;
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    if (nb_args == 2) {
+        NetClientState *ncs[255];
+        int count, i;
+        count = qemu_find_net_clients_except(NULL, ncs,
+                                             NET_CLIENT_OPTIONS_KIND_NONE, 255);
+        for (i = 0; i < count; i++) {
+            const char *name = ncs[i]->name;
+            if (!strncmp(str, name, len)) {
+                readline_add_completion(rs, name);
+            }
+        }
+    } else if (nb_args == 3) {
+        add_completion_option(rs, str, "on");
+        add_completion_option(rs, str, "off");
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
net/net.c +1 -1
index 9db4dba..0ff2e40 100644
@@ -633,7 +633,7 @@ int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
         if (nc->info->type == type) {
             continue;
         }
-        if (!strcmp(nc->name, id)) {
+        if (!id || !strcmp(nc->name, id)) {
             if (ret < max) {
                 ncs[ret] = nc;
             }
Signature · 1 line
1.8.3.2
#0 lore raw

cover Miscellaneous command completion patches

Compared to v1:
* Dropped patch 02/07 for help completion conversion.
* Nothing else changed. 04,05 and 06 are R-b by Stefan.

Hani Benhabiles (6):
monitor: Convert sendkey to use command_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.
monitor: Add set_link arguments completion.
monitor: Add netdev_add type argument completion.
monitor: Add netdev_del id argument completion.

 hmp-commands.hx |   8 ++-
 hmp.h           |   6 +++
 monitor.c       | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 net/net.c       |   2 +-
 4 files changed, 158 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.3.2
#5 lore raw

PATCH 5/6 monitor: Add netdev_add type argument completion.

Also update the command's documentation.

---
 hmp-commands.hx |  3 ++-
 hmp.h           |  1 +
 monitor.c       | 15 +++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
hmp-commands.hx +2 -1
index 3e7b29c..a7f9b2f 100644
@@ -1234,9 +1234,10 @@ ETEXI
     {
         .name       = "netdev_add",
         .args_type  = "netdev:O",
-        .params     = "[user|tap|socket|hubport|netmap],id=str[,prop=value][,...]",
+        .params     = "[user|tap|socket|vde|bridge|hubport|netmap],id=str[,prop=value][,...]",
         .help       = "add host network device",
         .mhandler.cmd = hmp_netdev_add,
+        .command_completion = netdev_add_completion,
     },
 
 STEXI
hmp.h +1 -0
index 91c9c85..bcecd0d 100644
@@ -101,5 +101,6 @@ void sendkey_completion(ReadLineState *rs, int nb_args, const char *str);
 void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
 void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
+void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +15 -0
index 5ead568..a4c429c 100644
@@ -4286,6 +4286,21 @@ void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str)
     qapi_free_ChardevBackendInfoList(start);
 }
 
+void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    size_t len;
+    int i;
+
+    if (nb_args != 2) {
+        return;
+    }
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    for (i = 0; NetClientOptionsKind_lookup[i]; i++) {
+        add_completion_option(rs, str, NetClientOptionsKind_lookup[i]);
+    }
+}
+
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     GSList *list, *elt;
Signature · 1 line
1.8.3.2
#6 lore raw

PATCH 6/6 monitor: Add netdev_del id argument completion.

In reply to Hani Benhabiles
---
 hmp-commands.hx |  1 +
 hmp.h           |  1 +
 monitor.c       | 26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+)
hmp-commands.hx +1 -0
index a7f9b2f..2e462c0 100644
@@ -1252,6 +1252,7 @@ ETEXI
         .params     = "id",
         .help       = "remove host network device",
         .mhandler.cmd = hmp_netdev_del,
+        .command_completion = netdev_del_completion,
     },
 
 STEXI
hmp.h +1 -0
index bcecd0d..aba59e9 100644
@@ -102,5 +102,6 @@ void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
 void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
 void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str);
+void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
monitor.c +26 -0
index a4c429c..7f68549 100644
@@ -4476,6 +4476,32 @@ void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    int len, count, i;
+    NetClientState *ncs[255];
+
+    if (nb_args != 2) {
+        return;
+    }
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_OPTIONS_KIND_NIC,
+                                         255);
+    for (i = 0; i < count; i++) {
+        QemuOpts *opts;
+        const char *name = ncs[i]->name;
+        if (strncmp(str, name, len)) {
+            continue;
+        }
+        opts = qemu_opts_find(qemu_find_opts_err("netdev", NULL), name);
+        if (opts) {
+            readline_add_completion(rs, name);
+        }
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
Signature · 1 line
1.8.3.2
#7 lore raw
In reply to Hani Benhabiles
Quoted 8 lines · Hani Benhabiles

Compared to v1:
* Dropped patch 02/07 for help completion conversion.
* Nothing else changed. 04,05 and 06 are R-b by Stefan.

Hani Benhabiles (6):
monitor: Convert sendkey to use command_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.

Don't know much about readline completion internals, but the way the valid choices are figured in these three patches looks sane to me.

cheers,
Gerd

#8 lore raw
In reply to Hani Benhabiles
Quoted 12 lines · On Wed, 7 May 2014 23:41:26 +0100 Hani Benhabiles <[email protected]> wrote:

Compared to v1:
* Dropped patch 02/07 for help completion conversion.
* Nothing else changed. 04,05 and 06 are R-b by Stefan.

Hani Benhabiles (6):
monitor: Convert sendkey to use command_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.
monitor: Add set_link arguments completion.
monitor: Add netdev_add type argument completion.
monitor: Add netdev_del id argument completion.

Quoted 6 lines
 hmp-commands.hx |   8 ++-
 hmp.h           |   6 +++
 monitor.c       | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 net/net.c       |   2 +-
 4 files changed, 158 insertions(+), 11 deletions(-)

Applied to the qmp branch, thanks.

#9 lore raw
In reply to Hani Benhabiles
Quoted 4 lines · Hani Benhabiles

Compared to v1:
* Dropped patch 02/07 for help completion conversion.
* Nothing else changed. 04,05 and 06 are R-b by Stefan.

Quoted 8 lines

Hani Benhabiles (6):
monitor: Convert sendkey to use command_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.
monitor: Add set_link arguments completion.
monitor: Add netdev_add type argument completion.
monitor: Add netdev_del id argument completion.

Ping.

Luiz, is there anything still holding this series ? All 6 patches are Reviewed/Acked.

Quoted 9 lines
 hmp-commands.hx |   8 ++-
 hmp.h           |   6 +++
 monitor.c       | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 net/net.c       |   2 +-
 4 files changed, 158 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.3.2
#10 lore raw
Quoted 14 lines · On Thu, 15 May 2014 20:42:03 +0100 Hani Benhabiles <[email protected]> wrote:
Quoted 4 lines · Hani Benhabiles

Compared to v1:
* Dropped patch 02/07 for help completion conversion.
* Nothing else changed. 04,05 and 06 are R-b by Stefan.

Quoted 8 lines

Hani Benhabiles (6):
monitor: Convert sendkey to use command_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.
monitor: Add set_link arguments completion.
monitor: Add netdev_add type argument completion.
monitor: Add netdev_del id argument completion.

Quoted 4 lines

Ping.

Luiz, is there anything still holding this series ? All 6 patches are Reviewed/Acked.

I applied them a little more than one hour ago.

#11 lore raw
Quoted 17 lines · Luiz Capitulino
Quoted 14 lines · On Thu, 15 May 2014 20:42:03 +0100 Hani Benhabiles <[email protected]> wrote:
Quoted 12 lines · Hani Benhabiles

Compared to v1:
* Dropped patch 02/07 for help completion conversion.
* Nothing else changed. 04,05 and 06 are R-b by Stefan.

Hani Benhabiles (6):
monitor: Convert sendkey to use command_completion.
monitor: Add chardev-remove command completion.
monitor: Add chardev-add backend argument completion.
monitor: Add set_link arguments completion.
monitor: Add netdev_add type argument completion.
monitor: Add netdev_del id argument completion.

Quoted 6 lines
Quoted 4 lines

Ping.

Luiz, is there anything still holding this series ? All 6 patches are Reviewed/Acked.

I applied them a little more than one hour ago.

Thanks, just noticed it.