qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates
@ 2015-05-01 15:03 phoeagon
  2015-05-06 16:42 ` Max Reitz
  0 siblings, 1 reply; 5+ messages in thread
From: phoeagon @ 2015-05-01 15:03 UTC (permalink / raw)
  To: qemu-devel

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

Looks like VDI is the only writable image format that does not use
write-with-barrier(sync) when updating the metadata. A sequence of commits
b0ad5a455d~078a458e077d6b0db2 fixes this for QCOW/COW/QCOW2/VPC/VMDK, but
the VDI does not issue a barrier by sync after updating the metadata.

This commit adds a `bdrv_flush` after updating block map.


Signed-off-by: Zhe Qiu <address@hidden>
---------------
>From 2ea36d9a0e676b534483dc54c191f421f9889dc6 Mon Sep 17 00:00:00 2001
From: phoeagon <address@hidden>
Date: Fri, 1 May 2015 19:00:22 +0800
Subject: [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c

In reference to
b0ad5a455d7e5352d4c86ba945112011dbeadfb8~078a458e077d6b0db262c4b05fee51d01de2d1d2,
metadata writes to qcow2/cow/qcow/vpc/vmdk are all synced prior to
succeeding writes.
---
 block/vdi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/vdi.c b/block/vdi.c
index 7642ef3..5d09b36 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -713,6 +713,7 @@ static int vdi_co_write(BlockDriverState *bs,
         logout("will write %u block map sectors starting from entry %u\n",
                n_sectors, bmap_first);
         ret = bdrv_write(bs->file, offset, base, n_sectors);
+        ret = bdrv_flush(bs->file);
     }

     return ret;
-- 
2.3.7

[-- Attachment #2: Type: text/html, Size: 1912 bytes --]

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

* Re: [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates
  2015-05-01 15:03 [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates phoeagon
@ 2015-05-06 16:42 ` Max Reitz
  2015-05-06 17:23   ` phoeagon
  0 siblings, 1 reply; 5+ messages in thread
From: Max Reitz @ 2015-05-06 16:42 UTC (permalink / raw)
  To: phoeagon, qemu-devel

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

@subject: It's a bit long, and it's missing a prefix telling what this 
patch is about. I would have probably used "block/vdi: Use bdrv_flush 
after metadata updates" or something like that.

On 01.05.2015 17:03, phoeagon wrote:
> Looks like VDI is the only writable image format that does not use 
> write-with-barrier(sync) when updating the metadata. A sequence of 
> commits b0ad5a455d~078a458e077d6b0db2 fixes this for 
> QCOW/COW/QCOW2/VPC/VMDK, but the VDI does not issue a barrier by sync 
> after updating the metadata.
>
> This commit adds a `bdrv_flush` after updating block map.
>
>
> Signed-off-by: Zhe Qiu <address@hidden>

Hm, this doesn't look quite right. :-)

> ---------------

These should be only "---", I guess, so the block below is omitted from 
the commit message.

> From 2ea36d9a0e676b534483dc54c191f421f9889dc6 Mon Sep 17 00:00:00 2001
> From: phoeagon <address@hidden>
> Date: Fri, 1 May 2015 19:00:22 +0800
> Subject: [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c
>
> In reference to 
> b0ad5a455d7e5352d4c86ba945112011dbeadfb8~078a458e077d6b0db262c4b05fee51d01de2d1d2, 
> metadata writes to qcow2/cow/qcow/vpc/vmdk are all synced prior to 
> succeeding writes.
> ---
>  block/vdi.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/block/vdi.c b/block/vdi.c
> index 7642ef3..5d09b36 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -713,6 +713,7 @@ static int vdi_co_write(BlockDriverState *bs,
>          logout("will write %u block map sectors starting from entry 
> %u\n",
>                 n_sectors, bmap_first);
>          ret = bdrv_write(bs->file, offset, base, n_sectors);
> +        ret = bdrv_flush(bs->file);

This overwrites the return value from bdrv_write(), which I don't think 
is right. We could either ignore bdrv_flush()'s return value, or make it 
something like "if (ret < 0) { bdrv_flush(bs->file); } else { ret = 
bdrv_flush(bs->file); }" or "ret_flush = bdrv_flush(bs->file); if (!(ret 
< 0)) { ret = ret_flush; }". Or skip the flush in case bdrv_write() 
failed ("if (ret < 0) { return ret; } ret = bdrv_flush(bs->file);"), 
like bdrv_pwrite_sync() does.

The idea of the change (adding the flush) looks good, though.

Max

>      }
>      return ret;
> -- 
> 2.3.7
>


[-- Attachment #2: Type: text/html, Size: 4446 bytes --]

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

* Re: [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates
  2015-05-06 16:42 ` Max Reitz
