@@ -3091,6 +3091,25 @@ bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag)
/**************************************************************/
/* handling of snapshots */
+/* return whether internal snapshot can be read on @bs */
+int bdrv_can_read_snapshot(BlockDriverState *bs)
+{
+ BlockDriver *drv = bs->drv;
+ if (!drv || !bdrv_is_inserted(bs)) {
+ return 0;
+ }
+
+ if (!drv->bdrv_snapshot_create) {
+ if (bs->file != NULL) {
+ return bdrv_can_read_snapshot(bs->file);
+ }
+ return 0;
+ }
+
+ return 1;
+}
+
+/* return whether internal snapshot can be write on @bs */
int bdrv_can_snapshot(BlockDriverState *bs)
{
BlockDriver *drv = bs->drv;
@@ -318,6 +318,7 @@ void bdrv_get_full_backing_filename(BlockDriverState *bs,
char *dest, size_t sz);
BlockInfo *bdrv_query_info(BlockDriverState *s);
BlockStats *bdrv_query_stats(const BlockDriverState *bs);
+int bdrv_can_read_snapshot(BlockDriverState *bs);
int bdrv_can_snapshot(BlockDriverState *bs);
int bdrv_is_snapshot(BlockDriverState *bs);
BlockDriverState *bdrv_snapshots(void);
Compared to bdrv_can_snapshot(), this function return whether bs* is ready to read snapshot info from instead of write. If yes, caller can then query snapshot information, but taking snapshot is not always possible for that *bs may be read only. Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> --- block.c | 19 +++++++++++++++++++ include/block/block.h | 1 + 2 files changed, 20 insertions(+), 0 deletions(-)