提交 289b276c 编写于 作者: K Kevin Wolf

block/hmp: Factor out print_block_info()

The new function prints the info for a single BlockDriverState.
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 9e193c5a
...@@ -290,78 +290,58 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict) ...@@ -290,78 +290,58 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)
qapi_free_CpuInfoList(cpu_list); 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; 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) { monitor_printf(mon, "%s", info->device);
if (device && strcmp(device, info->value->device)) { if (inserted) {
continue;
}
if (info != block_list) {
monitor_printf(mon, "\n");
}
monitor_printf(mon, "%s", info->value->device);
if (info->value->has_inserted) {
monitor_printf(mon, ": %s (%s%s%s)\n", monitor_printf(mon, ": %s (%s%s%s)\n",
info->value->inserted->file, inserted->file,
info->value->inserted->drv, inserted->drv,
info->value->inserted->ro ? ", read-only" : "", inserted->ro ? ", read-only" : "",
info->value->inserted->encrypted ? ", encrypted" : ""); inserted->encrypted ? ", encrypted" : "");
} else { } else {
monitor_printf(mon, ": [not inserted]\n"); monitor_printf(mon, ": [not inserted]\n");
} }
if (info->value->has_io_status && info->value->io_status != BLOCK_DEVICE_IO_STATUS_OK) { if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
monitor_printf(mon, " I/O status: %s\n", monitor_printf(mon, " I/O status: %s\n",
BlockDeviceIoStatus_lookup[info->value->io_status]); BlockDeviceIoStatus_lookup[info->io_status]);
} }
if (info->value->removable) { if (info->removable) {
monitor_printf(mon, " Removable device: %slocked, tray %s\n", monitor_printf(mon, " Removable device: %slocked, tray %s\n",
info->value->locked ? "" : "not ", info->locked ? "" : "not ",
info->value->tray_open ? "open" : "closed"); info->tray_open ? "open" : "closed");
} }
if (!info->value->has_inserted) { if (!inserted) {
continue; return;
} }
inserted = info->value->inserted;
monitor_printf(mon, " Cache mode: %s%s%s\n", monitor_printf(mon, " Cache mode: %s%s%s\n",
inserted->cache->writeback ? "writeback" : "writethrough", inserted->cache->writeback ? "writeback" : "writethrough",
inserted->cache->direct ? ", direct" : "", inserted->cache->direct ? ", direct" : "",
inserted->cache->no_flush ? ", ignore flushes" : ""); inserted->cache->no_flush ? ", ignore flushes" : "");
if (info->value->inserted->has_backing_file) { if (inserted->has_backing_file) {
monitor_printf(mon, monitor_printf(mon,
" Backing file: %s " " Backing file: %s "
"(chain depth: %" PRId64 ")\n", "(chain depth: %" PRId64 ")\n",
info->value->inserted->backing_file, inserted->backing_file,
info->value->inserted->backing_file_depth); inserted->backing_file_depth);
} }
if (info->value->inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) { if (inserted->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF) {
monitor_printf(mon, " Detect zeroes: %s\n", monitor_printf(mon, " Detect zeroes: %s\n",
BlockdevDetectZeroesOptions_lookup[info->value->inserted->detect_zeroes]); BlockdevDetectZeroesOptions_lookup[inserted->detect_zeroes]);
} }
if (info->value->inserted->bps if (inserted->bps || inserted->bps_rd || inserted->bps_wr ||
|| info->value->inserted->bps_rd inserted->iops || inserted->iops_rd || inserted->iops_wr)
|| 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 monitor_printf(mon, " I/O throttling: bps=%" PRId64
" bps_rd=%" PRId64 " bps_wr=%" PRId64 " bps_rd=%" PRId64 " bps_wr=%" PRId64
...@@ -374,24 +354,24 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) ...@@ -374,24 +354,24 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
" iops_rd_max=%" PRId64 " iops_rd_max=%" PRId64
" iops_wr_max=%" PRId64 " iops_wr_max=%" PRId64
" iops_size=%" PRId64 "\n", " iops_size=%" PRId64 "\n",
info->value->inserted->bps, inserted->bps,
info->value->inserted->bps_rd, inserted->bps_rd,
info->value->inserted->bps_wr, inserted->bps_wr,
info->value->inserted->bps_max, inserted->bps_max,
info->value->inserted->bps_rd_max, inserted->bps_rd_max,
info->value->inserted->bps_wr_max, inserted->bps_wr_max,
info->value->inserted->iops, inserted->iops,
info->value->inserted->iops_rd, inserted->iops_rd,
info->value->inserted->iops_wr, inserted->iops_wr,
info->value->inserted->iops_max, inserted->iops_max,
info->value->inserted->iops_rd_max, inserted->iops_rd_max,
info->value->inserted->iops_wr_max, inserted->iops_wr_max,
info->value->inserted->iops_size); inserted->iops_size);
} }
if (verbose) { if (verbose) {
monitor_printf(mon, "\nImages:\n"); monitor_printf(mon, "\nImages:\n");
image_info = info->value->inserted->image; image_info = inserted->image;
while (1) { while (1) {
bdrv_image_info_dump((fprintf_function)monitor_printf, bdrv_image_info_dump((fprintf_function)monitor_printf,
mon, image_info); mon, image_info);
...@@ -402,6 +382,28 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) ...@@ -402,6 +382,28 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
} }
} }
} }
}
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);
block_list = qmp_query_block(false);
for (info = block_list; info; info = info->next) {
if (device && strcmp(device, info->value->device)) {
continue;
}
if (info != block_list) {
monitor_printf(mon, "\n");
}
print_block_info(mon, info->value, info->value->has_inserted
? info->value->inserted : NULL,
verbose);
} }
qapi_free_BlockInfoList(block_list); qapi_free_BlockInfoList(block_list);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册