Skip to contentSkip to conversation

disable blkverify external snapshot creation

PATCH Superseded Benoît Canet 3 participants 4 messages Sep 26, 2013 – Sep 27, 2013 Block layer

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 disable blkverify external snapshot creation

Hello,

Here is V2 of the external snapshot disabling patch.
The result is hopefully smaller and don't impact all BlockDriver anymore. Only the blkverify Driver is modified.

v2:
Use NULL fields to avoid having to fill the new field in every BlockDriver

       [Jeff]

Rename the field [Kevin]

Benoît Canet (1):
block: Add BlockDriver.bdrv_check_ext_snapshot.

 block.c                   | 14 ++++++++++++++
 block/blkverify.c         |  2 ++
 blockdev.c                |  5 +++++
 include/block/block.h     |  7 +++++++
 include/block/block_int.h |  8 ++++++++
 5 files changed, 36 insertions(+)
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH v2 1/1 block: Add BlockDriver.bdrv_check_ext_snapshot.

This field is used by blkverify to disable external snapshots creation. I will also be used by block filters like quorum to disable external snapshots creation.

---
 block.c                   | 14 ++++++++++++++
 block/blkverify.c         |  2 ++
 blockdev.c                |  5 +++++
 include/block/block.h     |  7 +++++++
 include/block/block_int.h |  8 ++++++++
 5 files changed, 36 insertions(+)
block.c +14 -0
index 4833b37..4da6fd9 100644
@@ -4632,3 +4632,17 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
     }
     return bs->drv->bdrv_amend_options(bs, options);
 }
+
+bool bdrv_check_ext_snapshot(BlockDriverState *bs)
+{
+    /* external snashots are enabled by defaults */
+    if (!bs->drv->bdrv_check_ext_snapshot) {
+        return true;
+    }
+    return bs->drv->bdrv_check_ext_snapshot(bs);
+}
+
+bool bdrv_forbid_ext_snapshot(BlockDriverState *bs)
+{
+    return false;
+}
block/blkverify.c +2 -0
index 2077d8a..c548923 100644
@@ -313,6 +313,8 @@ static BlockDriver bdrv_blkverify = {
     .bdrv_aio_readv         = blkverify_aio_readv,
     .bdrv_aio_writev        = blkverify_aio_writev,
     .bdrv_aio_flush         = blkverify_aio_flush,
+
+    .bdrv_check_ext_snapshot = bdrv_forbid_ext_snapshot,
 };
 
 static void bdrv_blkverify_init(void)
blockdev.c +5 -0
index 8aa66a9..5c16f1b 100644
@@ -1131,6 +1131,11 @@ static void external_snapshot_prepare(BlkTransactionState *common,
         }
     }
 
+    if (!bdrv_check_ext_snapshot(state->old_bs)) {
+        error_set(errp, QERR_FEATURE_DISABLED, "snapshot");
+        return;
+    }
+
     flags = state->old_bs->open_flags;
 
     /* create new image w/backing file */
include/block/block.h +7 -0
index f808550..df19610 100644
@@ -244,6 +244,13 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
 int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options);
 
+/* external snapshots */
+
+/* return true if external snapshot is allowed, false if not */
+bool bdrv_check_ext_snapshot(BlockDriverState *bs);
+/* helper used to forbid external snapshots like in blkverify */
+bool bdrv_forbid_ext_snapshot(BlockDriverState *bs);
+
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
                                      int sector_num);
include/block/block_int.h +8 -0
index 211087a..cb92355 100644
@@ -67,6 +67,14 @@ typedef struct BdrvTrackedRequest {
 struct BlockDriver {
     const char *format_name;
     int instance_size;
+
+    /* if not defined external snapshots are allowed
+     * if return true external snapshots are allowed
+     * if return false external snapshots are not allowed
+     * future block filters will query their children to build the response
+     */
+    bool (*bdrv_check_ext_snapshot)(BlockDriverState *bs);
+
     int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
     int (*bdrv_probe_device)(const char *filename);
 
Signature · 1 line
1.8.1.2
#2 lore raw

Re: [Qemu-devel] [PATCH V2] block: Add BlockDriver.bdrv_check_ext_snapshot.

Quoted 25 lines · Benoît Canet

This field is used by blkverify to disable external snapshots creation. I will also be used by block filters like quorum to disable external snapshots creation.

---
 block.c                   | 14 ++++++++++++++
 block/blkverify.c         |  2 ++
 blockdev.c                |  5 +++++
 include/block/block.h     |  7 +++++++
 include/block/block_int.h |  8 ++++++++
 5 files changed, 36 insertions(+)
block.c +4 -0
index 4833b37..4da6fd9 100644
@@ -4632,3 +4632,17 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
     }
     return bs->drv->bdrv_amend_options(bs, options);
 }
