From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6jJw-000394-R0 for qemu-devel@nongnu.org; Fri, 24 Jan 2014 11:09:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W6jJq-0000eM-Ow for qemu-devel@nongnu.org; Fri, 24 Jan 2014 11:09:28 -0500 Received: from paradis.irqsave.net ([62.212.105.220]:48260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W6jJq-0000ds-6g for qemu-devel@nongnu.org; Fri, 24 Jan 2014 11:09:22 -0500 Date: Fri, 24 Jan 2014 17:09:20 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140124160920.GD3087@irqsave.net> References: <1389968119-24771-1-git-send-email-kwolf@redhat.com> <1389968119-24771-22-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1389968119-24771-22-git-send-email-kwolf@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 21/29] block: Assert serialisation assumptions in pwritev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: pl@kamp.de, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, xiawenc@linux.vnet.ibm.com Le Friday 17 Jan 2014 =E0 15:15:11 (+0100), Kevin Wolf a =E9crit : > If a request calls wait_serialising_requests() and actually has to wait > in this function (i.e. a coroutine yield), other requests can run and > previously read data (like the head or tail buffer) could become > outdated. In this case, we would have to restart from the beginning to > read in the updated data. >=20 > However, we're lucky and don't actually need to do that: A request can > only wait in the first call of wait_serialising_requests() because we > mark it as serialising before that call, so any later requests would > wait. So as we don't wait in practice, we don't have to reload the data= . >=20 > This is an important assumption that may not be broken or data > corruption will happen. Document it with some assertions. >=20 > Signed-off-by: Kevin Wolf > --- > block.c | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) >=20 > diff --git a/block.c b/block.c > index 859e1aa..53d9bd5 100644 > --- a/block.c > +++ b/block.c > @@ -2123,14 +2123,15 @@ static bool tracked_request_overlaps(BdrvTracke= dRequest *req, > return true; > } > =20 > -static void coroutine_fn wait_serialising_requests(BdrvTrackedRequest = *self) > +static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest = *self) > { > BlockDriverState *bs =3D self->bs; > BdrvTrackedRequest *req; > bool retry; > + bool waited =3D false; > =20 > if (!bs->serialising_in_flight) { > - return; > + return false; > } > =20 > do { > @@ -2156,11 +2157,14 @@ static void coroutine_fn wait_serialising_reque= sts(BdrvTrackedRequest *self) > qemu_co_queue_wait(&req->wait_queue); > self->waiting_for =3D NULL; > retry =3D true; > + waited =3D true; > break; > } > } > } > } while (retry); > + > + return waited; > } > =20 > /* > @@ -3011,6 +3015,7 @@ static int coroutine_fn bdrv_aligned_pwritev(Bloc= kDriverState *bs, > QEMUIOVector *qiov, int flags) > { > BlockDriver *drv =3D bs->drv; > + bool waited; > int ret; > =20 > int64_t sector_num =3D offset >> BDRV_SECTOR_BITS; > @@ -3019,7 +3024,8 @@ static int coroutine_fn bdrv_aligned_pwritev(Bloc= kDriverState *bs, > assert((offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); > assert((bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); > =20 > - wait_serialising_requests(req); > + waited =3D wait_serialising_requests(req); > + assert(!waited || !req->serialising); I we apply De Morgan's law to the expression we have: assert(!(waited && req->serialising)); Is it really the condition we want ? Best regards Beno=EEt > =20 > ret =3D notifier_with_return_list_notify(&bs->before_write_notifie= rs, req); > =20 > @@ -3119,9 +3125,11 @@ static int coroutine_fn bdrv_co_do_pwritev(Block= DriverState *bs, > QEMUIOVector tail_qiov; > struct iovec tail_iov; > size_t tail_bytes; > + bool waited; > =20 > mark_request_serialising(&req, align); > - wait_serialising_requests(&req); > + waited =3D wait_serialising_requests(&req); > + assert(!waited || !use_local_qiov); > =20 > tail_buf =3D qemu_blockalign(bs, align); > tail_iov =3D (struct iovec) { > --=20 > 1.8.1.4 >=20 >=20