qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] monitor: Command completion for various commands
@ 2014-05-19 23:01 Hani Benhabiles
  2014-05-19 23:05 ` Hani Benhabiles
  0 siblings, 1 reply; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:01 UTC (permalink / raw)
  To: qemu-devel

A set of patches adding completion support for various hmp commands. Following
other series that were merged earlier.

Hani Benhabiles (7):
  monitor: Add ringbuf_write and ringbuf_read argument completion.
  monitor: Add watchdog_action argument completion.
  monitor: Add migrate_set_capability completion.
  monitor: Add host_net_add device argument completion.
  readline: Make completion strings always unique.
  monitor: Add host_net_remove arguments completion.
  monitor: Add delvm and loadvm argument completion.

 hmp-commands.hx       |  10 ++-
 hmp.h                 |  11 ++++
 include/sysemu/char.h |   3 +-
 monitor.c             | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-char.c           |   2 +-
 util/readline.c       |   6 ++
 6 files changed, 202 insertions(+), 4 deletions(-)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] monitor: Command completion for various commands
@ 2014-05-19 23:03 Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 1/7] monitor: Add ringbuf_write and ringbuf_read argument completion Hani Benhabiles
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

A set of patches adding completion support for various hmp commands. Following
other series that were merged earlier.

Hani Benhabiles (7):
  monitor: Add ringbuf_write and ringbuf_read argument completion.
  monitor: Add watchdog_action argument completion.
  monitor: Add migrate_set_capability completion.
  monitor: Add host_net_add device argument completion.
  readline: Make completion strings always unique.
  monitor: Add host_net_remove arguments completion.
  monitor: Add delvm and loadvm argument completion.

 hmp-commands.hx       |  10 ++-
 hmp.h                 |  11 ++++
 include/sysemu/char.h |   3 +-
 monitor.c             | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-char.c           |   2 +-
 util/readline.c       |   6 ++
 6 files changed, 202 insertions(+), 4 deletions(-)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 1/7] monitor: Add ringbuf_write and ringbuf_read argument completion.
  2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
@ 2014-05-19 23:03 ` Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 2/7] monitor: Add watchdog_action " Hani Benhabiles
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

Export chr_is_ringbuf() function. Also remove left-over function prototypes
while at it.

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 hmp-commands.hx       |  2 ++
 hmp.h                 |  2 ++
 include/sysemu/char.h |  3 +--
 monitor.c             | 39 +++++++++++++++++++++++++++++++++++++++
 qemu-char.c           |  2 +-
 5 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 2e462c0..dcec5ef 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -852,6 +852,7 @@ ETEXI
         .params     = "device data",
         .help       = "Write to a ring buffer character device",
         .mhandler.cmd = hmp_ringbuf_write,
+        .command_completion = ringbuf_write_completion,
     },
 
 STEXI
@@ -868,6 +869,7 @@ ETEXI
         .params     = "device size",
         .help       = "Read from a ring buffer character device",
         .mhandler.cmd = hmp_ringbuf_read,
+        .command_completion = ringbuf_write_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index aba59e9..212e5d2 100644
--- a/hmp.h
+++ b/hmp.h
@@ -103,5 +103,7 @@ 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);
+void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
+void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index b81a6ff..7f5eeb3 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -286,9 +286,8 @@ void qemu_chr_add_handlers(CharDriverState *s,
 void qemu_chr_be_generic_open(CharDriverState *s);
 void qemu_chr_accept_input(CharDriverState *s);
 int qemu_chr_add_client(CharDriverState *s, int fd);
-void qemu_chr_info_print(Monitor *mon, const QObject *ret_data);
-void qemu_chr_info(Monitor *mon, QObject **ret_data);
 CharDriverState *qemu_chr_find(const char *name);
+bool chr_is_ringbuf(const CharDriverState *chr);
 
 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
 
diff --git a/monitor.c b/monitor.c
index 593679a..93eb6d8 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4411,6 +4411,45 @@ void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
     qapi_free_ChardevInfoList(start);
 }
 
