|
|
218e99 |
From 9b3702c45245f7bbb51350c25e8cf304c490b96a Mon Sep 17 00:00:00 2001
|
|
|
218e99 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
218e99 |
Date: Thu, 7 Nov 2013 07:19:42 +0100
|
|
|
218e99 |
Subject: [PATCH 05/81] block: make bdrv_co_is_allocated static
|
|
|
218e99 |
|
|
|
218e99 |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
218e99 |
Message-id: <1382084091-16636-6-git-send-email-pbonzini@redhat.com>
|
|
|
218e99 |
Patchwork-id: 54988
|
|
|
218e99 |
O-Subject: [RHEL 7.0 qemu-kvm PATCH 05/26] block: make bdrv_co_is_allocated static
|
|
|
218e99 |
Bugzilla: 989646
|
|
|
218e99 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
218e99 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
218e99 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
218e99 |
|
|
|
218e99 |
bdrv_is_allocated can detect coroutine context and go through a fast
|
|
|
218e99 |
path, similar to other block layer functions.
|
|
|
218e99 |
|
|
|
218e99 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
218e99 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
218e99 |
(cherry picked from commit bdad13b9deec47d5d9eaf7f43867d19a79471244)
|
|
|
218e99 |
|
|
|
218e99 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
218e99 |
---
|
|
|
218e99 |
block.c | 24 +++++++++++++++---------
|
|
|
218e99 |
block/raw.c | 2 +-
|
|
|
218e99 |
block/stream.c | 4 ++--
|
|
|
218e99 |
include/block/block.h | 2 --
|
|
|
218e99 |
4 files changed, 18 insertions(+), 14 deletions(-)
|
|
|
218e99 |
|
|
|
218e99 |
diff --git a/block.c b/block.c
|
|
|
218e99 |
index d5aeff7..0607cc6 100644
|
|
|
218e99 |
--- a/block.c
|
|
|
218e99 |
+++ b/block.c
|
|
|
218e99 |
@@ -2555,7 +2555,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
|
|
|
218e99 |
if (flags & BDRV_REQ_COPY_ON_READ) {
|
|
|
218e99 |
int pnum;
|
|
|
218e99 |
|
|
|
218e99 |
- ret = bdrv_co_is_allocated(bs, sector_num, nb_sectors, &pnum);
|
|
|
218e99 |
+ ret = bdrv_is_allocated(bs, sector_num, nb_sectors, &pnum);
|
|
|
218e99 |
if (ret < 0) {
|
|
|
218e99 |
goto out;
|
|
|
218e99 |
}
|
|
|
218e99 |
@@ -3027,8 +3027,9 @@ typedef struct BdrvCoIsAllocatedData {
|
|
|
218e99 |
* 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes
|
|
|
218e99 |
* beyond the end of the disk image it will be clamped.
|
|
|
218e99 |
*/
|
|
|
218e99 |
-int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
|
|
218e99 |
- int nb_sectors, int *pnum)
|
|
|
218e99 |
+static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs,
|
|
|
218e99 |
+ int64_t sector_num,
|
|
|
218e99 |
+ int nb_sectors, int *pnum)
|
|
|
218e99 |
{
|
|
|
218e99 |
int64_t n;
|
|
|
218e99 |
|
|
|
218e99 |
@@ -3078,10 +3079,15 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
|
|
218e99 |
.done = false,
|
|
|
218e99 |
};
|
|
|
218e99 |
|
|
|
218e99 |
- co = qemu_coroutine_create(bdrv_is_allocated_co_entry);
|
|
|
218e99 |
- qemu_coroutine_enter(co, &data);
|
|
|
218e99 |
- while (!data.done) {
|
|
|
218e99 |
- qemu_aio_wait();
|
|
|
218e99 |
+ if (qemu_in_coroutine()) {
|
|
|
218e99 |
+ /* Fast-path if already in coroutine context */
|
|
|
218e99 |
+ bdrv_is_allocated_co_entry(&data);
|
|
|
218e99 |
+ } else {
|
|
|
218e99 |
+ co = qemu_coroutine_create(bdrv_is_allocated_co_entry);
|
|
|
218e99 |
+ qemu_coroutine_enter(co, &data);
|
|
|
218e99 |
+ while (!data.done) {
|
|
|
218e99 |
+ qemu_aio_wait();
|
|
|
218e99 |
+ }
|
|
|
218e99 |
}
|
|
|
218e99 |
return data.ret;
|
|
|
218e99 |
}
|
|
|
218e99 |
@@ -3109,8 +3115,8 @@ int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top,
|
|
|
218e99 |
intermediate = top;
|
|
|
218e99 |
while (intermediate && intermediate != base) {
|
|
|
218e99 |
int pnum_inter;
|
|
|
218e99 |
- ret = bdrv_co_is_allocated(intermediate, sector_num, nb_sectors,
|
|
|
218e99 |
- &pnum_inter);
|
|
|
218e99 |
+ ret = bdrv_is_allocated(intermediate, sector_num, nb_sectors,
|
|
|
218e99 |
+ &pnum_inter);
|
|
|
218e99 |
if (ret < 0) {
|
|
|
218e99 |
return ret;
|
|
|
218e99 |
} else if (ret) {
|
|
|
218e99 |
diff --git a/block/raw.c b/block/raw.c
|
|
|
218e99 |
index 8c81de9..f78ff39 100644
|
|
|
218e99 |
--- a/block/raw.c
|
|
|
218e99 |
+++ b/block/raw.c
|
|
|
218e99 |
@@ -39,7 +39,7 @@ static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs,
|
|
|
218e99 |
int64_t sector_num,
|
|
|
218e99 |
int nb_sectors, int *pnum)
|
|
|
218e99 |
{
|
|
|
218e99 |
- return bdrv_co_is_allocated(bs->file, sector_num, nb_sectors, pnum);
|
|
|
218e99 |
+ return bdrv_is_allocated(bs->file, sector_num, nb_sectors, pnum);
|
|
|
218e99 |
}
|
|
|
218e99 |
|
|
|
218e99 |
static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
|
|
|
218e99 |
diff --git a/block/stream.c b/block/stream.c
|
|
|
218e99 |
index d6df06f..f8efa8a 100644
|
|
|
218e99 |
--- a/block/stream.c
|
|
|
218e99 |
+++ b/block/stream.c
|
|
|
218e99 |
@@ -115,8 +115,8 @@ wait:
|
|
|
218e99 |
break;
|
|
|
218e99 |
}
|
|
|
218e99 |
|
|
|
218e99 |
- ret = bdrv_co_is_allocated(bs, sector_num,
|
|
|
218e99 |
- STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
|
|
|
218e99 |
+ ret = bdrv_is_allocated(bs, sector_num,
|
|
|
218e99 |
+ STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
|
|
|
218e99 |
if (ret == 1) {
|
|
|
218e99 |
/* Allocated in the top, no need to copy. */
|
|
|
218e99 |
copy = false;
|
|
|
218e99 |
diff --git a/include/block/block.h b/include/block/block.h
|
|
|
218e99 |
index 1a3ed22..1932e67 100644
|
|
|
218e99 |
--- a/include/block/block.h
|
|
|
218e99 |
+++ b/include/block/block.h
|
|
|
218e99 |
@@ -192,8 +192,6 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
|
|
|
218e99 |
*/
|
|
|
218e99 |
int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
|
|
218e99 |
int nb_sectors);
|
|
|
218e99 |
-int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
|
|
218e99 |
- int nb_sectors, int *pnum);
|
|
|
218e99 |
int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top,
|
|
|
218e99 |
BlockDriverState *base,
|
|
|
218e99 |
int64_t sector_num,
|
|
|
218e99 |
--
|
|
|
218e99 |
1.7.1
|
|
|
218e99 |
|