Skip to contentSkip to conversation

block: add the optional file entry to query-block

PATCH Superseded Federico Simoncelli 4 participants 4 messages Jun 28, 2013 – Jul 2, 2013 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: add the optional file entry to query-block

This patch adds the optional file entry to the query-block output. The value is a json-object representing the information about the underlying file or device (when present).

---
 block/qapi.c               |    9 ++++++++-
 qapi-schema.json           |    4 +++-
 qmp-commands.hx            |    8 ++++++++
 tests/qemu-iotests/043.out |   15 +++++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)
block/qapi.c +8 -1
index a4bc411..03cd222 100644
@@ -119,7 +119,7 @@ void bdrv_query_image_info(BlockDriverState *bs,
 
     info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
-    info->virtual_size    = total_sectors * 512;
+    info->virtual_size    = bdrv_getlength(bs);
     info->actual_size     = bdrv_get_allocated_file_size(bs);
     info->has_actual_size = info->actual_size >= 0;
     if (bdrv_is_encrypted(bs)) {
@@ -171,6 +171,13 @@ void bdrv_query_image_info(BlockDriverState *bs,
         return;
     }
 
+    if (bs->file) {
+        bdrv_query_image_info(bs->file, &info->file, &err);
+        if (info->file) {
+            info->has_file = true;
+        }
+    }
+
     *p_info = info;
 }
 
qapi-schema.json +3 -1
index a30a728..524a4a0 100644
@@ -238,6 +238,8 @@
 #
 # @backing-image: #optional info of the backing image (since 1.6)
 #
+# @file: #optional info of the underlying file (since 1.6)
+#
 # Since: 1.3
 #
 ##
@@ -248,7 +250,7 @@
            '*cluster-size': 'int', '*encrypted': 'bool',
            '*backing-filename': 'str', '*full-backing-filename': 'str',
            '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'],
-           '*backing-image': 'ImageInfo' } }
+           '*backing-image': 'ImageInfo', '*file': 'ImageInfo' } }
 
 ##
 # @ImageCheck:
qmp-commands.hx +8 -0
index 8cea5e5..c25ac77 100644
@@ -1745,6 +1745,8 @@ Each json-object contain the following:
              - "backing-image": the detail of the backing image, it is an
                                 optional json-object only present when a
                                 backing image present for this image
+             - "file": an optional json-object representing the information
+                       about the underlying file or device (when present)
 
 - "io-status": I/O operation status, only present if the device supports it
                and the VM is configured to stop on errors. It's always reset
@@ -1796,6 +1798,12 @@ Example:
                       "format":"qcow2",
                       "virtual-size":2048000
                   }
+                  "file":{
+                      "filename":"disks/test.qcow2",
+                      "format": "file",
+                      "virtual-size": 262144,
+                      "actual-size": 139264
+                  }
                }
             },
             "type":"unknown"
tests/qemu-iotests/043.out +15 -0
index ad23337..6aea37b 100644
@@ -44,6 +44,11 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT", 
         "cluster-size": 65536, 
         "format": "IMGFMT", 
+        "file": {
+            "virtual-size": 327680, 
+            "filename": "TEST_DIR/t.IMGFMT", 
+            "format": "file", 
+        }, 
         "backing-filename": "TEST_DIR/t.IMGFMT.2.base", 
         "dirty-flag": false
     }, 
@@ -52,6 +57,11 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT.2.base", 
         "cluster-size": 65536, 
         "format": "IMGFMT", 
+        "file": {
+            "virtual-size": 327680, 
+            "filename": "TEST_DIR/t.IMGFMT.2.base", 
+            "format": "file", 
+        }, 
         "backing-filename": "TEST_DIR/t.IMGFMT.1.base", 
         "dirty-flag": false
     }, 
@@ -60,6 +70,11 @@ cluster_size: 65536
         "filename": "TEST_DIR/t.IMGFMT.1.base", 
         "cluster-size": 65536, 
         "format": "IMGFMT", 
+        "file": {
+            "virtual-size": 327680, 
+            "filename": "TEST_DIR/t.IMGFMT.1.base", 
+            "format": "file", 
+        }, 
         "dirty-flag": false
     }
 ]
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Federico Simoncelli

This patch adds the optional file entry to the query-block output. The value is a json-object representing the information about the underlying file or device (when present).

---
 block/qapi.c               |    9 ++++++++-
 qapi-schema.json           |    4 +++-
 qmp-commands.hx            |    8 ++++++++
 tests/qemu-iotests/043.out |   15 +++++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)

block/qapi.c void bdrv_query_image_info(BlockDriverState *bs, · line 122

Quoted 7 lines

+++ b/block/qapi.c

block/qapi.c +1 -1
@@ -119,7 +119,7 @@ void bdrv_query_image_info(BlockDriverState *bs,
 
     info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
-    info->virtual_size    = total_sectors * 512;
+    info->virtual_size    = bdrv_getlength(bs);

This change seems independently useful, but I'm not sure if it's worth splitting out into a separate patch.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw

Am 28.06.2013 um 21:32 hat Eric Blake geschrieben:

Quoted 18 lines · Federico Simoncelli
Quoted 11 lines

This patch adds the optional file entry to the query-block output. The value is a json-object representing the information about the underlying file or device (when present).

---
 block/qapi.c               |    9 ++++++++-
 qapi-schema.json           |    4 +++-
 qmp-commands.hx            |    8 ++++++++
 tests/qemu-iotests/043.out |   15 +++++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)
Quoted 3 lines

+++ b/block/qapi.c

(quoted diff) +0 -0
@@ -119,7 +119,7 @@ void bdrv_query_image_info(BlockDriverState *bs,
 
Quoted 7 lines

block/qapi.c void bdrv_query_image_info(BlockDriverState *bs, · line 122

Quoted 4 lines
block/qapi.c +1 -1
     info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
-    info->virtual_size    = total_sectors * 512;
+    info->virtual_size    = bdrv_getlength(bs);

This change seems independently useful, but I'm not sure if it's worth splitting out into a separate patch.

It probably is, because (a) it's a separate logical change and (b) this isn't entirely correct. bdrv_getlength() can fail, so we need to do more than just changing this one line. If bdrv_getlength() fails we should error out instead of outputting a negative size.

Kevin

#3 lore raw
In reply to Federico Simoncelli
Quoted 17 lines · Federico Simoncelli

This patch adds the optional file entry to the query-block output. The value is a json-object representing the information about the underlying file or device (when present).

---
 block/qapi.c               |    9 ++++++++-
 qapi-schema.json           |    4 +++-
 qmp-commands.hx            |    8 ++++++++
 tests/qemu-iotests/043.out |   15 +++++++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)
block/qapi.c +0 -0
index a4bc411..03cd222 100644

block/qapi.c void bdrv_query_image_info(BlockDriverState *bs, · line 125

Quoted 8 lines
block/qapi.c +1 -1
@@ -119,7 +119,7 @@ void bdrv_query_image_info(BlockDriverState *bs,
 
     info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
-    info->virtual_size    = total_sectors * 512;
+    info->virtual_size    = bdrv_getlength(bs);
     info->actual_size     = bdrv_get_allocated_file_size(bs);
     info->has_actual_size = info->actual_size >= 0;
     if (bdrv_is_encrypted(bs)) {

Now total_sectors is unused. Why make this change?