+static void ringbuf_completion(ReadLineState *rs, const char *str)
+{
+    size_t len;
+    ChardevInfoList *list, *start;
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+
+    start = list = qmp_query_chardev(NULL);
+    while (list) {
+        ChardevInfo *chr_info = list->value;
+
+        if (!strncmp(chr_info->label, str, len)) {
+            CharDriverState *chr = qemu_chr_find(chr_info->label);
+            if (chr && chr_is_ringbuf(chr)) {
+                readline_add_completion(rs, chr_info->label);
+            }
+        }
+        list = list->next;
+    }
+    qapi_free_ChardevInfoList(start);
+}
+
+void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    if (nb_args != 2) {
+        return;
+    }
+    ringbuf_completion(rs, str);
+}
+
+void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    if (nb_args != 2) {
+        return;
+    }
+    ringbuf_completion(rs, str);
+}
+
 void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     size_t len;
diff --git a/qemu-char.c b/qemu-char.c
index 54ed244..34c8f08 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2849,7 +2849,7 @@ fail:
     return NULL;
 }
 
-static bool chr_is_ringbuf(const CharDriverState *chr)
+bool chr_is_ringbuf(const CharDriverState *chr)
 {
     return chr->chr_write == ringbuf_chr_write;
 }
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 2/7] monitor: Add watchdog_action argument completion.
  2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 1/7] monitor: Add ringbuf_write and ringbuf_read argument completion Hani Benhabiles
@ 2014-05-19 23:03 ` Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 3/7] monitor: Add migrate_set_capability completion Hani Benhabiles
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 hmp-commands.hx |  1 +
 hmp.h           |  2 ++
 monitor.c       | 14 ++++++++++++++
 3 files changed, 17 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index dcec5ef..45e1763 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1359,6 +1359,7 @@ ETEXI
         .params     = "[reset|shutdown|poweroff|pause|debug|none]",
         .help       = "change watchdog action",
         .mhandler.cmd = do_watchdog_action,
+        .command_completion = watchdog_action_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index 212e5d2..a70804d 100644
--- a/hmp.h
+++ b/hmp.h
@@ -105,5 +105,7 @@ void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
 void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
+void watchdog_action_completion(ReadLineState *rs, int nb_args,
+                                const char *str);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 93eb6d8..fb300c2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4558,6 +4558,20 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    if (nb_args != 2) {
+        return;
+    }
+    readline_set_completion_index(rs, strlen(str));
+    add_completion_option(rs, str, "reset");
+    add_completion_option(rs, str, "shutdown");
+    add_completion_option(rs, str, "poweroff");
+    add_completion_option(rs, str, "pause");
+    add_completion_option(rs, str, "debug");
+    add_completion_option(rs, str, "none");
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 3/7] monitor: Add migrate_set_capability completion.
  2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 1/7] monitor: Add ringbuf_write and ringbuf_read argument completion Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 2/7] monitor: Add watchdog_action " Hani Benhabiles
@ 2014-05-19 23:03 ` Hani Benhabiles
  2014-05-21 18:42   ` Dr. David Alan Gilbert
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion Hani Benhabiles
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 hmp-commands.hx |  1 +
 hmp.h           |  2 ++
 monitor.c       | 21 +++++++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 45e1763..919af6e 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -975,6 +975,7 @@ ETEXI
         .params     = "capability state",
         .help       = "Enable/Disable the usage of a capability for migration",
         .mhandler.cmd = hmp_migrate_set_capability,
+        .command_completion = migrate_set_capability_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index a70804d..0c814d0 100644
--- a/hmp.h
+++ b/hmp.h
@@ -107,5 +107,7 @@ void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
 void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
 void watchdog_action_completion(ReadLineState *rs, int nb_args,
                                 const char *str);
+void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
+                                       const char *str);
 
 #endif
diff --git a/monitor.c b/monitor.c
index fb300c2..6a3a5c9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4572,6 +4572,27 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
     add_completion_option(rs, str, "none");
 }
 
+void migrate_set_capability_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) {
+        int i;
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            const char *name = MigrationCapability_lookup[i];
+            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,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion.
  2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
                   ` (2 preceding siblings ...)
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 3/7] monitor: Add migrate_set_capability completion Hani Benhabiles
@ 2014-05-19 23:03 ` Hani Benhabiles
  2014-05-23 12:05   ` Stefan Hajnoczi
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 5/7] readline: Make completion strings always unique Hani Benhabiles
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

