From e9ff957ac26e0e11869a3568cfa7423ae33c51e7 Mon Sep 17 00:00:00 2001 From: "Denis V. Lunev" Date: Thu, 19 Nov 2015 09:42:01 +0300 Subject: snapshot: create helper to test that block drivers supports snapshots The patch enforces proper locking for this operation. Signed-off-by: Denis V. Lunev Reviewed-by: Greg Kurz Reviewed-by: Stefan Hajnoczi Reviewed-by: Fam Zheng Reviewed-by: Juan Quintela CC: Kevin Wolf Tested-by: Greg Kurz Signed-off-by: Juan Quintela --- block/snapshot.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'block') diff --git a/block/snapshot.c b/block/snapshot.c index 89500f2..d929d08 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -356,3 +356,27 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs, return ret; } + + +/* Group operations. All block drivers are involved. + * These functions will properly handle dataplane (take aio_context_acquire + * when appropriate for appropriate block drivers) */ + +bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs) +{ + bool ok = true; + BlockDriverState *bs = NULL; + + while (ok && (bs = bdrv_next(bs))) { + AioContext *ctx = bdrv_get_aio_context(bs); + + aio_context_acquire(ctx); + if (bdrv_is_inserted(bs) && !bdrv_is_read_only(bs)) { + ok = bdrv_can_snapshot(bs); + } + aio_context_release(ctx); + } + + *first_bad_bs = bs; + return ok; +} -- cgit v1.1