From adc543748b20def826281f9e6fda52f026dc099d Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Thu, 24 Mar 2016 14:32:39 +0100 Subject: [PATCH] block: split large discard requests from block frontend Large discard requests lead to sign expansion errors in qemu. Since there is no API to tell a guest about the limitations qmeu has to split a large request itself. [bsc#964427] Signed-off-by: Olaf Hering --- block/io.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index a7dbf85..560fa4c 100644 --- a/block/io.c +++ b/block/io.c @@ -2487,7 +2487,7 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque) rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors); } -int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, +static int __bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { BdrvTrackedRequest req; @@ -2569,6 +2569,26 @@ out: return ret; } +int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, + int nb_sectors) +{ + int num, ret; + int limit = BDRV_REQUEST_MAX_SECTORS; + int remaining = nb_sectors; + int64_t sector_offset = sector_num; + + do { + num = remaining > limit ? limit : remaining; + ret = __bdrv_co_discard(bs, sector_offset, num); + if (ret < 0) + break; + remaining -= num; + sector_offset += num; + } while (remaining > 0); + + return ret; +} + int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { Coroutine *co;