[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 10/16] block/io: introduce block driver snapshot-access API
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v5 10/16] block/io: introduce block driver snapshot-access API |
Date: |
Mon, 28 Feb 2022 12:39:21 +0100 |
Add new block driver handlers and corresponding generic wrappers.
It will be used to allow copy-before-write filter to provide
reach fleecing interface in further commit.
In future this approach may be used to allow reading qcow2 internal
snapshots, for example to export them through NBD.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
---
include/block/block_int.h | 27 +++++++++++++++
block/io.c | 69 +++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 27008cfb22..c43315ae6e 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -376,6 +376,24 @@ struct BlockDriver {
*/
void (*bdrv_cancel_in_flight)(BlockDriverState *bs);
+ /*
+ * Snapshot-access API.
+ *
+ * Block-driver may provide snapshot-access API: special functions to
access
+ * some internal "snapshot". The functions are similar with normal
+ * read/block_status/discard handler, but don't have any specific handling
+ * in generic block-layer: no serializing, no alignment, no tracked
+ * requests. So, block-driver that realizes these APIs is fully responsible
+ * for synchronization between snapshot-access API and normal IO requests.
+ */
+ int coroutine_fn (*bdrv_co_preadv_snapshot)(BlockDriverState *bs,
+ int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset);
+ int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs,
+ bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum,
+ int64_t *map, BlockDriverState **file);
+ int coroutine_fn (*bdrv_co_pdiscard_snapshot)(BlockDriverState *bs,
+ int64_t offset, int64_t bytes);
+
/*
* Invalidate any cached meta-data.
*/
@@ -1078,6 +1096,15 @@ extern BlockDriver bdrv_file;
extern BlockDriver bdrv_raw;
extern BlockDriver bdrv_qcow2;
+int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child,
+ int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset);
+int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs,
+ bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum,
+ int64_t *map, BlockDriverState **file);
+int coroutine_fn bdrv_co_pdiscard_snapshot(BlockDriverState *bs,
+ int64_t offset, int64_t bytes);
+
+
int coroutine_fn bdrv_co_preadv(BdrvChild *child,
int64_t offset, int64_t bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags);
diff --git a/block/io.c b/block/io.c
index 4e4cb556c5..0bcf09a491 100644
--- a/block/io.c
+++ b/block/io.c
@@ -3587,3 +3587,72 @@ void bdrv_cancel_in_flight(BlockDriverState *bs)
bs->drv->bdrv_cancel_in_flight(bs);
}
}
+
+int coroutine_fn
+bdrv_co_preadv_snapshot(BdrvChild *child, int64_t offset, int64_t bytes,
+ QEMUIOVector *qiov, size_t qiov_offset)
+{
+ BlockDriverState *bs = child->bs;
+ BlockDriver *drv = bs->drv;
+ int ret;
+
+ if (!drv) {
+ return -ENOMEDIUM;
+ }
+
+ if (!drv->bdrv_co_preadv_snapshot) {
+ return -ENOTSUP;
+ }
+
+ bdrv_inc_in_flight(bs);
+ ret = drv->bdrv_co_preadv_snapshot(bs, offset, bytes, qiov, qiov_offset);
+ bdrv_dec_in_flight(bs);
+
+ return ret;
+}
+
+int coroutine_fn
+bdrv_co_snapshot_block_status(BlockDriverState *bs,
+ bool want_zero, int64_t offset, int64_t bytes,
+ int64_t *pnum, int64_t *map,
+ BlockDriverState **file)
+{
+ BlockDriver *drv = bs->drv;
+ int ret;
+
+ if (!drv) {
+ return -ENOMEDIUM;
+ }
+
+ if (!drv->bdrv_co_snapshot_block_status) {
+ return -ENOTSUP;
+ }
+
+ bdrv_inc_in_flight(bs);
+ ret = drv->bdrv_co_snapshot_block_status(bs, want_zero, offset, bytes,
+ pnum, map, file);
+ bdrv_dec_in_flight(bs);
+
+ return ret;
+}
+
+int coroutine_fn
+bdrv_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes)
+{
+ BlockDriver *drv = bs->drv;
+ int ret;
+
+ if (!drv) {
+ return -ENOMEDIUM;
+ }
+
+ if (!drv->bdrv_co_pdiscard_snapshot) {
+ return -ENOTSUP;
+ }
+
+ bdrv_inc_in_flight(bs);
+ ret = drv->bdrv_co_pdiscard_snapshot(bs, offset, bytes);
+ bdrv_dec_in_flight(bs);
+
+ return ret;
+}
--
2.31.1
- [PATCH v5 00/16] Make image fleecing more usable, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 01/16] block/block-copy: move copy_bitmap initialization to block_copy_state_new(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 02/16] block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 04/16] block/copy-before-write: add bitmap open parameter, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 05/16] block/block-copy: add block_copy_reset(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 06/16] block: intoduce reqlist, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 07/16] block/reqlist: reqlist_find_conflict(): use ranges_overlap(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 03/16] block/block-copy: block_copy_state_new(): add bitmap parameter, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 10/16] block/io: introduce block driver snapshot-access API,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v5 08/16] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 11/16] block: introduce snapshot-access block driver, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 09/16] block/reqlist: add reqlist_wait_all(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 12/16] block: copy-before-write: realize snapshot-access API, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 13/16] iotests/image-fleecing: add test-case for fleecing format node, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 14/16] iotests.py: add qemu_io_pipe_and_status(), Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 15/16] iotests/image-fleecing: add test case with bitmap, Vladimir Sementsov-Ogievskiy, 2022/02/28
- [PATCH v5 16/16] iotests/image-fleecing: test push backup with fleecing, Vladimir Sementsov-Ogievskiy, 2022/02/28