[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 14/29] block: Switch BdrvTrackedRequest to by
From: |
Benoît Canet |
Subject: |
Re: [Qemu-devel] [PATCH v3 14/29] block: Switch BdrvTrackedRequest to byte granularity |
Date: |
Tue, 21 Jan 2014 14:49:31 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Le Friday 17 Jan 2014 à 15:15:04 (+0100), Kevin Wolf a écrit :
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
> 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 328f592..85f28ab 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, unsigned int bytes)
> +{
> /* 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.
> @@ -2728,10 +2744,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;
> @@ -2980,10 +2996,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 fb1d355..97a4d23 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 */
> --
> 1.8.1.4
>
>
Reviewed-by: Benoit Canet <address@hidden>
- [Qemu-devel] [PATCH v3 12/29] block: write: Handle COR dependency after I/O throttling, (continued)
- [Qemu-devel] [PATCH v3 12/29] block: write: Handle COR dependency after I/O throttling, Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 13/29] block: Introduce bdrv_co_do_pwritev(), Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 16/29] block: Make zero-after-EOF work with larger alignment, Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 14/29] block: Switch BdrvTrackedRequest to byte granularity, Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 15/29] block: Allow waiting for overlapping requests between begin/end, Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 17/29] block: Generalise and optimise COR serialisation, Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 18/29] block: Make overlap range for serialisation dynamic, Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 19/29] block: Allow wait_serialising_requests() at any point, Kevin Wolf, 2014/01/17
- [Qemu-devel] [PATCH v3 20/29] block: Align requests in bdrv_co_do_pwritev(), Kevin Wolf, 2014/01/17