Patchwork [V6,02/14] block: add bdrv_can_read_snapshot() function

login
register
mail settings
Submitter Wayne Xia
Date Feb. 18, 2013, 2:09 p.m.
Message ID <1361196578-19016-3-git-send-email-xiawenc@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/221436/
State New
Headers show

Comments

Wayne Xia - Feb. 18, 2013, 2:09 p.m.
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>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block.c               |   19 +++++++++++++++++++
 include/block/block.h |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)
Eric Blake - Feb. 19, 2013, 8:29 p.m.
On 02/18/2013 07:09 AM, Wenchao Xia wrote:
>   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>
> Reviewed-by: Eric Blake <eblake@redhat.com>

Per the cover letter, you modified this patch in v6 by changing a return
type from int to bool.  In general, a reviewed-by should be dropped if
your changes were non-trivial, to point out that the reviewer needs to
look at the updated patch (after all, if there were existing callers,
changing from int to bool can change semantics of some of those existing
callers).  Thankfully, for this patch, v6 still earns:

Reviewed-by: Eric Blake <eblake@redhat.com>

Patch

diff --git a/block.c b/block.c
index 50dab8e..19c2d7b 100644
--- a/block.c
+++ b/block.c
@@ -3058,6 +3058,25 @@  bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag)
 /**************************************************************/
 /* handling of snapshots */
 
+/* return whether internal snapshot can be read on @bs */
+bool bdrv_can_read_snapshot(BlockDriverState *bs)
+{
+    BlockDriver *drv = bs->drv;
+    if (!drv || !bdrv_is_inserted(bs)) {
+        return false;
+    }
+
+    if (!drv->bdrv_snapshot_create) {
+        if (bs->file != NULL) {
+            return bdrv_can_read_snapshot(bs->file);
+        }
+        return false;
+    }
+
+    return true;
+}
+
+/* return whether internal snapshot can be write on @bs */
 int bdrv_can_snapshot(BlockDriverState *bs)
 {
     BlockDriver *drv = bs->drv;
diff --git a/include/block/block.h b/include/block/block.h
index 5c3b911..4c48052 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -321,6 +321,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);
+bool bdrv_can_read_snapshot(BlockDriverState *bs);
 int bdrv_can_snapshot(BlockDriverState *bs);
 int bdrv_is_snapshot(BlockDriverState *bs);
 BlockDriverState *bdrv_snapshots(void);