block: QMP cache info and HMP node support
v2 cover block: QMP cache info and HMP node support
This was supposed to be the first part of a series allowing to override the cache mode for backing files, and more specifically to support the test cases for that series.
However, this work turned out to be a bit more complicated than I had hoped, and the query improvement is nice to have on its own, so I'm sending this out as a standalone series.
v2:
- Markus didn't like QMP query-* commands that filter, so this series is mainly about HMP now [Markus]
- Use BlockdevCacheInfo instead of BlockdevCacheOptions [Markus]
- API version changed to 2.3
- Added 'info block -n' which lists all names nodes
- Added a tab completion fix for HMP, bug exposed by 'info block -n'
Kevin Wolf (5):
block/qapi: Add cache information to query-block block/hmp: Factor out print_block_info() block/hmp: Allow info = NULL in print_block_info() block/hmp: Allow node-name in 'info block'
monitor: Fix HMP tab completion
block/qapi.c | 7 ++ hmp.c | 219 ++++++++++++++++++++++++++++----------------- monitor.c | 8 +- qapi/block-core.json | 20 ++++- tests/qemu-iotests/051.out | 1 + tests/qemu-iotests/067.out | 10 +-- 6 files changed, 173 insertions(+), 92 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/5 block/qapi: Add cache information to query-block
--- block/qapi.c | 7 +++++++ hmp.c | 8 ++++++++ qapi/block-core.json | 20 +++++++++++++++++++- tests/qemu-iotests/051.out | 1 + tests/qemu-iotests/067.out | 10 +++++----- 5 files changed, 40 insertions(+), 6 deletions(-)
block/qapi.c +7 -0
@@ -47,6 +47,13 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs) info->encrypted = bs->encrypted; info->encryption_key_missing =bdrv_key_required (bs); + info->cache =g_new (BlockdevCacheInfo,1 ); + *info->cache = (BlockdevCacheInfo ) { + .writeback =bdrv_enable_write_cache (bs), + .direct = !!(bs->open_flags &BDRV_O_NOCACHE ), + .no_flush = !!(bs->open_flags &BDRV_O_NO_FLUSH ), + }; +if (bs->node_name[0 ]) { info->has_node_name = true; info->node_name =g_strdup (bs->node_name);
hmp.c +8 -0
@@ -294,6 +294,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict) {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 );
@@ -335,6 +336,13 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)continue ; } + 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" :"" ); +if (info->value->inserted->has_backing_file) {monitor_printf (mon, " Backing file: %s "
qapi/block-core.json +19 -1
@@ -186,6 +186,22 @@ '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } } ## +# @BlockdevCacheInfo +# +# Cache mode information for a block device +# +# @writeback: true if writeback mode is enabled +# @direct: true if the host page cache is bypassed (O_DIRECT) +# @no-flush: true if flush requests are ignored for the device +# +# Since: 2.3 +## +{ 'type': 'BlockdevCacheInfo', + 'data': { 'writeback': 'bool', + 'direct': 'bool', + 'no-flush': 'bool' } } + +## # @BlockDeviceInfo: # # Information about the backing device for a block device.
@@ -242,6 +258,8 @@ # # @iops_size: #optional an I/O size in bytes (Since 1.7) # +# @cache: the cache mode used for the block device (since: 2.3) +# # Since: 0.14.0 # ##
@@ -256,7 +274,7 @@ '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', '*iops_rd_max': 'int', '*iops_wr_max': 'int', - '*iops_size': 'int' } } + '*iops_size': 'int', 'cache': 'BlockdevCacheInfo' } } ## # @BlockDeviceIoStatus:
tests/qemu-iotests/051.out +1 -0
@@ -50,6 +50,7 @@ Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,backing.file.filename=TEST_DI QEMU X.Y.Z monitor - type 'help' for more information (qemu) i[K[Din[K[D[Dinf[K[D[D[Dinfo[K[D[D[D[Dinfo [K[D[D[D[D[Dinfo b[K[D[D[D[D[D[Dinfo bl[K[D[D[D[D[D[D[Dinfo blo[K[D[D[D[D[D[D[D[Dinfo bloc[K[D[D[D[D[D[D[D[D[Dinfo block[K ide0-hd0: TEST_DIR/t.qcow2 (qcow2) + Cache mode: writeback Backing file: TEST_DIR/t.qcow2.orig (chain depth: 1) (qemu) q[K[Dqu[K[D[Dqui[K[D[D[Dquit[K
tests/qemu-iotests/067.out +1 -1
@@ -6,7 +6,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virtio-blk-pci,drive=disk,id=virtio0 QMP_VERSION {"return": {}} -{"return": [{"io-status": "ok", "device": "disk", "locked": false, "removable": false, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]} +{"return": [{"io-status": "ok", "device": "disk", "locked": false, "removable": false, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "cache": {"no-flush": false, "direct": false, "writeback": true}, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknow! n"}]} {"return": {}} {"return": {}}
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/virtio0/virtio-backend"}}
@@ -24,7 +24,7 @@ QMP_VERSION
Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk
QMP_VERSION
{"return": {}}
-{"return": [{"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]} +{"return": [{"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "cache": {"no-flush": false, "direct": false, "writeback": true}, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknow!
n"}]}
{"return": {}}
{"return": {}}
{"return": {}}
@@ -44,7 +44,7 @@ Testing:
QMP_VERSION
{"return": {}}
{"return": "OK\r\n"}
-{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}]} +{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "cache": {"no-flush": false, "direct": false, "writeback": true}, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknow!
n"}]}
{"return": {}}
{"return": {}}
{"return": {}}
@@ -64,14 +64,14 @@ Testing:
QMP_VERSION
{"return": {}}
{"return": {}}
-{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}]} +{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "cache": {"no-flush": false, "direct": false, "writeback": true}, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknow!
n"}]}
{"return": {}}
{"return": {}}
{"return": {}}
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/virtio0/virtio-backend"}}
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_DELETED", "data": {"device": "virtio0", "path": "/machine/peripheral/virtio0"}}
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "RESET"}-{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"io-status": "ok", "device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": false, "type": "unknown"}]} +{"return": [{"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"io-status": "ok", "device": "disk", "locked": false, "removable": true, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "cache": {"no-flush": false, "direct": false, "writeback": true}, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "tray_open": fal!
se, "type": "unknown"}]}
{"return": {}}
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "SHUTDOWN"}
{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "ide1-cd0", "tray-open": true}}Signature · 1 line
1.8.3.1
PATCH v2 2/5 block/hmp: Factor out print_block_info()
In reply to Kevin WolfThe new function prints the info for a single BlockDriverState.
--- hmp.c | 192 +++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 97 insertions(+), 95 deletions(-)
hmp.c +97 -95
@@ -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);
Signature · 1 line
1.8.3.1
PATCH v2 3/5 block/hmp: Allow info = NULL in print_block_info()
In reply to Kevin WolfThis allows printing infos of BlockDriverStates that aren't at the root of the graph (and logically implementing a BlockBackend).
--- hmp.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
hmp.c +25 -9
@@ -295,7 +295,21 @@ static void print_block_info(Monitor *mon, BlockInfo *info, {ImageInfo *image_info; -monitor_printf (mon,"%s" , info->device); +assert (!info || !info->has_inserted || info->inserted == inserted); + +if (info) { +monitor_printf (mon,"%s" , info->device); +if (inserted && inserted->has_node_name) { +monitor_printf (mon," (%s)" , inserted->node_name); + } + }else { +assert (inserted); +monitor_printf (mon,"%s" , + inserted->has_node_name + ? inserted->node_name + :"<anonymous>" ); + } +if (inserted) { monitor_printf(mon, ": %s (%s%s%s)\n", inserted->file,
@@ -306,15 +320,17 @@ static void print_block_info(Monitor *mon, BlockInfo *info,monitor_printf (mon,": [not inserted]\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]); - } +if (info) { +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]); + } -if (info->removable) { -monitor_printf (mon," Removable device: %slocked, tray %s\n" , - info->locked ?"" :"not " , - info->tray_open ?"open" :"closed" ); +if (info->removable) { +monitor_printf (mon," Removable device: %slocked, tray %s\n" , + info->locked ?"" :"not " , + info->tray_open ?"open" :"closed" ); + } }
Signature · 1 line
1.8.3.1
PATCH v2 4/5 block/hmp: Allow node-name in 'info block'
In reply to Kevin WolfThe optional parameter specifying a block device allows now to use a node-name instead of a drive name (and therefore to inspect any node in the graph). The new -n options allows listing all named nodes instead of BlockBackends.
--- hmp.c | 31 ++++++++++++++++++++++++++++++- monitor.c | 6 +++--- 2 files changed, 33 insertions(+), 4 deletions(-)
hmp.c +30 -1
@@ -403,10 +403,18 @@ static void print_block_info(Monitor *mon, BlockInfo *info,void hmp_info_block (Monitor *mon,const QDict *qdict) {BlockInfoList *block_list, *info; +BlockDeviceInfoList *blockdev_list, *blockdev;const char *device =qdict_get_try_str (qdict,"device" );bool verbose =qdict_get_try_bool (qdict,"verbose" ,0 ); +bool nodes =qdict_get_try_bool (qdict,"nodes" ,0 ); +bool printed = false; - block_list =qmp_query_block (false); +/* Print BlockBackend information */ +if (!nodes) { + block_list =qmp_query_block (false); + }else { + block_list =NULL ; + }for (info = block_list; info; info = info->next) {if (device &&strcmp (device, info->value->device)) {
@@ -420,9 +428,30 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)print_block_info (mon, info->value, info->value->has_inserted ? info->value->inserted :NULL , verbose); + printed = true; }qapi_free_BlockInfoList (block_list); + +if ((!device && !nodes) || printed) { +return ; + } + +/* Print node information */ + blockdev_list =qmp_query_named_block_nodes (NULL ); +for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) { +assert (blockdev->value->has_node_name); +if (device &&strcmp (device, blockdev->value->node_name)) { +continue ; + } + +if (blockdev != blockdev_list) { +monitor_printf (mon,"\n" ); + } + +print_block_info (mon,NULL , blockdev->value, verbose); + } +qapi_free_BlockDeviceInfoList (blockdev_list); }void hmp_info_blockstats (Monitor *mon,const QDict *qdict)
monitor.c +3 -3
@@ -2628,10 +2628,10 @@ static mon_cmd_t info_cmds[] = { }, { .name = "block", - .args_type = "verbose:-v,device:B?", - .params = "[-v] [device]", + .args_type = "nodes:-n,verbose:-v,device:B?", + .params = "[-n] [-v] [device]", .help ="show info of one block device or all block devices " - "(and details of images with -v option)", + "(-n: show named nodes; -v: show details)", .mhandler.cmd = hmp_info_block, }, {
Signature · 1 line
1.8.3.1
PATCH v2 5/5 monitor: Fix HMP tab completion
In reply to Kevin WolfCommands with multiple boolean flag options (like 'info block') didn't provide correct completion because only the first one was skipped.
--- monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
monitor.c +1 -1
@@ -4698,7 +4698,7 @@ static void monitor_find_completion_by_table(Monitor *mon, } } str = args[nb_args -1 ]; -if (*ptype =='-' && ptype[1 ] !='\0' ) { +while (*ptype =='-' && ptype[1 ] !='\0' ) { ptype =next_arg_type (ptype); }switch (*ptype) {
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v2 1/5] block/qapi: Add cache information to query-block
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
Signed-off-by Kevin Wolf <[email protected]>--- block/qapi.c | 7 +++++++ hmp.c | 8 ++++++++ qapi/block-core.json | 20 +++++++++++++++++++- tests/qemu-iotests/051.out | 1 + tests/qemu-iotests/067.out | 10 +++++----- 5 files changed, 40 insertions(+), 6 deletions(-)
tests/qemu-iotests/067.out Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 · line 9
Quoted 7 lines
+++ b/tests/qemu-iotests/067.out
tests/qemu-iotests/067.out +1
-1@@ -6,7 +6,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,if=none,id=disk -device virtio-blk-pci,drive=disk,id=virtio0 QMP_VERSION {"return": {}} -{"return": [{"io-status": "ok", "device": "disk", "locked": false, "removable": false, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}]} +{"return": [{"io-status": "ok", "device": "disk", "locked": false, "removable": false, "inserted": {"iops_rd": 0, "detect_zeroes": "off", "image": {"virtual-size": 134217728, "filename": "TEST_DIR/t.qcow2", "cluster-size": 65536, "format": "qcow2", "actual-size": SIZE, "format-specific": {"type": "qcow2", "data": {"compat": "1.1", "lazy-refcounts": false, "corrupt": false}}, "dirty-flag": false}, "iops_wr": 0, "ro": false, "backing_file_depth": 0, "drv": "qcow2", "iops": 0, "bps_wr": 0, "encrypted": false, "bps": 0, "bps_rd": 0, "cache": {"no-flush": false, "direct": false, "writeback": true}, "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false}, "type": "unknown"}, {"io-status": "ok", "device": "ide1-cd0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "floppy0", "locked": false, "removable": true, "tray_open": false, "type": "unknown"}, {"device": "sd0", "locked": false, "removable": true, "tray_open": false, "type": "unknow!
Will conflict with the patch to add -qmp-pretty to avoid the long lines; but the resolution is straightforward for whoever loses the race.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Kevin Wolf
AppliedAm 12.11.2014 um 17:11 hat Kevin Wolf geschrieben:
Quoted 16 lines
This was supposed to be the first part of a series allowing to override the cache mode for backing files, and more specifically to support the test cases for that series.
However, this work turned out to be a bit more complicated than I had hoped, and the query improvement is nice to have on its own, so I'm sending this out as a standalone series.
v2:
- Markus didn't like QMP query-* commands that filter, so this series is mainly about HMP now [Markus]
- Use BlockdevCacheInfo instead of BlockdevCacheOptions [Markus]
- API version changed to 2.3
- Added 'info block -n' which lists all names nodes
- Added a tab completion fix for HMP, bug exposed by 'info block -n'
Quoted 6 lines
Kevin Wolf (5):
block/qapi: Add cache information to query-block block/hmp: Factor outprint_block_info()block/hmp: Allow info = NULL inprint_block_info()block/hmp: Allow node-name in 'info block'
monitor: Fix HMP tab completion
Applied to block-next (with the trivial conflict resolution in patch 1 that Eric predicted).
Kevin