@ 2015-05-06 17:23   ` phoeagon
  2015-05-06 17:28     ` Eric Blake
  2015-05-06 17:36     ` Max Reitz
  0 siblings, 2 replies; 5+ messages in thread
From: phoeagon @ 2015-05-06 17:23 UTC (permalink / raw)
  To: Max Reitz, qemu-devel

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

Thanks for your input.

So I changed it to:
1. Only call bdrv_flush when bdrv_pwrite was successful
2. Only if bdrv_flush was unsuccessful that the return value of
vdi_co_write is updated.
In this way we try to avoid messing up any potential return value checks
possible while still propagating bdrv_flush errors.
That return value was a catch and I admit I'm no pro with the return value
convention in QEMU. bdrv_pwrite doesn't return the same value as
bdrv_pwrite_sync I assume (they do return negative values when fail, but
different values when successful)
---


Signed-off-by: Zhe Qiu <address@hidden>

>From 19b2fabbe00765b418362d8c1891f266091621f3 Mon Sep 17 00:00:00 2001
From: phoeagon <address-hidden>
Date: Thu, 7 May 2015 01:09:38 +0800
Subject: [PATCH] block/vdi: Use bdrv_flush after metadata updates

In reference to
b0ad5a455d7e5352d4c86ba945112011dbeadfb8~078a458e077d6b0db262c4b05fee51d01de2d1d2,
metadata writes to qcow2/cow/qcow/vpc/vmdk are all synced prior to
succeeding writes.

---
 block/vdi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/vdi.c b/block/vdi.c
index 5d09b36..54a5fa8 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -713,7 +713,11 @@ static int vdi_co_write(BlockDriverState *bs,
         logout("will write %u block map sectors starting from entry %u\n",
                n_sectors, bmap_first);
         ret = bdrv_write(bs->file, offset, base, n_sectors);
+        if (!(ret < 0)) {
+            int flush_ret = bdrv_flush(bs->file);
+            if (flush_ret < 0)
+                ret = flush_ret;
+        }
     }

     return ret;
-- 
2.4.0

[-- Attachment #2: Type: text/html, Size: 3862 bytes --]

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

* Re: [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates
  2015-05-06 17:23   ` phoeagon
@ 2015-05-06 17:28     ` Eric Blake
  2015-05-06 17:36     ` Max Reitz
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Blake @ 2015-05-06 17:28 UTC (permalink / raw)
  To: phoeagon, Max Reitz, qemu-devel

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

On 05/06/2015 11:23 AM, phoeagon wrote:
> Thanks for your input.
> 
> So I changed it to:
> 1. Only call bdrv_flush when bdrv_pwrite was successful
> 2. Only if bdrv_flush was unsuccessful that the return value of
> vdi_co_write is updated.
> In this way we try to avoid messing up any potential return value checks
> possible while still propagating bdrv_flush errors.
> That return value was a catch and I admit I'm no pro with the return value
> convention in QEMU. bdrv_pwrite doesn't return the same value as
> bdrv_pwrite_sync I assume (they do return negative values when fail, but
> different values when successful)
> ---
> 

The text above [1]...

> 
> Signed-off-by: Zhe Qiu <address@hidden>

This S-o-b is still broken.

> 
>>From 19b2fabbe00765b418362d8c1891f266091621f3 Mon Sep 17 00:00:00 2001

When sending a revised patch, it's better to send it as a new top-level
thread, and with 'v2' somewhere in the subject line (hint: git
send-email -v2).  Your placement of the Signed-off-by line before the
From: attribution line is incorrect

> From: phoeagon <address-hidden>
> Date: Thu, 7 May 2015 01:09:38 +0800
> Subject: [PATCH] block/vdi: Use bdrv_flush after metadata updates
> 
> In reference to
> b0ad5a455d7e5352d4c86ba945112011dbeadfb8~078a458e077d6b0db262c4b05fee51d01de2d1d2,
> metadata writes to qcow2/cow/qcow/vpc/vmdk are all synced prior to
> succeeding writes.
> 
> ---

...[1] is more useful here, after the commit message body.

I highly suggest you read http://wiki.qemu.org/Contribute/SubmitAPatch;
it is also a good idea to use 'git send-email' to send a patch to
yourself, then 'git am' on that message to see if it survived the round
trip through email, before sending to the list.

