Skip to contentSkip to conversation

virtagent - fsfreeze support

PATCH Superseded [email protected] 2 participants 6 messages Feb 2, 2011 – Feb 4, 2011

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover virtagent - fsfreeze support

From: Jes Sorensen <[email protected]>

Hi

This is a first attempt to add fsfreeze support to virtagent. The idea is for the guest agent to walk the list of locally mounted file systems in the guest, and issuing an ioctl to freeze them. The host can then do a live snapshot of the guest, obtaining stable file systems. After the snapshot, the host then calls the thaw function in virtagent, which goes through the list of previously frozen file systems and unfreezes them.

The list walking ignores remote file systems such as NFS and CIFS as well as all pseudo file systems.

The guest agent code is in the first patch, and host agent code is in the second patch. For now there is only human monitor support, but it should be pretty straight forward to add QMP support as well.

Comments and suggestions welcome!

v2 of the patch addresses the issues pointed out by Stefan and Michael.

Cheers,
Jes

Jes Sorensen (2):
Add virtagent file system freeze/thaw
Add monitor commands for fsfreeze support

 hmp-commands.hx    |   48 +++++++++++
 virtagent-common.h |    9 ++
 virtagent-server.c |  190 ++++++++++++++++++++++++++++++++++++++++++
 virtagent.c        |  235 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 virtagent.h        |    9 ++
 5 files changed, 491 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.3.5
#1 lore raw

PATCH v2 1/2 Add virtagent file system freeze/thaw

From: Jes Sorensen <[email protected]>

Implement freeze/thaw support in the guest, allowing the host to request the guest freezes all it's file systems before a live snapshot is performed.
- fsfreeze(): Walk the list of mounted local real file systems, and freeze them.
- fsthaw(): Walk the list of previously frozen file systems and
thaw them.
- fsstatus(): Return the current status of freeze/thaw. The host must poll this function, in case fsfreeze() returned with a timeout, to wait for the operation to finish.

---
 virtagent-common.h |    8 ++
 virtagent-server.c |  190 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 198 insertions(+), 0 deletions(-)
virtagent-common.h +8 -0
index 5d8f5c1..7c6d9ef 100644
@@ -61,6 +61,14 @@ typedef struct VAContext {
     const char *channel_path;
 } VAContext;
 
