From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5bhy-0002bc-Pd for qemu-devel@nongnu.org; Tue, 21 Jan 2014 08:49:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5bht-0007Gg-Mu for qemu-devel@nongnu.org; Tue, 21 Jan 2014 08:49:38 -0500 Received: from paradis.irqsave.net ([62.212.105.220]:47961) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5bht-0007GX-6I for qemu-devel@nongnu.org; Tue, 21 Jan 2014 08:49:33 -0500 Date: Tue, 21 Jan 2014 14:49:31 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140121134931.GI9834@irqsave.net> References: <1389968119-24771-1-git-send-email-kwolf@redhat.com> <1389968119-24771-15-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-15-git-send-email-kwolf@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 14/29] block: Switch BdrvTrackedRequest to byte granularity 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:04 (+0100), Kevin Wolf a =E9crit : > Signed-off-by: Kevin Wolf > --- > block.c | 52 +++++++++++++++++++++++++++++++--------= -------- > block/backup.c | 7 ++++++- > include/block/block_int.h | 4 ++-- > 3 files changed, 42 insertions(+), 21 deletions(-) >=20 > diff --git a/block.c b/block.c > index 328f592..85f28ab 100644 > --- a/block.c > +++ b/block.c > @@ -2037,13 +2037,13 @@ static void tracked_request_end(BdrvTrackedRequ= est *req) > */ > static void tracked_request_begin(BdrvTrackedRequest *req, > BlockDriverState *bs, > - int64_t sector_num, > - int nb_sectors, bool is_write) > + int64_t offset, > + unsigned int bytes, bool is_write) > { > *req =3D (BdrvTrackedRequest){ > .bs =3D bs, > - .sector_num =3D sector_num, > - .nb_sectors =3D nb_sectors, > + .offset =3D offset, > + .bytes =3D bytes, > .is_write =3D is_write, > .co =3D qemu_coroutine_self(), > }; > @@ -2074,25 +2074,43 @@ void bdrv_round_to_clusters(BlockDriverState *b= s, > } > } > =20 > +static void round_bytes_to_clusters(BlockDriverState *bs, > + int64_t offset, unsigned int bytes= , > + int64_t *cluster_offset, > + unsigned int *cluster_bytes) > +{ > + BlockDriverInfo bdi; > + > + if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size =3D=3D 0) { > + *cluster_offset =3D offset; > + *cluster_bytes =3D bytes; > + } else { > + *cluster_offset =3D QEMU_ALIGN_DOWN(offset, bdi.cluster_size); > + *cluster_bytes =3D QEMU_ALIGN_UP(offset - *cluster_offset + by= tes, > + bdi.cluster_size); > + } > +} > + > static bool tracked_request_overlaps(BdrvTrackedRequest *req, > - int64_t sector_num, int nb_sector= s) { > + int64_t offset, unsigned int byte= s) > +{ > /* aaaa bbbb */ > - if (sector_num >=3D req->sector_num + req->nb_sectors) { > + if (offset >=3D req->offset + req->bytes) { > return false; > } > /* bbbb aaaa */ > - if (req->sector_num >=3D sector_num + nb_sectors) { > + if (req->offset >=3D offset + bytes) { > return false; > } > return true; > } > =20 > static void coroutine_fn wait_for_overlapping_requests(BlockDriverStat= e *bs, > - int64_t sector_num, int nb_sectors) > + int64_t offset, unsigned int bytes) > { > BdrvTrackedRequest *req; > - int64_t cluster_sector_num; > - int cluster_nb_sectors; > + int64_t cluster_offset; > + unsigned int cluster_bytes; > bool retry; > =20 > /* If we touch the same cluster it counts as an overlap. This gua= rantees > @@ -2101,14 +2119,12 @@ static void coroutine_fn wait_for_overlapping_r= equests(BlockDriverState *bs, > * CoR read and write operations are atomic and guest writes canno= t > * interleave between them. > */ > - bdrv_round_to_clusters(bs, sector_num, nb_sectors, > - &cluster_sector_num, &cluster_nb_sectors); > + round_bytes_to_clusters(bs, offset, bytes, &cluster_offset, &clust= er_bytes); > =20 > do { > retry =3D false; > QLIST_FOREACH(req, &bs->tracked_requests, list) { > - if (tracked_request_overlaps(req, cluster_sector_num, > - cluster_nb_sectors)) { > + if (tracked_request_overlaps(req, cluster_offset, cluster_= bytes)) { > /* Hitting this means there was a reentrant request, f= or > * example, a block driver issuing nested requests. T= his must > * never happen since it means deadlock. > @@ -2728,10 +2744,10 @@ static int coroutine_fn bdrv_aligned_preadv(Blo= ckDriverState *bs, > } > =20 > if (bs->copy_on_read_in_flight) { > - wait_for_overlapping_requests(bs, sector_num, nb_sectors); > + wait_for_overlapping_requests(bs, offset, bytes); > } > =20 > - tracked_request_begin(&req, bs, sector_num, nb_sectors, false); > + tracked_request_begin(&req, bs, offset, bytes, false); > =20 > if (flags & BDRV_REQ_COPY_ON_READ) { > int pnum; > @@ -2980,10 +2996,10 @@ static int coroutine_fn bdrv_aligned_pwritev(Bl= ockDriverState *bs, > assert((bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); > =20 > if (bs->copy_on_read_in_flight) { > - wait_for_overlapping_requests(bs, sector_num, nb_sectors); > + wait_for_overlapping_requests(bs, offset, bytes); > } > =20 > - tracked_request_begin(&req, bs, sector_num, nb_sectors, true); > + tracked_request_begin(&req, bs, offset, bytes, true); > =20 > ret =3D notifier_with_return_list_notify(&bs->before_write_notifie= rs, &req); > =20 > diff --git a/block/backup.c b/block/backup.c > index 0198514..15a2e55 100644 > --- a/block/backup.c > +++ b/block/backup.c > @@ -181,8 +181,13 @@ static int coroutine_fn backup_before_write_notify= ( > void *opaque) > { > BdrvTrackedRequest *req =3D opaque; > + int64_t sector_num =3D req->offset >> BDRV_SECTOR_BITS; > + int nb_sectors =3D req->bytes >> BDRV_SECTOR_BITS; > =20 > - return backup_do_cow(req->bs, req->sector_num, req->nb_sectors, NU= LL); > + assert((req->offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); > + assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); > + > + return backup_do_cow(req->bs, sector_num, nb_sectors, NULL); > } > =20 > static void backup_set_speed(BlockJob *job, int64_t speed, Error **err= p) > diff --git a/include/block/block_int.h b/include/block/block_int.h > index fb1d355..97a4d23 100644 > --- a/include/block/block_int.h > +++ b/include/block/block_int.h > @@ -57,8 +57,8 @@ > =20 > typedef struct BdrvTrackedRequest { > BlockDriverState *bs; > - int64_t sector_num; > - int nb_sectors; > + int64_t offset; > + unsigned int bytes; > bool is_write; > QLIST_ENTRY(BdrvTrackedRequest) list; > Coroutine *co; /* owner, used for deadlock detection */ > --=20 > 1.8.1.4 >=20 >=20 Reviewed-by: Benoit Canet