* [Qemu-devel] [PATCH v2 01/17] monitor: Fix drive_del id argument type completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 02/17] monitor: Add command_completion callback to mon_cmd_t Hani Benhabiles
` (16 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index f3fc514..6bf4797 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -176,7 +176,7 @@ ETEXI
{
.name = "drive_del",
- .args_type = "id:s",
+ .args_type = "id:B",
.params = "device",
.help = "remove host block device",
.user_print = monitor_user_noop,
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 02/17] monitor: Add command_completion callback to mon_cmd_t.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 01/17] monitor: Fix drive_del id argument type completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-04-11 17:14 ` Luiz Capitulino
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 03/17] monitor: Add device_add and device_del completion Hani Benhabiles
` (15 subsequent siblings)
17 siblings, 1 reply; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Convert object_add and object_del commands to use the new callback.
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 2 ++
hmp.h | 3 +++
monitor.c | 19 +++++++++++++------
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 6bf4797..1b382b6 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1254,6 +1254,7 @@ ETEXI
.params = "[qom-type=]type,id=str[,prop=value][,...]",
.help = "create QOM object",
.mhandler.cmd = hmp_object_add,
+ .command_completion = object_add_completion,
},
STEXI
@@ -1268,6 +1269,7 @@ ETEXI
.params = "id",
.help = "destroy QOM object",
.mhandler.cmd = hmp_object_del,
+ .command_completion = object_del_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index ed58f0e..2f2c059 100644
--- a/hmp.h
+++ b/hmp.h
@@ -15,6 +15,7 @@
#define HMP_H
#include "qemu-common.h"
+#include "qemu/readline.h"
#include "qapi-types.h"
#include "qapi/qmp/qdict.h"
@@ -92,5 +93,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict);
void hmp_cpu_add(Monitor *mon, const QDict *qdict);
void hmp_object_add(Monitor *mon, const QDict *qdict);
void hmp_object_del(Monitor *mon, const QDict *qdict);
+void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
+void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
#endif
diff --git a/monitor.c b/monitor.c
index 342e83b..566a83f 100644
--- a/monitor.c
+++ b/monitor.c
@@ -137,6 +137,7 @@ typedef struct mon_cmd_t {
* used, and mhandler of 1st level plays the role of help function.
*/
struct mon_cmd_t *sub_table;
+ void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
} mon_cmd_t;
/* file descriptors passed via SCM_RIGHTS */
@@ -4298,11 +4299,15 @@ static void device_add_completion(ReadLineState *rs, const char *str)
g_slist_free(list);
}
-static void object_add_completion(ReadLineState *rs, const char *str)
+void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
{
GSList *list, *elt;
size_t len;
+ if (nb_args != 2) {
+ return;
+ }
+
len = strlen(str);
readline_set_completion_index(rs, len);
list = elt = object_class_get_list(TYPE_USER_CREATABLE, false);
@@ -4337,11 +4342,14 @@ static void device_del_completion(ReadLineState *rs, BusState *bus,
}
}
-static void object_del_completion(ReadLineState *rs, const char *str)
+void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
{
ObjectPropertyInfoList *list, *start;
size_t len;
+ if (nb_args != 2) {
+ return;
+ }
len = strlen(str);
readline_set_completion_index(rs, len);
@@ -4395,6 +4403,9 @@ static void monitor_find_completion_by_table(Monitor *mon,
return monitor_find_completion_by_table(mon, cmd->sub_table,
&args[1], nb_args - 1);
}
+ if (cmd->command_completion) {
+ return cmd->command_completion(mon->rs, nb_args, args[nb_args - 1]);
+ }
ptype = next_arg_type(cmd->args_type);
for(i = 0; i < nb_args - 2; i++) {
@@ -4424,8 +4435,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
case 'O':
if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
device_add_completion(mon->rs, str);
- } else if (!strcmp(cmd->name, "object_add") && nb_args == 2) {
- object_add_completion(mon->rs, str);
}
break;
case 's':
@@ -4445,8 +4454,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
size_t len = strlen(str);
readline_set_completion_index(mon->rs, len);
device_del_completion(mon->rs, sysbus_get_default(), str, len);
- } else if (!strcmp(cmd->name, "object_del") && nb_args == 2) {
- object_del_completion(mon->rs, str);
}
break;
default:
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Qemu-devel] [PATCH v2 02/17] monitor: Add command_completion callback to mon_cmd_t.
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 02/17] monitor: Add command_completion callback to mon_cmd_t Hani Benhabiles
@ 2014-04-11 17:14 ` Luiz Capitulino
0 siblings, 0 replies; 24+ messages in thread
From: Luiz Capitulino @ 2014-04-11 17:14 UTC (permalink / raw)
To: Hani Benhabiles; +Cc: kwolf, aliguori, qemu-devel, stefanha, imammedo
On Sun, 30 Mar 2014 11:58:24 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:
> Convert object_add and object_del commands to use the new callback.
>
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
> hmp-commands.hx | 2 ++
> hmp.h | 3 +++
> monitor.c | 19 +++++++++++++------
> 3 files changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 6bf4797..1b382b6 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1254,6 +1254,7 @@ ETEXI
> .params = "[qom-type=]type,id=str[,prop=value][,...]",
> .help = "create QOM object",
> .mhandler.cmd = hmp_object_add,
> + .command_completion = object_add_completion,
> },
>
> STEXI
> @@ -1268,6 +1269,7 @@ ETEXI
> .params = "id",
> .help = "destroy QOM object",
> .mhandler.cmd = hmp_object_del,
> + .command_completion = object_del_completion,
> },
>
> STEXI
> diff --git a/hmp.h b/hmp.h
> index ed58f0e..2f2c059 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -15,6 +15,7 @@
> #define HMP_H
>
> #include "qemu-common.h"
> +#include "qemu/readline.h"
> #include "qapi-types.h"
> #include "qapi/qmp/qdict.h"
>
> @@ -92,5 +93,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict);
> void hmp_cpu_add(Monitor *mon, const QDict *qdict);
> void hmp_object_add(Monitor *mon, const QDict *qdict);
> void hmp_object_del(Monitor *mon, const QDict *qdict);
> +void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
> +void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
>
> #endif
> diff --git a/monitor.c b/monitor.c
> index 342e83b..566a83f 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -137,6 +137,7 @@ typedef struct mon_cmd_t {
> * used, and mhandler of 1st level plays the role of help function.
> */
> struct mon_cmd_t *sub_table;
> + void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
> } mon_cmd_t;
>
> /* file descriptors passed via SCM_RIGHTS */
> @@ -4298,11 +4299,15 @@ static void device_add_completion(ReadLineState *rs, const char *str)
> g_slist_free(list);
> }
>
> -static void object_add_completion(ReadLineState *rs, const char *str)
> +void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
> {
> GSList *list, *elt;
> size_t len;
>
> + if (nb_args != 2) {
> + return;
> + }
> +
> len = strlen(str);
> readline_set_completion_index(rs, len);
> list = elt = object_class_get_list(TYPE_USER_CREATABLE, false);
> @@ -4337,11 +4342,14 @@ static void device_del_completion(ReadLineState *rs, BusState *bus,
> }
> }
>
> -static void object_del_completion(ReadLineState *rs, const char *str)
> +void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
> {
> ObjectPropertyInfoList *list, *start;
> size_t len;
>
> + if (nb_args != 2) {
> + return;
> + }
> len = strlen(str);
> readline_set_completion_index(rs, len);
>
> @@ -4395,6 +4403,9 @@ static void monitor_find_completion_by_table(Monitor *mon,
> return monitor_find_completion_by_table(mon, cmd->sub_table,
> &args[1], nb_args - 1);
> }
> + if (cmd->command_completion) {
> + return cmd->command_completion(mon->rs, nb_args, args[nb_args - 1]);
> + }
Honest question: have you checked if this plays well if the recursive call to
monitor_find_completion_by_table()?
>
> ptype = next_arg_type(cmd->args_type);
> for(i = 0; i < nb_args - 2; i++) {
> @@ -4424,8 +4435,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
> case 'O':
> if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
> device_add_completion(mon->rs, str);
> - } else if (!strcmp(cmd->name, "object_add") && nb_args == 2) {
> - object_add_completion(mon->rs, str);
> }
> break;
> case 's':
> @@ -4445,8 +4454,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
> size_t len = strlen(str);
> readline_set_completion_index(mon->rs, len);
> device_del_completion(mon->rs, sysbus_get_default(), str, len);
> - } else if (!strcmp(cmd->name, "object_del") && nb_args == 2) {
> - object_del_completion(mon->rs, str);
> }
> break;
> default:
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 03/17] monitor: Add device_add and device_del completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 01/17] monitor: Fix drive_del id argument type completion Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 02/17] monitor: Add command_completion callback to mon_cmd_t Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-04-11 17:30 ` Luiz Capitulino
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 04/17] monitor: Add chardev-remove id argument completion Hani Benhabiles
` (14 subsequent siblings)
17 siblings, 1 reply; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 2 ++
hmp.h | 2 ++
monitor.c | 34 +++++++++++++++++++++-------------
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 1b382b6..4c4d261 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -658,6 +658,7 @@ ETEXI
.help = "add device, like -device on the command line",
.user_print = monitor_user_noop,
.mhandler.cmd_new = do_device_add,
+ .command_completion = device_add_completion,
},
STEXI
@@ -673,6 +674,7 @@ ETEXI
.params = "device",
.help = "remove device",
.mhandler.cmd = hmp_device_del,
+ .command_completion = device_del_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index 2f2c059..20ef454 100644
--- a/hmp.h
+++ b/hmp.h
@@ -95,5 +95,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict);
void hmp_object_del(Monitor *mon, const QDict *qdict);
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);
#endif
diff --git a/monitor.c b/monitor.c
index 566a83f..710ba25 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4278,11 +4278,15 @@ static const char *next_arg_type(const char *typestr)
return (p != NULL ? ++p : typestr);
}
-static void device_add_completion(ReadLineState *rs, const char *str)
+void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
{
GSList *list, *elt;
size_t len;
+ if (nb_args != 2) {
+ return;
+ }
+
len = strlen(str);
readline_set_completion_index(rs, len);
list = elt = object_class_get_list(TYPE_DEVICE, false);
@@ -4323,8 +4327,8 @@ void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
g_slist_free(list);
}
-static void device_del_completion(ReadLineState *rs, BusState *bus,
- const char *str, size_t len)
+static void device_del_bus_completion(ReadLineState *rs, BusState *bus,
+ const char *str, size_t len)
{
BusChild *kid;
@@ -4337,11 +4341,24 @@ static void device_del_completion(ReadLineState *rs, BusState *bus,
}
QLIST_FOREACH(dev_child, &dev->child_bus, sibling) {
- device_del_completion(rs, dev_child, str, len);
+ device_del_bus_completion(rs, dev_child, str, len);
}
}
}
+void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ size_t len;
+
+ if (nb_args != 2) {
+ return;
+ }
+
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ device_del_bus_completion(rs, sysbus_get_default(), str, len);
+}
+
void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
{
ObjectPropertyInfoList *list, *start;
@@ -4432,11 +4449,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
readline_set_completion_index(mon->rs, strlen(str));
bdrv_iterate(block_completion_it, &mbs);
break;
- case 'O':
- if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
- device_add_completion(mon->rs, str);
- }
- break;
case 's':
case 'S':
if (!strcmp(cmd->name, "sendkey")) {
@@ -4450,10 +4462,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
} else if (!strcmp(cmd->name, "help|?")) {
monitor_find_completion_by_table(mon, cmd_table,
&args[1], nb_args - 1);
- } else if (!strcmp(cmd->name, "device_del") && nb_args == 2) {
- size_t len = strlen(str);
- readline_set_completion_index(mon->rs, len);
- device_del_completion(mon->rs, sysbus_get_default(), str, len);
}
break;
default:
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Qemu-devel] [PATCH v2 03/17] monitor: Add device_add and device_del completion.
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 03/17] monitor: Add device_add and device_del completion Hani Benhabiles
@ 2014-04-11 17:30 ` Luiz Capitulino
0 siblings, 0 replies; 24+ messages in thread
From: Luiz Capitulino @ 2014-04-11 17:30 UTC (permalink / raw)
To: Hani Benhabiles; +Cc: kwolf, aliguori, qemu-devel, stefanha, imammedo
On Sun, 30 Mar 2014 11:58:25 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:
> Signed-off-by: Hani Benhabiles <hani@linux.com>
This is not related to this change, but device_add seems to return
non-hotpluggable devices in the completion list (eg. Opteron_G5-x86_64-cpu).
Might be worth fixing in this series.
One more comment below.
> ---
> hmp-commands.hx | 2 ++
> hmp.h | 2 ++
> monitor.c | 34 +++++++++++++++++++++-------------
> 3 files changed, 25 insertions(+), 13 deletions(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 1b382b6..4c4d261 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -658,6 +658,7 @@ ETEXI
> .help = "add device, like -device on the command line",
> .user_print = monitor_user_noop,
> .mhandler.cmd_new = do_device_add,
> + .command_completion = device_add_completion,
> },
>
> STEXI
> @@ -673,6 +674,7 @@ ETEXI
> .params = "device",
> .help = "remove device",
> .mhandler.cmd = hmp_device_del,
> + .command_completion = device_del_completion,
> },
>
> STEXI
> diff --git a/hmp.h b/hmp.h
> index 2f2c059..20ef454 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -95,5 +95,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict);
> void hmp_object_del(Monitor *mon, const QDict *qdict);
> 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);
>
> #endif
> diff --git a/monitor.c b/monitor.c
> index 566a83f..710ba25 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4278,11 +4278,15 @@ static const char *next_arg_type(const char *typestr)
> return (p != NULL ? ++p : typestr);
> }
>
> -static void device_add_completion(ReadLineState *rs, const char *str)
> +void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
> {
> GSList *list, *elt;
> size_t len;
>
> + if (nb_args != 2) {
> + return;
> + }
> +
> len = strlen(str);
> readline_set_completion_index(rs, len);
> list = elt = object_class_get_list(TYPE_DEVICE, false);
> @@ -4323,8 +4327,8 @@ void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
> g_slist_free(list);
> }
>
> -static void device_del_completion(ReadLineState *rs, BusState *bus,
> - const char *str, size_t len)
> +static void device_del_bus_completion(ReadLineState *rs, BusState *bus,
> + const char *str, size_t len)
> {
You don't have to respin just because of this, but it's not clear to me why
you're renaming that function.
> BusChild *kid;
>
> @@ -4337,11 +4341,24 @@ static void device_del_completion(ReadLineState *rs, BusState *bus,
> }
>
> QLIST_FOREACH(dev_child, &dev->child_bus, sibling) {
> - device_del_completion(rs, dev_child, str, len);
> + device_del_bus_completion(rs, dev_child, str, len);
> }
> }
> }
>
> +void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
> +{
> + size_t len;
> +
> + if (nb_args != 2) {
> + return;
> + }
> +
> + len = strlen(str);
> + readline_set_completion_index(rs, len);
> + device_del_bus_completion(rs, sysbus_get_default(), str, len);
> +}
> +
> void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
> {
> ObjectPropertyInfoList *list, *start;
> @@ -4432,11 +4449,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
> readline_set_completion_index(mon->rs, strlen(str));
> bdrv_iterate(block_completion_it, &mbs);
> break;
> - case 'O':
> - if (!strcmp(cmd->name, "device_add") && nb_args == 2) {
> - device_add_completion(mon->rs, str);
> - }
> - break;
> case 's':
> case 'S':
> if (!strcmp(cmd->name, "sendkey")) {
> @@ -4450,10 +4462,6 @@ static void monitor_find_completion_by_table(Monitor *mon,
> } else if (!strcmp(cmd->name, "help|?")) {
> monitor_find_completion_by_table(mon, cmd_table,
> &args[1], nb_args - 1);
> - } else if (!strcmp(cmd->name, "device_del") && nb_args == 2) {
> - size_t len = strlen(str);
> - readline_set_completion_index(mon->rs, len);
> - device_del_completion(mon->rs, sysbus_get_default(), str, len);
> }
> break;
> default:
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 04/17] monitor: Add chardev-remove id argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (2 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 03/17] monitor: Add device_add and device_del completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-04-11 17:36 ` Luiz Capitulino
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 05/17] monitor: Add chardev-add backend " Hani Benhabiles
` (13 subsequent siblings)
17 siblings, 1 reply; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 1 +
hmp.h | 1 +
monitor.c | 23 +++++++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 4c4d261..4f0f053 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1630,6 +1630,7 @@ ETEXI
.params = "id",
.help = "remove chardev",
.mhandler.cmd = hmp_chardev_remove,
+ .command_completion = chardev_remove_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index 20ef454..42b4d6b 100644
--- a/hmp.h
+++ b/hmp.h
@@ -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 chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
#endif
diff --git a/monitor.c b/monitor.c
index 710ba25..040da9b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4346,6 +4346,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;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Qemu-devel] [PATCH v2 04/17] monitor: Add chardev-remove id argument completion.
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 04/17] monitor: Add chardev-remove id argument completion Hani Benhabiles
@ 2014-04-11 17:36 ` Luiz Capitulino
0 siblings, 0 replies; 24+ messages in thread
From: Luiz Capitulino @ 2014-04-11 17:36 UTC (permalink / raw)
To: Hani Benhabiles; +Cc: kwolf, aliguori, qemu-devel, stefanha, imammedo
On Sun, 30 Mar 2014 11:58:26 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:
> Signed-off-by: Hani Benhabiles <hani@linux.com>
Gerd, can you review this one and the patch (04/18). Both look good
to me, btw.
> ---
> hmp-commands.hx | 1 +
> hmp.h | 1 +
> monitor.c | 23 +++++++++++++++++++++++
> 3 files changed, 25 insertions(+)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 4c4d261..4f0f053 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1630,6 +1630,7 @@ ETEXI
> .params = "id",
> .help = "remove chardev",
> .mhandler.cmd = hmp_chardev_remove,
> + .command_completion = chardev_remove_completion,
> },
>
> STEXI
> diff --git a/hmp.h b/hmp.h
> index 20ef454..42b4d6b 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -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 chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
>
> #endif
> diff --git a/monitor.c b/monitor.c
> index 710ba25..040da9b 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4346,6 +4346,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;
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 05/17] monitor: Add chardev-add backend argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (3 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 04/17] monitor: Add chardev-remove id argument completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 06/17] monitor: Add cpu index " Hani Benhabiles
` (12 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 1 +
hmp.h | 1 +
monitor.c | 23 +++++++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 4f0f053..a411d4f 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1614,6 +1614,7 @@ ETEXI
.params = "args",
.help = "add chardev",
.mhandler.cmd = hmp_chardev_add,
+ .command_completion = chardev_add_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index 42b4d6b..6de5d1a 100644
--- a/hmp.h
+++ b/hmp.h
@@ -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 chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
+void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
#endif
diff --git a/monitor.c b/monitor.c
index 040da9b..27caa74 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4278,6 +4278,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;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 06/17] monitor: Add cpu index argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (4 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 05/17] monitor: Add chardev-add backend " Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 07/17] monitor: Add set_link arguments completion Hani Benhabiles
` (11 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 1 +
hmp.h | 1 +
monitor.c | 24 ++++++++++++++++++++++++
3 files changed, 26 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index a411d4f..813c0fb 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -690,6 +690,7 @@ ETEXI
.params = "index",
.help = "set the default CPU",
.mhandler.cmd = hmp_cpu,
+ .command_completion = cpu_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index 6de5d1a..8701b16 100644
--- a/hmp.h
+++ b/hmp.h
@@ -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 chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str);
void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
+void cpu_completion(ReadLineState *rs, int nb_args, const char *str);
#endif
diff --git a/monitor.c b/monitor.c
index 27caa74..29d4f37 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4429,6 +4429,30 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
qapi_free_ObjectPropertyInfoList(start);
}
+void cpu_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ CpuInfoList *cpu_list, *start;
+ size_t len;
+
+ if (nb_args != 2) {
+ return;
+ }
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+
+ start = cpu_list = qmp_query_cpus(NULL);
+ while (cpu_list) {
+ char name[16];
+ snprintf(name, sizeof(name), "%" PRId64, cpu_list->value->CPU);
+
+ if (!strncmp(str, name, len)) {
+ readline_add_completion(rs, name);
+ }
+ cpu_list = cpu_list->next;
+ }
+ qapi_free_CpuInfoList(start);
+}
+
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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 07/17] monitor: Add set_link arguments completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (5 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 06/17] monitor: Add cpu index " Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-04-11 17:40 ` Luiz Capitulino
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 08/17] monitor: Add netdev_add type argument completion Hani Benhabiles
` (10 subsequent siblings)
17 siblings, 1 reply; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
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.
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 1 +
hmp.h | 1 +
monitor.c | 34 ++++++++++++++++++++++++++++++++++
net/net.c | 2 +-
4 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 813c0fb..fbd303a 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1332,6 +1332,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
diff --git a/hmp.h b/hmp.h
index 8701b16..33a883d 100644
--- a/hmp.h
+++ b/hmp.h
@@ -100,5 +100,6 @@ void device_del_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 cpu_completion(ReadLineState *rs, int nb_args, const char *str);
+void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
#endif
diff --git a/monitor.c b/monitor.c
index 29d4f37..009f269 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4278,6 +4278,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;
@@ -4453,6 +4464,29 @@ void cpu_completion(ReadLineState *rs, int nb_args, const char *str)
qapi_free_CpuInfoList(start);
}
+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,
diff --git a/net/net.c b/net/net.c
index e3ef1e4..86dd051 100644
--- a/net/net.c
+++ b/net/net.c
@@ -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;
}
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Qemu-devel] [PATCH v2 07/17] monitor: Add set_link arguments completion.
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 07/17] monitor: Add set_link arguments completion Hani Benhabiles
@ 2014-04-11 17:40 ` Luiz Capitulino
0 siblings, 0 replies; 24+ messages in thread
From: Luiz Capitulino @ 2014-04-11 17:40 UTC (permalink / raw)
To: Hani Benhabiles; +Cc: kwolf, aliguori, qemu-devel, stefanha, imammedo
On Sun, 30 Mar 2014 11:58:29 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:
> 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.
>
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
> hmp-commands.hx | 1 +
> hmp.h | 1 +
> monitor.c | 34 ++++++++++++++++++++++++++++++++++
> net/net.c | 2 +-
> 4 files changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 813c0fb..fbd303a 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1332,6 +1332,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
> diff --git a/hmp.h b/hmp.h
> index 8701b16..33a883d 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -100,5 +100,6 @@ void device_del_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 cpu_completion(ReadLineState *rs, int nb_args, const char *str);
> +void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
>
> #endif
> diff --git a/monitor.c b/monitor.c
> index 29d4f37..009f269 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4278,6 +4278,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;
> @@ -4453,6 +4464,29 @@ void cpu_completion(ReadLineState *rs, int nb_args, const char *str)
> qapi_free_CpuInfoList(start);
> }
>
> +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");
> + }
> +}
> +
This prints both, the backend and frontend. Shouldn't it print only one of
them?
> static void monitor_find_completion_by_table(Monitor *mon,
> const mon_cmd_t *cmd_table,
> char **args,
> diff --git a/net/net.c b/net/net.c
> index e3ef1e4..86dd051 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -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;
> }
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 08/17] monitor: Add netdev_add type argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (6 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 07/17] monitor: Add set_link arguments completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-04-11 17:44 ` Luiz Capitulino
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 09/17] monitor: Add netdev_del id " Hani Benhabiles
` (9 subsequent siblings)
17 siblings, 1 reply; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Also update the command's documentation.
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 3 ++-
hmp.h | 1 +
monitor.c | 18 ++++++++++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index fbd303a..b009561 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1226,9 +1226,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
diff --git a/hmp.h b/hmp.h
index 33a883d..9dab1a3 100644
--- a/hmp.h
+++ b/hmp.h
@@ -101,5 +101,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 cpu_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
diff --git a/monitor.c b/monitor.c
index 009f269..5293370 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4312,6 +4312,24 @@ 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;
+
+ if (nb_args != 2) {
+ return;
+ }
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ add_completion_option(rs, str, "user");
+ add_completion_option(rs, str, "tap");
+ add_completion_option(rs, str, "socket");
+ add_completion_option(rs, str, "vde");
+ add_completion_option(rs, str, "bridge");
+ add_completion_option(rs, str, "hubport");
+ add_completion_option(rs, str, "netmap");
+}
+
void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
{
GSList *list, *elt;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [Qemu-devel] [PATCH v2 08/17] monitor: Add netdev_add type argument completion.
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 08/17] monitor: Add netdev_add type argument completion Hani Benhabiles
@ 2014-04-11 17:44 ` Luiz Capitulino
0 siblings, 0 replies; 24+ messages in thread
From: Luiz Capitulino @ 2014-04-11 17:44 UTC (permalink / raw)
To: Hani Benhabiles; +Cc: kwolf, aliguori, qemu-devel, stefanha, imammedo
On Sun, 30 Mar 2014 11:58:30 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:
> Also update the command's documentation.
>
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
> hmp-commands.hx | 3 ++-
> hmp.h | 1 +
> monitor.c | 18 ++++++++++++++++++
> 3 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index fbd303a..b009561 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1226,9 +1226,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
> diff --git a/hmp.h b/hmp.h
> index 33a883d..9dab1a3 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -101,5 +101,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 cpu_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
> diff --git a/monitor.c b/monitor.c
> index 009f269..5293370 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4312,6 +4312,24 @@ 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;
> +
> + if (nb_args != 2) {
> + return;
> + }
> + len = strlen(str);
> + readline_set_completion_index(rs, len);
> + add_completion_option(rs, str, "user");
> + add_completion_option(rs, str, "tap");
> + add_completion_option(rs, str, "socket");
> + add_completion_option(rs, str, "vde");
> + add_completion_option(rs, str, "bridge");
> + add_completion_option(rs, str, "hubport");
> + add_completion_option(rs, str, "netmap");
Having hardcoded values doesn't look good to me at all. I think we need
a way to query those, and then we add completion.
> +}
> +
> void device_add_completion(ReadLineState *rs, int nb_args, const char *str)
> {
> GSList *list, *elt;
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 09/17] monitor: Add netdev_del id argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (7 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 08/17] monitor: Add netdev_add type argument completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 10/17] monitor: Add ringbuf_write and ringbuf_read " Hani Benhabiles
` (8 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 1 +
hmp.h | 1 +
monitor.c | 26 ++++++++++++++++++++++++++
3 files changed, 28 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index b009561..d252ffc 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1244,6 +1244,7 @@ ETEXI
.params = "id",
.help = "remove host network device",
.mhandler.cmd = hmp_netdev_del,
+ .command_completion = netdev_del_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index 9dab1a3..c98722b 100644
--- a/hmp.h
+++ b/hmp.h
@@ -102,5 +102,6 @@ void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str);
void cpu_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
diff --git a/monitor.c b/monitor.c
index 5293370..d1b0d6c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4505,6 +4505,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,
--
1.8.3.2
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [Qemu-devel] [PATCH v2 10/17] monitor: Add ringbuf_write and ringbuf_read argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (8 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 09/17] monitor: Add netdev_del id " Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 11/17] monitor: Add watchdog_action " Hani Benhabiles
` (7 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, 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 d252ffc..300be4e 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 c98722b..d7d0770 100644
--- a/hmp.h
+++ b/hmp.h
@@ -103,5 +103,7 @@ void cpu_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 d1b0d6c..839f8f1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4421,6 +4421,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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 11/17] monitor: Add watchdog_action argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (9 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 10/17] monitor: Add ringbuf_write and ringbuf_read " Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 12/17] monitor: Add migrate_set_capability completion Hani Benhabiles
` (6 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, 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 300be4e..669a845 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1351,6 +1351,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 d7d0770..eca50b4 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 839f8f1..cb1fb7c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4570,6 +4570,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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 12/17] monitor: Add migrate_set_capability completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (10 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 11/17] monitor: Add watchdog_action " Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 13/17] monitor: Add host_net_add device argument completion Hani Benhabiles
` (5 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, 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 669a845..8c674ba 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 eca50b4..3570530 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 cb1fb7c..2974a66 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4584,6 +4584,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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 13/17] monitor: Add host_net_add device argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (11 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 12/17] monitor: Add migrate_set_capability completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 14/17] readline: Make completion strings always unique Hani Benhabiles
` (4 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, 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 8c674ba..9da5866 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1201,9 +1201,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 3570530..c82fd87 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 2974a66..4c20bc5 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4605,6 +4605,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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 14/17] readline: Make completion strings always unique.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (12 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 13/17] monitor: Add host_net_add device argument completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 15/17] monitor: Add host_net_remove arguments completion Hani Benhabiles
` (3 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, 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 8441be4..6aeae6a 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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 15/17] monitor: Add host_net_remove arguments completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (13 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 14/17] readline: Make completion strings always unique Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 16/17] monitor: Add mouse_set index argument completion Hani Benhabiles
` (2 subsequent siblings)
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, 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 9da5866..b41a6d6 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1219,6 +1219,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 c82fd87..12f0364 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 4c20bc5..9781ee2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4619,6 +4619,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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 16/17] monitor: Add mouse_set index argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (14 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 15/17] monitor: Add host_net_remove arguments completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 17/17] monitor: Add delvm and loadvm " Hani Benhabiles
2014-04-11 17:50 ` [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Luiz Capitulino
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, lcapitulino, stefanha, imammedo
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
hmp-commands.hx | 1 +
hmp.h | 1 +
monitor.c | 22 ++++++++++++++++++++++
3 files changed, 24 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index b41a6d6..04aa059 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -734,6 +734,7 @@ ETEXI
.params = "index",
.help = "set which mouse device receives events",
.mhandler.cmd = do_mouse_set,
+ .command_completion = mouse_set_completion,
},
STEXI
diff --git a/hmp.h b/hmp.h
index 12f0364..6e76473 100644
--- a/hmp.h
+++ b/hmp.h
@@ -112,5 +112,6 @@ 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 mouse_set_completion(ReadLineState *rs, int nb_args, const char *str);
#endif
diff --git a/monitor.c b/monitor.c
index 9781ee2..385fb70 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4657,6 +4657,28 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
}
}
+void mouse_set_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+ size_t len;
+ MouseInfoList *mice_list, *mouse;
+ if (nb_args != 2) {
+ return;
+ }
+ len = strlen(str);
+ readline_set_completion_index(rs, len);
+ mice_list = mouse = qmp_query_mice(NULL);
+ while (mouse) {
+ char name[16];
+ snprintf(name, sizeof(name), "%" PRId64, mouse->value->index);
+
+ if (!strncmp(str, name, len)) {
+ readline_add_completion(rs, name);
+ }
+ mouse = mouse->next;
+ }
+ qapi_free_MouseInfoList(mice_list);
+}
+
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] 24+ messages in thread
* [Qemu-devel] [PATCH v2 17/17] monitor: Add delvm and loadvm argument completion.
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (15 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 16/17] monitor: Add mouse_set index argument completion Hani Benhabiles
@ 2014-03-30 10:58 ` Hani Benhabiles
2014-04-11 17:50 ` [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Luiz Capitulino
17 siblings, 0 replies; 24+ messages in thread
From: Hani Benhabiles @ 2014-03-30 10:58 UTC (permalink / raw)
To: qemu-devel; +Cc: kwolf, aliguori, 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 04aa059..b59d0e0 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 6e76473..40d1513 100644
--- a/hmp.h
+++ b/hmp.h
@@ -113,5 +113,7 @@ 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 mouse_set_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 385fb70..ed57455 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)
@@ -4679,6 +4680,53 @@ void mouse_set_completion(ReadLineState *rs, int nb_args, const char *str)
qapi_free_MouseInfoList(mice_list);
}
+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] 24+ messages in thread
* Re: [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands
2014-03-30 10:58 [Qemu-devel] [PATCH v2 00/17] monitor: Completion support for various commands Hani Benhabiles
` (16 preceding siblings ...)
2014-03-30 10:58 ` [Qemu-devel] [PATCH v2 17/17] monitor: Add delvm and loadvm " Hani Benhabiles
@ 2014-04-11 17:50 ` Luiz Capitulino
17 siblings, 0 replies; 24+ messages in thread
From: Luiz Capitulino @ 2014-04-11 17:50 UTC (permalink / raw)
To: Hani Benhabiles; +Cc: kwolf, aliguori, qemu-devel, stefanha, imammedo
On Sun, 30 Mar 2014 11:58:22 +0100
Hani Benhabiles <kroosec@gmail.com> wrote:
> This patch series adds a new callback to mon_cmd_t which will make adding
> completion support for more commands cleaner.
>
> It then adds full or partial arguments completion for multiple hmp commands.
I was half-way through this series when something occurred to me: what
about merging only the existing completions first? I think that that can
be merged faster because it won't require other people's reviews and
discussions on new completions won't hold the entire series.
If you agree, please repost it and I'll try to review it quicker.
>
> Changes since v1:
> * Splitting patch 1/7 to 1/17, 2/17 and 3/17.
> * Changed command_completion's first argument from Monitor to ReadLineState.
> * Added new commands completions (10/17 to 17/17)
>
>
> Hani Benhabiles (17):
> monitor: Fix drive_del id argument type completion.
> monitor: Add command_completion callback to mon_cmd_t.
> monitor: Add device_add and device_del completion.
> monitor: Add chardev-remove id argument completion.
> monitor: Add chardev-add backend argument completion.
> monitor: Add cpu index argument completion.
> monitor: Add set_link arguments completion.
> monitor: Add netdev_add type argument completion.
> monitor: Add netdev_del id argument completion.
> 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 mouse_set index argument completion.
> monitor: Add delvm and loadvm argument completion.
>
> hmp-commands.hx | 25 +++-
> hmp.h | 23 +++
> include/sysemu/char.h | 3 +-
> monitor.c | 397 +++++++++++++++++++++++++++++++++++++++++++++++---
> net/net.c | 2 +-
> qemu-char.c | 2 +-
> util/readline.c | 6 +
> 7 files changed, 432 insertions(+), 26 deletions(-)
>
^ permalink raw reply [flat|nested] 24+ messages in thread