qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qcow2: Flush image after creation
@ 2013-10-23 19:40 Max Reitz
  2013-10-24 10:00 ` Kevin Wolf
  2013-10-24 10:04 ` Eric Blake
  0 siblings, 2 replies; 3+ messages in thread
From: Max Reitz @ 2013-10-23 19:40 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz

Opening the qcow2 image with BDRV_O_NO_FLUSH prevents any flushes during
the image creation. This means that the image has not yet been flushed
to disk when qemu-img create exits. This flush is delayed until the next
operation on the image involving opening it without BDRV_O_NO_FLUSH and
closing (or directly flushing) it. For large images and/or images with a
small cluster size and preallocated metadata, this flush may take a
significant amount of time and may occur unexpectedly.

Reopening the image without BDRV_O_NO_FLUSH right before the end of
qcow2_create2() results in preponing the potentially costly flush into
the image creation, which is expected to take some time (whereas
successive image operations may be not).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/qcow2.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index c1abaff..8b98c3a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1584,7 +1584,15 @@ static int qcow2_create2(const char *filename, int64_t total_size,
         }
     }
 
-    ret = 0;
+    bdrv_close(bs);
+
+    /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
+    ret = bdrv_open(bs, filename, NULL,
+        BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err);
+    if (error_is_set(&local_err)) {
+        error_propagate(errp, local_err);
+    }
+
 out:
     bdrv_unref(bs);
     return ret;
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PATCH] qcow2: Flush image after creation
  2013-10-23 19:40 [Qemu-devel] [PATCH] qcow2: Flush image after creation Max Reitz
@ 2013-10-24 10:00 ` Kevin Wolf
  2013-10-24 10:04 ` Eric Blake
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Wolf @ 2013-10-24 10:00 UTC (permalink / raw)
  To: Max Reitz; +Cc: qemu-devel, Stefan Hajnoczi

Am 23.10.2013 um 21:40 hat Max Reitz geschrieben:
> Opening the qcow2 image with BDRV_O_NO_FLUSH prevents any flushes during
> the image creation. This means that the image has not yet been flushed
> to disk when qemu-img create exits. This flush is delayed until the next
> operation on the image involving opening it without BDRV_O_NO_FLUSH and
> closing (or directly flushing) it. For large images and/or images with a
> small cluster size and preallocated metadata, this flush may take a
> significant amount of time and may occur unexpectedly.
> 
> Reopening the image without BDRV_O_NO_FLUSH right before the end of
> qcow2_create2() results in preponing the potentially costly flush into
> the image creation, which is expected to take some time (whereas
> successive image operations may be not).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index c1abaff..8b98c3a 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -1584,7 +1584,15 @@ static int qcow2_create2(const char *filename, int64_t total_size,
>          }
>      }
>  
> -    ret = 0;

I would prefer to keep the explicit ret = 0 there (just like the
unnecessary last 'goto out:', it just makes things more obvious and
consistent)

> +    bdrv_close(bs);
> +
> +    /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
> +    ret = bdrv_open(bs, filename, NULL,
> +        BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err);
> +    if (error_is_set(&local_err)) {
> +        error_propagate(errp, local_err);

So a goto here wouldn't hurt either. Note how the unnecessary goto in
the block before allowed you to just add your new code without modifying
existing parts.

> +    }
> +
>  out:
>      bdrv_unref(bs);
>      return ret;

Kevin

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

* Re: [Qemu-devel] [PATCH] qcow2: Flush image after creation
  2013-10-23 19:40 [Qemu-devel] [PATCH] qcow2: Flush image after creation Max Reitz
  2013-10-24 10:00 ` Kevin Wolf
@ 2013-10-24 10:04 ` Eric Blake
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Blake @ 2013-10-24 10:04 UTC (permalink / raw)
  To: Max Reitz, qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi

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

On 10/23/2013 08:40 PM, Max Reitz wrote:
> Opening the qcow2 image with BDRV_O_NO_FLUSH prevents any flushes during
> the image creation. This means that the image has not yet been flushed
> to disk when qemu-img create exits. This flush is delayed until the next
> operation on the image involving opening it without BDRV_O_NO_FLUSH and
> closing (or directly flushing) it. For large images and/or images with a
> small cluster size and preallocated metadata, this flush may take a
> significant amount of time and may occur unexpectedly.
> 
> Reopening the image without BDRV_O_NO_FLUSH right before the end of
> qcow2_create2() results in preponing the potentially costly flush into

s/preponing/hoisting/

> the image creation, which is expected to take some time (whereas
> successive image operations may be not).
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)

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

> -    ret = 0;
> +    bdrv_close(bs);
> +
> +    /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returning */
> +    ret = bdrv_open(bs, filename, NULL,
> +        BDRV_O_RDWR | BDRV_O_CACHE_WB, drv, &local_err);

I would probably have indented as:

ret = bdrv_open(bs, filename, NULL,
                BDRV_O_RDWR | BDRV_O_CACHE_WB,
                drv, &local_err);

but it's trivial enough that I'm also fine with your choice.

-- 
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: 621 bytes --]

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

end of thread, other threads:[~2013-10-24 10:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23 19:40 [Qemu-devel] [PATCH] qcow2: Flush image after creation Max Reitz
2013-10-24 10:00 ` Kevin Wolf
2013-10-24 10:04 ` Eric Blake

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).