qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 57/93] block: Create authorizations mechanism for external snapshot and resize.
Date: Fri, 24 Jan 2014 18:21:40 +0100	[thread overview]
Message-ID: <1390584136-24703-58-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1390584136-24703-1-git-send-email-kwolf@redhat.com>

From: Benoît Canet <benoit@irqsave.net>

Signed-off-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c                   | 65 ++++++++++++++++++++++++++++++++++++++++-------
 block/blkverify.c         |  2 +-
 blockdev.c                |  2 +-
 include/block/block.h     | 20 +++++++--------
 include/block/block_int.h | 12 ++++++---
 5 files changed, 77 insertions(+), 24 deletions(-)

diff --git a/block.c b/block.c
index 064df90..18c0a8d 100644
--- a/block.c
+++ b/block.c
@@ -5094,21 +5094,68 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
     return bs->drv->bdrv_amend_options(bs, options);
 }
 
-ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs)
+/* Used to recurse on single child block filters.
+ * Single child block filter will store their child in bs->file.
+ */
+bool bdrv_generic_is_first_non_filter(BlockDriverState *bs,
+                                      BlockDriverState *candidate)
 {
-    if (bs->drv->bdrv_check_ext_snapshot) {
-        return bs->drv->bdrv_check_ext_snapshot(bs);
+    if (!bs->drv) {
+        return false;
+    }
+
+    if (!bs->drv->authorizations[BS_IS_A_FILTER]) {
+        if (bs == candidate) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    if (!bs->drv->authorizations[BS_FILTER_PASS_DOWN]) {
+        return false;
     }
 
-    if (bs->file && bs->file->drv && bs->file->drv->bdrv_check_ext_snapshot) {
-        return bs->file->drv->bdrv_check_ext_snapshot(bs);
+    if (!bs->file) {
+        return false;
+    }
+
+    return bdrv_recurse_is_first_non_filter(bs->file, candidate);
+}
+
+bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
+                                      BlockDriverState *candidate)
+{
+    if (bs->drv && bs->drv->bdrv_recurse_is_first_non_filter) {
+        return bs->drv->bdrv_recurse_is_first_non_filter(bs, candidate);
     }
 
-    /* external snapshots are allowed by default */
-    return EXT_SNAPSHOT_ALLOWED;
+    return bdrv_generic_is_first_non_filter(bs, candidate);
 }
 
-ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs)
+/* This function checks if the candidate is the first non filter bs down it's
+ * bs chain. Since we don't have pointers to parents it explore all bs chains
+ * from the top. Some filters can choose not to pass down the recursion.
+ */
+bool bdrv_is_first_non_filter(BlockDriverState *candidate)
 {
-    return EXT_SNAPSHOT_FORBIDDEN;
+    BlockDriverState *bs;
+
+    /* walk down the bs forest recursively */
+    QTAILQ_FOREACH(bs, &bdrv_states, device_list) {
+        bool perm;
+
+        if (!bs->file) {
+            continue;
+        }
+
+        perm = bdrv_recurse_is_first_non_filter(bs->file, candidate);
+
+        /* candidate is the first non filter */
+        if (perm) {
+            return true;
+        }
+    }
+
+    return false;
 }
diff --git a/block/blkverify.c b/block/blkverify.c
index a2e8f5f..cfcbcf4 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -404,7 +404,7 @@ static BlockDriver bdrv_blkverify = {
     .bdrv_aio_writev        = blkverify_aio_writev,
     .bdrv_aio_flush         = blkverify_aio_flush,
 
-    .bdrv_check_ext_snapshot = bdrv_check_ext_snapshot_forbidden,
+    .authorizations         = { true, false },
 };
 
 static void bdrv_blkverify_init(void)
diff --git a/blockdev.c b/blockdev.c
index 2f4065e..32a356e 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1243,7 +1243,7 @@ static void external_snapshot_prepare(BlkTransactionState *common,
         }
     }
 