+enum va_fsfreeze_status {
+    FREEZE_ERROR = -1,
+    FREEZE_THAWED = 0,
+    FREEZE_INPROGRESS = 1,
+    FREEZE_FROZEN = 2,
+    FREEZE_THAWINPROGRESS = 3,
+};
+
 enum va_job_status {
     VA_JOB_STATUS_PENDING = 0,
     VA_JOB_STATUS_OK,
virtagent-server.c +190 -0

208 lines not on this page · raw message

Signature · 1 line
1.7.3.5
#2 lore raw

[Qemu-devel] Re: [PATCH 1/2] Add virtagent file system freeze/thaw

Quoted 60 lines · On 02/02/2011 02:42 AM, [email protected] wrote:

From: Jes Sorensen<[email protected]>

Implement freeze/thaw support in the guest, allowing the host to request the guest freezes all it's file systems before a live snapshot is performed.
- fsfreeze(): Walk the list of mounted local real file systems, and freeze them.
- fsthaw(): Walk the list of previously frozen file systems and
thaw them.
- fsstatus(): Return the current status of freeze/thaw. The host must poll this function, in case fsfreeze() returned with a timeout, to wait for the operation to finish.

---
  virtagent-common.h |    8 ++
  virtagent-server.c |  190 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 198 insertions(+), 0 deletions(-)
virtagent-common.h +8 -0
index 5d8f5c1..7c6d9ef 100644
@@ -61,6 +61,14 @@ typedef struct VAContext {
      const char *channel_path;
  } VAContext;
 
+enum va_fsfreeze_status {
+    FREEZE_ERROR = -1,
+    FREEZE_THAWED = 0,
+    FREEZE_INPROGRESS = 1,
+    FREEZE_FROZEN = 2,
+    FREEZE_THAWINPROGRESS = 3,
+};
+
  enum va_job_status {
      VA_JOB_STATUS_PENDING = 0,
      VA_JOB_STATUS_OK,
virtagent-server.c +7 -0
index 7bb35b2..ffbe163 100644
@@ -14,6 +14,10 @@
  #include<syslog.h>
  #include "qemu_socket.h"
  #include "virtagent-common.h"
+#include<mntent.h>
+#include<sys/types.h>
+#include<sys/ioctl.h>
+#include<linux/fs.h>
 
  static VAServerData *va_server_data;
  static bool va_enable_syslog = false; /* enable syslog'ing of RPCs */
@@ -217,6 +221,186 @@ static xmlrpc_value *va_hello(xmlrpc_env *env,
      return result;
  }
 
+
+/*
+ * Walk the mount table and build a list of local file systems

virtagent-server.c static xmlrpc_value *va_hello(xmlrpc_env *env, · line 236

Quoted 10 lines
virtagent-server.c +10 -0
+ */
+
+struct direntry {
+    char *dirname;
+    char *devtype;
+    struct direntry *next;
+};
+
+static struct direntry *va_mount_list;
+static int va_fsfreeze_status;

And what I meant in the last RFC about using "objects" was to encapsulate global state information for a particular group of commands in single data type/variable. We're gonna end up with a similar set of variables for stateful RPCs like copyfile and potentially a few for things like spice. So to avoid having things get too cluttered up I'd prefer something like, in this particular case:

typedef struct VAFSFreezeState {
    struct direntry *mount_list;
    int status;
} VAFSFeezeState;

static VAFSFreezeState va_fsfreeze_state;

Quoted 4 lines
virtagent-server.c +4 -0
+
+static int build_mount_list(void)
+{
+    struct mntent *mnt;

virtagent-server.c static xmlrpc_value *va_hello(xmlrpc_env *env, · line 250

Quoted 10 lines
virtagent-server.c +10 -0
+    struct direntry *entry;
+    struct direntry *next;
+    char const *mtab = MOUNTED;
+    FILE *fp;
+
+    fp = setmntent(mtab, "r");
+    if (!fp) {
+	fprintf(stderr, "unable to read mtab\n");
+	goto fail;
+    }

You have tabs instead of spaces here

Quoted 10 lines
virtagent-server.c +10 -0
+
+    while ((mnt = getmntent(fp))) {
+	/*
+	 * An entry which device name doesn't start with a '/' is
+	 * either a dummy file system or a network file system.
+	 * Add special handling for smbfs and cifs as is done by
+	 * coreutils as well.
+	 */
+	if ((mnt->mnt_fsname[0] != '/') ||
+	    (strcmp(mnt->mnt_type, "smbfs") == 0) ||

virtagent-server.c static xmlrpc_value *va_hello(xmlrpc_env *env, · line 270

Quoted 10 lines
virtagent-server.c +10 -0
+	    (strcmp(mnt->mnt_type, "cifs") == 0)) {
+	    continue;
+	}
+
+	entry = qemu_malloc(sizeof(struct direntry));
+	entry->dirname = qemu_strdup(mnt->mnt_dir);
+	entry->devtype = qemu_strdup(mnt->mnt_type);
+	entry->next = va_mount_list;
+
+	va_mount_list = entry;

Here too

virtagent-server.c static xmlrpc_value *va_hello(xmlrpc_env *env, · line 279

Quoted 9 lines
virtagent-server.c +9 -0
+    }
+
+    endmntent(fp);
+
+    return 0;
+
+fail:
+    while(va_mount_list) {
+	next = va_mount_list->next;

Here too. Might be some other spots but you get the point :)

Quoted 140 lines
virtagent-server.c +130 -0
+        qemu_free(va_mount_list->dirname);
+        qemu_free(va_mount_list->devtype);
+        qemu_free(va_mount_list);
+        va_mount_list = next;
+    }
+
+    return -1;
+}
+
+/*
+ * va_fsfreeze(): Walk list of mounted file systems in the guest, and
+ *   freeze the ones which are real local file systems.
+ * rpc return values: Number of file systems frozen, -1 on error.
+ */
+static xmlrpc_value *va_fsfreeze(xmlrpc_env *env,
+                                 xmlrpc_value *params,
+                                 void *user_data)
+{
+    xmlrpc_int32 ret = 0, i = 0;
+    xmlrpc_value *result;
+    struct direntry *entry;
+    int fd;
+    SLOG("va_fsfreeze()");
+
+    if (va_fsfreeze_status != FREEZE_THAWED) {
+        ret = 0;
+        goto out;
+    }
+
+    ret = build_mount_list();
+    if (ret<  0) {
+        goto out;
+    }
+
+    va_fsfreeze_status = FREEZE_INPROGRESS;
+
+    entry = va_mount_list;
+    while(entry) {
+        fd = qemu_open(entry->dirname, O_RDONLY);
+        if (fd == -1) {
+            ret = errno;
+            goto error;
+        }
+        ret = ioctl(fd, FIFREEZE);
+        close(fd);
+        if (ret<  0&&  ret != EOPNOTSUPP) {
+            goto error;
+        }
+
+        entry = entry->next;
+        i++;
+    }
+
+    va_fsfreeze_status = FREEZE_FROZEN;
+    ret = i;
+out:
+    result = xmlrpc_build_value(env, "i", ret);
+    return result;
+error:
+    if (i>  0) {
+        va_fsfreeze_status = FREEZE_ERROR;
+    }
+    goto out;
+}
+
+/*
+ * va_fsthaw(): Walk list of frozen file systems in the guest, and
+ *   thaw them.
+ * rpc return values: Number of file systems thawed on success, -1 on error.
+ */
+static xmlrpc_value *va_fsthaw(xmlrpc_env *env,
+                               xmlrpc_value *params,
+                               void *user_data)
+{
+    xmlrpc_int32 ret;
+    xmlrpc_value *result;
+    struct direntry *entry;
+    int fd, i = 0;
+    SLOG("va_fsthaw()");
+
+    if (va_fsfreeze_status != FREEZE_FROZEN) {
+        ret = 0;
+        goto out;
+    }
+
+    while((entry = va_mount_list)) {
+        fd = qemu_open(entry->dirname, O_RDONLY);
+        if (fd == -1) {
+            ret = -1;
+            goto out;
+        }
+        ret = ioctl(fd, FITHAW);
+        close(fd);
+        if (ret<  0&&  ret != EOPNOTSUPP) {
+            ret = -1;
+            goto out;
+        }
+
+        va_mount_list = entry->next;
+        qemu_free(entry->dirname);
+        qemu_free(entry->devtype);
+        qemu_free(entry);
+        i++;
+    }
+
+    va_fsfreeze_status = FREEZE_THAWED;
+    ret = i;
+out:
+    result = xmlrpc_build_value(env, "i", ret);
+    return result;
+}
+
+/* va_fsstatus(): Return status of freeze/thaw
+ * rpc return values: fsfreeze_status
+ */
+static xmlrpc_value *va_fsstatus(xmlrpc_env *env,
+                                 xmlrpc_value *params,
+                                 void *user_data)
+{
+    xmlrpc_value *result = xmlrpc_build_value(env, "i", va_fsfreeze_status);
+    SLOG("va_fsstatus()");
+    return result;
+}
+
  typedef struct RPCFunction {
      xmlrpc_value *(*func)(xmlrpc_env *env, xmlrpc_value *param, void *unused);
      const char *func_name;
@@ -237,6 +421,12 @@ static RPCFunction guest_functions[] = {
        .func_name = "va.ping" },
      { .func = va_capabilities,
        .func_name = "va.capabilities" },
+    { .func = va_fsfreeze,
+      .func_name = "va.fsfreeze" },
+    { .func = va_fsthaw,
+      .func_name = "va.fsthaw" },
+    { .func = va_fsstatus,
+      .func_name = "va.fsstatus" },
      { NULL, NULL }
  };
  static RPCFunction host_functions[] = {
#3 lore raw

[Qemu-devel] Re: [PATCH 1/2] Add virtagent file system freeze/thaw

Quoted 25 lines · Michael Roth
Quoted 7 lines
virtagent-server.c +3 -0
@@ -217,6 +221,186 @@ static xmlrpc_value *va_hello(xmlrpc_env *env,
      return result;
  }
 
+
+/*
+ * Walk the mount table and build a list of local file systems

virtagent-server.c static xmlrpc_value *va_hello(xmlrpc_env *env, · line 236

Quoted 10 lines
virtagent-server.c +10 -0
+ */
+
+struct direntry {
+    char *dirname;
+    char *devtype;
+    struct direntry *next;
+};
+
+static struct direntry *va_mount_list;
+static int va_fsfreeze_status;

And what I meant in the last RFC about using "objects" was to encapsulate global state information for a particular group of commands in single data type/variable. We're gonna end up with a similar set of variables for stateful RPCs like copyfile and potentially a few for things like spice. So to avoid having things get too cluttered up I'd prefer something like, in this particular case:

Quoted 6 lines
typedef struct VAFSFreezeState {
    struct direntry *mount_list;
    int status;
} VAFSFeezeState;

static VAFSFreezeState va_fsfreeze_state;

Ok, I got rid of the tabs (damn I thought I had caught them all), and added a struct to keep the freeze state. I didn't add any typedef grossness though.

v3 coming up.

Cheers,
Jes

#4 lore raw

PATCH v2 2/2 Add monitor commands for fsfreeze support

In reply to [email protected]

From: Jes Sorensen <[email protected]>

This patch adds the following monitor commands:

agent_fsfreeze:
- Freezes all local file systems in the guest. Command will print the number of file systems that were frozen.
agent_fsthaw:
- Thaws all local file systems in the guest. Command will print the number of file systems that were thawed.
agent_fsstatus:
- Prints the current status of file systems in the guest:
Thawed, frozen, thaw in progress, freeze in progress, error.

---
 hmp-commands.hx    |   48 +++++++++++
 virtagent-common.h |    1 +
 virtagent.c        |  235 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 virtagent.h        |    9 ++
 4 files changed, 293 insertions(+), 0 deletions(-)
hmp-commands.hx +48 -0
index 9c7ac0b..f4150da 100644
@@ -1310,6 +1310,54 @@ STEXI
 Fetch and re-negotiate guest agent capabilties
 ETEXI
 
+    {
+        .name       = "agent_fsfreeze",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Freeze all local file systems mounted in the guest",
+        .user_print = do_agent_fsfreeze_print,
+        .mhandler.cmd_async = do_agent_fsfreeze,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+
+STEXI
+@item agent_fsfreeze
+@findex agent_fsfreeze
+Freeze all local mounted file systems in guest
+ETEXI
+
+    {
+        .name       = "agent_fsthaw",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Thaw all local file systems mounted in the guest",
+        .user_print = do_agent_fsthaw_print,
+        .mhandler.cmd_async = do_agent_fsthaw,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+
+STEXI
+@item agent_fsthaw
+@findex agent_fsthaw
+Thaw all local mounted file systems in guest
+ETEXI
+
+    {
+        .name       = "agent_fsstatus",
+        .args_type  = "",
+        .params     = "",
+        .help       = "Display status of file system freeze progress in guest",
+        .user_print = do_agent_fsstatus_print,
+        .mhandler.cmd_async = do_agent_fsstatus,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+
+STEXI
+@item agent_fsstatus
+@findex agent_fsstatus
+Get status of file system freeze in guest
+ETEXI
+
 STEXI
 @end table
 ETEXI
virtagent-common.h +1 -0
index 7c6d9ef..ff7bf23 100644
@@ -24,6 +24,7 @@
 #include "monitor.h"
 #include "virtagent-server.h"
 #include "virtagent.h"
+#include "qint.h"
 
 #define DEBUG_VA
 
virtagent.c +235 -0

238 lines not on this page · raw message

virtagent.h +9 -0
index dba90d0..0d7575d 100644
@@ -46,5 +46,14 @@ int do_agent_capabilities(Monitor *mon, const QDict *mon_params,
                   MonitorCompletion cb, void *opaque);
 int va_client_init_capabilities(void);
 int va_send_hello(void);
+void do_agent_fsfreeze_print(Monitor *mon, const QObject *qobject);
+int do_agent_fsfreeze(Monitor *mon, const QDict *mon_params,
+                      MonitorCompletion cb, void *opaque);
+void do_agent_fsthaw_print(Monitor *mon, const QObject *qobject);
+int do_agent_fsthaw(Monitor *mon, const QDict *mon_params,
+                    MonitorCompletion cb, void *opaque);
+void do_agent_fsstatus_print(Monitor *mon, const QObject *qobject);
+int do_agent_fsstatus(Monitor *mon, const QDict *mon_params,
+                      MonitorCompletion cb, void *opaque);
 
 #endif /* VIRTAGENT_H */
Signature · 1 line
1.7.3.5
#5 lore raw
In reply to [email protected]

Hi Jes,

Can you add Badari (CC'd) to the next round? He's looked at potentially using virtagent for snapshots in the past and might have some insights here. Thanks.

Quoted 38 lines · On 02/02/2011 02:42 AM, [email protected] wrote:

From: Jes Sorensen<[email protected]>

Hi

This is a first attempt to add fsfreeze support to virtagent. The idea is for the guest agent to walk the list of locally mounted file systems in the guest, and issuing an ioctl to freeze them. The host can then do a live snapshot of the guest, obtaining stable file systems. After the snapshot, the host then calls the thaw function in virtagent, which goes through the list of previously frozen file systems and unfreezes them.

The list walking ignores remote file systems such as NFS and CIFS as well as all pseudo file systems.

The guest agent code is in the first patch, and host agent code is in the second patch. For now there is only human monitor support, but it should be pretty straight forward to add QMP support as well.

Comments and suggestions welcome!

v2 of the patch addresses the issues pointed out by Stefan and Michael.

Cheers,
Jes

Jes Sorensen (2):
Add virtagent file system freeze/thaw
Add monitor commands for fsfreeze support

  hmp-commands.hx    |   48 +++++++++++
  virtagent-common.h |    9 ++
  virtagent-server.c |  190 ++++++++++++++++++++++++++++++++++++++++++
  virtagent.c        |  235 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  virtagent.h        |    9 ++
  5 files changed, 491 insertions(+), 0 deletions(-)