qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Shinkevich via <qemu-devel@nongnu.org>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com,
	armbru@redhat.com, jsnow@redhat.com, eblake@redhat.com,
	den@openvz.org, vsementsov@virtuozzo.com,
	andrey.shinkevich@virtuozzo.com
Subject: [PATCH v8 4/7] copy-on-read: pass base file name to COR driver
Date: Fri, 28 Aug 2020 19:52:56 +0300	[thread overview]
Message-ID: <1598633579-221780-5-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
In-Reply-To: <1598633579-221780-1-git-send-email-andrey.shinkevich@virtuozzo.com>

To limit the guest's COR operations by the base node in the backing
chain during stream job, pass the base file name to the copy-on-read
driver. The rest of the functionality will be implemented in the patch
that follows.

Signed-off-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
---
 block/copy-on-read.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 block/copy-on-read.h |  1 +
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/block/copy-on-read.c b/block/copy-on-read.c
index 0ede7aa..1f858bb 100644
--- a/block/copy-on-read.c
+++ b/block/copy-on-read.c
@@ -24,19 +24,45 @@
 #include "block/block_int.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
+#include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qdict.h"
 #include "block/copy-on-read.h"
 
 
 typedef struct BDRVStateCOR {
     bool active;
+    BlockDriverState *base_bs;
 } BDRVStateCOR;
 
+/*
+ * Non-zero pointers are the caller's responsibility.
+ */
+static BlockDriverState *get_base_by_name(BlockDriverState *bs,
+                                          const char *base_name, Error **errp)
+{
+    BlockDriverState *base_bs = NULL;
+    AioContext *aio_context;
+
+    base_bs = bdrv_find_backing_image(bs, base_name);
+    if (base_bs == NULL) {
+        error_setg(errp, QERR_BASE_NOT_FOUND, base_name);
+        return NULL;
+    }
+
+    aio_context = bdrv_get_aio_context(bs);
+    aio_context_acquire(aio_context);
+    assert(bdrv_get_aio_context(base_bs) == aio_context);
+    aio_context_release(aio_context);
+
+    return base_bs;
+}
 
 static int cor_open(BlockDriverState *bs, QDict *options, int flags,
                     Error **errp)
 {
+    BlockDriverState *base_bs = NULL;
     BDRVStateCOR *state = bs->opaque;
+    const char *base_name = qdict_get_try_str(options, "base");
 
     bs->file = bdrv_open_child(NULL, options, "file", bs, &child_of_bds,
                                BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY,
@@ -52,7 +78,15 @@ static int cor_open(BlockDriverState *bs, QDict *options, int flags,
         ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) &
             bs->file->bs->supported_zero_flags);
 
+    if (base_name) {
+        qdict_del(options, "base");
+        base_bs = get_base_by_name(bs, base_name, errp);
+        if (!base_bs) {
+            return -EINVAL;
+        }
+    }
     state->active = true;
+    state->base_bs = base_bs;
 
     /*
      * We don't need to call bdrv_child_refresh_perms() now as the permissions
@@ -190,6 +224,7 @@ static void bdrv_copy_on_read_init(void)
 
 
 static BlockDriverState *create_filter_node(BlockDriverState *bs,
+                                            const char *base_name,
                                             const char *filter_node_name,
                                             Error **errp)
 {
@@ -197,6 +232,9 @@ static BlockDriverState *create_filter_node(BlockDriverState *bs,
 
     qdict_put_str(opts, "driver", "copy-on-read");
     qdict_put_str(opts, "file", bdrv_get_node_name(bs));
+    if (base_name) {
+        qdict_put_str(opts, "base", base_name);
+    }
     if (filter_node_name) {
         qdict_put_str(opts, "node-name", filter_node_name);
     }
@@ -206,13 +244,14 @@ static BlockDriverState *create_filter_node(BlockDriverState *bs,
 
 
 BlockDriverState *bdrv_cor_filter_append(BlockDriverState *bs,
+                                         const char *base_name,
                                          const char *filter_node_name,
                                          Error **errp)
 {
     BlockDriverState *cor_filter_bs;
     Error *local_err = NULL;
 
-    cor_filter_bs = create_filter_node(bs, filter_node_name, errp);
+    cor_filter_bs = create_filter_node(bs, base_name, filter_node_name, errp);
     if (cor_filter_bs == NULL) {
         error_prepend(errp, "Could not create filter node: ");
         return NULL;
diff --git a/block/copy-on-read.h b/block/copy-on-read.h
index 1686e4e..6a7c8bb 100644
--- a/block/copy-on-read.h
+++ b/block/copy-on-read.h
@@ -28,6 +28,7 @@
 #include "block/block_int.h"
 
 BlockDriverState *bdrv_cor_filter_append(BlockDriverState *bs,
+                                         const char *base_name,
                                          const char *filter_node_name,
                                          Error **errp);
 void bdrv_cor_filter_drop(BlockDriverState *cor_filter_bs);
-- 
1.8.3.1



  parent reply	other threads:[~2020-08-28 16:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-28 16:52 [PATCH v8 0/7] Apply COR-filter to the block-stream permanently Andrey Shinkevich via
2020-08-28 16:52 ` [PATCH v8 1/7] copy-on-read: Support preadv/pwritev_part functions Andrey Shinkevich via
2020-08-28 16:52 ` [PATCH v8 2/7] copy-on-read: add filter append/drop functions Andrey Shinkevich via
2020-09-04 11:22   ` Max Reitz
2020-09-17 16:09     ` Andrey Shinkevich
2020-09-23 14:38       ` Vladimir Sementsov-Ogievskiy
2020-09-24 13:25         ` Max Reitz
2020-09-24 14:51           ` Vladimir Sementsov-Ogievskiy
2020-09-24 15:00             ` Max Reitz
2020-09-24 17:29               ` Andrey Shinkevich
2020-09-24 17:40                 ` Andrey Shinkevich
2020-09-24 17:49                   ` Vladimir Sementsov-Ogievskiy
2020-08-28 16:52 ` [PATCH v8 3/7] qapi: add filter-node-name to block-stream Andrey Shinkevich via
2020-08-28 16:52 ` Andrey Shinkevich via [this message]
2020-09-04 12:17   ` [PATCH v8 4/7] copy-on-read: pass base file name to COR driver Max Reitz
2020-09-04 12:26     ` Vladimir Sementsov-Ogievskiy
2020-08-28 16:52 ` [PATCH v8 5/7] copy-on-read: limit guest writes to base in " Andrey Shinkevich via
2020-09-04 12:50   ` Max Reitz
2020-09-04 13:59     ` Vladimir Sementsov-Ogievskiy
2020-09-22 13:13       ` Andrey Shinkevich
2020-09-24 11:18         ` Max Reitz
2020-08-28 16:52 ` [PATCH v8 6/7] block-stream: freeze link to base node during stream job Andrey Shinkevich via
2020-09-04 13:21   ` Max Reitz
2020-09-04 13:48     ` Vladimir Sementsov-Ogievskiy
2020-09-07 11:44       ` Max Reitz
2020-09-07 12:17         ` Vladimir Sementsov-Ogievskiy
2020-09-24 12:46           ` Max Reitz
2020-08-28 16:52 ` [PATCH v8 7/7] block: apply COR-filter to block-stream jobs Andrey Shinkevich via
2020-09-04 13:41   ` Max Reitz

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=1598633579-221780-5-git-send-email-andrey.shinkevich@virtuozzo.com \
    --to=qemu-devel@nongnu.org \
    --cc=andrey.shinkevich@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=vsementsov@virtuozzo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).