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