All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com,
	armbru@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
	andrey.shinkevich@virtuozzo.com, den@openvz.org,
	mreitz@redhat.com, jsnow@redhat.com
Subject: [PATCH v3 12/15] copy-on-read: add filter append/drop functions
Date: Tue, 12 May 2020 17:53:13 +0300	[thread overview]
Message-ID: <1589295196-773454-13-git-send-email-andrey.shinkevich@virtuozzo.com> (raw)
In-Reply-To: <1589295196-773454-1-git-send-email-andrey.shinkevich@virtuozzo.com>

Provide API for the COR-filter insertion/removal.
Also, drop the filter child permissions for an inactive state when the
filter node is being removed.

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

diff --git a/block/copy-on-read.c b/block/copy-on-read.c
index 4030d56..31e1619 100644
--- a/block/copy-on-read.c
+++ b/block/copy-on-read.c
@@ -24,8 +24,15 @@
 #include "qemu/cutils.h"
 #include "block/block_int.h"
 #include "qemu/module.h"
+#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
+#include "block/copy-on-read.h"
 
 
+typedef struct BDRVStateCOR {
+    bool active;
+} BDRVStateCOR;
+
 static int cor_open(BlockDriverState *bs, QDict *options, int flags,
                     Error **errp)
 {
@@ -57,6 +64,17 @@ static void cor_child_perm(BlockDriverState *bs, BdrvChild *c,
                            uint64_t perm, uint64_t shared,
                            uint64_t *nperm, uint64_t *nshared)
 {
+    BDRVStateCOR *s = bs->opaque;
+
+    if (!s->active) {
+        /*
+         * While the filter is being removed
+         */
+        *nperm = 0;
+        *nshared = BLK_PERM_ALL;
+        return;
+    }
+
     *nperm = perm & PERM_PASSTHROUGH;
     *nshared = (shared & PERM_PASSTHROUGH) | PERM_UNCHANGED;
 
@@ -150,6 +168,7 @@ static int cor_change_backing_file(BlockDriverState *bs,
 
 static BlockDriver bdrv_copy_on_read = {
     .format_name                        = "copy-on-read",
+    .instance_size                      = sizeof(BDRVStateCOR),
 
     .bdrv_open                          = cor_open,
     .bdrv_child_perm                    = cor_child_perm,
@@ -178,4 +197,83 @@ static void bdrv_copy_on_read_init(void)
     bdrv_register(&bdrv_copy_on_read);
 }
 
+
+static BlockDriverState *create_filter_node(BlockDriverState *bs,
+                                            const char *filter_node_name,
+                                            Error **errp)
+{
+    QDict *opts = qdict_new();
+
+    qdict_put_str(opts, "driver", "copy-on-read");
+    qdict_put_str(opts, "file", bdrv_get_node_name(bs));
+    if (filter_node_name) {
+        qdict_put_str(opts, "node-name", filter_node_name);
+    }
+
+    return bdrv_open(NULL, NULL, opts, BDRV_O_RDWR, errp);
+}
+
+
+BlockDriverState *bdrv_cor_filter_append(BlockDriverState *bs,
+                                         const char *filter_node_name,
+                                         Error **errp)
+{
+    BlockDriverState *cor_filter_bs;
+    BDRVStateCOR *state;
+    Error *local_err = NULL;
+
+    cor_filter_bs = create_filter_node(bs, filter_node_name, errp);
+    if (cor_filter_bs == NULL) {
+        error_prepend(errp, "Could not create filter node: ");
+        return NULL;
+    }
+
+    if (!filter_node_name) {
+        cor_filter_bs->implicit = true;
+    }
+
+    bdrv_drained_begin(bs);
+    bdrv_replace_node(bs, cor_filter_bs, &local_err);
+    bdrv_drained_end(bs);
+
+    if (local_err) {
+        bdrv_unref(cor_filter_bs);
+        error_propagate(errp, local_err);
+        return NULL;
+    }
+
+    state = cor_filter_bs->opaque;
+    state->active = true;
+
+    return cor_filter_bs;
+}
+
+
+void bdrv_cor_filter_drop(BlockDriverState *cor_filter_bs)
+{
+    BdrvChild *child;
+    BlockDriverState *bs;
+    BDRVStateCOR *s = cor_filter_bs->opaque;
+
+    child = bdrv_filtered_rw_child(cor_filter_bs);
+    if (!child) {
+        return;
+    }
+    bs = child->bs;
+
+    /* Retain the BDS until we complete the graph change. */
+    bdrv_ref(bs);
+    /* Hold a guest back from writing while permissions are being reset. */
+    bdrv_drained_begin(bs);
+    /* Drop permissions before the graph change. */
+    s->active = false;
+    bdrv_child_refresh_perms(cor_filter_bs, child, &error_abort);
+    bdrv_replace_node(cor_filter_bs, bs, &error_abort);
+
+    bdrv_drained_end(bs);
+    bdrv_unref(bs);
+    bdrv_unref(cor_filter_bs);
+}
+
+
 block_init(bdrv_copy_on_read_init);
-- 
1.8.3.1



  parent reply	other threads:[~2020-05-12 14:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 14:53 [PATCH v3 00/15] Apply COR-filter to the block-stream permanently Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 01/15] block: Mark commit and mirror as filter drivers Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 02/15] copy-on-read: Support compressed writes Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 03/15] block: Add child access functions Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 04/15] block: Add chain helper functions Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 05/15] block: Include filters when freezing backing chain Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 06/15] block: Use CAFs in block status functions Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 07/15] commit: Deal with filters when blocking intermediate nodes Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 08/15] block: Use CAFs when working with backing chains Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 09/15] block: prepare block-stream for using COR-filter Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 10/15] copy-on-read: Support change filename functions Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 11/15] copy-on-read: Support preadv/pwritev_part functions Andrey Shinkevich
2020-05-12 14:53 ` Andrey Shinkevich [this message]
2020-05-12 14:53 ` [PATCH v3 13/15] qapi: add filter-node-name to block-stream Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 14/15] iotests: prepare 245 for using filter in block-stream Andrey Shinkevich
2020-05-12 14:53 ` [PATCH v3 15/15] block: apply COR-filter to block-stream jobs Andrey Shinkevich
2020-05-12 18:20 ` [PATCH v3 00/15] Apply COR-filter to the block-stream permanently no-reply
2020-05-12 18:24 ` no-reply
2020-05-12 18:27 ` no-reply

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=1589295196-773454-13-git-send-email-andrey.shinkevich@virtuozzo.com \
    --to=andrey.shinkevich@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=fam@euphon.net \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --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 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.