-    if (bdrv_check_ext_snapshot(state->old_bs) != EXT_SNAPSHOT_ALLOWED) {
+    if (!bdrv_is_first_non_filter(state->old_bs)) {
         error_set(errp, QERR_FEATURE_DISABLED, "snapshot");
         return;
     }
diff --git a/include/block/block.h b/include/block/block.h
index b4a77e6..59d9f12 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -287,16 +287,16 @@ int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options);
 /* external snapshots */
 
 typedef enum {
-    EXT_SNAPSHOT_ALLOWED,
-    EXT_SNAPSHOT_FORBIDDEN,
-} ExtSnapshotPerm;
-
-/* return EXT_SNAPSHOT_ALLOWED if external snapshot is allowed
- * return EXT_SNAPSHOT_FORBIDDEN if external snapshot is forbidden
- */
-ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs);
-/* helper used to forbid external snapshots like in blkverify */
-ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs);
+    BS_IS_A_FILTER,
+    BS_FILTER_PASS_DOWN,
+    BS_AUTHORIZATION_COUNT,
+} BsAuthorization;
+
+bool bdrv_generic_is_first_non_filter(BlockDriverState *bs,
+                                      BlockDriverState *candidate);
+bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
+                                      BlockDriverState *candidate);
+bool bdrv_is_first_non_filter(BlockDriverState *candidate);
 
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index f3f518c..611a955 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -69,10 +69,16 @@ struct BlockDriver {
     const char *format_name;
     int instance_size;
 
-    /* if not defined external snapshots are allowed
-     * future block filters will query their children to build the response
+    /* this table of boolean contains authorizations for the block operations */
+    bool authorizations[BS_AUTHORIZATION_COUNT];
+    /* for snapshots complex block filter like Quorum can implement the
+     * following recursive callback instead of BS_IS_A_FILTER.
+     * It's purpose is to recurse on the filter children while calling
+     * bdrv_recurse_is_first_non_filter on them.
+     * For a sample implementation look in the future Quorum block filter.
      */
-    ExtSnapshotPerm (*bdrv_check_ext_snapshot)(BlockDriverState *bs);
+    bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs,
+                                             BlockDriverState *candidate);
 
     int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
     int (*bdrv_probe_device)(const char *filename);
-- 
1.8.1.4

  parent reply	other threads:[~2014-01-24 17:24 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-24 17:20 [Qemu-devel] [PULL v2 00/93] Block patches Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 01/93] rbd: switch from pipe to QEMUBH completion notification Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 02/93] qemu-iotests: Introduce _unsupported_imgopts Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 03/93] qemu-iotests: Add _unsupported_imgopts for vmdk subformats Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 04/93] qemu-iotests: Clean up all extents for vmdk Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 05/93] block/iscsi: return -ENOMEM if an async call fails immediately Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 06/93] gluster: Convert aio routines into coroutines Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 07/93] gluster: Implement .bdrv_co_write_zeroes for gluster Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 08/93] gluster: Add support for creating zero-filled image Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 09/93] sheepdog: fix clone operation by 'qemu-img create -b' Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 10/93] qtest: Fix the bug about disable vnc causes "make check" fail Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 11/93] docs: qcow2 compat=1.1 is now the default Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 12/93] vmdk: Fix big flat extent IO Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 13/93] readline: decouple readline from the monitor Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 14/93] readline: move readline to a generic location Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 15/93] osdep: add qemu_set_tty_echo() Kevin Wolf
