|
|
9ae3a8 |
From 374f2dab9cd7bd26bca73ef93cf75ed919d278f4 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <374f2dab9cd7bd26bca73ef93cf75ed919d278f4.1389014116.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
|
|
|
9ae3a8 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 9 Dec 2013 14:09:11 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 23/50] block: generalize BlockLimits handling to cover
|
|
|
9ae3a8 |
bdrv_aio_discard too
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1386598178-11845-26-git-send-email-pbonzini@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 56062
|
|
|
9ae3a8 |
O-Subject: [RHEL 7.0 qemu-kvm PATCH 25/52] block: generalize BlockLimits handling to cover bdrv_aio_discard too
|
|
|
9ae3a8 |
Bugzilla: 1007815
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bdrv_co_discard is only covering drivers which have a .bdrv_co_discard()
|
|
|
9ae3a8 |
implementation, but not those with .bdrv_aio_discard(). Not very nice,
|
|
|
9ae3a8 |
and easy to avoid.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Suggested-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Peter Lieven <pl@kamp.de>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit d51e9fe505f7c7b97762100dd0e42cef43c90524)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 80 +++++++++++++++++++++++++++++++++--------------------------------
|
|
|
9ae3a8 |
1 file changed, 41 insertions(+), 39 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Michal Novotny <minovotn@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block.c | 80 +++++++++++++++++++++++++++++++++--------------------------------
|
|
|
9ae3a8 |
1 file changed, 41 insertions(+), 39 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block.c b/block.c
|
|
|
9ae3a8 |
index 60484a6..8dfc207 100644
|
|
|
9ae3a8 |
--- a/block.c
|
|
|
9ae3a8 |
+++ b/block.c
|
|
|
9ae3a8 |
@@ -4469,6 +4469,8 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque)
|
|
|
9ae3a8 |
int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
int nb_sectors)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
+ int max_discard;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
if (!bs->drv) {
|
|
|
9ae3a8 |
return -ENOMEDIUM;
|
|
|
9ae3a8 |
} else if (bdrv_check_request(bs, sector_num, nb_sectors)) {
|
|
|
9ae3a8 |
@@ -4486,55 +4488,55 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (bs->drv->bdrv_co_discard) {
|
|
|
9ae3a8 |
- int max_discard = bs->bl.max_discard ?
|
|
|
9ae3a8 |
- bs->bl.max_discard : MAX_DISCARD_DEFAULT;
|
|
|
9ae3a8 |
+ if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) {
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- while (nb_sectors > 0) {
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
- int num = nb_sectors;
|
|
|
9ae3a8 |
+ max_discard = bs->bl.max_discard ? bs->bl.max_discard : MAX_DISCARD_DEFAULT;
|
|
|
9ae3a8 |
+ while (nb_sectors > 0) {
|
|
|
9ae3a8 |
+ int ret;
|
|
|
9ae3a8 |
+ int num = nb_sectors;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* align request */
|
|
|
9ae3a8 |
- if (bs->bl.discard_alignment &&
|
|
|
9ae3a8 |
- num >= bs->bl.discard_alignment &&
|
|
|
9ae3a8 |
- sector_num % bs->bl.discard_alignment) {
|
|
|
9ae3a8 |
- if (num > bs->bl.discard_alignment) {
|
|
|
9ae3a8 |
- num = bs->bl.discard_alignment;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- num -= sector_num % bs->bl.discard_alignment;
|
|
|
9ae3a8 |
+ /* align request */
|
|
|
9ae3a8 |
+ if (bs->bl.discard_alignment &&
|
|
|
9ae3a8 |
+ num >= bs->bl.discard_alignment &&
|
|
|
9ae3a8 |
+ sector_num % bs->bl.discard_alignment) {
|
|
|
9ae3a8 |
+ if (num > bs->bl.discard_alignment) {
|
|
|
9ae3a8 |
+ num = bs->bl.discard_alignment;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+ num -= sector_num % bs->bl.discard_alignment;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- /* limit request size */
|
|
|
9ae3a8 |
- if (num > max_discard) {
|
|
|
9ae3a8 |
- num = max_discard;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
+ /* limit request size */
|
|
|
9ae3a8 |
+ if (num > max_discard) {
|
|
|
9ae3a8 |
+ num = max_discard;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ if (bs->drv->bdrv_co_discard) {
|
|
|
9ae3a8 |
ret = bs->drv->bdrv_co_discard(bs, sector_num, num);
|
|
|
9ae3a8 |
- if (ret) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ BlockDriverAIOCB *acb;
|
|
|
9ae3a8 |
+ CoroutineIOCompletion co = {
|
|
|
9ae3a8 |
+ .coroutine = qemu_coroutine_self(),
|
|
|
9ae3a8 |
+ };
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
|
|
|
9ae3a8 |
+ bdrv_co_io_em_complete, &co);
|
|
|
9ae3a8 |
+ if (acb == NULL) {
|
|
|
9ae3a8 |
+ return -EIO;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ qemu_coroutine_yield();
|
|
|
9ae3a8 |
+ ret = co.ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- sector_num += num;
|
|
|
9ae3a8 |
- nb_sectors -= num;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
- } else if (bs->drv->bdrv_aio_discard) {
|
|
|
9ae3a8 |
- BlockDriverAIOCB *acb;
|
|
|
9ae3a8 |
- CoroutineIOCompletion co = {
|
|
|
9ae3a8 |
- .coroutine = qemu_coroutine_self(),
|
|
|
9ae3a8 |
- };
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
|
|
|
9ae3a8 |
- bdrv_co_io_em_complete, &co);
|
|
|
9ae3a8 |
- if (acb == NULL) {
|
|
|
9ae3a8 |
- return -EIO;
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- qemu_coroutine_yield();
|
|
|
9ae3a8 |
- return co.ret;
|
|
|
9ae3a8 |
+ if (ret) {
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ sector_num += num;
|
|
|
9ae3a8 |
+ nb_sectors -= num;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.11.7
|
|
|
9ae3a8 |
|