Patchwork Display sector count in 'info block' output

login
register
mail settings
Submitter Daniel P. Berrange
Date Sept. 2, 2011, 3:01 p.m.
Message ID <1314975700-20235-1-git-send-email-dan@berrange.com>
Download mbox | patch
Permalink /patch/113157/
State New
Headers show

Comments

Daniel P. Berrange - Sept. 2, 2011, 3:01 p.m.
From: "Daniel P. Berrange" <dan@berrange.com>

To aid in knowing whether a 'block_resize' was succesful, display
the sector count in the 'info block' output

Signed-off-by: Daniel P. Berrange <dan@berrange.com>
---
 block.c         |    6 ++++--
 qmp-commands.hx |    1 +
 2 files changed, 5 insertions(+), 2 deletions(-)
Stefan Hajnoczi - Sept. 2, 2011, 3:37 p.m.
On Fri, Sep 2, 2011 at 4:01 PM, Daniel P. Berrange <dan@berrange.com> wrote:
> From: "Daniel P. Berrange" <dan@berrange.com>
>
> To aid in knowing whether a 'block_resize' was succesful, display
> the sector count in the 'info block' output
>
> Signed-off-by: Daniel P. Berrange <dan@berrange.com>
> ---
>  block.c         |    6 ++++--
>  qmp-commands.hx |    1 +
>  2 files changed, 5 insertions(+), 2 deletions(-)

Please use bdrv_getlength().  That way units are in bytes, not
"sectors" (could be confusing, e.g. on 4 KB devices).  Also for
"growable" block devices we actually query instead of reading the
cached total_sectors field.

Stefan
Daniel P. Berrange - Sept. 2, 2011, 4:38 p.m.
On Fri, Sep 02, 2011 at 04:37:24PM +0100, Stefan Hajnoczi wrote:
> On Fri, Sep 2, 2011 at 4:01 PM, Daniel P. Berrange <dan@berrange.com> wrote:
> > From: "Daniel P. Berrange" <dan@berrange.com>
> >
> > To aid in knowing whether a 'block_resize' was succesful, display
> > the sector count in the 'info block' output
> >
> > Signed-off-by: Daniel P. Berrange <dan@berrange.com>
> > ---
> >  block.c         |    6 ++++--
> >  qmp-commands.hx |    1 +
> >  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> Please use bdrv_getlength().  That way units are in bytes, not
> "sectors" (could be confusing, e.g. on 4 KB devices).  Also for
> "growable" block devices we actually query instead of reading the
> cached total_sectors field.

Good points, I've sent a v2 using bytes instead of sectors.

Regards,
Daniel

Patch

diff --git a/block.c b/block.c
index 03a21d8..fdb0665 100644
--- a/block.c
+++ b/block.c
@@ -1844,6 +1844,7 @@  static void bdrv_print_dict(QObject *obj, void *opaque)
 
         monitor_printf(mon, " file=");
         monitor_print_filename(mon, qdict_get_str(qdict, "file"));
+        monitor_printf(mon, " sectors=%" PRId64, qdict_get_int(qdict, "sectors"));
         if (qdict_haskey(qdict, "backing_file")) {
             monitor_printf(mon, " backing_file=");
             monitor_print_filename(mon, qdict_get_str(qdict, "backing_file"));
@@ -1884,10 +1885,11 @@  void bdrv_info(Monitor *mon, QObject **ret_data)
             QDict *bs_dict = qobject_to_qdict(bs_obj);
 
             obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
-                                     "'encrypted': %i }",
+                                     "'encrypted': %i, 'sectors': %" PRId64 " }",
                                      bs->filename, bs->read_only,
                                      bs->drv->format_name,
-                                     bdrv_is_encrypted(bs));
+                                     bdrv_is_encrypted(bs),
+                                     bs->total_sectors);
             if (bs->backing_file[0] != '\0') {
                 QDict *qdict = qobject_to_qdict(obj);
                 qdict_put(qdict, "backing_file",
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 27cc66e..07a20ff 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1134,6 +1134,7 @@  Each json-object contain the following:
 - "inserted": only present if the device is inserted, it is a json-object
    containing the following:
          - "file": device file name (json-string)
+         - "sectors": total sector count (json-int)
          - "ro": true if read-only, false otherwise (json-bool)
          - "drv": driver format name (json-string)
              - Possible values: "blkdebug", "bochs", "cloop", "cow", "dmg",