Skip to contentSkip to conversation

block: add dirty flag status to qemu-img

PATCH Superseded Dong Xu Wang 3 participants 5 messages Dec 31, 2011 – Jan 11, 2012 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 block: add dirty flag status to qemu-img

From: Dong Xu Wang <[email protected]>

Some block drivers can verify their image files are clean or not. So we can show it while using "qemu-img info"

CC Kevin Wolf <[email protected]>
CC Stefan Hajnoczi <[email protected]>

---
Previous discussion can be found at:
http://patchwork.ozlabs.org/patch/128730/

 block.c     |   14 ++++++++++++++
 block.h     |    2 ++
 block_int.h |    1 +
 qemu-img.c  |    3 +++
 4 files changed, 20 insertions(+), 0 deletions(-)
block.c +14 -0
index 3f072f6..24fd774 100644
@@ -186,6 +186,20 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs,
     qemu_co_queue_next(&bs->throttled_reqs);
 }
 
+/* check if the image is dirty */
+int bdrv_is_dirty(BlockDriverState *bs)
+{
+    BlockDriver *drv = bs->drv;
+
+    if (!drv) {
+        return 0;
+    }
+    if (!drv->bdrv_is_dirty) {
+        return 0;
+    }
+    return drv->bdrv_is_dirty(bs);
+}
+
 /* check if the path starts with "<protocol>:" */
 static int path_has_protocol(const char *path)
 {
block.h +2 -0
index 3bd4398..e3f3b55 100644
@@ -104,6 +104,8 @@ void bdrv_io_limits_enable(BlockDriverState *bs);
 void bdrv_io_limits_disable(BlockDriverState *bs);
 bool bdrv_io_limits_enabled(BlockDriverState *bs);
 
+int bdrv_is_dirty(BlockDriverState *bs);
+
 void bdrv_init(void);
 void bdrv_init_with_whitelist(void);
 BlockDriver *bdrv_find_protocol(const char *filename);
block_int.h +1 -0
index 311bd2a..46afffb 100644
@@ -84,6 +84,7 @@ struct BlockDriver {
     int (*bdrv_create)(const char *filename, QEMUOptionParameter *options);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
+    int (*bdrv_is_dirty)(BlockDriverState *bs);
     /* aio */
     BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
qemu-img.c +3 -0
index 01cc0d3..a79c274 100644
@@ -1153,6 +1153,9 @@ static int img_info(int argc, char **argv)
     if (bdrv_is_encrypted(bs)) {
         printf("encrypted: yes\n");
     }
+    if (bdrv_is_dirty(bs)) {
+        printf("dirty,need check: yes\n");
+    }
     if (bdrv_get_info(bs, &bdi) >= 0) {
         if (bdi.cluster_size != 0) {
             printf("cluster_size: %d\n", bdi.cluster_size);
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 2/2 block: track dirty flag status in qed

From: Dong Xu Wang <[email protected]>

qed driver use QED_F_NEED_CHECK to mark if the image is clean.

CC Kevin Wolf <[email protected]>
CC Stefan Hajnoczi <[email protected]>
---
 block/qed.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
block/qed.c +7 -0
index 8da3ebe..1e909b1 100644
@@ -1429,6 +1429,12 @@ static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result)
     return qed_check(s, result, false);
 }
 
+static int bdrv_qed_is_dirty(BlockDriverState *bs)
+{
+    BDRVQEDState *s = bs->opaque;
+    return s->header.features & QED_F_NEED_CHECK;
+}
+
 static QEMUOptionParameter qed_create_options[] = {
     {
         .name = BLOCK_OPT_SIZE,
@@ -1474,6 +1480,7 @@ static BlockDriver bdrv_qed = {
     .bdrv_get_info            = bdrv_qed_get_info,
     .bdrv_change_backing_file = bdrv_qed_change_backing_file,
     .bdrv_check               = bdrv_qed_check,
+    .bdrv_is_dirty            = bdrv_qed_is_dirty,
 };
 
 static void bdrv_qed_init(void)
Signature · 1 line
1.7.5.4
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] block: track dirty flag status in qed

block/qed.c static int bdrv_qed_check(BlockDriverState *bs, BdrvCheckResult *result) · line 1436

Quoted 5 lines · Dong Xu Wang
block/qed.c +5 -0
+static int bdrv_qed_is_dirty(BlockDriverState *bs)
+{
+    BDRVQEDState *s = bs->opaque;
+    return s->header.features & QED_F_NEED_CHECK;
+}

Looks good.

Note that the image will be checked and then QED_F_NEED_CHECK is cleared when the image is opened for read/write. So the flag is only reported if the image was opened read-only, or if we're writing to the image and it allocated new clusters recently.

Stefan

#3 lore raw
In reply to Dong Xu Wang
Quoted 1 line · Dong Xu Wang

+int bdrv_is_dirty(BlockDriverState *bs)

bool would be nicer instead of int. Traditionally we used int but C99 has been around for a long time now and it's more appropriate.

qemu-img.c static int img_info(int argc, char **argv) · line 1158

Quoted 11 lines
qemu-img.c +3 -0
index 01cc0d3..a79c274 100644
@@ -1153,6 +1153,9 @@ static int img_info(int argc, char **argv)
     if (bdrv_is_encrypted(bs)) {
         printf("encrypted: yes\n");
     }
+    if (bdrv_is_dirty(bs)) {
+        printf("dirty,need check: yes\n");
+    }

I suggest avoiding the comma and just saying "needs check: yes\n".

#4 lore raw

Am 11.01.2012 15:35, schrieb Stefan Hajnoczi:

Quoted 7 lines
Quoted 1 line · Dong Xu Wang

+int bdrv_is_dirty(BlockDriverState *bs)

bool would be nicer instead of int. Traditionally we used int but C99 has been around for a long time now and it's more appropriate.

Quoted 13 lines

qemu-img.c static int img_info(int argc, char **argv) · line 1158

Quoted 11 lines
qemu-img.c +3 -0
index 01cc0d3..a79c274 100644
@@ -1153,6 +1153,9 @@ static int img_info(int argc, char **argv)
    if (bdrv_is_encrypted(bs)) {
        printf("encrypted: yes\n");
    }
+    if (bdrv_is_dirty(bs)) {
+        printf("dirty,need check: yes\n");
+    }

I suggest avoiding the comma and just saying "needs check: yes\n".

In fact I would reverse the logic and make it something like "cleanly shut down: no", it will better describe the situation when the VM is still running. Same for the function names, "dirty" could mean anything.

Kevin