>  block/vdi.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/block/vdi.c b/block/vdi.c
> index 5d09b36..54a5fa8 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -713,7 +713,11 @@ static int vdi_co_write(BlockDriverState *bs,
>          logout("will write %u block map sectors starting from entry %u\n",
>                 n_sectors, bmap_first);
>          ret = bdrv_write(bs->file, offset, base, n_sectors);
> +        if (!(ret < 0)) {

This looks odd.  Better might be: 'if (ret >= 0) {'

> +            int flush_ret = bdrv_flush(bs->file);
> +            if (flush_ret < 0)
> +                ret = flush_ret;

Missing {} (hint: scripts/checkpatch.pl is an important part of good
patch submission)

> +        }
>      }
> 
>      return ret;
> 

-- 
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] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates
  2015-05-06 17:23   ` phoeagon
  2015-05-06 17:28     ` Eric Blake
@ 2015-05-06 17:36     ` Max Reitz
  1 sibling, 0 replies; 5+ messages in thread
From: Max Reitz @ 2015-05-06 17:36 UTC (permalink / raw)
  To: phoeagon, qemu-devel; +Cc: Stefan Weil, qemu-block

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

CC-ing qemu-block and Stefan Weil (maintainer of vdi).

On 06.05.2015 19:23, phoeagon wrote:
> Thanks for your input.
>
> So I changed it to:
> 1. Only call bdrv_flush when bdrv_pwrite was successful
> 2. Only if bdrv_flush was unsuccessful that the return value of 
> vdi_co_write is updated.

One of both is enough. Both are too much. :-)

It is indeed correct, technically (because ret is 0 before the 
bdrv_write()), but it's too verbose. (See below)

> In this way we try to avoid messing up any potential return value 
> checks possible while still propagating bdrv_flush errors.
> That return value was a catch and I admit I'm no pro with the return 
> value convention in QEMU. bdrv_pwrite doesn't return the same value as 
> bdrv_pwrite_sync I assume (they do return negative values when fail, 
> but different values when successful)

It doesn't really matter, I think. Returning any non-negative value from 
vdi_co_write() should be enough to signal success.

> ---
>
>
> Signed-off-by: Zhe Qiu <address@hidden>
>
> From 19b2fabbe00765b418362d8c1891f266091621f3 Mon Sep 17 00:00:00 2001
> From: phoeagon <address-hidden>
> Date: Thu, 7 May 2015 01:09:38 +0800
> Subject: [PATCH] block/vdi: Use bdrv_flush after metadata updates
>
> In reference to 
> b0ad5a455d7e5352d4c86ba945112011dbeadfb8~078a458e077d6b0db262c4b05fee51d01de2d1d2, 
> metadata writes to qcow2/cow/qcow/vpc/vmdk are all synced prior to 
> succeeding writes.
>
> ---
>  block/vdi.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/block/vdi.c b/block/vdi.c
> index 5d09b36..54a5fa8 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -713,7 +713,11 @@ static int vdi_co_write(BlockDriverState *bs,
>          logout("will write %u block map sectors starting from entry 
> %u\n",
>                 n_sectors, bmap_first);
>          ret = bdrv_write(bs->file, offset, base, n_sectors);
> +        if (!(ret < 0)) {
> +            int flush_ret = bdrv_flush(bs->file);
> +            if (flush_ret < 0)
> +                ret = flush_ret;
> +        }

I think bdrv_write() always returns 0 on success. In any case, it's fine 
for vdi_co_write() to return 0 on success (which is what bdrv_flush() 
returns), so shorting these four lines to "ret = bdrv_flush(bs->file);" 
is enough.

The patch is correct, though, so if you want to leave it as it is, all 
you need to do is bring it into proper form 
(http://wiki.qemu.org/Contribute/SubmitAPatch).

The previous version was nearly right, except for the things I 
mentioned: The subject needs to start with the part of qemu the patch is 
targeting (in this case "block/vdi: " or simply "vdi: "), the 
Signed-off-by needs to contain your name (or any alias you desire) and 
your email address, and comments for the patch should be separated from 
the actual commit message by "---".

Finally, for sending the next version, please change the "[PATCH]" in 
the subject to "[PATCH v3]" in order to indicate that it will be version 
3 of this patch.

Thanks!

Max

>      }
>      return ret;
> -- 
> 2.4.0


[-- Attachment #2: Type: text/html, Size: 7645 bytes --]

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

end of thread, other threads:[~2015-05-06 17:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-01 15:03 [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates phoeagon
2015-05-06 16:42 ` Max Reitz
2015-05-06 17:23   ` phoeagon
2015-05-06 17:28     ` Eric Blake
2015-05-06 17:36     ` Max Reitz

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