All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, armbru@redhat.com,
	xiechanglong.d@gmail.com, wencongyang2@huawei.com,
	fam@euphon.net, stefanha@redhat.com, eblake@redhat.com,
	hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com,
	jsnow@redhat.com, nikita.lapshin@virtuozzo.com
Subject: [PATCH v4 10/18] block/io: introduce block driver snapshot-access API
Date: Wed, 16 Feb 2022 20:46:09 +0100	[thread overview]
Message-ID: <20220216194617.126484-11-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20220216194617.126484-1-vsementsov@virtuozzo.com>

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 interanal
snaphots, for example to export them through NBD.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.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



  parent reply	other threads:[~2022-02-16 20:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16 19:45 [PATCH v4 00/18] Make image fleecing more usable Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 01/18] block/block-copy: move copy_bitmap initialization to block_copy_state_new() Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 02/18] block/dirty-bitmap: bdrv_merge_dirty_bitmap(): add return value Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 03/18] block/block-copy: block_copy_state_new(): add bitmap parameter Vladimir Sementsov-Ogievskiy
2022-02-24 12:01   ` Hanna Reitz
2022-02-16 19:46 ` [PATCH v4 04/18] block/copy-before-write: add bitmap open parameter Vladimir Sementsov-Ogievskiy
2022-02-24 12:07   ` Hanna Reitz
2022-02-24 13:27     ` Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 05/18] block/block-copy: add block_copy_reset() Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 06/18] block: intoduce reqlist Vladimir Sementsov-Ogievskiy
2022-02-24 12:08   ` Hanna Reitz
2022-02-16 19:46 ` [PATCH v4 07/18] block/reqlist: reqlist_find_conflict(): use ranges_overlap() Vladimir Sementsov-Ogievskiy
2022-02-24 12:08   ` Hanna Reitz
2022-02-16 19:46 ` [PATCH v4 08/18] block/dirty-bitmap: introduce bdrv_dirty_bitmap_status() Vladimir Sementsov-Ogievskiy
2022-02-24 12:20   ` Hanna Reitz
2022-02-16 19:46 ` [PATCH v4 09/18] block/reqlist: add reqlist_wait_all() Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` Vladimir Sementsov-Ogievskiy [this message]
2022-02-24 12:24   ` [PATCH v4 10/18] block/io: introduce block driver snapshot-access API Hanna Reitz
2022-02-16 19:46 ` [PATCH v4 11/18] block: introduce snapshot-access filter Vladimir Sementsov-Ogievskiy
2022-02-24 12:29   ` Hanna Reitz
2022-02-16 19:46 ` [PATCH v4 12/18] block: copy-before-write: realize snapshot-access API Vladimir Sementsov-Ogievskiy
2022-02-24 12:46   ` Hanna Reitz
2022-02-24 13:42     ` Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 13/18] iotests/image-fleecing: add test-case for fleecing format node Vladimir Sementsov-Ogievskiy
2022-02-24 12:48   ` Hanna Reitz
2022-02-16 19:46 ` [PATCH v4 14/18] iotests.py: add qemu_io_pipe_and_status() Vladimir Sementsov-Ogievskiy
2022-02-24 12:52   ` Hanna Reitz
2022-02-24 13:42     ` Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 15/18] iotests/image-fleecing: add test case with bitmap Vladimir Sementsov-Ogievskiy
2022-02-24 12:58   ` Hanna Reitz
2022-02-24 14:07     ` Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 16/18] block: blk_root(): return non-const pointer Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 17/18] qapi: backup: add immutable-source parameter Vladimir Sementsov-Ogievskiy
2022-02-24 13:05   ` Hanna Reitz
2022-02-24 14:14     ` Vladimir Sementsov-Ogievskiy
2022-02-16 19:46 ` [PATCH v4 18/18] iotests/image-fleecing: test push backup with fleecing Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220216194617.126484-11-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=nikita.lapshin@virtuozzo.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=wencongyang2@huawei.com \
    --cc=xiechanglong.d@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.