2014-01-24 17:20 ` [Qemu-devel] [PULL 16/93] qemu-io: use readline.c Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 17/93] qemu-io: add command completion Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 18/93] blkdebug: Use errp for read_config() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 19/93] blkdebug: Don't require sophisticated filename Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 20/93] qdict: Add qdict_array_split() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 21/93] qapi: extend qdict_flatten() for QLists Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 22/93] qemu-option: Add qemu_config_parse_qdict() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 23/93] blkdebug: Always call read_config() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 24/93] blkdebug: Use command-line in read_config() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 25/93] block: Allow reference for bdrv_file_open() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 26/93] block: Pass reference to bdrv_file_open() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 27/93] block: Allow block devices without files Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 28/93] block: Add bdrv_open_image() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 29/93] block: Use bdrv_open_image() in bdrv_open() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 30/93] block: Allow recursive "file"s Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 31/93] blockdev: Move "file" to legacy_opts Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 32/93] blkdebug: Allow command-line file configuration Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 33/93] blkverify: Allow command-line configuration Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 34/93] blkverify: Don't require protocol filename Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 35/93] qapi: Add "errno" to the list of polluted words Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 36/93] qapi: QMP interface for blkdebug and blkverify Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 37/93] qemu-io: Make filename optional Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 38/93] tests: Add test for qdict_array_split() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 39/93] tests: Add test for qdict_flatten() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 40/93] iotests: Test new blkdebug/blkverify interface Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 41/93] iotests: Test file format nesting Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 42/93] block: fix backing file segfault Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 43/93] dataplane: fix shadowed return value Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 44/93] qcow2: fix wrong value of L1E_OFFSET_MASK, L2E_OFFSET_MASK and REFT_OFFSET_MASK Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 45/93] vmdk: Check for overhead when opening Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 46/93] qemu-progress: Drop unused include Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 47/93] qemu-progress: Fix progress printing on SIGUSR1 Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 48/93] Documentation: qemu-img: Mention SIGUSR1 progress report Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 49/93] sheepdog: fix 'qemu-img map' Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 50/93] drive mirror:fix memory leak Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 51/93] vmdk: Fix format specific information (create type) for streamOptimized Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 52/93] qapi: Add "backing" to BlockStats Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 53/93] block: Add bs->node_name to hold the name of a bs node of the bs graph Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 54/93] block: Allow the user to define "node-name" option both on command line and QMP Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 55/93] qmp: Add QMP query-named-block-nodes to list the named BlockDriverState nodes Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 56/93] qmp: Allow to change password on named block driver states Kevin Wolf
2014-01-24 17:21 ` Kevin Wolf [this message]
2014-01-24 17:21 ` [Qemu-devel] [PULL 58/93] qmp: Allow block_resize to manipulate bs graph nodes Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 59/93] qmp: Allow to take external snapshots on bs graphs node Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 60/93] block/curl: Implement the libcurl timer callback interface Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 61/93] block: resize backing file image during offline commit, if necessary Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 62/93] block: resize backing image during active layer commit, if needed Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 63/93] block: update block commit documentation regarding image truncation Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 64/93] block: Fix bdrv_commit return value Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 65/93] block: Move initialisation of BlockLimits to bdrv_refresh_limits() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 66/93] block: Inherit opt_transfer_length Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 67/93] block: Update BlockLimits when they might have changed Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 68/93] qemu_memalign: Allow small alignments Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 69/93] block: Detect unaligned length in bdrv_qiov_is_aligned() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 70/93] block: Don't use guest sector size for qemu_blockalign() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 71/93] block: rename buffer_alignment to guest_block_size Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 72/93] raw: Probe required direct I/O alignment Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 73/93] block: Introduce bdrv_aligned_preadv() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 74/93] block: Introduce bdrv_co_do_preadv() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 75/93] block: Introduce bdrv_aligned_pwritev() Kevin Wolf
2014-01-24 17:21 ` [Qemu-devel] [PULL 76/93] block: write: Handle COR dependency after I/O throttling Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 77/93] block: Introduce bdrv_co_do_pwritev() Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 78/93] block: Switch BdrvTrackedRequest to byte granularity Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 79/93] block: Allow waiting for overlapping requests between begin/end Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 80/93] block: Make zero-after-EOF work with larger alignment Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 81/93] block: Generalise and optimise COR serialisation Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 82/93] block: Make overlap range for serialisation dynamic Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 83/93] block: Allow wait_serialising_requests() at any point Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 84/93] block: Align requests in bdrv_co_do_pwritev() Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 85/93] block: Assert serialisation assumptions in pwritev Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 86/93] block: Change coroutine wrapper to byte granularity Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 87/93] block: Make bdrv_pread() a bdrv_prwv_co() wrapper Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 88/93] block: Make bdrv_pwrite() " Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 89/93] iscsi: Set bs->request_alignment Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 90/93] blkdebug: Make required alignment configurable Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 91/93] qemu-io: New command 'sleep' Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 92/93] qemu-iotests: Test pwritev RMW logic Kevin Wolf
2014-01-24 17:22 ` [Qemu-devel] [PULL 93/93] block: Switch bdrv_io_limits_intercept() to byte granularity Kevin Wolf

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=1390584136-24703-58-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /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).