From 9aca7b7392f7f20f28545737aaad95805a608578 Mon Sep 17 00:00:00 2001
Message-Id: <9aca7b7392f7f20f28545737aaad95805a608578.1350493760.git.minovotn@redhat.com>
In-Reply-To: <c93188b6c6973932d2adaa52e6a4920db13b4e62.1350493760.git.minovotn@redhat.com>
References: <c93188b6c6973932d2adaa52e6a4920db13b4e62.1350493760.git.minovotn@redhat.com>
From: Jeffrey Cody <jcody@redhat.com>
Date: Wed, 17 Oct 2012 05:59:40 +0200
Subject: [PATCH 27/35] block: after creating a live snapshot, make old image
 read-only

RH-Author: Jeffrey Cody <jcody@redhat.com>
Message-id: <d86c06edd564e2ee88370fb0dd7b56a631a70383.1350447475.git.jcody@redhat.com>
Patchwork-id: 43285
O-Subject: [RHEL6.4 qemu-kvm PATCH v4 27/35] block: after creating a live snapshot, make old image read-only
Bugzilla: 767233
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Eric Blake <eblake@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

Currently, after a live snapshot of a drive, the image that has
been 'demoted' to be below the new active layer remains r/w.
This patch reopens it read-only.

Note that we do not check for error on the reopen(), because we
will not abort the snapshots if the reopen fails.

This patch depends on the bdrv_reopen() series.

Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 870f5681c9dbafc738082b1fd48e0cc013bf43c7)

Conflicts:
	blockdev.c
---
 blockdev.c | 5 +++++
 1 file changed, 5 insertions(+)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 blockdev.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index 7c509c3..f187c90 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1040,6 +1040,11 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp)
         case BLOCKDEV_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC:
             /* This removes our old bs from the bdrv_states, and adds the new bs */
             bdrv_append(states->new_bs, states->old_bs);
+            /* We don't need (or want) to use the transactional
+             * bdrv_reopen_multiple() across all the entries at once, because we
+             * don't want to abort all of them if one of them fails the reopen */
+            bdrv_reopen(states->new_bs, states->new_bs->open_flags & ~BDRV_O_RDWR,
+                        NULL);
             break;
 
         case BLOCKDEV_ACTION_KIND___COM_REDHAT_DRIVE_MIRROR:
-- 
1.7.11.7

