aboutsummaryrefslogtreecommitdiff
path: root/qga
diff options
context:
space:
mode:
authorMichael Roth <mdroth@linux.vnet.ibm.com>2012-04-17 19:01:45 -0500
committerMichael Roth <mdroth@linux.vnet.ibm.com>2012-04-30 08:42:10 -0500
commitf22d85e9e67262db34504f4079745f9843da6a92 (patch)
tree4eb65b26bec47ed0b9b9f6014ad5278b1e89f048 /qga
parent9e8aded432884477bcd4fa1c7e849a196412bcc4 (diff)
qemu-ga: add a whitelist for fsfreeze-safe commands
Currently we rely on fsfreeze/thaw commands disabling/enabling logging then having other commands check whether logging is disabled to avoid executing if they aren't safe for running while a filesystem is frozen. Instead, have an explicit whitelist of fsfreeze-safe commands, and consolidate logging and command enablement/disablement into a pair of helper functions: ga_set_frozen()/ga_unset_frozen() Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga')
-rw-r--r--qga/commands-posix.c35
-rw-r--r--qga/guest-agent-core.h3
2 files changed, 12 insertions, 26 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 869d6ee831..d58730ad80 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -316,16 +316,6 @@ static void guest_file_init(void)
#if defined(CONFIG_FSFREEZE)
-static void disable_logging(void)
-{
- ga_disable_logging(ga_state);
-}
-
-static void enable_logging(void)
-{
- ga_enable_logging(ga_state);
-}
-
typedef struct GuestFsfreezeMount {
char *dirname;
char *devtype;
@@ -334,10 +324,6 @@ typedef struct GuestFsfreezeMount {
typedef QTAILQ_HEAD(, GuestFsfreezeMount) GuestFsfreezeMountList;
-struct {
- GuestFsfreezeStatus status;
-} guest_fsfreeze_state;
-
static void guest_fsfreeze_free_mount_list(GuestFsfreezeMountList *mounts)
{
GuestFsfreezeMount *mount, *temp;
@@ -400,7 +386,11 @@ static int guest_fsfreeze_build_mount_list(GuestFsfreezeMountList *mounts)
*/
GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
{
- return guest_fsfreeze_state.status;
+ if (ga_is_frozen(ga_state)) {
+ return GUEST_FSFREEZE_STATUS_FROZEN;
+ }
+
+ return GUEST_FSFREEZE_STATUS_THAWED;
}
/*
@@ -424,7 +414,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
}
/* cannot risk guest agent blocking itself on a write in this state */
- disable_logging();
+ ga_set_frozen(ga_state);
QTAILQ_FOREACH(mount, &mounts, next) {
fd = qemu_open(mount->dirname, O_RDONLY);
@@ -459,7 +449,6 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)
close(fd);
}
- guest_fsfreeze_state.status = GUEST_FSFREEZE_STATUS_FROZEN;
guest_fsfreeze_free_mount_list(&mounts);
return i;
@@ -519,23 +508,17 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
close(fd);
}
- guest_fsfreeze_state.status = GUEST_FSFREEZE_STATUS_THAWED;
- enable_logging();
+ ga_unset_frozen(ga_state);
guest_fsfreeze_free_mount_list(&mounts);
return i;
}
-static void guest_fsfreeze_init(void)
-{
- guest_fsfreeze_state.status = GUEST_FSFREEZE_STATUS_THAWED;
-}
-
static void guest_fsfreeze_cleanup(void)
{
int64_t ret;
Error *err = NULL;
- if (guest_fsfreeze_state.status == GUEST_FSFREEZE_STATUS_FROZEN) {
+ if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) {
ret = qmp_guest_fsfreeze_thaw(&err);
if (ret < 0 || err) {
slog("failed to clean up frozen filesystems");
@@ -964,7 +947,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
void ga_command_state_init(GAState *s, GACommandState *cs)
{
#if defined(CONFIG_FSFREEZE)
- ga_command_state_add(cs, guest_fsfreeze_init, guest_fsfreeze_cleanup);
+ ga_command_state_add(cs, NULL, guest_fsfreeze_cleanup);
#endif
ga_command_state_add(cs, guest_file_init, NULL);
}
diff --git a/qga/guest-agent-core.h b/qga/guest-agent-core.h
index 304525d3c2..bbb8b9b125 100644
--- a/qga/guest-agent-core.h
+++ b/qga/guest-agent-core.h
@@ -32,3 +32,6 @@ void ga_disable_logging(GAState *s);
void ga_enable_logging(GAState *s);
void slog(const gchar *fmt, ...);
void ga_set_response_delimited(GAState *s);
+bool ga_is_frozen(GAState *s);
+void ga_set_frozen(GAState *s);
+void ga_unset_frozen(GAState *s);