Also fix the parameters documentation.

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 hmp-commands.hx |  3 ++-
 hmp.h           |  1 +
 monitor.c       | 14 ++++++++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 919af6e..6aaec1b 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1209,9 +1209,10 @@ ETEXI
     {
         .name       = "host_net_add",
         .args_type  = "device:s,opts:s?",
-        .params     = "tap|user|socket|vde|netmap|dump [options]",
+        .params     = "tap|user|socket|vde|bridge|dump [options]",
         .help       = "add host VLAN client",
         .mhandler.cmd = net_host_device_add,
+        .command_completion = host_net_add_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index 0c814d0..22ee836 100644
--- a/hmp.h
+++ b/hmp.h
@@ -109,5 +109,6 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args,
                                 const char *str);
 void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
                                        const char *str);
+void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 6a3a5c9..365c66a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4593,6 +4593,20 @@ void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
     }
 }
 
+void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    if (nb_args != 2) {
+        return;
+    }
+    readline_set_completion_index(rs, strlen(str));
+    add_completion_option(rs, str, "tap");
+    add_completion_option(rs, str, "user");
+    add_completion_option(rs, str, "socket");
+    add_completion_option(rs, str, "vde");
+    add_completion_option(rs, str, "dump");
+    add_completion_option(rs, str, "bridge");
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 5/7] readline: Make completion strings always unique.
  2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
                   ` (3 preceding siblings ...)
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion Hani Benhabiles
@ 2014-05-19 23:03 ` Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 6/7] monitor: Add host_net_remove arguments completion Hani Benhabiles
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 7/7] monitor: Add delvm and loadvm argument completion Hani Benhabiles
  6 siblings, 0 replies; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

