[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/41] block: honour BlockLimits in bdrv_co_discard
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 10/41] block: honour BlockLimits in bdrv_co_discard |
Date: |
Fri, 29 Nov 2013 17:45:25 +0100 |
From: Peter Lieven <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Peter Lieven <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
block.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index b4194da..df5a603 100644
--- a/block.c
+++ b/block.c
@@ -4243,6 +4243,11 @@ static void coroutine_fn bdrv_discard_co_entry(void
*opaque)
rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
}
+/* if no limit is specified in the BlockLimits use a default
+ * of 32768 512-byte sectors (16 MiB) per request.
+ */
+#define MAX_DISCARD_DEFAULT 32768
+
int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
int nb_sectors)
{
@@ -4264,7 +4269,37 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs,
int64_t sector_num,
}
if (bs->drv->bdrv_co_discard) {
- return bs->drv->bdrv_co_discard(bs, sector_num, nb_sectors);
+ int max_discard = bs->bl.max_discard ?
+ bs->bl.max_discard : MAX_DISCARD_DEFAULT;
+
+ while (nb_sectors > 0) {
+ int ret;
+ int num = nb_sectors;
+
+ /* align request */
+ if (bs->bl.discard_alignment &&
+ num >= bs->bl.discard_alignment &&
+ sector_num % bs->bl.discard_alignment) {
+ if (num > bs->bl.discard_alignment) {
+ num = bs->bl.discard_alignment;
+ }
+ num -= sector_num % bs->bl.discard_alignment;
+ }
+
+ /* limit request size */
+ if (num > max_discard) {
+ num = max_discard;
+ }
+
+ ret = bs->drv->bdrv_co_discard(bs, sector_num, num);
+ if (ret) {
+ return ret;
+ }
+
+ sector_num += num;
+ nb_sectors -= num;
+ }
+ return 0;
} else if (bs->drv->bdrv_aio_discard) {
BlockDriverAIOCB *acb;
CoroutineIOCompletion co = {
--
1.8.1.4
- [Qemu-devel] [PULL 00/41] Block patches for 2.0 (flushing block-next), Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 04/41] block: add logical block provisioning info to BlockDriverInfo, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 02/41] block: add flags to bdrv_*_write_zeroes, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 01/41] block: make BdrvRequestFlags public, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 03/41] block: introduce BDRV_REQ_MAY_UNMAP request flag, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 07/41] block: add BlockLimits structure to BlockDriverState, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 06/41] block/iscsi: add .bdrv_get_info, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 05/41] block: add wrappers for logical block provisioning information, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 08/41] block/raw: copy BlockLimits on raw_open, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 09/41] block: honour BlockLimits in bdrv_co_do_write_zeroes, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 10/41] block: honour BlockLimits in bdrv_co_discard,
Kevin Wolf <=
- [Qemu-devel] [PULL 11/41] iscsi: set limits in BlockDriverState, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 12/41] iscsi: simplify iscsi_co_discard, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 13/41] iscsi: add bdrv_co_write_zeroes, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 14/41] block: introduce bdrv_make_zero, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 15/41] block/get_block_status: fix BDRV_BLOCK_ZERO for unallocated blocks, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 16/41] qemu-img: add support for fully allocated images, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 17/41] qemu-img: conditionally zero out target on convert, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 18/41] util/error: Save errno from clobbering, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 19/41] Test coroutine execution order, Kevin Wolf, 2013/11/29
- [Qemu-devel] [PULL 20/41] sheepdog: implement .bdrv_get_allocated_file_size, Kevin Wolf, 2013/11/29