Skip to contentSkip to conversation

disable blkverify external snapshot creation

PATCH Superseded Benoît Canet 3 participants 4 messages Sep 30, 2013 – Oct 1, 2013 Block layer

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 disable blkverify external snapshot creation

Hello,

Here is the new version of the snapshot forbidding patch.

v3:
functions return an enum [Jeff]
rename forbiding function [Kevin]

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     | 14 ++++++++++++++
 include/block/block_int.h |  6 ++++++
 5 files changed, 41 insertions(+)
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH v3 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     | 14 ++++++++++++++
 include/block/block_int.h |  6 ++++++
 5 files changed, 41 insertions(+)
block.c +14 -0
index 93e113a..d54b5e2 100644
@@ -4632,3 +4632,17 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
     }
     return bs->drv->bdrv_amend_options(bs, options);
 }
+
+ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs)
+{
+    /* external snashots are allowed by defaults */
+    if (!bs->drv->bdrv_check_ext_snapshot) {
+        return EXT_SNAPSHOT_ALLOWED;
+    }
+    return bs->drv->bdrv_check_ext_snapshot(bs);
+}
+
+ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs)
+{
+    return EXT_SNAPSHOT_FORBIDDEN;
+}
block/blkverify.c +2 -0
index 2077d8a..b64c638 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_check_ext_snapshot_forbidden,
 };
 
 static void bdrv_blkverify_init(void)
blockdev.c +5 -0
index 8aa66a9..92029d8 100644
@@ -1131,6 +1131,11 @@ static void external_snapshot_prepare(BlkTransactionState *common,
         }
     }
 
+    if (bdrv_check_ext_snapshot(state->old_bs) != EXT_SNAPSHOT_ALLOWED) {
+        error_set(errp, QERR_FEATURE_DISABLED, "snapshot");
+        return;
+    }
+
     flags = state->old_bs->open_flags;
 
     /* create new image w/backing file */
include/block/block.h +14 -0
index f808550..2bf0e12 100644
@@ -244,6 +244,20 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
 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_FORBIDEN if external snapshot is forbiden
+ */
+ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs);
+/* helper used to forbid external snapshots like in blkverify */
+ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs);
+
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
                                      int sector_num);
include/block/block_int.h +6 -0
index 211087a..e6a14ae 100644
@@ -67,6 +67,12 @@ typedef struct BdrvTrackedRequest {
 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
+     */
+    ExtSnapshotPerm (*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
Reviewed-by on v3 1/1
#2 lore raw

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

Quoted 5 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.

Quoted 105 lines
---
 block.c                   | 14 ++++++++++++++
 block/blkverify.c         |  2 ++
 blockdev.c                |  5 +++++
 include/block/block.h     | 14 ++++++++++++++
 include/block/block_int.h |  6 ++++++
 5 files changed, 41 insertions(+)
block.c +14 -0
index 93e113a..d54b5e2 100644
@@ -4632,3 +4632,17 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
     }
     return bs->drv->bdrv_amend_options(bs, options);
 }
+
+ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs)
+{
+    /* external snashots are allowed by defaults */
+    if (!bs->drv->bdrv_check_ext_snapshot) {
+        return EXT_SNAPSHOT_ALLOWED;
+    }
+    return bs->drv->bdrv_check_ext_snapshot(bs);
+}
+
+ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs)
+{
+    return EXT_SNAPSHOT_FORBIDDEN;
+}
block/blkverify.c +2 -0
index 2077d8a..b64c638 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_check_ext_snapshot_forbidden,
 };
 
 static void bdrv_blkverify_init(void)
blockdev.c +5 -0
index 8aa66a9..92029d8 100644
@@ -1131,6 +1131,11 @@ static void external_snapshot_prepare(BlkTransactionState *common,
         }
     }
 
+    if (bdrv_check_ext_snapshot(state->old_bs) != EXT_SNAPSHOT_ALLOWED) {
+        error_set(errp, QERR_FEATURE_DISABLED, "snapshot");
+        return;
+    }
+
     flags = state->old_bs->open_flags;
 
     /* create new image w/backing file */
include/block/block.h +14 -0
index f808550..2bf0e12 100644
@@ -244,6 +244,20 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
 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_FORBIDEN if external snapshot is forbiden
+ */
+ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs);
+/* helper used to forbid external snapshots like in blkverify */
+ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs);
+
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
                                      int sector_num);
include/block/block_int.h +6 -0
index 211087a..e6a14ae 100644
@@ -67,6 +67,12 @@ typedef struct BdrvTrackedRequest {
 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
+     */
+    ExtSnapshotPerm (*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 V3] block: Add BlockDriver.bdrv_check_ext_snapshot.

In reply to Benoît Canet
Quoted 110 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     | 14 ++++++++++++++
 include/block/block_int.h |  6 ++++++
 5 files changed, 41 insertions(+)
block.c +14 -0
index 93e113a..d54b5e2 100644
@@ -4632,3 +4632,17 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
     }
     return bs->drv->bdrv_amend_options(bs, options);
 }
+
+ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs)
+{
+    /* external snashots are allowed by defaults */
+    if (!bs->drv->bdrv_check_ext_snapshot) {
+        return EXT_SNAPSHOT_ALLOWED;
+    }
+    return bs->drv->bdrv_check_ext_snapshot(bs);
+}
+
+ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs)
+{
+    return EXT_SNAPSHOT_FORBIDDEN;
+}
block/blkverify.c +2 -0
index 2077d8a..b64c638 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_check_ext_snapshot_forbidden,
 };
 
 static void bdrv_blkverify_init(void)
blockdev.c +5 -0
index 8aa66a9..92029d8 100644
@@ -1131,6 +1131,11 @@ static void external_snapshot_prepare(BlkTransactionState *common,
         }
     }
 
+    if (bdrv_check_ext_snapshot(state->old_bs) != EXT_SNAPSHOT_ALLOWED) {
+        error_set(errp, QERR_FEATURE_DISABLED, "snapshot");
+        return;
+    }
+
     flags = state->old_bs->open_flags;
 
     /* create new image w/backing file */
include/block/block.h +14 -0
index f808550..2bf0e12 100644
@@ -244,6 +244,20 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
 
 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_FORBIDEN if external snapshot is forbiden
+ */
+ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs);
+/* helper used to forbid external snapshots like in blkverify */
+ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs);
+
 /* async block I/O */
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
                                      int sector_num);
include/block/block_int.h +6 -0
index 211087a..e6a14ae 100644
@@ -67,6 +67,12 @@ typedef struct BdrvTrackedRequest {
 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
+     */
+    ExtSnapshotPerm (*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

Well this doesn't work with protocols.
When using quorum info block show virtio1 as raw.
When doing a snapshot with quorum snapshot "desactivated" by this patch it seems blockdev is manipulating a raw BlockDriverState and not the quorum one so this fail.

(qemu) info block
virtio0: /home/benoit/images/debian.raw (raw)
[not inserted]
virtio1: (raw) <- quorum
[not inserted]
ide1-cd0: [not inserted]
Removable device: not locked, tray closed

(qemu) snapshot_blkdev virtio1 blah
Could not open '': Could not open '': No such file or directory: No such file or (qemu) qemu: terminating on signal 2

Kevin: Is making quorum a protocol a good idea to start with ?
Do you have an idea on how to fix this ?

Best regards

Benoît