There is no need to clutter the user's choices with repeating the same value
multiple times.

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 util/readline.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/util/readline.c b/util/readline.c
index 8baec55..7214e84 100644
--- a/util/readline.c
+++ b/util/readline.c
@@ -263,6 +263,12 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
 void readline_add_completion(ReadLineState *rs, const char *str)
 {
     if (rs->nb_completions < READLINE_MAX_COMPLETIONS) {
+        int i;
+        for (i = 0; i < rs->nb_completions; i++) {
+            if (!strcmp(rs->completions[i], str)) {
+                return;
+            }
+        }
         rs->completions[rs->nb_completions++] = g_strdup(str);
     }
 }
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 6/7] monitor: Add host_net_remove arguments completion.
  2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
                   ` (4 preceding siblings ...)
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 5/7] readline: Make completion strings always unique Hani Benhabiles
@ 2014-05-19 23:03 ` Hani Benhabiles
  2014-05-23 12:09   ` Stefan Hajnoczi
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 7/7] monitor: Add delvm and loadvm argument completion Hani Benhabiles
  6 siblings, 1 reply; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

Relies on readline unique completion strings patch to make the added vlan/hub
completion values unique, instead of using something like a hash table.

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 hmp-commands.hx |  1 +
 hmp.h           |  2 ++
 monitor.c       | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 6aaec1b..935f744 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1227,6 +1227,7 @@ ETEXI
         .params     = "vlan_id name",
         .help       = "remove host VLAN client",
         .mhandler.cmd = net_host_device_remove,
+        .command_completion = host_net_remove_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index 22ee836..a53ad51 100644
--- a/hmp.h
+++ b/hmp.h
@@ -110,5 +110,7 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args,
 void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
                                        const char *str);
 void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str);
+void host_net_remove_completion(ReadLineState *rs, int nb_args,
+                                const char *str);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 365c66a..805d29f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4607,6 +4607,44 @@ void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str)
     add_completion_option(rs, str, "bridge");
 }
 
+void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    NetClientState *ncs[255];
+    int count, i, len;
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    if (nb_args == 2) {
+        count = qemu_find_net_clients_except(NULL, ncs,
+                                             NET_CLIENT_OPTIONS_KIND_NONE, 255);
+        for (i = 0; i < count; i++) {
+            int id;
+            char name[16];
+
+            if (net_hub_id_for_client(ncs[i], &id)) {
+                continue;
+            }
+            snprintf(name, sizeof(name), "%d", id);
+            if (!strncmp(str, name, len)) {
+                readline_add_completion(rs, name);
+            }
+        }
+        return;
+    } else if (nb_args == 3) {
+        count = qemu_find_net_clients_except(NULL, ncs,
+                                             NET_CLIENT_OPTIONS_KIND_NIC, 255);
+        for (i = 0; i < count; i++) {
+            const char *name;
+
+            name = ncs[i]->name;
+            if (!strncmp(str, name, len)) {
+                readline_add_completion(rs, name);
+            }
+        }
+        return;
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 7/7] monitor: Add delvm and loadvm argument completion.
  2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
                   ` (5 preceding siblings ...)
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 6/7] monitor: Add host_net_remove arguments completion Hani Benhabiles
@ 2014-05-19 23:03 ` Hani Benhabiles
  6 siblings, 0 replies; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, mdroth, lcapitulino, stefanha, imammedo

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 hmp-commands.hx |  2 ++
 hmp.h           |  2 ++
 monitor.c       | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 935f744..d68a00b 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -335,6 +335,7 @@ ETEXI
         .params     = "tag|id",
         .help       = "restore a VM snapshot from its tag or id",
         .mhandler.cmd = do_loadvm,
+        .command_completion = loadvm_completion,
     },
 
 STEXI
@@ -350,6 +351,7 @@ ETEXI
         .params     = "tag|id",
         .help       = "delete a VM snapshot from its tag or id",
         .mhandler.cmd = do_delvm,
+        .command_completion = delvm_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index a53ad51..2d9b0a2 100644
--- a/hmp.h
+++ b/hmp.h
@@ -112,5 +112,7 @@ void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
 void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void host_net_remove_completion(ReadLineState *rs, int nb_args,
                                 const char *str);
+void delvm_completion(ReadLineState *rs, int nb_args, const char *str);
+void loadvm_completion(ReadLineState *rs, int nb_args, const char *str);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 805d29f..b6ac4e0 100644
--- a/monitor.c
+++ b/monitor.c
@@ -69,6 +69,7 @@
 #include "qmp-commands.h"
 #include "hmp.h"
 #include "qemu/thread.h"
+#include "block/qapi.h"
 
 /* for pic/irq_info */
 #if defined(TARGET_SPARC)
@@ -4645,6 +4646,53 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+static void vm_completion(ReadLineState *rs, const char *str)
+{
+    size_t len;
+    BlockDriverState *bs = NULL;
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    while ((bs = bdrv_next(bs))) {
+        SnapshotInfoList *snapshots, *snapshot;
+
+        if (!bdrv_can_snapshot(bs)) {
+            continue;
+        }
+        if (bdrv_query_snapshot_info_list(bs, &snapshots, NULL)) {
+            continue;
+        }
+        snapshot = snapshots;
+        while (snapshot) {
+            char *completion = snapshot->value->name;
+            if (!strncmp(str, completion, len)) {
+                readline_add_completion(rs, completion);
+            }
+            completion = snapshot->value->id;
+            if (!strncmp(str, completion, len)) {
+                readline_add_completion(rs, completion);
+            }
+            snapshot = snapshot->next;
+        }
+        qapi_free_SnapshotInfoList(snapshots);
+    }
+
+}
+
+void delvm_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    if (nb_args == 2) {
+        vm_completion(rs, str);
+    }
+}
+
+void loadvm_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    if (nb_args == 2) {
+        vm_completion(rs, str);
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] monitor: Command completion for various commands
  2014-05-19 23:01 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
@ 2014-05-19 23:05 ` Hani Benhabiles
  0 siblings, 0 replies; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-19 23:05 UTC (permalink / raw)
  To: qemu-devel