+
+bool bdrv_check_ext_snapshot(BlockDriverState *bs)
+{
+    /* external snashots are enabled by defaults */

block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4648

Quoted 10 lines
block.c +10 -0
+    if (!bs->drv->bdrv_check_ext_snapshot) {
+        return true;
+    }
+    return bs->drv->bdrv_check_ext_snapshot(bs);
+}
+
+bool bdrv_forbid_ext_snapshot(BlockDriverState *bs)
+{
+    return false;
+}

The only problem I have with this now, is that "bdrv_forbid_ext_snapshot()" returns false, to indicate that "forbid ext snapshot" is true. Looking at the function above, I would come to the opposite conclusion as to what it does.

I understand why - you want the function name assigned to .bdrv_check_ext_snapshot to reflect the action, but then that causes the boolean return to be misleading. Maybe returning an enum would be more natural?

I apologize if this seems too pedantic. :)

Thanks,
Jeff

Quoted 70 lines
block/blkverify.c +2 -0
index 2077d8a..c548923 100644
@@ -313,6 +313,8 @@ static BlockDriver bdrv_blkverify = {
     .bdrv_aio_readv         = blkverify_aio_readv,
     .bdrv_aio_writev        = blkverify_aio_writev,
     .bdrv_aio_flush         = blkverify_aio_flush,
+
+    .bdrv_check_ext_snapshot = bdrv_forbid_ext_snapshot,
 };
 
 static void bdrv_blkverify_init(void)
blockdev.c +5 -0
index 8aa66a9..5c16f1b 100644
@@ -1131,6 +1131,11 @@ static void external_snapshot_prepare(BlkTransactionState *common,
         }
     }
 
+    if (!bdrv_check_ext_snapshot(state->old_bs)) {
+        error_set(errp, QERR_FEATURE_DISABLED, "snapshot");
+        return;
+    }
+
     flags = state->old_bs->open_flags;
 
     /* create new image w/backing file */
include/block/block.h +7 -0
index f808550..df19610 100644
@@ -244,6 +244,13 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
 int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options);
 
+/* external snapshots */
+
+/* return true if external snapshot is allowed, false if not */
+bool bdrv_check_ext_snapshot(BlockDriverState *bs);
+/* helper used to forbid external snapshots like in blkverify */
+bool bdrv_forbid_ext_snapshot(BlockDriverState *bs);
+
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
                                      int sector_num);
include/block/block_int.h +8 -0
index 211087a..cb92355 100644
@@ -67,6 +67,14 @@ typedef struct BdrvTrackedRequest {
 struct BlockDriver {
     const char *format_name;
     int instance_size;
+
+    /* if not defined external snapshots are allowed
+     * if return true external snapshots are allowed
+     * if return false external snapshots are not allowed
+     * future block filters will query their children to build the response
+     */
+    bool (*bdrv_check_ext_snapshot)(BlockDriverState *bs);
+
     int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename);
     int (*bdrv_probe_device)(const char *filename);
 
Signature · 1 line
1.8.1.2
#3 lore raw

Re: [Qemu-devel] [PATCH V2] block: Add BlockDriver.bdrv_check_ext_snapshot.

Am 26.09.2013 um 18:48 hat Jeff Cody geschrieben:

Quoted 42 lines · Benoît Canet
Quoted 25 lines

This field is used by blkverify to disable external snapshots creation. I will also be used by block filters like quorum to disable external snapshots creation.

---
 block.c                   | 14 ++++++++++++++
 block/blkverify.c         |  2 ++
 blockdev.c                |  5 +++++
 include/block/block.h     |  7 +++++++
 include/block/block_int.h |  8 ++++++++
 5 files changed, 36 insertions(+)
block.c +4 -0
index 4833b37..4da6fd9 100644
@@ -4632,3 +4632,17 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
     }
     return bs->drv->bdrv_amend_options(bs, options);
 }
+
+bool bdrv_check_ext_snapshot(BlockDriverState *bs)
+{
+    /* external snashots are enabled by defaults */

block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4648

Quoted 10 lines
block.c +10 -0
+    if (!bs->drv->bdrv_check_ext_snapshot) {
+        return true;
+    }
+    return bs->drv->bdrv_check_ext_snapshot(bs);
+}
+
+bool bdrv_forbid_ext_snapshot(BlockDriverState *bs)
+{
+    return false;
+}

The only problem I have with this now, is that "bdrv_forbid_ext_snapshot()" returns false, to indicate that "forbid ext snapshot" is true. Looking at the function above, I would come to the opposite conclusion as to what it does.

Quoted 6 lines

I understand why - you want the function name assigned to .bdrv_check_ext_snapshot to reflect the action, but then that causes the boolean return to be misleading. Maybe returning an enum would be more natural?

I apologize if this seems too pedantic. :)

Perhaps rename the function to bdrv_check_ext_snapshot_forbidden() or something like that?

Kevin