qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qcow2: Don't write with BDRV_O_INCOMING
@ 2014-03-11 14:15 Kevin Wolf
  2014-03-11 15:25 ` Eric Blake
  2014-03-11 18:45 ` Stefan Hajnoczi
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2014-03-11 14:15 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, stefanha

qcow2_open() causes writes when repairing an image with the dirty flag
set and when clearing autoclear flags. It shouldn't do this when another
qemu instance is still actively working on this image file.

One effect of the bug is that images may have a cleared dirty flag while
the migration source host still has it in use with lazy refcounts
enabled, so refcounts are not accurate and the dirty flag must remain
set.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow2.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index b5b1e8c..da82646 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -644,7 +644,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
     }
 
     /* Clear unknown autoclear feature bits */
-    if (!bs->read_only && s->autoclear_features != 0) {
+    if (!bs->read_only && !(flags & BDRV_O_INCOMING) && s->autoclear_features) {
         s->autoclear_features = 0;
         ret = qcow2_update_header(bs);
         if (ret < 0) {
@@ -657,7 +657,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
     qemu_co_mutex_init(&s->lock);
 
     /* Repair image if dirty */
-    if (!(flags & BDRV_O_CHECK) && !bs->read_only &&
+    if (!(flags & (BDRV_O_CHECK | BDRV_O_INCOMING)) && !bs->read_only &&
         (s->incompatible_features & QCOW2_INCOMPAT_DIRTY)) {
         BdrvCheckResult result = {0};
 
@@ -1137,10 +1137,12 @@ static void qcow2_close(BlockDriverState *bs)
     /* else pre-write overlap checks in cache_destroy may crash */
     s->l1_table = NULL;
 
-    qcow2_cache_flush(bs, s->l2_table_cache);
-    qcow2_cache_flush(bs, s->refcount_block_cache);
+    if (!(bs->open_flags & BDRV_O_INCOMING)) {
+        qcow2_cache_flush(bs, s->l2_table_cache);
+        qcow2_cache_flush(bs, s->refcount_block_cache);
 
-    qcow2_mark_clean(bs);
+        qcow2_mark_clean(bs);
+    }
 
     qcow2_cache_destroy(bs, s->l2_table_cache);
     qcow2_cache_destroy(bs, s->refcount_block_cache);
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: Don't write with BDRV_O_INCOMING
  2014-03-11 14:15 [Qemu-devel] [PATCH] qcow2: Don't write with BDRV_O_INCOMING Kevin Wolf
@ 2014-03-11 15:25 ` Eric Blake
  2014-03-11 18:45 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2014-03-11 15:25 UTC (permalink / raw)
  To: Kevin Wolf, qemu-devel; +Cc: stefanha

[-- Attachment #1: Type: text/plain, Size: 791 bytes --]

On 03/11/2014 08:15 AM, Kevin Wolf wrote:
> qcow2_open() causes writes when repairing an image with the dirty flag
> set and when clearing autoclear flags. It shouldn't do this when another
> qemu instance is still actively working on this image file.
> 
> One effect of the bug is that images may have a cleared dirty flag while
> the migration source host still has it in use with lazy refcounts
> enabled, so refcounts are not accurate and the dirty flag must remain
> set.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/qcow2.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] qcow2: Don't write with BDRV_O_INCOMING
  2014-03-11 14:15 [Qemu-devel] [PATCH] qcow2: Don't write with BDRV_O_INCOMING Kevin Wolf
  2014-03-11 15:25 ` Eric Blake
@ 2014-03-11 18:45 ` Stefan Hajnoczi
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2014-03-11 18:45 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel, stefanha

On Tue, Mar 11, 2014 at 03:15:03PM +0100, Kevin Wolf wrote:
> qcow2_open() causes writes when repairing an image with the dirty flag
> set and when clearing autoclear flags. It shouldn't do this when another
> qemu instance is still actively working on this image file.
> 
> One effect of the bug is that images may have a cleared dirty flag while
> the migration source host still has it in use with lazy refcounts
> enabled, so refcounts are not accurate and the dirty flag must remain
> set.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block/qcow2.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-03-11 18:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-11 14:15 [Qemu-devel] [PATCH] qcow2: Don't write with BDRV_O_INCOMING Kevin Wolf
2014-03-11 15:25 ` Eric Blake
2014-03-11 18:45 ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).