On Tue, May 20, 2014 at 12:01:01AM +0100, Hani Benhabiles wrote:
> A set of patches adding completion support for various hmp commands. Following
> other series that were merged earlier.
> 

Resent the complete series. Please ignore this incomplete one.

Sorry for the flood.

> Hani Benhabiles (7):
>   monitor: Add ringbuf_write and ringbuf_read argument completion.
>   monitor: Add watchdog_action argument completion.
>   monitor: Add migrate_set_capability completion.
>   monitor: Add host_net_add device argument completion.
>   readline: Make completion strings always unique.
>   monitor: Add host_net_remove arguments completion.
>   monitor: Add delvm and loadvm argument completion.
> 
>  hmp-commands.hx       |  10 ++-
>  hmp.h                 |  11 ++++
>  include/sysemu/char.h |   3 +-
>  monitor.c             | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  qemu-char.c           |   2 +-
>  util/readline.c       |   6 ++
>  6 files changed, 202 insertions(+), 4 deletions(-)
> 
> -- 
> 1.8.3.2
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/7] monitor: Add migrate_set_capability completion.
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 3/7] monitor: Add migrate_set_capability completion Hani Benhabiles
@ 2014-05-21 18:42   ` Dr. David Alan Gilbert
  2014-05-22  7:05     ` Markus Armbruster
  0 siblings, 1 reply; 16+ messages in thread
From: Dr. David Alan Gilbert @ 2014-05-21 18:42 UTC (permalink / raw)
  To: Hani Benhabiles
  Cc: kwolf, mdroth, qemu-devel, lcapitulino, stefanha, imammedo

* Hani Benhabiles (kroosec@gmail.com) wrote:
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
>  hmp-commands.hx |  1 +
>  hmp.h           |  2 ++
>  monitor.c       | 21 +++++++++++++++++++++
>  3 files changed, 24 insertions(+)
> 
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 45e1763..919af6e 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -975,6 +975,7 @@ ETEXI
>          .params     = "capability state",
>          .help       = "Enable/Disable the usage of a capability for migration",
>          .mhandler.cmd = hmp_migrate_set_capability,
> +        .command_completion = migrate_set_capability_completion,
>      },
>  
>  STEXI
> diff --git a/hmp.h b/hmp.h
> index a70804d..0c814d0 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -107,5 +107,7 @@ void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
>  void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
>  void watchdog_action_completion(ReadLineState *rs, int nb_args,
>                                  const char *str);
> +void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
> +                                       const char *str);

Thank you for doing this; I spend way too much time typing these commands.

>  #endif
> diff --git a/monitor.c b/monitor.c
> index fb300c2..6a3a5c9 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4572,6 +4572,27 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
>      add_completion_option(rs, str, "none");
>  }
>  
> +void migrate_set_capability_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) {
> +        int i;
> +        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
> +            const char *name = MigrationCapability_lookup[i];
> +            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");
> +    }

It's a shame you have to do all of these manually; if we could tell something
that we had an enum of 'MigrationCapability' then it could remove the command
specific glue.

Dave

