From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49608) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yq3Fi-0007Do-Jr for qemu-devel@nongnu.org; Wed, 06 May 2015 13:37:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yq3Fb-0002ov-Sl for qemu-devel@nongnu.org; Wed, 06 May 2015 13:36:58 -0400 Message-ID: <554A512A.4070109@redhat.com> Date: Wed, 06 May 2015 19:36:42 +0200 From: Max Reitz MIME-Version: 1.0 References: <554A4458.7090901@redhat.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------070009070005000707070500" Subject: Re: [Qemu-devel] [PATCH] use bdrv_flush to provide barrier semantic in block/vdi.c for metadata updates List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: phoeagon , qemu-devel@nongnu.org Cc: Stefan Weil , qemu-block@nongnu.org This is a multi-part message in MIME format. --------------070009070005000707070500 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 > > From 19b2fabbe00765b418362d8c1891f266091621f3 Mon Sep 17 00:00:00 2001 > From: phoeagon > 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 --------------070009070005000707070500 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
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)

I= n this way we try to avoid messing up any potential return value checks possible while still=C2=A0propagating bdrv_flu= sh errors.=C2=A0
T= hat 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:=C2=A0[PATCH]=C2=A0blo= ck/vdi: Use bdrv_flush after metadata updates

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

---
=C2=A0block/vdi.c | 6 +++++-
=C2=A01 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,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0logout("will write %u bl= ock map sectors starting from entry %u\n",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 n_= sectors, bmap_first);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ret =3D bdrv_write(bs-&g= t;file, offset, base, n_sectors);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!(ret < 0)) {
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0int flush_ret =3D= bdrv_flush(bs->file);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (flush_ret &= lt; 0)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0r= et =3D flush_ret;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0}

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 =3D 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

=C2=A0 =C2=A0 =C2=A0}
=C2=A0
=C2=A0 =C2=A0 =C2=A0return ret;
--=C2=A0
2.4.0

--------------070009070005000707070500--