From: Olaf Hering <olaf@aepfle.de>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH] block: split large discard requests from block frontend
Date: Thu, 17 Nov 2016 17:27:19 +0100 [thread overview]
Message-ID: <20161117162719.GA18909@aepfle.de> (raw)
In-Reply-To: <20161117135409.GA31152@aepfle.de>
[-- Attachment #1: Type: text/plain, Size: 2577 bytes --]
On Thu, Nov 17, Olaf Hering wrote:
> Looking at current master, BLKIF_OP_DISCARD is indeed broken. The values
> passed from the guest are u64 and get stashed into signed values. I will
> add a loop to repeatedly call blk_aio_pdiscard with small chunks of
> BDRV_REQUEST_MAX_SECTORS.
I have not compile tested the change below, but thats the way how I
would deal with it:
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 3a7dc19..5962c4b 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -660,6 +660,38 @@ static void qemu_aio_complete(void *opaque, int ret)
qemu_bh_schedule(ioreq->blkdev->bh);
}
+static bool blk_split_discard(struct ioreq *ioreq, blkif_sector_t sector_number, uint64_t nr_sectors)
+{
+ struct XenBlkDev *blkdev = ioreq->blkdev;
+ int64_t byte_offset;
+ int bytes;
+ uint64_t byte_limit = INT64_MAX + INT_MAX;
+ uint64_t sec_start = sector_number;
+ uint64_t sec_count = nr_sectors;
+ uint64_t byte_remaining;
+ uint64_t limit = BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS;
+
+ /* Wrap around? */
+ if ((sec_start + sec_count) < sec_count)
+ return false;
+ /* Overflowing byte limit? */
+ if ((sec_start + sec_count) > (byte_limit >> BDRV_SECTOR_BITS))
+ return false;
+
+ byte_offset = sec_start << BDRV_SECTOR_BITS;
+ byte_remaining = sec_count << BDRV_SECTOR_BITS;
+ do {
+ bytes = byte_remaining > limit ? limit : byte_remaining;
+ ioreq->aio_inflight++;
+ blk_aio_pdiscard(blkdev->blk, byte_offset, bytes,
+ qemu_aio_complete, ioreq);
+ byte_remaining -= bytes;
+ byte_offset += bytes;
+ } while (byte_remaining > 0);
+
+ return true;
+}
+
static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
{
struct XenBlkDev *blkdev = ioreq->blkdev;
@@ -708,12 +740,9 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
break;
case BLKIF_OP_DISCARD:
{
- struct blkif_request_discard *discard_req = (void *)&ioreq->req;
- ioreq->aio_inflight++;
- blk_aio_pdiscard(blkdev->blk,
- discard_req->sector_number << BDRV_SECTOR_BITS,
- discard_req->nr_sectors << BDRV_SECTOR_BITS,
- qemu_aio_complete, ioreq);
+ struct blkif_request_discard *req = (void *)&ioreq->req;
+ if (blk_split_discard(ioreq, req->sector_number, req->nr_sectors))
+ goto err;
break;
}
default:
Olaf
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 163 bytes --]
prev parent reply other threads:[~2016-11-17 16:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-01 12:22 [Qemu-devel] [PATCH] block: split large discard requests from block frontend Olaf Hering
2016-04-01 17:19 ` [Qemu-devel] [Qemu-block] " Max Reitz
2016-04-01 17:49 ` Olaf Hering
2016-05-06 16:44 ` Max Reitz
2016-11-17 13:54 ` Olaf Hering
2016-11-17 16:27 ` Olaf Hering [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161117162719.GA18909@aepfle.de \
--to=olaf@aepfle.de \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).