> +}
> +
>  static void monitor_find_completion_by_table(Monitor *mon,
>                                               const mon_cmd_t *cmd_table,
>                                               char **args,
> -- 
> 1.8.3.2
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/7] monitor: Add migrate_set_capability completion.
  2014-05-21 18:42   ` Dr. David Alan Gilbert
@ 2014-05-22  7:05     ` Markus Armbruster
  0 siblings, 0 replies; 16+ messages in thread
From: Markus Armbruster @ 2014-05-22  7:05 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: kwolf, Hani Benhabiles, qemu-devel, mdroth, lcapitulino, stefanha,
	imammedo

"Dr. David Alan Gilbert" <dgilbert@redhat.com> writes:

> * Hani Benhabiles (kroosec@gmail.com) wrote:
>> Signed-off-by: Hani Benhabiles <hani@linux.com>
>> ---
>>  hmp-commands.hx |  1 +
>>  hmp.h           |  2 ++
>>  monitor.c       | 21 +++++++++++++++++++++
>>  3 files changed, 24 insertions(+)
>> 
>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>> index 45e1763..919af6e 100644
>> --- a/hmp-commands.hx
>> +++ b/hmp-commands.hx
>> @@ -975,6 +975,7 @@ ETEXI
>>          .params     = "capability state",
>>          .help       = "Enable/Disable the usage of a capability for migration",
>>          .mhandler.cmd = hmp_migrate_set_capability,
>> +        .command_completion = migrate_set_capability_completion,
>>      },
>>  
>>  STEXI
>> diff --git a/hmp.h b/hmp.h
>> index a70804d..0c814d0 100644
>> --- a/hmp.h
>> +++ b/hmp.h
>> @@ -107,5 +107,7 @@ void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
>>  void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
>>  void watchdog_action_completion(ReadLineState *rs, int nb_args,
>>                                  const char *str);
>> +void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
>> +                                       const char *str);
>
> Thank you for doing this; I spend way too much time typing these commands.
>
>>  #endif
>> diff --git a/monitor.c b/monitor.c
>> index fb300c2..6a3a5c9 100644
>> --- a/monitor.c
>> +++ b/monitor.c
>> @@ -4572,6 +4572,27 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
>>      add_completion_option(rs, str, "none");
>>  }
>>  
>> +void migrate_set_capability_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) {
>> +        int i;
>> +        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
>> +            const char *name = MigrationCapability_lookup[i];
>> +            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");
>> +    }
>
> It's a shame you have to do all of these manually; if we could tell something
> that we had an enum of 'MigrationCapability' then it could remove the command
> specific glue.

HMP command arguments are specified by an args_type string, which can't
express "enumeration", so we use strings instead.

We could hack in another arguments type 'E', abusing the parameter name
like type 'O'.  But I think the args_type string is long past its "best
before" date.

We could replace it by a command schema, like QMP's.  Differences to QMP
include: arguments are positional, fewer types are accepted, and there's
convenience syntax such as size suffixes.

Not exactly an easy task, I'm afraid.

[...]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion.
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion Hani Benhabiles
@ 2014-05-23 12:05   ` Stefan Hajnoczi
  2014-05-25 16:12     ` Hani Benhabiles
  0 siblings, 1 reply; 16+ messages in thread
From: Stefan Hajnoczi @ 2014-05-23 12:05 UTC (permalink / raw)
  To: Hani Benhabiles
  Cc: kwolf, mdroth, qemu-devel, lcapitulino, stefanha, imammedo

