qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PULL 14/73] block/hmp: Factor out print_block_info()
Date: Wed, 10 Dec 2014 11:33:40 +0100	[thread overview]
Message-ID: <1418207679-32260-15-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1418207679-32260-1-git-send-email-kwolf@redhat.com>

The new function prints the info for a single BlockDriverState.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 hmp.c | 192 +++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 97 insertions(+), 95 deletions(-)

diff --git a/hmp.c b/hmp.c
index 05c3730..2e2b91b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -290,118 +290,120 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)
     qapi_free_CpuInfoList(cpu_list);
 }
 
-void hmp_info_block(Monitor *mon, const QDict *qdict)
+static void print_block_info(Monitor *mon, BlockInfo *info,
+                             BlockDeviceInfo *inserted, bool verbose)
 {
-    BlockInfoList *block_list, *info;
     ImageInfo *image_info;
-    BlockDeviceInfo *inserted;
-    const char *device = qdict_get_try_str(qdict, "device");
-    bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
-
-    block_list = qmp_query_block(NULL);
 
-    for (info = block_list; info; info = info->next) {
-        if (device && strcmp(device, info->value->device)) {
-            continue;
-        }
+    monitor_printf(mon, "%s", info->device);
+    if (inserted) {
+        monitor_printf(mon, ": %s (%s%s%s)\n",
+                       inserted->file,
+                       inserted->drv,
+                       inserted->ro ? ", read-only" : "",
+                       inserted->encrypted ? ", encrypted" : "");
+    } else {
+        monitor_printf(mon, ": [not inserted]\n");
+    }
 
-        if (info != block_list) {
-            monitor_printf(mon, "\n");
-        }
+    if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
+        monitor_printf(mon, "    I/O status:       %s\n",
+                       BlockDeviceIoStatus_lookup[info->io_status]);
+    }
 
-        monitor_printf(mon, "%s", info->value->device);
-        if (info->value->has_inserted) {
-            monitor_printf(mon, ": %s (%s%s%s)\n",
-                           info->value->inserted->file,
-                           info->value->inserted->drv,
-                           info->value->inserted->ro ? ", read-only" : "",
-                           info->value->inserted->encrypted ? ", encrypted" : "");
-        } else {
-            monitor_printf(mon, ": [not inserted]\n");
-        }
+    if (info->removable) {
+        monitor_printf(mon, "    Removable device: %slocked, tray %s\n",
+                       info->locked ? "" : "not ",
+                       info->tray_open ? "open" : "closed");
+    }
 
-        if (info->value->has_io_status && info->value->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
-            monitor_printf(mon, "    I/O status:       %s\n",
-                           BlockDeviceIoStatus_lookup[info->value->io_status]);
-        }
 
-        if (info->value->removable) {
-            monitor_printf(mon, "    Removable device: %slocked, tray %s\n",
-                           info->value->locked ? "" : "not ",
-                           info->value->tray_open ? "open" : "closed");
-        }
+    if (!inserted) {
+        return;
+    }
 
+    monitor_printf(mon, "    Cache mode:       %s%s%s\n",
+                   inserted->cache->writeback ? "writeback" : "writethrough",
+                   inserted->cache->direct ? ", direct" : "",
+                   inserted->cache->no_flush ? ", ignore flushes" : "");
 
-        if (!info->value->has_inserted) {
-            continue;
+    if (inserted->has_backing_file) {
+        monitor_printf(mon,
+                       "    Backing file:     %s "
+                       "(chain depth: %" PRId64 ")\n",
+                       inserted->backing_file,
+                       inserted->backing_file_depth);
+    }
+
+    if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
+        monitor_printf(mon, "    Detect zeroes:    %s\n",
+                       BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
+    }
+
+    if (inserted->bps  || inserted->bps_rd  || inserted->bps_wr  ||
+        inserted->iops || inserted->iops_rd || inserted->iops_wr)
+    {
+        monitor_printf(mon, "    I/O throttling:   bps=%" PRId64
+                        " bps_rd=%" PRId64  " bps_wr=%" PRId64
+                        " bps_max=%" PRId64
+                        " bps_rd_max=%" PRId64
+                        " bps_wr_max=%" PRId64
+                        " iops=%" PRId64 " iops_rd=%" PRId64
+                        " iops_wr=%" PRId64
+                        " iops_max=%" PRId64
+                        " iops_rd_max=%" PRId64
+                        " iops_wr_max=%" PRId64
+                        " iops_size=%" PRId64 "\n",
+                        inserted->bps,
+                        inserted->bps_rd,
+                        inserted->bps_wr,
+                        inserted->bps_max,
+                        inserted->bps_rd_max,
+                        inserted->bps_wr_max,
+                        inserted->iops,
+                        inserted->iops_rd,
+                        inserted->iops_wr,
+                        inserted->iops_max,
+                        inserted->iops_rd_max,
+                        inserted->iops_wr_max,
+                        inserted->iops_size);
+    }
+
+    if (verbose) {
+        monitor_printf(mon, "\nImages:\n");
+        image_info = inserted->image;
+        while (1) {
+                bdrv_image_info_dump((fprintf_function)monitor_printf,
+                                     mon, image_info);
+            if (image_info->has_backing_image) {
+                image_info = image_info->backing_image;
+            } else {
+                break;
+            }
         }
+    }
+}
 
-        inserted = info->value->inserted;
-
-        monitor_printf(mon, "    Cache mode:       %s%s%s\n",
-                       inserted->cache->writeback ? "writeback" : "writethrough",
-                       inserted->cache->direct ? ", direct" : "",
-                       inserted->cache->no_flush ? ", ignore flushes" : "");
+void hmp_info_block(Monitor *mon, const QDict *qdict)
+{
+    BlockInfoList *block_list, *info;
+    const char *device = qdict_get_try_str(qdict, "device");
+    bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
 
-        if (info->value->inserted->has_backing_file) {
-            monitor_printf(mon,
-                           "    Backing file:     %s "
-                           "(chain depth: %" PRId64 ")\n",
-                           info->value->inserted->backing_file,
-                           info->value->inserted->backing_file_depth);
-        }
+    block_list = qmp_query_block(false);
 
-        if (info->value->inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
-            monitor_printf(mon, "    Detect zeroes:    %s\n",
-                           BlockdevDetectZeroesOptions_lookup[info->value->inserted->detect_zeroes]);
+    for (info = block_list; info; info = info->next) {
+        if (device && strcmp(device, info->value->device)) {
+            continue;
         }
 
-        if (info->value->inserted->bps
-            || info->value->inserted->bps_rd
-            || info->value->inserted->bps_wr
-            || info->value->inserted->iops
-            || info->value->inserted->iops_rd
-            || info->value->inserted->iops_wr)
-        {
-            monitor_printf(mon, "    I/O throttling:   bps=%" PRId64
-                            " bps_rd=%" PRId64  " bps_wr=%" PRId64
-                            " bps_max=%" PRId64
-                            " bps_rd_max=%" PRId64
-                            " bps_wr_max=%" PRId64
-                            " iops=%" PRId64 " iops_rd=%" PRId64
-                            " iops_wr=%" PRId64
-                            " iops_max=%" PRId64
-                            " iops_rd_max=%" PRId64
-                            " iops_wr_max=%" PRId64
-                            " iops_size=%" PRId64 "\n",
-                            info->value->inserted->bps,
-                            info->value->inserted->bps_rd,
-                            info->value->inserted->bps_wr,
-                            info->value->inserted->bps_max,
-                            info->value->inserted->bps_rd_max,
-                            info->value->inserted->bps_wr_max,
-                            info->value->inserted->iops,
-                            info->value->inserted->iops_rd,
-                            info->value->inserted->iops_wr,
-                            info->value->inserted->iops_max,
-                            info->value->inserted->iops_rd_max,
-                            info->value->inserted->iops_wr_max,
-                            info->value->inserted->iops_size);
+        if (info != block_list) {
+            monitor_printf(mon, "\n");
         }
 
-        if (verbose) {
-            monitor_printf(mon, "\nImages:\n");
-            image_info = info->value->inserted->image;
-            while (1) {
-                    bdrv_image_info_dump((fprintf_function)monitor_printf,
-                                         mon, image_info);
-                if (image_info->has_backing_image) {
-                    image_info = image_info->backing_image;
-                } else {
-                    break;
-                }
-            }
-        }
+        print_block_info(mon, info->value, info->value->has_inserted
+                                           ? info->value->inserted : NULL,
+                         verbose);
     }
 
     qapi_free_BlockInfoList(block_list);
-- 
1.8.3.1

  parent reply	other threads:[~2014-12-10 10:35 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-10 10:33 [Qemu-devel] [PULL 00/73] Merging block-next for 2.3 Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 01/73] block: Add bdrv_next_node Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 02/73] block: Add bdrv_get_node_name Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 03/73] block: Include "node-name" if present in query-blockstats Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 04/73] qmp: Add optional switch "query-nodes" " Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 05/73] qjson: Drop trailing space for pretty formatting Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 06/73] chardev: Add -qmp-pretty Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 07/73] iotests: _filter_qmp for pretty JSON output Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 08/73] iotests: Use -qmp-pretty in 067 Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 09/73] blockdev: acquire AioContext in blockdev-snapshot-delete-internal-sync Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 10/73] blockdev: check for BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 11/73] blockdev: acquire AioContext in eject, change, and block_passwd Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 12/73] blockdev: acquire AioContext in change-backing-file Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 13/73] block/qapi: Add cache information to query-block Kevin Wolf
2014-12-10 10:33 ` Kevin Wolf [this message]
2014-12-10 10:33 ` [Qemu-devel] [PULL 15/73] block/hmp: Allow info = NULL in print_block_info() Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 16/73] block/hmp: Allow node-name in 'info block' Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 17/73] monitor: Fix HMP tab completion Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 18/73] blkdebug: Simplify and improve filename generation Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 19/73] iotests: Plain blkdebug " Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 20/73] ahci: avoid #ifdef DEBUG_AHCI bitrot Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 21/73] ahci: replace SATA FIS type magic numbers with constants Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 22/73] block: Lift more functions into BlockBackend Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 23/73] block: Add AioContextNotifier functions to BB Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 24/73] block: Add blk_add_close_notifier() for BB Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 25/73] nbd: Change external interface to BlockBackend Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 26/73] nbd: Use BlockBackend internally Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 27/73] qemu-nbd: Use BlockBackend where reasonable Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 28/73] tests: Use "command -v" instead of which(1) in shell scripts Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 29/73] qemu-io: Allow explicitly specifying format Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 30/73] qemu-iotests: Use qemu-io -f $IMGFMT Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 31/73] qemu-iotests: Add qemu-io format option in Python tests Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 32/73] qtests: Specify image format explicitly Kevin Wolf
2014-12-10 10:33 ` [Qemu-devel] [PULL 33/73] block: Factor bdrv_probe_all() out of find_image_format() Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 34/73] block: Read only one sector for format probing Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 35/73] raw: Prohibit dangerous writes for probed images Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 36/73] qemu-iotests: Fix stderr handling in common.qemu Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 37/73] qemu-iotests: Test writing non-raw image headers to raw image Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 38/73] blockdev: update outdated qmp_transaction() comments Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 39/73] blockdev: drop unnecessary DriveBackupState field assignment Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 40/73] blockdev: acquire AioContext in QMP 'transaction' actions Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 41/73] blockdev: check for BLOCK_OP_TYPE_INTERNAL_SNAPSHOT Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 42/73] qcow2: Fix header extension size check Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 43/73] qcow2.py: Add required padding for header extensions Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 44/73] block: Don't probe for unknown backing file format Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 45/73] block: do not use get_clock() Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 46/73] qemu-iotests: 060: Filter the real disk size Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 47/73] qemu-iotests: 082: " Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 48/73] nvme: 64kB page size fixes Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 49/73] ide: Check validity of logical block size Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 50/73] iotests: Specify qcow2 format for qemu-io in 059 Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 51/73] block: Make essential BlockDriver objects public Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 52/73] block: Omit bdrv_find_format for essential drivers Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 53/73] block/vvfat: qcow driver may not be found Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 54/73] block/nfs: Add create_opts Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 55/73] block: Check create_opts before image creation Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 56/73] qemu-img: " Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 57/73] qemu-img: Check create_opts before image amendment Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 58/73] iotests: Only kill NBD server if it runs Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 59/73] iotests: Add test for unsupported image creation Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 60/73] qcow2: Prevent numerical overflow Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 61/73] qcow2: Flushing the caches in qcow2_close may fail Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 62/73] qcow2: Respect bdrv_truncate() error Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 63/73] block/raw-posix: Fix ret in raw_open_common() Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 64/73] qemu-iotests: Skip 099 for VMDK subformats with desc file Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 65/73] block: remove BLOCK_OPT_NOCOW from vdi_create_opts Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 66/73] block: remove BLOCK_OPT_NOCOW from vpc_create_opts Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 67/73] block: Use g_new0() for a bit of extra type checking Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 68/73] vmdk: Use g_random_int to generate CID Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 69/73] vmdk: Fix comment to match code of extent lines Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 70/73] vmdk: Clean up descriptor file reading Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 71/73] vmdk: Check descriptor file length when reading it Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 72/73] vmdk: Remove unnecessary initialization Kevin Wolf
2014-12-10 10:34 ` [Qemu-devel] [PULL 73/73] vmdk: Set errp on failures in vmdk_open_vmdk4 Kevin Wolf
2014-12-11 15:45 ` [Qemu-devel] [PULL 00/73] Merging block-next for 2.3 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418207679-32260-15-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).