[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v9 5/9] copy-on-read: limit guest COR activity to base in COR dri
From: |
Andrey Shinkevich |
Subject: |
[PATCH v9 5/9] copy-on-read: limit guest COR activity to base in COR driver |
Date: |
Mon, 28 Sep 2020 15:59:57 +0300 |
Limit the guest's COR operations by the base node in the backing chain
when the base node name is given. It will be useful for a block stream
job when the COR-filter is applied.
Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
block/copy-on-read.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/block/copy-on-read.c b/block/copy-on-read.c
index e04092f..f53f7e0 100644
--- a/block/copy-on-read.c
+++ b/block/copy-on-read.c
@@ -121,8 +121,42 @@ static int coroutine_fn
cor_co_preadv_part(BlockDriverState *bs,
size_t qiov_offset,
int flags)
{
- return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_offset,
- flags | BDRV_REQ_COPY_ON_READ);
+ int64_t n = 0;
+ int64_t size = offset + bytes;
+ int local_flags;
+ int ret;
+ BDRVStateCOR *state = bs->opaque;
+
+ if (!state->base_bs) {
+ return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_offset,
+ flags | BDRV_REQ_COPY_ON_READ);
+ }
+
+ while (offset < size) {
+ local_flags = flags;
+
+ /* In case of failure, try to copy-on-read anyway */
+ ret = bdrv_is_allocated(bs->file->bs, offset, bytes, &n);
+ if (!ret) {
+ ret = bdrv_is_allocated_above(bdrv_cow_bs(bs->file->bs),
+ state->base_bs, false, offset, n,
&n);
+ if (ret > 0) {
+ local_flags |= BDRV_REQ_COPY_ON_READ;
+ }
+ }
+
+ ret = bdrv_co_preadv_part(bs->file, offset, n, qiov, qiov_offset,
+ local_flags);
+ if (ret < 0) {
+ return ret;
+ }
+
+ offset += n;
+ qiov_offset += n;
+ bytes -= n;
+ }
+
+ return 0;
}
--
1.8.3.1
- [PATCH v9 0/9] Apply COR-filter to the block-stream permanently, Andrey Shinkevich, 2020/09/28
- [PATCH v9 1/9] copy-on-read: Support preadv/pwritev_part functions, Andrey Shinkevich, 2020/09/28
- [PATCH v9 2/9] copy-on-read: add filter append/drop functions, Andrey Shinkevich, 2020/09/28
- [PATCH v9 3/9] qapi: add filter-node-name to block-stream, Andrey Shinkevich, 2020/09/28
- [PATCH v9 4/9] copy-on-read: pass base node name to COR driver, Andrey Shinkevich, 2020/09/28
- [PATCH v9 5/9] copy-on-read: limit guest COR activity to base in COR driver,
Andrey Shinkevich <=
- [PATCH v9 6/9] copy-on-read: skip non-guest reads if no copy needed, Andrey Shinkevich, 2020/09/28
- [PATCH v9 7/9] stream: skip filters when writing backing file name to QCOW2 header, Andrey Shinkevich, 2020/09/28
- [PATCH v9 8/9] block: remove unused backing-file name parameter, Andrey Shinkevich, 2020/09/28
- [PATCH v9 9/9] block: apply COR-filter to block-stream jobs, Andrey Shinkevich, 2020/09/28
- Re: [PATCH v9 0/9] Apply COR-filter to the block-stream permanently, no-reply, 2020/09/28
- Re: [PATCH v9 0/9] Apply COR-filter to the block-stream permanently, no-reply, 2020/09/28