From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1gsq-0003Bk-Dp for qemu-devel@nongnu.org; Fri, 10 Jan 2014 13:32:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W1gsk-0006Eh-6G for qemu-devel@nongnu.org; Fri, 10 Jan 2014 13:32:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:62446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1gsj-0006Ec-Tj for qemu-devel@nongnu.org; Fri, 10 Jan 2014 13:32:34 -0500 Message-ID: <52D03D19.80302@redhat.com> Date: Fri, 10 Jan 2014 19:34:01 +0100 From: Max Reitz MIME-Version: 1.0 References: <1386940979-3824-1-git-send-email-kwolf@redhat.com> <1386940979-3824-15-git-send-email-kwolf@redhat.com> In-Reply-To: <1386940979-3824-15-git-send-email-kwolf@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 14/24] block: Switch BdrvTrackedRequest to byte granularity List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-devel@nongnu.org Cc: pbonzini@redhat.com, pl@kamp.de, stefanha@redhat.com On 13.12.2013 14:22, Kevin Wolf wrote: > 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(-) > > diff --git a/block.c b/block.c > index a80db2e..fa888d9 100644 > --- a/block.c > +++ b/block.c > @@ -2037,13 +2037,13 @@ static void tracked_request_end(BdrvTrackedRequest *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 = (BdrvTrackedRequest){ > .bs = bs, > - .sector_num = sector_num, > - .nb_sectors = nb_sectors, > + .offset = offset, > + .bytes = bytes, > .is_write = is_write, > .co = qemu_coroutine_self(), > }; > @@ -2074,25 +2074,43 @@ void bdrv_round_to_clusters(BlockDriverState *bs, > } > } > > +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 == 0) { > + *cluster_offset = offset; > + *cluster_bytes = bytes; > + } else { > + *cluster_offset = QEMU_ALIGN_DOWN(offset, bdi.cluster_size); > + *cluster_bytes = QEMU_ALIGN_UP(offset - *cluster_offset + bytes, > + bdi.cluster_size); > + } > +} > + > static bool tracked_request_overlaps(BdrvTrackedRequest *req, > - int64_t sector_num, int nb_sectors) { > + int64_t offset, int bytes) Shouldn't this be "unsigned int bytes"? Max > +{ > /* aaaa bbbb */ > - if (sector_num >= req->sector_num + req->nb_sectors) { > + if (offset >= req->offset + req->bytes) { > return false; > } > /* bbbb aaaa */ > - if (req->sector_num >= sector_num + nb_sectors) { > + if (req->offset >= offset + bytes) { > return false; > } > return true; > } > > static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *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; > > /* If we touch the same cluster it counts as an overlap. This guarantees > @@ -2101,14 +2119,12 @@ static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs, > * CoR read and write operations are atomic and guest writes cannot > * 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, &cluster_bytes); > > do { > retry = 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, for > * example, a block driver issuing nested requests. This must > * never happen since it means deadlock. > @@ -2723,10 +2739,10 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs, > } > > if (bs->copy_on_read_in_flight) { > - wait_for_overlapping_requests(bs, sector_num, nb_sectors); > + wait_for_overlapping_requests(bs, offset, bytes); > } > > - tracked_request_begin(&req, bs, sector_num, nb_sectors, false); > + tracked_request_begin(&req, bs, offset, bytes, false); > > if (flags & BDRV_REQ_COPY_ON_READ) { > int pnum; > @@ -2974,10 +2990,10 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs, > assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0); > > if (bs->copy_on_read_in_flight) { > - wait_for_overlapping_requests(bs, sector_num, nb_sectors); > + wait_for_overlapping_requests(bs, offset, bytes); > } > > - tracked_request_begin(&req, bs, sector_num, nb_sectors, true); > + tracked_request_begin(&req, bs, offset, bytes, true); > > ret = notifier_with_return_list_notify(&bs->before_write_notifiers, &req); > > 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 = opaque; > + int64_t sector_num = req->offset >> BDRV_SECTOR_BITS; > + int nb_sectors = req->bytes >> BDRV_SECTOR_BITS; > > - return backup_do_cow(req->bs, req->sector_num, req->nb_sectors, NULL); > + assert((req->offset & (BDRV_SECTOR_SIZE - 1)) == 0); > + assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) == 0); > + > + return backup_do_cow(req->bs, sector_num, nb_sectors, NULL); > } > > static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) > diff --git a/include/block/block_int.h b/include/block/block_int.h > index 0a01b69..a11e5c9 100644 > --- a/include/block/block_int.h > +++ b/include/block/block_int.h > @@ -57,8 +57,8 @@ > > 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 */