On Tue, May 20, 2014 at 12:03:17AM +0100, Hani Benhabiles wrote:
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 919af6e..6aaec1b 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1209,9 +1209,10 @@ ETEXI
>      {
>          .name       = "host_net_add",
>          .args_type  = "device:s,opts:s?",
> -        .params     = "tap|user|socket|vde|netmap|dump [options]",
> +        .params     = "tap|user|socket|vde|bridge|dump [options]",

Why did you delete "netmap"?  I guess "bridge" should have been appended.

> diff --git a/monitor.c b/monitor.c
> index 6a3a5c9..365c66a 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4593,6 +4593,20 @@ void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
>      }
>  }
>  
> +void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str)
> +{
> +    if (nb_args != 2) {
> +        return;
> +    }
> +    readline_set_completion_index(rs, strlen(str));
> +    add_completion_option(rs, str, "tap");
> +    add_completion_option(rs, str, "user");
> +    add_completion_option(rs, str, "socket");
> +    add_completion_option(rs, str, "vde");
> +    add_completion_option(rs, str, "dump");
> +    add_completion_option(rs, str, "bridge");

Please take a look at net_host_check_device() and share the list from
there.  (Some of the netdevs depend on build-time options.)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 6/7] monitor: Add host_net_remove arguments completion.
  2014-05-19 23:03 ` [Qemu-devel] [PATCH 6/7] monitor: Add host_net_remove arguments completion Hani Benhabiles
@ 2014-05-23 12:09   ` Stefan Hajnoczi
  0 siblings, 0 replies; 16+ messages in thread
From: Stefan Hajnoczi @ 2014-05-23 12:09 UTC (permalink / raw)
  To: Hani Benhabiles
  Cc: kwolf, mdroth, qemu-devel, lcapitulino, stefanha, imammedo

On Tue, May 20, 2014 at 12:03:19AM +0100, Hani Benhabiles wrote:
> Relies on readline unique completion strings patch to make the added vlan/hub
> completion values unique, instead of using something like a hash table.
> 
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
>  hmp-commands.hx |  1 +
>  hmp.h           |  2 ++
>  monitor.c       | 38 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 41 insertions(+)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion.
  2014-05-23 12:05   ` Stefan Hajnoczi
@ 2014-05-25 16:12     ` Hani Benhabiles
  2014-05-26  9:20       ` Stefan Hajnoczi
  0 siblings, 1 reply; 16+ messages in thread
From: Hani Benhabiles @ 2014-05-25 16:12 UTC (permalink / raw)
  To: Stefan Hajnoczi
  Cc: kwolf, mdroth, qemu-devel, lcapitulino, stefanha, imammedo

On Fri, May 23, 2014 at 02:05:03PM +0200, Stefan Hajnoczi wrote:
> On Tue, May 20, 2014 at 12:03:17AM +0100, Hani Benhabiles wrote:
> > diff --git a/hmp-commands.hx b/hmp-commands.hx
> > index 919af6e..6aaec1b 100644
> > --- a/hmp-commands.hx
> > +++ b/hmp-commands.hx
> > @@ -1209,9 +1209,10 @@ ETEXI
> >      {
> >          .name       = "host_net_add",
> >          .args_type  = "device:s,opts:s?",
> > -        .params     = "tap|user|socket|vde|netmap|dump [options]",
> > +        .params     = "tap|user|socket|vde|bridge|dump [options]",
> 
> Why did you delete "netmap"?  I guess "bridge" should have been appended.
> 

Because "netmap" fails the net_host_check_device() check:

(qemu) host_net_add user
(qemu) host_net_add foooo
invalid host network device foooo
(qemu) host_net_add netmap
invalid host network device netmap

Should "netmap" be added there ?

> > diff --git a/monitor.c b/monitor.c
> > index 6a3a5c9..365c66a 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -4593,6 +4593,20 @@ void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
> >      }
> >  }
> >  
> > +void host_net_add_completion(ReadLineState *rs, int nb_args, const char *str)
> > +{
> > +    if (nb_args != 2) {
> > +        return;
> > +    }
> > +    readline_set_completion_index(rs, strlen(str));
> > +    add_completion_option(rs, str, "tap");
> > +    add_completion_option(rs, str, "user");
> > +    add_completion_option(rs, str, "socket");
> > +    add_completion_option(rs, str, "vde");
> > +    add_completion_option(rs, str, "dump");
> > +    add_completion_option(rs, str, "bridge");
> 
> Please take a look at net_host_check_device() and share the list from
> there.  (Some of the netdevs depend on build-time options.)

Ok, will add a patch to share the valid_params_list[] in include/net/net.h.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion.
  2014-05-25 16:12     ` Hani Benhabiles
