diff mbox

[1/2] block: flush backing_hd in the right place

Message ID 20100112124923.GA19631@lst.de
State New
Headers show

Commit Message

Christoph Hellwig Jan. 12, 2010, 12:49 p.m. UTC
The backing device is only modified from bdrv_commit.  So instead of
flushing it every time bdrv_flush is called for the front-end device
only flush it after we're written data to it in bdrv_commit.

Signed-off-by: Christoph Hellwig <hch@lst.de>

Comments

Kevin Wolf Jan. 12, 2010, 5:42 p.m. UTC | #1
Am 12.01.2010 13:49, schrieb Christoph Hellwig:
> 
> The backing device is only modified from bdrv_commit.  So instead of
> flushing it every time bdrv_flush is called for the front-end device
> only flush it after we're written data to it in bdrv_commit.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Index: qemu/block.c
> ===================================================================
> --- qemu.orig/block.c	2010-01-12 11:34:35.549024986 +0100
> +++ qemu/block.c	2010-01-12 11:43:28.965006129 +0100
> @@ -623,6 +623,12 @@ int bdrv_commit(BlockDriverState *bs)
>      if (drv->bdrv_make_empty)
>  	return drv->bdrv_make_empty(bs);
>  
> +    /*
> +     * Make sure all data we wrote to the backing device is actually
> +     * stable on disk.
> +     */
> +    if (bs->backing_hd)
> +        bdrv_flush(bs->backing_hd);
>      return 0;
>  }

Format drivers with a bdrv_make_empty return before the flush, so it
won't work for qcow1. Looks good otherwise.

If it has done a bdrv_make_empty we might also want to flush bs?

Kevin
Christoph Hellwig Jan. 12, 2010, 5:44 p.m. UTC | #2
On Tue, Jan 12, 2010 at 06:42:20PM +0100, Kevin Wolf wrote:
> > @@ -623,6 +623,12 @@ int bdrv_commit(BlockDriverState *bs)
> >      if (drv->bdrv_make_empty)
> >  	return drv->bdrv_make_empty(bs);
> >  
> > +    /*
> > +     * Make sure all data we wrote to the backing device is actually
> > +     * stable on disk.
> > +     */
> > +    if (bs->backing_hd)
> > +        bdrv_flush(bs->backing_hd);
> >      return 0;
> >  }
> 
> Format drivers with a bdrv_make_empty return before the flush, so it
> won't work for qcow1. Looks good otherwise.

Oh, okay.

> If it has done a bdrv_make_empty we might also want to flush bs?

Indeed.  I'll spin a new version.
Anthony Liguori Jan. 13, 2010, 11:26 p.m. UTC | #3
On 01/12/2010 06:49 AM, Christoph Hellwig wrote:
> The backing device is only modified from bdrv_commit.  So instead of
> flushing it every time bdrv_flush is called for the front-end device
> only flush it after we're written data to it in bdrv_commit.
>
> Signed-off-by: Christoph Hellwig<hch@lst.de>
>    

Applied.  Thanks.

Regards,

Anthony Liguori

> Index: qemu/block.c
> ===================================================================
> --- qemu.orig/block.c	2010-01-12 11:34:35.549024986 +0100
> +++ qemu/block.c	2010-01-12 11:43:28.965006129 +0100
> @@ -623,6 +623,12 @@ int bdrv_commit(BlockDriverState *bs)
>       if (drv->bdrv_make_empty)
>   	return drv->bdrv_make_empty(bs);
>
> +    /*
> +     * Make sure all data we wrote to the backing device is actually
> +     * stable on disk.
> +     */
> +    if (bs->backing_hd)
> +        bdrv_flush(bs->backing_hd);
>       return 0;
>   }
>
> @@ -1124,12 +1130,8 @@ const char *bdrv_get_device_name(BlockDr
>
>   void bdrv_flush(BlockDriverState *bs)
>   {
> -    if (!bs->drv)
> -        return;
> -    if (bs->drv->bdrv_flush)
> +    if (bs->drv&&  bs->drv->bdrv_flush)
>           bs->drv->bdrv_flush(bs);
> -    if (bs->backing_hd)
> -        bdrv_flush(bs->backing_hd);
>   }
>
>   void bdrv_flush_all(void)
> @@ -1806,11 +1808,6 @@ BlockDriverAIOCB *bdrv_aio_flush(BlockDr
>
>       if (!drv)
>           return NULL;
> -
> -    /*
> -     * Note that unlike bdrv_flush the driver is reponsible for flushing a
> -     * backing image if it exists.
> -     */
>       return drv->bdrv_aio_flush(bs, cb, opaque);
>   }
>
>
>
>
>
Kevin Wolf Jan. 14, 2010, 10:21 a.m. UTC | #4
Am 14.01.2010 00:26, schrieb Anthony Liguori:
> On 01/12/2010 06:49 AM, Christoph Hellwig wrote:
>> The backing device is only modified from bdrv_commit.  So instead of
>> flushing it every time bdrv_flush is called for the front-end device
>> only flush it after we're written data to it in bdrv_commit.
>>
>> Signed-off-by: Christoph Hellwig<hch@lst.de>
>>    
> 
> Applied.  Thanks.

Anthony, you seem to have missed the v2 patch that considered my review
comments. Can you please apply the diff between v1 and v2 on top?

Kevin
diff mbox

Patch

Index: qemu/block.c
===================================================================
--- qemu.orig/block.c	2010-01-12 11:34:35.549024986 +0100
+++ qemu/block.c	2010-01-12 11:43:28.965006129 +0100
@@ -623,6 +623,12 @@  int bdrv_commit(BlockDriverState *bs)
     if (drv->bdrv_make_empty)
 	return drv->bdrv_make_empty(bs);
 
+    /*
+     * Make sure all data we wrote to the backing device is actually
+     * stable on disk.
+     */
+    if (bs->backing_hd)
+        bdrv_flush(bs->backing_hd);
     return 0;
 }
 
@@ -1124,12 +1130,8 @@  const char *bdrv_get_device_name(BlockDr
 
 void bdrv_flush(BlockDriverState *bs)
 {
-    if (!bs->drv)
-        return;
-    if (bs->drv->bdrv_flush)
+    if (bs->drv && bs->drv->bdrv_flush)
         bs->drv->bdrv_flush(bs);
-    if (bs->backing_hd)
-        bdrv_flush(bs->backing_hd);
 }
 
 void bdrv_flush_all(void)
@@ -1806,11 +1808,6 @@  BlockDriverAIOCB *bdrv_aio_flush(BlockDr
 
     if (!drv)
         return NULL;
-
-    /*
-     * Note that unlike bdrv_flush the driver is reponsible for flushing a
-     * backing image if it exists.
-     */
     return drv->bdrv_aio_flush(bs, cb, opaque);
 }