qemu-ga: fsfreeze fix and guest-info extensions
Hi Anthony,
The following patches add support for indicating whether a guest agent command returns a response, as well as a fix to unfreeze filesystems LIFO order to avoid deadlocks in some cases where images are loopback-mounted to frozen filesystem.
The following changes since commit f2c6bcfc2e15e1dc5c69c3e579ff2063068ecb85:
Merge remote-tracking branch 'sstabellini/xen-2013-10-10' into staging (2013-10-10 10:03:38 -0700)
are available in the git repository at:
git://github.com/mdroth/qemu.git qga-pull-2013-10-10
for you to fetch changes up to 0106dc4f05231b44f54fae5d0ee42031298588bd:
qemu-ga: Extend 'guest-info' command to expose flag 'success-response' (2013-10-10 14:52:37 -0500)
----------------------------------------------------------------
Mark Wu (2):
qemu-ga: Add interface to traverse the qmp command list by QmpCommand
qemu-ga: Extend 'guest-info' command to expose flag 'success-response'
Tomoki Sekiyama (1):
qemu-ga: execute fsfreeze-freeze in reverse order of mounts
include/qapi/qmp/dispatch.h | 7 ++-- qapi/qmp-registry.c | 33 +++++++------------ qga/commands-posix.c | 4 +-- qga/commands.c | 39 +++++++++------------- qga/main.c | 75 +++++++++++++++++-------------------------- qga/qapi-schema.json | 5 ++- 6 files changed, 69 insertions(+), 94 deletions(-)
PATCH 1/3 qemu-ga: execute fsfreeze-freeze in reverse order of mounts
From: Tomoki Sekiyama <[email protected]>
Currently, fsfreeze-freeze may cause deadlock if a guest has loopback mounts of image files in its disk; e.g.:
# mount | grep ^/
/dev/vda1 / type ext4 (rw,noatime,seclabel,data=ordered)
/tmp/disk.img on /mnt type ext4 (rw,relatime,seclabel)To avoid the deadlock, this freezes filesystems in reverse order of mounts.
*fix up commit msg
--- qga/commands-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
qga/commands-posix.c +2 -2
@@ -566,7 +566,7 @@ typedef struct FsMount {QTAILQ_ENTRY (FsMount) next; } FsMount; -typedef QTAILQ_HEAD(, FsMount) FsMountList; +typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList;static void free_fs_mount_list (FsMountList *mounts) {
@@ -728,7 +728,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)/* cannot risk guest agent blocking itself on a write in this state */ ga_set_frozen (ga_state); - QTAILQ_FOREACH(mount, &mounts, next) { + QTAILQ_FOREACH_REVERSE(mount, &mounts, FsMountList, next) { fd =qemu_open (mount->dirname,O_RDONLY );if (fd ==-1 ) {error_setg_errno (err, errno,"failed to open %s" , mount->dirname);
Signature · 1 line
1.7.9.5
PATCH 2/3 qemu-ga: Add interface to traverse the qmp command list by QmpCommand
In reply to Michael RothFrom: Mark Wu <[email protected]>
In the original code, qmp_get_command_list is used to construct a list of all commands' name. To get the information of all qga commands, it traverses the name list and search the command info with its name. So it can cause O(n^2) in the number of commands.
This patch adds an interface to traverse the qmp command list by QmpCommand to replace qmp_get_command_list. It can decrease the complexity from O(n^2) to O(n).
*fix up commit subject
--- include/qapi/qmp/dispatch.h | 6 ++-- qapi/qmp-registry.c | 30 +++++------------ qga/commands.c | 38 +++++++++------------- qga/main.c | 75 +++++++++++++++++-------------------------- 4 files changed, 57 insertions(+), 92 deletions(-)
include/qapi/qmp/dispatch.h +4 -2
@@ -47,9 +47,11 @@ QmpCommand *qmp_find_command(const char *name);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); -char **qmp_get_command_list (void ); +bool qmp_command_is_enabled (const QmpCommand *cmd); +const char *qmp_command_name (const QmpCommand *cmd);QObject *qmp_build_error_object (Error *errp); +typedef void (*qmp_cmd_callback_fn )(QmpCommand *cmd,void *opaque); +void qmp_for_each_command (qmp_cmd_callback_fn fn,void *opaque);#endif
qapi/qmp-registry.c +8 -22
@@ -66,35 +66,21 @@ void qmp_enable_command(const char *name)qmp_toggle_command (name, true); } -bool qmp_command_is_enabled (const char *name) +bool qmp_command_is_enabled (const QmpCommand *cmd) { -QmpCommand *cmd; - - QTAILQ_FOREACH(cmd, &qmp_commands, node) { -if (strcmp (cmd->name, name) ==0 ) { -return cmd->enabled; - } - } +return cmd->enabled; +} -return false; +const char *qmp_command_name (const QmpCommand *cmd) +{ +return cmd->name; } -char **qmp_get_command_list (void ) +void qmp_for_each_command (qmp_cmd_callback_fn fn,void *opaque) {QmpCommand *cmd; -int count =1 ; -char **list_head, **list; - - QTAILQ_FOREACH(cmd, &qmp_commands, node) { - count++; - } - - list_head = list =g_malloc0 (count *sizeof (char *)); QTAILQ_FOREACH(cmd, &qmp_commands, node) { - *list =g_strdup (cmd->name); - list++; +fn (cmd, opaque); } - -return list_head; }
qga/commands.c +15 -23
@@ -45,35 +45,27 @@ void qmp_guest_ping(Error **err)slog ("guest-ping called" ); } -struct GuestAgentInfo *qmp_guest_info (Error **err) +static void qmp_command_info (QmpCommand *cmd,void *opaque) { -GuestAgentInfo *info =g_malloc0 (sizeof (GuestAgentInfo)); +GuestAgentInfo *info = opaque;GuestAgentCommandInfo *cmd_info;GuestAgentCommandInfoList *cmd_info_list; -char **cmd_list_head, **cmd_list; - - info->version =g_strdup (QEMU_VERSION ); - - cmd_list_head = cmd_list =qmp_get_command_list (); -if (*cmd_list_head ==NULL ) { - goto out; - } -while (*cmd_list) { - 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 =g_malloc0 (sizeof (GuestAgentCommandInfo)); + cmd_info->name =g_strdup (qmp_command_name (cmd)); + cmd_info->enabled =qmp_command_is_enabled (cmd); - cmd_info_list =g_malloc0 (sizeof (GuestAgentCommandInfoList)); - cmd_info_list->value = cmd_info; - cmd_info_list->next = info->supported_commands; - info->supported_commands = cmd_info_list; + cmd_info_list =g_malloc0 (sizeof (GuestAgentCommandInfoList)); + cmd_info_list->value = cmd_info; + cmd_info_list->next = info->supported_commands; + info->supported_commands = cmd_info_list; +} -g_free (*cmd_list); - cmd_list++; - } +struct GuestAgentInfo *qmp_guest_info (Error **err) +{ +GuestAgentInfo *info =g_malloc0 (sizeof (GuestAgentInfo)); -out: -g_free (cmd_list_head); + info->version =g_strdup (QEMU_VERSION ); +qmp_for_each_command (qmp_command_info, info);return info; }
qga/main.c +30 -45
120 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 3/3 qemu-ga: Extend 'guest-info' command to expose flag 'success-response'
In reply to Michael RothFrom: Mark Wu <[email protected]>
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.
*fixed up commit subject
--- include/qapi/qmp/dispatch.h | 1 + qapi/qmp-registry.c | 5 +++++ qga/commands.c | 1 + qga/qapi-schema.json | 5 ++++- 4 files changed, 11 insertions(+), 1 deletion(-)
include/qapi/qmp/dispatch.h +1 -0
@@ -49,6 +49,7 @@ void qmp_disable_command(const char *name);void qmp_enable_command (const char *name);bool qmp_command_is_enabled (const QmpCommand *cmd);const char *qmp_command_name (const QmpCommand *cmd); +bool qmp_has_success_response (const QmpCommand *cmd);QObject *qmp_build_error_object (Error *errp);typedef void (*qmp_cmd_callback_fn )(QmpCommand *cmd,void *opaque);void qmp_for_each_command (qmp_cmd_callback_fn fn,void *opaque);
qapi/qmp-registry.c +5 -0
@@ -76,6 +76,11 @@ const char *qmp_command_name(const QmpCommand *cmd)return cmd->name; } +bool qmp_has_success_response (const QmpCommand *cmd) +{ +return !(cmd->options &QCO_NO_SUCCESS_RESP ); +} +void qmp_for_each_command (qmp_cmd_callback_fn fn,void *opaque) {QmpCommand *cmd;
qga/commands.c +1 -0
@@ -54,6 +54,7 @@ static void qmp_command_info(QmpCommand *cmd, void *opaque) cmd_info =g_malloc0 (sizeof (GuestAgentCommandInfo)); cmd_info->name =g_strdup (qmp_command_name (cmd)); cmd_info->enabled =qmp_command_is_enabled (cmd); + cmd_info->success_response =qmp_has_success_response (cmd); 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 +# (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.7.9.5