@ 2014-05-26  9:20       ` Stefan Hajnoczi
  0 siblings, 0 replies; 16+ messages in thread
From: Stefan Hajnoczi @ 2014-05-26  9:20 UTC (permalink / raw)
  To: Hani Benhabiles
  Cc: kwolf, mdroth, Stefan Hajnoczi, qemu-devel, lcapitulino, imammedo

On Sun, May 25, 2014 at 05:12:55PM +0100, Hani Benhabiles wrote:
> On Fri, May 23, 2014 at 02:05:03PM +0200, Stefan Hajnoczi wrote:
> > On Tue, May 20, 2014 at 12:03:17AM +0100, Hani Benhabiles wrote:
> > > diff --git a/hmp-commands.hx b/hmp-commands.hx
> > > index 919af6e..6aaec1b 100644
> > > --- a/hmp-commands.hx
> > > +++ b/hmp-commands.hx
> > > @@ -1209,9 +1209,10 @@ ETEXI
> > >      {
> > >          .name       = "host_net_add",
> > >          .args_type  = "device:s,opts:s?",
> > > -        .params     = "tap|user|socket|vde|netmap|dump [options]",
> > > +        .params     = "tap|user|socket|vde|bridge|dump [options]",
> > 
> > Why did you delete "netmap"?  I guess "bridge" should have been appended.
> > 
> 
> Because "netmap" fails the net_host_check_device() check:
> 
> (qemu) host_net_add user
> (qemu) host_net_add foooo
> invalid host network device foooo
> (qemu) host_net_add netmap
> invalid host network device netmap
> 
> Should "netmap" be added there ?

Probably because your QEMU was not built with (optional) netmap support.
It's primarily used on FreeBSD but there is Linux code as well:
https://code.google.com/p/netmap/

Stefan

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2014-05-26  9:20 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-19 23:03 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
2014-05-19 23:03 ` [Qemu-devel] [PATCH 1/7] monitor: Add ringbuf_write and ringbuf_read argument completion Hani Benhabiles
2014-05-19 23:03 ` [Qemu-devel] [PATCH 2/7] monitor: Add watchdog_action " Hani Benhabiles
2014-05-19 23:03 ` [Qemu-devel] [PATCH 3/7] monitor: Add migrate_set_capability completion Hani Benhabiles
2014-05-21 18:42   ` Dr. David Alan Gilbert
2014-05-22  7:05     ` Markus Armbruster
2014-05-19 23:03 ` [Qemu-devel] [PATCH 4/7] monitor: Add host_net_add device argument completion Hani Benhabiles
2014-05-23 12:05   ` Stefan Hajnoczi
2014-05-25 16:12     ` Hani Benhabiles
2014-05-26  9:20       ` Stefan Hajnoczi
2014-05-19 23:03 ` [Qemu-devel] [PATCH 5/7] readline: Make completion strings always unique Hani Benhabiles
2014-05-19 23:03 ` [Qemu-devel] [PATCH 6/7] monitor: Add host_net_remove arguments completion Hani Benhabiles
2014-05-23 12:09   ` Stefan Hajnoczi
2014-05-19 23:03 ` [Qemu-devel] [PATCH 7/7] monitor: Add delvm and loadvm argument completion Hani Benhabiles
  -- strict thread matches above, loose matches on Subject: below --
2014-05-19 23:01 [Qemu-devel] monitor: Command completion for various commands Hani Benhabiles
2014-05-19 23:05 ` Hani Benhabiles

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).