Add infrastructure to forbid external snapshot
PATCH 1/1 Add infrastructure to forbid external snapshot
This paves the way for the quorum block driver to be merged.
Benoît Canet (1):
block: Add bdrv_forbid_ext_snapshots.
block.c | 27 +++++++++++++++++++++++++++ block/blkdebug.c | 2 ++ block/blkverify.c | 2 ++ block/bochs.c | 2 ++ block/cloop.c | 2 ++ block/cow.c | 2 ++ block/curl.c | 10 ++++++++++ block/dmg.c | 2 ++ block/gluster.c | 8 ++++++++ block/iscsi.c | 2 ++ block/nbd.c | 6 ++++++ block/parallels.c | 2 ++ block/qcow.c | 2 ++ block/qcow2.c | 2 ++ block/qed.c | 2 ++ block/raw-posix.c | 10 ++++++++++ block/raw-win32.c | 4 ++++ block/raw_bsd.c | 4 +++- block/rbd.c | 2 ++ block/sheepdog.c | 6 ++++++ block/ssh.c | 2 ++ block/vdi.c | 2 ++ block/vhdx.c | 2 ++ block/vmdk.c | 2 ++ block/vpc.c | 2 ++ block/vvfat.c | 2 ++ blockdev.c | 5 +++++ include/block/block.h | 10 ++++++++++ include/block/block_int.h | 7 +++++++ 29 files changed, 132 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1.2
PATCH 1/1 block: Add bdrv_forbid_ext_snapshots.
Drivers having a bs->file where set to recurse the call to their child. Protocol and drivers designed to be on the bottom of the stack where set to allow snapshots.
Future protocols like quorum where creating snapshots does not make sense without block filters will be set to forbid snapshots.
--- block.c | 27 +++++++++++++++++++++++++++ block/blkdebug.c | 2 ++ block/blkverify.c | 2 ++ block/bochs.c | 2 ++ block/cloop.c | 2 ++ block/cow.c | 2 ++ block/curl.c | 10 ++++++++++ block/dmg.c | 2 ++ block/gluster.c | 8 ++++++++ block/iscsi.c | 2 ++ block/nbd.c | 6 ++++++ block/parallels.c | 2 ++ block/qcow.c | 2 ++ block/qcow2.c | 2 ++ block/qed.c | 2 ++ block/raw-posix.c | 10 ++++++++++ block/raw-win32.c | 4 ++++ block/raw_bsd.c | 4 +++- block/rbd.c | 2 ++ block/sheepdog.c | 6 ++++++ block/ssh.c | 2 ++ block/vdi.c | 2 ++ block/vhdx.c | 2 ++ block/vmdk.c | 2 ++ block/vpc.c | 2 ++ block/vvfat.c | 2 ++ blockdev.c | 5 +++++ include/block/block.h | 10 ++++++++++ include/block/block_int.h | 7 +++++++ 29 files changed, 132 insertions(+), 1 deletion(-)
block.c +27 -0
@@ -4651,3 +4651,30 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) }return bs->drv->bdrv_amend_options (bs, options); } + +bool bdrv_is_ext_snapshot_forbidden (BlockDriverState *bs) +{ +/* allow snapshot by default */ +if (!bs->drv->bdrv_forbid_ext_snapshots) { +return false; + } +return bs->drv->bdrv_forbid_ext_snapshots (bs); +} + +bool bdrv_recurse_forbid_ext_snapshots (BlockDriverState *bs) +{ +if (!bs->file->drv) { +return false; + } +return bs->file->drv->bdrv_forbid_ext_snapshots (bs->file); +} + +bool bdrv_forbid_ext_snapshots (BlockDriverState *bs) +{ +return true; +} + +bool bdrv_allow_ext_snapshots (BlockDriverState *bs) +{ +return false; +}
block/blkdebug.c +2 -0
@@ -641,6 +641,8 @@ static BlockDriver bdrv_blkdebug = { .bdrv_debug_breakpoint = blkdebug_debug_breakpoint, .bdrv_debug_resume = blkdebug_debug_resume, .bdrv_debug_is_suspended = blkdebug_debug_is_suspended, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_blkdebug_init (void )
block/blkverify.c +2 -0
@@ -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_forbid_ext_snapshots = bdrv_forbid_ext_snapshots, };static void bdrv_blkverify_init (void )
block/bochs.c +2 -0
@@ -242,6 +242,8 @@ static BlockDriver bdrv_bochs = { .bdrv_open = bochs_open, .bdrv_read = bochs_co_read, .bdrv_close = bochs_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_bochs_init (void )
block/cloop.c +2 -0
@@ -195,6 +195,8 @@ static BlockDriver bdrv_cloop = { .bdrv_open = cloop_open, .bdrv_read = cloop_co_read, .bdrv_close = cloop_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_cloop_init (void )
block/cow.c +2 -0
@@ -393,6 +393,8 @@ static BlockDriver bdrv_cow = { .bdrv_co_get_block_status = cow_co_get_block_status, .create_options = cow_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_cow_init (void )
block/curl.c +10 -0
@@ -617,6 +617,8 @@ static BlockDriver bdrv_http = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_https = {
@@ -630,6 +632,8 @@ static BlockDriver bdrv_https = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_ftp = {
@@ -643,6 +647,8 @@ static BlockDriver bdrv_ftp = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_ftps = {
@@ -656,6 +662,8 @@ static BlockDriver bdrv_ftps = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_tftp = {
@@ -669,6 +677,8 @@ static BlockDriver bdrv_tftp = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void curl_block_init (void )
block/dmg.c +2 -0
@@ -382,6 +382,8 @@ static BlockDriver bdrv_dmg = { .bdrv_open = dmg_open, .bdrv_read = dmg_co_read, .bdrv_close = dmg_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_dmg_init (void )
block/gluster.c +8 -0
@@ -626,6 +626,8 @@ static BlockDriver bdrv_gluster = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static BlockDriver bdrv_gluster_tcp = {
@@ -647,6 +649,8 @@ static BlockDriver bdrv_gluster_tcp = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static BlockDriver bdrv_gluster_unix = {
@@ -668,6 +672,8 @@ static BlockDriver bdrv_gluster_unix = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static BlockDriver bdrv_gluster_rdma = {
@@ -689,6 +695,8 @@ static BlockDriver bdrv_gluster_rdma = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_gluster_init (void )
block/iscsi.c +2 -0
@@ -1544,6 +1544,8 @@ static BlockDriver bdrv_iscsi = { .bdrv_ioctl = iscsi_ioctl, .bdrv_aio_ioctl = iscsi_aio_ioctl, #endif + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static QemuOptsList qemu_iscsi_opts = {
block/nbd.c +6 -0
@@ -651,6 +651,8 @@ static BlockDriver bdrv_nbd = { .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard, .bdrv_getlength = nbd_getlength, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_nbd_tcp = {
@@ -665,6 +667,8 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard, .bdrv_getlength = nbd_getlength, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_nbd_unix = {
@@ -679,6 +683,8 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard, .bdrv_getlength = nbd_getlength, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_nbd_init (void )
block/parallels.c +2 -0
@@ -168,6 +168,8 @@ static BlockDriver bdrv_parallels = { .bdrv_open = parallels_open, .bdrv_read = parallels_co_read, .bdrv_close = parallels_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_parallels_init (void )
block/qcow.c +2 -0
@@ -918,6 +918,8 @@ static BlockDriver bdrv_qcow = { .bdrv_get_info = qcow_get_info, .create_options = qcow_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_qcow_init (void )
block/qcow2.c +2 -0
@@ -2141,6 +2141,8 @@ static BlockDriver bdrv_qcow2 = { .create_options = qcow2_create_options, .bdrv_check = qcow2_check, .bdrv_amend_options = qcow2_amend_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_qcow2_init (void )
block/qed.c +2 -0
@@ -1615,6 +1615,8 @@ static BlockDriver bdrv_qed = { .bdrv_change_backing_file = bdrv_qed_change_backing_file, .bdrv_invalidate_cache = bdrv_qed_invalidate_cache, .bdrv_check = bdrv_qed_check, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_qed_init (void )
block/raw-posix.c +10 -0
@@ -1222,6 +1222,8 @@ static BlockDriver bdrv_file = { = raw_get_allocated_file_size, .create_options = raw_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };/***********************************************/
@@ -1568,6 +1570,8 @@ static BlockDriver bdrv_host_device = { .bdrv_ioctl = hdev_ioctl, .bdrv_aio_ioctl = hdev_aio_ioctl, #endif + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };#ifdef __linux__
@@ -1692,6 +1696,8 @@ static BlockDriver bdrv_host_floppy = { .bdrv_is_inserted = floppy_is_inserted, .bdrv_media_changed = floppy_media_changed, .bdrv_eject = floppy_eject, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,
@@ -1799,6 +1805,8 @@ static BlockDriver bdrv_host_cdrom = {/* generic scsi device */ .bdrv_ioctl = hdev_ioctl, .bdrv_aio_ioctl = hdev_aio_ioctl, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };#endif /* __linux__ */
@@ -1917,6 +1925,8 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_is_inserted = cdrom_is_inserted, .bdrv_eject = cdrom_eject, .bdrv_lock_medium = cdrom_lock_medium, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };#endif /* __FreeBSD__ */
block/raw-win32.c +4 -0
@@ -475,6 +475,8 @@ static BlockDriver bdrv_file = { = raw_get_allocated_file_size, .create_options = raw_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };/***********************************************/
@@ -614,6 +616,8 @@ static BlockDriver bdrv_host_device = { .bdrv_getlength = raw_getlength, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_file_init (void )
block/raw_bsd.c +3 -1
@@ -185,7 +185,9 @@ static BlockDriver bdrv_raw = { .bdrv_ioctl = &raw_ioctl, .bdrv_aio_ioctl = &raw_aio_ioctl, .create_options = &raw_create_options[0], - .bdrv_has_zero_init = &raw_has_zero_init + .bdrv_has_zero_init = &raw_has_zero_init, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_raw_init (void )
block/rbd.c +2 -0
@@ -1030,6 +1030,8 @@ static BlockDriver bdrv_rbd = { .bdrv_snapshot_delete = qemu_rbd_snap_remove, .bdrv_snapshot_list = qemu_rbd_snap_list, .bdrv_snapshot_goto = qemu_rbd_snap_rollback, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_rbd_init (void )
block/sheepdog.c +6 -0
@@ -2361,6 +2361,8 @@ static BlockDriver bdrv_sheepdog = { .bdrv_load_vmstate = sd_load_vmstate, .create_options = sd_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_sheepdog_tcp = {
@@ -2390,6 +2392,8 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_load_vmstate = sd_load_vmstate, .create_options = sd_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_sheepdog_unix = {
@@ -2419,6 +2423,8 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_load_vmstate = sd_load_vmstate, .create_options = sd_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_sheepdog_init (void )
block/ssh.c +2 -0
@@ -1052,6 +1052,8 @@ static BlockDriver bdrv_ssh = { .bdrv_getlength = ssh_getlength, .bdrv_co_flush_to_disk = ssh_co_flush, .create_options = ssh_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_ssh_init (void )
block/vdi.c +2 -0
@@ -805,6 +805,8 @@ static BlockDriver bdrv_vdi = { .create_options = vdi_create_options, .bdrv_check = vdi_check, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vdi_init (void )
block/vhdx.c +2 -0
@@ -963,6 +963,8 @@ static BlockDriver bdrv_vhdx = { .bdrv_reopen_prepare = vhdx_reopen_prepare, .bdrv_co_readv = vhdx_co_readv, .bdrv_co_writev = vhdx_co_writev, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vhdx_init (void )
block/vmdk.c +2 -0
@@ -1868,6 +1868,8 @@ static BlockDriver bdrv_vmdk = { .bdrv_has_zero_init = vmdk_has_zero_init, .create_options = vmdk_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vmdk_init (void )
block/vpc.c +2 -0
@@ -843,6 +843,8 @@ static BlockDriver bdrv_vpc = { .create_options = vpc_create_options, .bdrv_has_zero_init = vpc_has_zero_init, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vpc_init (void )
block/vvfat.c +2 -0
@@ -2993,6 +2993,8 @@ static BlockDriver bdrv_vvfat = { .bdrv_read = vvfat_co_read, .bdrv_write = vvfat_co_write, .bdrv_co_get_block_status = vvfat_co_get_block_status, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_vvfat_init (void )
blockdev.c +5 -0
@@ -1133,6 +1133,11 @@ static void external_snapshot_prepare(BlkTransactionState *common, flags = state->old_bs->open_flags; +if (bdrv_is_ext_snapshot_forbidden (state->old_bs)) { +error_set (errp,QERR_FEATURE_DISABLED ,"snapshot" ); +return ; + } +/* create new image w/backing file */ if (mode !=NEW_IMAGE_MODE_EXISTING ) { bdrv_img_create(new_image_file, format,
include/block/block.h +10 -0
@@ -130,6 +130,16 @@ void bdrv_info(Monitor *mon, QObject **ret_data);void bdrv_stats_print (Monitor *mon,const QObject *data);void bdrv_info_stats (Monitor *mon,QObject **ret_data); +/* used to know if an external snapshot could be taken */ +bool bdrv_is_ext_snapshot_forbidden (BlockDriverState *bs); +/* generics .bdrv_forbid_snapshots implementations */ +/* Used by drivers having a bs->file */ +bool bdrv_recurse_forbid_ext_snapshots (BlockDriverState *bs); +/* Used by drivers where snapshots does not makes sense without block filters */ +bool bdrv_forbid_ext_snapshots (BlockDriverState *bs); +/* Used by regular protocols and bottom of the stack drivers */ +bool bdrv_allow_ext_snapshots (BlockDriverState *bs); +/* disk I/O throttling */ void bdrv_io_limits_enable (BlockDriverState *bs);void bdrv_io_limits_disable (BlockDriverState *bs);
include/block/block_int.h +7 -0
@@ -217,6 +217,13 @@ struct BlockDriver {*/ int (*bdrv_has_zero_init)(BlockDriverState *bs); +/* This function return true in BlockDriver for which the extern snapshot +* operation does not make sense. +* Else it's recursively called from the top to the down of the +* BlockDriverState chain. +*/ +bool (*bdrv_forbid_ext_snapshots)(BlockDriverState *bs); +QLIST_ENTRY (BlockDriver) list; };
Signature · 1 line
1.8.1.2
Re: [Qemu-devel] [PATCH] block: Add bdrv_forbid_ext_snapshots.
Quoted 44 lines · Benoît Canet
Drivers having a
bs->filewhere set to recurse the call to their child. Protocol and drivers designed to be on the bottom of the stack where set to allow snapshots.
Future protocols like quorum where creating snapshots does not make sense without block filters will be set to forbid snapshots.Signed-off-by Benoit Canet <[email protected]>--- block.c | 27 +++++++++++++++++++++++++++ block/blkdebug.c | 2 ++ block/blkverify.c | 2 ++ block/bochs.c | 2 ++ block/cloop.c | 2 ++ block/cow.c | 2 ++ block/curl.c | 10 ++++++++++ block/dmg.c | 2 ++ block/gluster.c | 8 ++++++++ block/iscsi.c | 2 ++ block/nbd.c | 6 ++++++ block/parallels.c | 2 ++ block/qcow.c | 2 ++ block/qcow2.c | 2 ++ block/qed.c | 2 ++ block/raw-posix.c | 10 ++++++++++ block/raw-win32.c | 4 ++++ block/raw_bsd.c | 4 +++- block/rbd.c | 2 ++ block/sheepdog.c | 6 ++++++ block/ssh.c | 2 ++ block/vdi.c | 2 ++ block/vhdx.c | 2 ++ block/vmdk.c | 2 ++ block/vpc.c | 2 ++ block/vvfat.c | 2 ++ blockdev.c | 5 +++++ include/block/block.h | 10 ++++++++++ include/block/block_int.h | 7 +++++++ 29 files changed, 132 insertions(+), 1 deletion(-)block.c +0
-0
block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4656
Quoted 6 lines
block.c +3
-0@@ -4651,3 +4651,30 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) }return bs->drv->bdrv_amend_options (bs, options); } + +bool bdrv_is_ext_snapshot_forbidden (BlockDriverState *bs) +{
I think either:
A) Name this function bdrv_forbid_ext_snapshots(), or
B) Name the BlockDriver function ptr to .bdrv_is_ext_snapshot_forbidden
The idea being that this function and the BlockDriver function ptr should have the same name (e.g. bdrv_has_zero_init, and bs->drv->bdrv_has_zero_init, etc..)
block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4659
Quoted 3 lines
block.c +3
-0+/* allow snapshot by default */ +if (!bs->drv->bdrv_forbid_ext_snapshots) { +return false;
Rather than return false here, we could do:
if (!bs->drv->bdrv_forbid_ext_snapshots) {
if (bs->file) {
return bdrv_is_ext_snapshot_forbidden(bs->file);
} else {
return false;
}
}That would then get rid of the need for bdrv_recurse_forbid_ext_snapshots(), if I understand correctly the goal. And then the only Block Drivers that need to populate .bdrv_is_ext_snapshot_forbidden() are the ones that explicitly forbid it themselves. I.e., the only image driver now that would need to populate this is blkverify (and later on quorum).
Quoted 4 lines
block.c +3
-0+ } +return bs->drv->bdrv_forbid_ext_snapshots (bs); +}
block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4670
Quoted 10 lines
block.c +8
-0+ +bool bdrv_recurse_forbid_ext_snapshots (BlockDriverState *bs) +{ +if (!bs->file->drv) { +return false; + } +return bs->file->drv->bdrv_forbid_ext_snapshots (bs->file); +}
(As I said above, I don't think this function is needed...)
block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4676
Quoted 6 lines
block.c +6
-0+ +bool bdrv_forbid_ext_snapshots (BlockDriverState *bs) +{ +return true; +} +
... and if you chose A above, then maybe just name this function something more like 'bdrv_ext_snapshots_forbidden()', etc.
block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4680
Quoted 4 lines
block.c +4
-0+bool bdrv_allow_ext_snapshots (BlockDriverState *bs) +{ +return false; +}
I understand why this returns false (it is actually 'false' meaning don't forbid external snapshots, as it is mapped to .bdrv_forbid_ext_snapshots()). But it is a bit discordant to have 'bdrv_allow_ext_snapshots()' return false to mean snapshots are allowed.
And again, as I said above, I don't think this is needed; if .bdrv_forbid_ext_snapshots is NULL, then the driver is not forbidding snapshots.
Thanks,
Jeff
Quoted 530 lines
block/blkdebug.c +2
-0@@ -641,6 +641,8 @@ static BlockDriver bdrv_blkdebug = { .bdrv_debug_breakpoint = blkdebug_debug_breakpoint, .bdrv_debug_resume = blkdebug_debug_resume, .bdrv_debug_is_suspended = blkdebug_debug_is_suspended, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_blkdebug_init (void )block/blkverify.c +2
-0@@ -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_forbid_ext_snapshots = bdrv_forbid_ext_snapshots, };static void bdrv_blkverify_init (void )block/bochs.c +2
-0@@ -242,6 +242,8 @@ static BlockDriver bdrv_bochs = { .bdrv_open = bochs_open, .bdrv_read = bochs_co_read, .bdrv_close = bochs_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_bochs_init (void )block/cloop.c +2
-0@@ -195,6 +195,8 @@ static BlockDriver bdrv_cloop = { .bdrv_open = cloop_open, .bdrv_read = cloop_co_read, .bdrv_close = cloop_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_cloop_init (void )block/cow.c +2
-0@@ -393,6 +393,8 @@ static BlockDriver bdrv_cow = { .bdrv_co_get_block_status = cow_co_get_block_status, .create_options = cow_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_cow_init (void )block/curl.c +10
-0@@ -617,6 +617,8 @@ static BlockDriver bdrv_http = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_https = {@@ -630,6 +632,8 @@ static BlockDriver bdrv_https = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_ftp = {@@ -643,6 +647,8 @@ static BlockDriver bdrv_ftp = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_ftps = {@@ -656,6 +662,8 @@ static BlockDriver bdrv_ftps = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_tftp = {@@ -669,6 +677,8 @@ static BlockDriver bdrv_tftp = { .bdrv_getlength = curl_getlength, .bdrv_aio_readv = curl_aio_readv, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void curl_block_init (void )block/dmg.c +2
-0@@ -382,6 +382,8 @@ static BlockDriver bdrv_dmg = { .bdrv_open = dmg_open, .bdrv_read = dmg_co_read, .bdrv_close = dmg_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_dmg_init (void )block/gluster.c +8
-0@@ -626,6 +626,8 @@ static BlockDriver bdrv_gluster = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static BlockDriver bdrv_gluster_tcp = {@@ -647,6 +649,8 @@ static BlockDriver bdrv_gluster_tcp = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static BlockDriver bdrv_gluster_unix = {@@ -668,6 +672,8 @@ static BlockDriver bdrv_gluster_unix = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static BlockDriver bdrv_gluster_rdma = {@@ -689,6 +695,8 @@ static BlockDriver bdrv_gluster_rdma = { .bdrv_aio_discard = qemu_gluster_aio_discard, #endif .create_options = qemu_gluster_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_gluster_init (void )block/iscsi.c +2
-0@@ -1544,6 +1544,8 @@ static BlockDriver bdrv_iscsi = { .bdrv_ioctl = iscsi_ioctl, .bdrv_aio_ioctl = iscsi_aio_ioctl, #endif + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static QemuOptsList qemu_iscsi_opts = {block/nbd.c +6
-0@@ -651,6 +651,8 @@ static BlockDriver bdrv_nbd = { .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard, .bdrv_getlength = nbd_getlength, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_nbd_tcp = {@@ -665,6 +667,8 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard, .bdrv_getlength = nbd_getlength, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_nbd_unix = {@@ -679,6 +683,8 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_discard = nbd_co_discard, .bdrv_getlength = nbd_getlength, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_nbd_init (void )block/parallels.c +2
-0@@ -168,6 +168,8 @@ static BlockDriver bdrv_parallels = { .bdrv_open = parallels_open, .bdrv_read = parallels_co_read, .bdrv_close = parallels_close, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_parallels_init (void )block/qcow.c +2
-0@@ -918,6 +918,8 @@ static BlockDriver bdrv_qcow = { .bdrv_get_info = qcow_get_info, .create_options = qcow_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_qcow_init (void )block/qcow2.c +2
-0@@ -2141,6 +2141,8 @@ static BlockDriver bdrv_qcow2 = { .create_options = qcow2_create_options, .bdrv_check = qcow2_check, .bdrv_amend_options = qcow2_amend_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_qcow2_init (void )block/qed.c +2
-0@@ -1615,6 +1615,8 @@ static BlockDriver bdrv_qed = { .bdrv_change_backing_file = bdrv_qed_change_backing_file, .bdrv_invalidate_cache = bdrv_qed_invalidate_cache, .bdrv_check = bdrv_qed_check, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_qed_init (void )block/raw-posix.c +10
-0@@ -1222,6 +1222,8 @@ static BlockDriver bdrv_file = { = raw_get_allocated_file_size, .create_options = raw_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };/***********************************************/ @@ -1568,6 +1570,8 @@ static BlockDriver bdrv_host_device = { .bdrv_ioctl = hdev_ioctl, .bdrv_aio_ioctl = hdev_aio_ioctl, #endif + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };#ifdef __linux__@@ -1692,6 +1696,8 @@ static BlockDriver bdrv_host_floppy = { .bdrv_is_inserted = floppy_is_inserted, .bdrv_media_changed = floppy_media_changed, .bdrv_eject = floppy_eject, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, }; static int cdrom_open(BlockDriverState *bs, QDict *options, int flags,@@ -1799,6 +1805,8 @@ static BlockDriver bdrv_host_cdrom = {/* generic scsi device */ .bdrv_ioctl = hdev_ioctl, .bdrv_aio_ioctl = hdev_aio_ioctl, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };#endif /* __linux__ */ @@ -1917,6 +1925,8 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_is_inserted = cdrom_is_inserted, .bdrv_eject = cdrom_eject, .bdrv_lock_medium = cdrom_lock_medium, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };#endif /* __FreeBSD__ */ block/raw-win32.c +4
-0@@ -475,6 +475,8 @@ static BlockDriver bdrv_file = { = raw_get_allocated_file_size, .create_options = raw_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };/***********************************************/ @@ -614,6 +616,8 @@ static BlockDriver bdrv_host_device = { .bdrv_getlength = raw_getlength, .bdrv_get_allocated_file_size = raw_get_allocated_file_size, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_file_init (void )block/raw_bsd.c +3
-1@@ -185,7 +185,9 @@ static BlockDriver bdrv_raw = { .bdrv_ioctl = &raw_ioctl, .bdrv_aio_ioctl = &raw_aio_ioctl, .create_options = &raw_create_options[0], - .bdrv_has_zero_init = &raw_has_zero_init + .bdrv_has_zero_init = &raw_has_zero_init, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_raw_init (void )block/rbd.c +2
-0@@ -1030,6 +1030,8 @@ static BlockDriver bdrv_rbd = { .bdrv_snapshot_delete = qemu_rbd_snap_remove, .bdrv_snapshot_list = qemu_rbd_snap_list, .bdrv_snapshot_goto = qemu_rbd_snap_rollback, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_rbd_init (void )block/sheepdog.c +6
-0@@ -2361,6 +2361,8 @@ static BlockDriver bdrv_sheepdog = { .bdrv_load_vmstate = sd_load_vmstate, .create_options = sd_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_sheepdog_tcp = {@@ -2390,6 +2392,8 @@ static BlockDriver bdrv_sheepdog_tcp = { .bdrv_load_vmstate = sd_load_vmstate, .create_options = sd_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static BlockDriver bdrv_sheepdog_unix = {@@ -2419,6 +2423,8 @@ static BlockDriver bdrv_sheepdog_unix = { .bdrv_load_vmstate = sd_load_vmstate, .create_options = sd_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_sheepdog_init (void )block/ssh.c +2
-0@@ -1052,6 +1052,8 @@ static BlockDriver bdrv_ssh = { .bdrv_getlength = ssh_getlength, .bdrv_co_flush_to_disk = ssh_co_flush, .create_options = ssh_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_ssh_init (void )block/vdi.c +2
-0@@ -805,6 +805,8 @@ static BlockDriver bdrv_vdi = { .create_options = vdi_create_options, .bdrv_check = vdi_check, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vdi_init (void )block/vhdx.c +2
-0@@ -963,6 +963,8 @@ static BlockDriver bdrv_vhdx = { .bdrv_reopen_prepare = vhdx_reopen_prepare, .bdrv_co_readv = vhdx_co_readv, .bdrv_co_writev = vhdx_co_writev, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vhdx_init (void )block/vmdk.c +2
-0@@ -1868,6 +1868,8 @@ static BlockDriver bdrv_vmdk = { .bdrv_has_zero_init = vmdk_has_zero_init, .create_options = vmdk_create_options, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vmdk_init (void )block/vpc.c +2
-0@@ -843,6 +843,8 @@ static BlockDriver bdrv_vpc = { .create_options = vpc_create_options, .bdrv_has_zero_init = vpc_has_zero_init, + + .bdrv_forbid_ext_snapshots = bdrv_recurse_forbid_ext_snapshots, };static void bdrv_vpc_init (void )block/vvfat.c +2
-0@@ -2993,6 +2993,8 @@ static BlockDriver bdrv_vvfat = { .bdrv_read = vvfat_co_read, .bdrv_write = vvfat_co_write, .bdrv_co_get_block_status = vvfat_co_get_block_status, + + .bdrv_forbid_ext_snapshots = bdrv_allow_ext_snapshots, };static void bdrv_vvfat_init (void )blockdev.c +5
-0@@ -1133,6 +1133,11 @@ static void external_snapshot_prepare(BlkTransactionState *common, flags = state->old_bs->open_flags; +if (bdrv_is_ext_snapshot_forbidden (state->old_bs)) { +error_set (errp,QERR_FEATURE_DISABLED ,"snapshot" ); +return ; + } +/* create new image w/backing file */ if (mode !=NEW_IMAGE_MODE_EXISTING ) { bdrv_img_create(new_image_file, format,include/block/block.h +10
-0@@ -130,6 +130,16 @@ void bdrv_info(Monitor *mon, QObject **ret_data);void bdrv_stats_print (Monitor *mon,const QObject *data);void bdrv_info_stats (Monitor *mon,QObject **ret_data); +/* used to know if an external snapshot could be taken */ +bool bdrv_is_ext_snapshot_forbidden (BlockDriverState *bs); +/* generics .bdrv_forbid_snapshots implementations */ +/* Used by drivers having a bs->file */ +bool bdrv_recurse_forbid_ext_snapshots (BlockDriverState *bs); +/* Used by drivers where snapshots does not makes sense without block filters */ +bool bdrv_forbid_ext_snapshots (BlockDriverState *bs); +/* Used by regular protocols and bottom of the stack drivers */ +bool bdrv_allow_ext_snapshots (BlockDriverState *bs); +/* disk I/O throttling */ void bdrv_io_limits_enable (BlockDriverState *bs);void bdrv_io_limits_disable (BlockDriverState *bs);include/block/block_int.h +7
-0@@ -217,6 +217,13 @@ struct BlockDriver {*/ int (*bdrv_has_zero_init)(BlockDriverState *bs); +/* This function return true in BlockDriver for which the extern snapshot +* operation does not make sense. +* Else it's recursively called from the top to the down of the +* BlockDriverState chain. +*/ +bool (*bdrv_forbid_ext_snapshots)(BlockDriverState *bs); +QLIST_ENTRY (BlockDriver) list; };Signature · 1 line
1.8.1.2
Re: [Qemu-devel] [PATCH] block: Add bdrv_forbid_ext_snapshots.
Am 26.09.2013 um 04:01 hat Jeff Cody geschrieben:
Quoted 25 lines · Benoît Canet
Quoted 13 lines
Drivers having a
bs->filewhere set to recurse the call to their child. Protocol and drivers designed to be on the bottom of the stack where set to allow snapshots.
Future protocols like quorum where creating snapshots does not make sense without block filters will be set to forbid snapshots.Signed-off-by Benoit Canet <[email protected]>block.c +0
-0block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4656
Quoted 6 lines
block.c +3
-0@@ -4651,3 +4651,30 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) }return bs->drv->bdrv_amend_options (bs, options); } + +bool bdrv_is_ext_snapshot_forbidden (BlockDriverState *bs) +{I think either:
A) Name this functionbdrv_forbid_ext_snapshots(), or
B) Name the BlockDriver function ptr to .bdrv_is_ext_snapshot_forbidden
Quoted 3 lines
The idea being that this function and the BlockDriver function ptr should have the same name (e.g.
bdrv_has_zero_init, andbs->drv->bdrv_has_zero_init, etc..)
Yes, I agree, some consistent naming is desirable. I don't think bdrv_forbid_ext_snapshots() is a good name, because it implies that calling this function is what forbids the snapshot (i.e. an action similar to adding a migration blocker), whereas in fact it just checks whether snapshots are forbidden.
How about bdrv_ext_snapshot_allowed(), which avoid double negations when we check for "not forbidden"? Or perhaps even bdrv_check_ext_snapshot(), which would be a more generic name that could be extended to the three-way distinction we intended to have in the end:
- External snapshots are forbidden
- May snapshot, but below this BDS (ask bs->file; this is for filters)
- Do the snapshot here
Kevin
Re: [Qemu-devel] [PATCH] block: Add bdrv_forbid_ext_snapshots.
Quoted 36 lines · Kevin Wolf
Am 26.09.2013 um 04:01 hat Jeff Cody geschrieben:
Quoted 25 lines · Benoît Canet
Quoted 13 lines
Drivers having a
bs->filewhere set to recurse the call to their child. Protocol and drivers designed to be on the bottom of the stack where set to allow snapshots.
Future protocols like quorum where creating snapshots does not make sense without block filters will be set to forbid snapshots.Signed-off-by Benoit Canet <[email protected]>block.c +0
-0block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4656
Quoted 6 lines
block.c +3
-0@@ -4651,3 +4651,30 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) }return bs->drv->bdrv_amend_options (bs, options); } + +bool bdrv_is_ext_snapshot_forbidden (BlockDriverState *bs) +{I think either:
A) Name this functionbdrv_forbid_ext_snapshots(), or
B) Name the BlockDriver function ptr to .bdrv_is_ext_snapshot_forbiddenQuoted 3 lines
The idea being that this function and the BlockDriver function ptr should have the same name (e.g.
bdrv_has_zero_init, andbs->drv->bdrv_has_zero_init, etc..)Yes, I agree, some consistent naming is desirable. I don't think
bdrv_forbid_ext_snapshots()is a good name, because it implies that calling this function is what forbids the snapshot (i.e. an action similar to adding a migration blocker), whereas in fact it just checks whether snapshots are forbidden.
Quoted 8 lines
How about
bdrv_ext_snapshot_allowed(), which avoid double negations when we check for "not forbidden"? Or perhaps evenbdrv_check_ext_snapshot(), which would be a more generic name that could be extended to the three-way distinction we intended to have in the end:- External snapshots are forbidden
- May snapshot, but below this BDS (askbs->file; this is for filters)
- Do the snapshot here
Whould .bdrv_check_ext_snapshot being NULL imply "- Do the snapshot here" as Jeff suggested ?
Best regards
Benoît
Quoted 2 lines
Kevin
Re: [Qemu-devel] [PATCH] block: Add bdrv_forbid_ext_snapshots.
Am 26.09.2013 um 15:35 hat Benoît Canet geschrieben:
Quoted 42 lines · Kevin Wolf
Quoted 41 lines
Am 26.09.2013 um 04:01 hat Jeff Cody geschrieben:
Quoted 25 lines · Benoît Canet
Quoted 13 lines
Drivers having a
bs->filewhere set to recurse the call to their child. Protocol and drivers designed to be on the bottom of the stack where set to allow snapshots.
Future protocols like quorum where creating snapshots does not make sense without block filters will be set to forbid snapshots.Signed-off-by Benoit Canet <[email protected]>block.c +0
-0block.c int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) · line 4656
Quoted 6 lines
block.c +3
-0@@ -4651,3 +4651,30 @@ int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options) }return bs->drv->bdrv_amend_options (bs, options); } + +bool bdrv_is_ext_snapshot_forbidden (BlockDriverState *bs) +{I think either:
A) Name this functionbdrv_forbid_ext_snapshots(), or
B) Name the BlockDriver function ptr to .bdrv_is_ext_snapshot_forbiddenQuoted 3 lines
The idea being that this function and the BlockDriver function ptr should have the same name (e.g.
bdrv_has_zero_init, andbs->drv->bdrv_has_zero_init, etc..)Yes, I agree, some consistent naming is desirable. I don't think
bdrv_forbid_ext_snapshots()is a good name, because it implies that calling this function is what forbids the snapshot (i.e. an action similar to adding a migration blocker), whereas in fact it just checks whether snapshots are forbidden.How about
bdrv_ext_snapshot_allowed(), which avoid double negations when we check for "not forbidden"? Or perhaps evenbdrv_check_ext_snapshot(), which would be a more generic name that could be extended to the three-way distinction we intended to have in the end:
Quoted 6 lines
Quoted 3 lines
- External snapshots are forbidden
- May snapshot, but below this BDS (askbs->file; this is for filters)
- Do the snapshot hereWhould .bdrv_check_ext_snapshot being NULL imply "- Do the snapshot here" as Jeff suggested ?
That would probably be the most convenient option.
Kevin