Extend qemu-ga's 'guest-info' command to expose flag 'success-response'
PATCH 1/1 Extend qemu-ga's 'guest-info' command to expose flag 'success-response'
Now we have several qemu-ga commands not returning response on success. It has been documented in qga/qapi-schema.json already. This patch exposes the 'success-response' flag by extending 'guest-info' command. With this change, the clients can handle the command response more flexibly.
Changes:
v2: add the notation 'since 1.7' to the option 'success-response' (per Eric Blake's comments)
--- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-registry.c | 13 +++++++++++++ qga/commands.c | 2 ++ qga/qapi-schema.json | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-)
include/qapi/qmp/dispatch.h +1 -0
@@ -48,6 +48,7 @@ QObject *qmp_dispatch(QObject *request);void qmp_disable_command (const char *name);void qmp_enable_command (const char *name);bool qmp_command_is_enabled (const char *name); +bool qmp_command_has_success_response (const char *name);char **qmp_get_command_list (void );QObject *qmp_build_error_object (Error *errp);
qapi/qmp-registry.c +13 -0
@@ -79,6 +79,19 @@ bool qmp_command_is_enabled(const char *name)return false; } +bool qmp_command_has_success_response (const char *name) +{ +QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { +if (strcmp (cmd->name, name) ==0 ) { +return cmd->options !=QCO_NO_SUCCESS_RESP ; + } + } + +return false; +} +char **qmp_get_command_list (void ) {QmpCommand *cmd;
qga/commands.c +2 -0
@@ -63,6 +63,8 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (*cmd_list); cmd_info->enabled =qmp_command_is_enabled (cmd_info->name); + cmd_info->success_response = +qmp_command_has_success_response (cmd_info->name); cmd_info_list =g_malloc0 (sizeof (GuestAgentCommandInfoList)); cmd_info_list->value = cmd_info;
qga/qapi-schema.json +4 -1
@@ -141,10 +141,13 @@ # # @enabled: whether command is currently enabled by guest admin # +# @success-response: whether command returns a response on success +# and only available since 1.7 +# # Since 1.1.0 ## { 'type': 'GuestAgentCommandInfo', - 'data': { 'name': 'str', 'enabled': 'bool' } } + 'data': { 'name': 'str', 'enabled': 'bool', 'success-response': 'bool' } } ## # @GuestAgentInfo
Signature · 1 line
1.8.3.1
Quoted 10 lines · On Sun, 22 Sep 2013 14:50:54 +0800 Mark Wu <[email protected]> wrote:
Now we have several qemu-ga commands not returning response on success. It has been documented in
qga/qapi-schema.jsonalready. This patch exposes the 'success-response' flag by extending 'guest-info' command. With this change, the clients can handle the command response more flexibly.Changes:
v2: add the notation 'since 1.7' to the option 'success-response' (per Eric Blake's comments)Signed-off-by Mark Wu <[email protected]>
Quoted 75 lines
--- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-registry.c | 13 +++++++++++++ qga/commands.c | 2 ++ qga/qapi-schema.json | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-)include/qapi/qmp/dispatch.h +1
-0@@ -48,6 +48,7 @@ QObject *qmp_dispatch(QObject *request);void qmp_disable_command (const char *name);void qmp_enable_command (const char *name);bool qmp_command_is_enabled (const char *name); +bool qmp_command_has_success_response (const char *name);char **qmp_get_command_list (void );QObject *qmp_build_error_object (Error *errp);qapi/qmp-registry.c +13
-0@@ -79,6 +79,19 @@ bool qmp_command_is_enabled(const char *name)return false; } +bool qmp_command_has_success_response (const char *name) +{ +QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { +if (strcmp (cmd->name, name) ==0 ) { +return cmd->options !=QCO_NO_SUCCESS_RESP ; + } + } + +return false; +} +char **qmp_get_command_list (void ) {QmpCommand *cmd;qga/commands.c +2
-0@@ -63,6 +63,8 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (*cmd_list); cmd_info->enabled =qmp_command_is_enabled (cmd_info->name); + cmd_info->success_response = +qmp_command_has_success_response (cmd_info->name); cmd_info_list =g_malloc0 (sizeof (GuestAgentCommandInfoList)); cmd_info_list->value = cmd_info;qga/qapi-schema.json +4
-1@@ -141,10 +141,13 @@ # # @enabled: whether command is currently enabled by guest admin # +# @success-response: whether command returns a response on success +# and only available since 1.7 +# # Since 1.1.0 ## { 'type': 'GuestAgentCommandInfo', - 'data': { 'name': 'str', 'enabled': 'bool' } } + 'data': { 'name': 'str', 'enabled': 'bool', 'success-response': 'bool' } } ## # @GuestAgentInfo
Quoted 8 lines · Mark Wu
Now we have several qemu-ga commands not returning response on success. It has been documented in
qga/qapi-schema.jsonalready. This patch exposes the 'success-response' flag by extending 'guest-info' command. With this change, the clients can handle the command response more flexibly.Changes:
v2: add the notation 'since 1.7' to the option 'success-response' (per Eric Blake's comments)
Typically, the patch changelog should be placed...
Quoted 3 lines
Signed-off-by Mark Wu <[email protected]>---
...after the --- separator (see
http://wiki.qemu.org/Contribute/SubmitAPatch for more hints).
qga/qapi-schema.json line 145
Quoted 7 lines
+++
b/qga/qapi-schema.jsonqga/qapi-schema.json +2
-0@@ -141,10 +141,13 @@ # # @enabled: whether command is currently enabled by guest admin # +# @success-response: whether command returns a response on success +# and only available since 1.7
More typically, this is written:
@success-response: whether command returns a response on
success (since 1.7)
but as we don't parse the documentation, it doesn't hurt as written.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoting Mark Wu (2013-09-22 01:50:54)
Quoted 10 lines
Now we have several qemu-ga commands not returning response on success. It has been documented in
qga/qapi-schema.jsonalready. This patch exposes the 'success-response' flag by extending 'guest-info' command. With this change, the clients can handle the command response more flexibly.Changes:
v2: add the notation 'since 1.7' to the option 'success-response' (per Eric Blake's comments)Signed-off-by Mark Wu <[email protected]>
Eric, do we have your reviewed-by other than the changes you mentioned? If so I can fix those up in my tree.
Quoted 77 lines
--- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-registry.c | 13 +++++++++++++ qga/commands.c | 2 ++ qga/qapi-schema.json | 5 ++++- 4 files changed, 20 insertions(+), 1 deletion(-)include/qapi/qmp/dispatch.h +1
-0@@ -48,6 +48,7 @@ QObject *qmp_dispatch(QObject *request);void qmp_disable_command (const char *name);void qmp_enable_command (const char *name);bool qmp_command_is_enabled (const char *name); +bool qmp_command_has_success_response (const char *name);char **qmp_get_command_list (void );QObject *qmp_build_error_object (Error *errp);qapi/qmp-registry.c +13
-0@@ -79,6 +79,19 @@ bool qmp_command_is_enabled(const char *name)return false; } +bool qmp_command_has_success_response (const char *name) +{ +QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { +if (strcmp (cmd->name, name) ==0 ) { +return cmd->options !=QCO_NO_SUCCESS_RESP ; + } + } + +return false; +} +char **qmp_get_command_list (void ) {QmpCommand *cmd;qga/commands.c +2
-0@@ -63,6 +63,8 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (*cmd_list); cmd_info->enabled =qmp_command_is_enabled (cmd_info->name); + cmd_info->success_response = +qmp_command_has_success_response (cmd_info->name); cmd_info_list =g_malloc0 (sizeof (GuestAgentCommandInfoList)); cmd_info_list->value = cmd_info;qga/qapi-schema.json +4
-1@@ -141,10 +141,13 @@ # # @enabled: whether command is currently enabled by guest admin # +# @success-response: whether command returns a response on success +# and only available since 1.7 +# # Since 1.1.0 ## { 'type': 'GuestAgentCommandInfo', - 'data': { 'name': 'str', 'enabled': 'bool' } } + 'data': { 'name': 'str', 'enabled': 'bool', 'success-response': 'bool' } } ## # @GuestAgentInfoSignature · 1 line
1.8.3.1
Quoted 10 lines · Michael Roth
Quoting Mark Wu (2013-09-22 01:50:54)
Quoted 9 lines
Now we have several qemu-ga commands not returning response on success. It has been documented in
qga/qapi-schema.jsonalready. This patch exposes the 'success-response' flag by extending 'guest-info' command. With this change, the clients can handle the command response more flexibly.Changes:
v2: add the notation 'since 1.7' to the option 'success-response' (per Eric Blake's comments)
Quoted 6 lines
Quoted 1 line
Signed-off-by Mark Wu <[email protected]>Reviewed-by Michael Roth <[email protected]>Eric, do we have your reviewed-by other than the changes you mentioned? If so I can fix those up in my tree.
Aha - force me to do a FULL review, rather than just an interface review. I found more issues, so this probably deserves a v2:
Quoted 7 lines
qapi/qmp-registry.c bool qmp_command_is_enabled(const char *name) · line 88
Quoted 7 lines
qapi/qmp-registry.c +7
-0+bool qmp_command_has_success_response (const char *name) +{ +QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { +if (strcmp (cmd->name, name) ==0 ) { +return cmd->options !=QCO_NO_SUCCESS_RESP ;
cmd->options is a bitmask - it is feasible that we may add more QCO_NO_* flags in the future, at which point inequality is NOT correct. Rather, you want:
return !(cmd->options & QCO_NO_SUCCESS_RESP);
Quoted 7 lines
qga/commands.c struct GuestAgentInfo *qmp_guest_info(Error **err) · line 67
Quoted 7 lines
+++
b/qga/commands.cqga/commands.c +2
-0@@ -63,6 +63,8 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (*cmd_list); cmd_info->enabled =qmp_command_is_enabled (cmd_info->name); + cmd_info->success_response = +qmp_command_has_success_response (cmd_info->name);
This feels wasteful. Why are we doing an O(n) lookup for BOTH qmp_command_is_enabled AND qmp_command_has_success_response, in an O(n) loop over command names? That's O(n^2) in the number of commands. Better would be getting a list of QmpCommand* instead of a list of char*, and looking directly in each object, for O(n) computation of the results.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoting Eric Blake (2013-09-24 14:13:08)
Quoted 13 lines · Michael Roth
Quoted 12 lines
Quoting Mark Wu (2013-09-22 01:50:54)
Quoted 10 lines
Now we have several qemu-ga commands not returning response on success. It has been documented in
qga/qapi-schema.jsonalready. This patch exposes the 'success-response' flag by extending 'guest-info' command. With this change, the clients can handle the command response more flexibly.Changes:
v2: add the notation 'since 1.7' to the option 'success-response' (per Eric Blake's comments)Signed-off-by Mark Wu <[email protected]>
Quoted 7 lines
Quoted 4 lines
Reviewed-by Michael Roth <[email protected]>Eric, do we have your reviewed-by other than the changes you mentioned? If so I can fix those up in my tree.
Aha - force me to do a FULL review, rather than just an interface review. I found more issues, so this probably deserves a v2:
Haha, you saw through my plan! :)
Quoted 15 lines
Quoted 8 lines
qapi/qmp-registry.c bool qmp_command_is_enabled(const char *name) · line 88
Quoted 8 lines
qapi/qmp-registry.c +7
-0+bool qmp_command_has_success_response (const char *name) +{ +QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { +if (strcmp (cmd->name, name) ==0 ) { +return cmd->options !=QCO_NO_SUCCESS_RESP ;
cmd->optionsis a bitmask - it is feasible that we may add more QCO_NO_* flags in the future, at which point inequality is NOT correct. Rather, you want:return !(cmd->options &
QCO_NO_SUCCESS_RESP);
Quoted 14 lines
Quoted 7 lines
qga/commands.c struct GuestAgentInfo *qmp_guest_info(Error **err) · line 67
Quoted 7 lines
+++
b/qga/commands.cqga/commands.c +2
-0@@ -63,6 +63,8 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (*cmd_list); cmd_info->enabled =qmp_command_is_enabled (cmd_info->name); + cmd_info->success_response = +qmp_command_has_success_response (cmd_info->name);This feels wasteful. Why are we doing an O(n) lookup for BOTH
qmp_command_is_enabledANDqmp_command_has_success_response, in an O(n) loop over command names? That's O(n^2) in the number of commands. Better would be getting a list of QmpCommand* instead of a list of char*, and looking directly in each object, for O(n) computation of the results.
Agreed, modifying qmp_get_command_list to return a list of QmpCommand would be nicer. Rather than looking directly at the fields though I think we should just fix up qmp_command_is_enabled() and friends to take a QmpCommand arg instead of a char*. We already have qmp_find_command to map char*->QmpCommand to support any cases where we rely on cmd names.
Quoted 4 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 12 lines · On Tue, 24 Sep 2013 16:07:29 -0500 Michael Roth <[email protected]>…
Quoted 12 lines
Quoted 7 lines
qapi/qmp-registry.c bool qmp_command_is_enabled(const char *name) · line 88
Quoted 7 lines
qapi/qmp-registry.c +7
-0+bool qmp_command_has_success_response (const char *name) +{ +QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { +if (strcmp (cmd->name, name) ==0 ) { +return cmd->options !=QCO_NO_SUCCESS_RESP ;
cmd->optionsis a bitmask - it is feasible that we may add more QCO_NO_* flags in the future, at which point inequality is NOT correct. Rather, you want:
Quoted 1 line
Quoted 1 line
return !(cmd->options &
QCO_NO_SUCCESS_RESP);
Good catch! IIRC I added cmd->options myself and didn't catch this...
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
+++
b/qga/commands.cqga/commands.c +1
-0@@ -63,6 +63,8 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (*cmd_list); cmd_info->enabled =qmp_command_is_enabled (cmd_info->name); + cmd_info->success_response =Quoted 8 lines
Quoted 1 line
qga/commands.c struct GuestAgentInfo *qmp_guest_info(Error **err) · line 67
Quoted 1 line
qga/commands.c +1
-0+qmp_command_has_success_response (cmd_info->name);This feels wasteful. Why are we doing an O(n) lookup for BOTH
qmp_command_is_enabledANDqmp_command_has_success_response, in an O(n) loop over command names? That's O(n^2) in the number of commands. Better would be getting a list of QmpCommand* instead of a list of char*, and looking directly in each object, for O(n) computation of the results.
Quoted 6 lines
Agreed, modifying
qmp_get_command_listto return a list of QmpCommand would be nicer. Rather than looking directly at the fields though I think we should just fix upqmp_command_is_enabled()and friends to take a QmpCommand arg instead of a char*. We already haveqmp_find_commandto map char*->QmpCommand to support any cases where we rely on cmd names.
I agree and I thought the same thing when I reviewed the patch, but I didn't mind as Mark is just using what's already there.
Hi guys,
Thanks a lot for all your insightful comments. I will post a patch to resolve the O(n2) problem according to Michael's comments soon and rebase the 'success-response' on it.
Mark.
Quoted 39 lines · Luiz Capitulino
Quoted 11 lines · On Tue, 24 Sep 2013 16:07:29 -0500 Michael Roth <[email protected]>…
Quoted 11 lines
Quoted 7 lines
qapi/qmp-registry.c bool qmp_command_is_enabled(const char *name) · line 88
Quoted 7 lines
qapi/qmp-registry.c +7
-0+bool qmp_command_has_success_response (const char *name) +{ +QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, &qmp_commands, node) { +if (strcmp (cmd->name, name) ==0 ) { +return cmd->options !=QCO_NO_SUCCESS_RESP ;
cmd->optionsis a bitmask - it is feasible that we may add more QCO_NO_* flags in the future, at which point inequality is NOT correct. Rather, you want:Quoted 1 line
Quoted 1 line
return !(cmd->options &
QCO_NO_SUCCESS_RESP);Good catch! IIRC I added
cmd->optionsmyself and didn't catch this...Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
+++
b/qga/commands.cqga/commands.c +0
-0@@ -63,6 +63,8 @@ struct GuestAgentInfo *qmp_guest_info(Error **err) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (*cmd_list); cmd_info->enabled =qmp_command_is_enabled (cmd_info->name);Quoted 8 lines
Quoted 2 lines
qga/commands.c struct GuestAgentInfo *qmp_guest_info(Error **err) · line 67
Quoted 2 lines
qga/commands.c +2
-0+ cmd_info->success_response = +qmp_command_has_success_response (cmd_info->name);This feels wasteful. Why are we doing an O(n) lookup for BOTH
qmp_command_is_enabledANDqmp_command_has_success_response, in an O(n) loop over command names? That's O(n^2) in the number of commands. Better would be getting a list of QmpCommand* instead of a list of char*, and looking directly in each object, for O(n) computation of the results.Quoted 6 lines
Agreed, modifying
qmp_get_command_listto return a list of QmpCommand would be nicer. Rather than looking directly at the fields though I think we should just fix upqmp_command_is_enabled()and friends to take a QmpCommand arg instead of a char*. We already haveqmp_find_commandto map char*->QmpCommand to support any cases where we rely on cmd names.I agree and I thought the same thing when I reviewed the patch, but I didn't mind as Mark is just using what's already there.