Skip to contentSkip to conversation

qemu-ga: execute fsfreeze-freeze in reverse order of mounts

PATCH Applied Tomoki Sekiyama 3 participants 3 messages Oct 1, 2013 – Oct 8, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-ga: execute fsfreeze-freeze in reverse order of mounts

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 freeze filesystems in reverse order of mounts.

---
 qga/commands-posix.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qga/commands-posix.c +2 -2
index e199738..f453132 100644
@@ -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);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Tomoki Sekiyama

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 freeze filesystems in reverse order of mounts.

s/freeze/freezes/

Quoted 5 lines
---
 qga/commands-posix.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Thaw already worked in the forward direction; with your patch, this means thaw undoes the actions by freeze in the opposite order (last frozen is first thawed), which is also a good thing.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Applied
#2 lore raw
In reply to Tomoki Sekiyama

Quoting Tomoki Sekiyama (2013-10-01 16:09:53)

Quoted 10 lines

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 freeze filesystems in reverse order of mounts.

Thanks, applied to qga tree:

https://github.com/mdroth/qemu/commits/qga

Quoted 26 lines
---
 qga/commands-posix.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
qga/commands-posix.c +2 -2
index e199738..f453132 100644
@@ -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);