From dc7297f2d96febb58be9fa55a0db2832974d9d44 Mon Sep 17 00:00:00 2001
From: Tomoki Sekiyama <tsekiyam@redhat.com>
Date: Tue, 15 Oct 2013 14:59:49 +0200
Subject: [PATCH 4/4] qemu-ga: execute fsfreeze-freeze in reverse order of mounts

RH-Author: Tomoki Sekiyama <tsekiyam@redhat.com>
Message-id: <1381849189-28183-1-git-send-email-tsekiyam@redhat.com>
Patchwork-id: 54945
O-Subject: [RHEL 6.5 qemu-kvm PATCH v2] qemu-ga: execute fsfreeze-freeze in reverse order of mounts
Bugzilla: 1015633
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>

From: Tomoki Sekiyama <tomoki.sekiyama@hds.com>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1015633
Brew: https://brewweb.devel.redhat.com/taskinfo?taskID=6406845
Upstream-status: merged; e5d9adbdab972a2172815c1174aed3fabcc448f1

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.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
*fix up commit msg
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
v1->v2: updated commit log and upstream status as it is merged
---
 qga/commands-posix.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 qga/commands-posix.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 87f596d..234f794 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -567,7 +567,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)
 {
@@ -729,7 +729,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);
-- 
1.7.1

