summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2026-08-28 16:04:34 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2026-08-29 12:07:45 +0400
commitf3900cfb0cddd2fcc3b9db20f52f3755e6ed962f (patch)
tree6cf4fe4278f1e3237b8fb05725a3875e4ff3a5dc /block
parentbcf97f76064885730f491b63d4543b60c87c09fd (diff)
downloadqemu-f3900cfb0cddd2fcc3b9db20f52f3755e6ed962f.tar.gz
qemu-f3900cfb0cddd2fcc3b9db20f52f3755e6ed962f.zip
monitor: tighten monitor_printf*()
Rename monitor_printf->monitor_hmp_printf, monitor_vprintf-> monitor_hmp_vprintf, and monitor_printc->monitor_hmp_printc, changing the first parameter from Monitor * to MonitorHMP * to enforce type safety. The implementation is also simplified: monitor_hmp_vprintf now directly calls g_strdup_vprintf + monitor_puts, removing the virtual dispatch via moncls->vprintf. The dev_print() callbacks are temporarily using the MONITOR_HMP(mon) cast, they are fixed in the following commits. Early return in qemu_vprintf() if "hmp" is NULL, relying on monitor_hmp_vprintf() handling NULL case is a bit uncommon. Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-37-9227de146347@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/monitor/block-hmp-cmds.c170
1 files changed, 83 insertions, 87 deletions
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
index a2666e2f1b..7bae4d425c 100644
--- a/block/monitor/block-hmp-cmds.c
+++ b/block/monitor/block-hmp-cmds.c
@@ -89,7 +89,6 @@ out:
void hmp_drive_add(MonitorHMP *hmp, const QDict *qdict)
{
- Monitor *mon = MONITOR(hmp);
Error *err = NULL;
DriveInfo *dinfo;
QemuOpts *opts;
@@ -119,7 +118,7 @@ void hmp_drive_add(MonitorHMP *hmp, const QDict *qdict)
switch (dinfo->type) {
case IF_NONE:
- monitor_printf(mon, "OK\n");
+ monitor_hmp_printf(hmp, "OK\n");
break;
default:
error_setg(&err, "Can't hot-add drive to type %d", dinfo->type);
@@ -552,9 +551,10 @@ void hmp_qemu_io(MonitorHMP *hmp, const QDict *qdict)
hmp_handle_error(hmp, err);
}
-static void print_block_info(Monitor *mon, BlockInfo *info,
+static void print_block_info(MonitorHMP *hmp, BlockInfo *info,
BlockDeviceInfo *inserted, bool verbose)
{
+ Monitor *mon = MONITOR(hmp);
ImageInfo *image_info;
assert(!info || !info->inserted || info->inserted == inserted);
@@ -562,7 +562,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
if (info && *info->device) {
monitor_puts(mon, info->device);
if (inserted && inserted->node_name) {
- monitor_printf(mon, " (%s)", inserted->node_name);
+ monitor_hmp_printf(hmp, " (%s)", inserted->node_name);
}
} else {
assert(info || inserted);
@@ -573,29 +573,29 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
}
if (inserted) {
- monitor_printf(mon, ": %s (%s%s%s%s)\n",
- inserted->file,
- inserted->drv,
- inserted->ro ? ", read-only" : "",
- inserted->encrypted ? ", encrypted" : "",
- inserted->active ? "" : ", inactive");
+ monitor_hmp_printf(hmp, ": %s (%s%s%s%s)\n",
+ inserted->file,
+ inserted->drv,
+ inserted->ro ? ", read-only" : "",
+ inserted->encrypted ? ", encrypted" : "",
+ inserted->active ? "" : ", inactive");
} else {
- monitor_printf(mon, ": [not inserted]\n");
+ monitor_hmp_printf(hmp, ": [not inserted]\n");
}
if (info) {
if (info->qdev) {
- monitor_printf(mon, " Attached to: %s\n", info->qdev);
+ monitor_hmp_printf(hmp, " Attached to: %s\n", info->qdev);
}
if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
- monitor_printf(mon, " I/O status: %s\n",
- BlockDeviceIoStatus_str(info->io_status));
+ monitor_hmp_printf(hmp, " I/O status: %s\n",
+ BlockDeviceIoStatus_str(info->io_status));
}
if (info->removable) {
- monitor_printf(mon, " Removable device: %slocked, tray %s\n",
- info->locked ? "" : "not ",
- info->tray_open ? "open" : "closed");
+ monitor_hmp_printf(hmp, " Removable device: %slocked, tray %s\n",
+ info->locked ? "" : "not ",
+ info->tray_open ? "open" : "closed");
}
}
@@ -604,28 +604,28 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
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" : "");
+ monitor_hmp_printf(hmp, " Cache mode: %s%s%s\n",
+ inserted->cache->writeback ? "writeback" : "writethrough",
+ inserted->cache->direct ? ", direct" : "",
+ inserted->cache->no_flush ? ", ignore flushes" : "");
if (inserted->backing_file) {
- monitor_printf(mon,
- " Backing file: %s "
- "(chain depth: %" PRId64 ")\n",
- inserted->backing_file,
- inserted->backing_file_depth);
+ monitor_hmp_printf(hmp,
+ " 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",
+ monitor_hmp_printf(hmp, " Detect zeroes: %s\n",
BlockdevDetectZeroesOptions_str(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
+ monitor_hmp_printf(hmp, " I/O throttling: bps=%" PRId64
" bps_rd=%" PRId64 " bps_wr=%" PRId64
" bps_max=%" PRId64
" bps_rd_max=%" PRId64
@@ -654,7 +654,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
}
if (verbose) {
- monitor_printf(mon, "\nImages:\n");
+ monitor_hmp_printf(hmp, "\nImages:\n");
image_info = inserted->image;
while (1) {
bdrv_node_info_dump(qapi_ImageInfo_base(image_info), 0, false);
@@ -669,7 +669,6 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
void hmp_info_block(MonitorHMP *hmp, const QDict *qdict)
{
- Monitor *mon = MONITOR(hmp);
BlockInfoList *block_list, *info;
BlockDeviceInfoList *blockdev_list, *blockdev;
const char *device = qdict_get_try_str(qdict, "device");
@@ -690,10 +689,10 @@ void hmp_info_block(MonitorHMP *hmp, const QDict *qdict)
}
if (info != block_list) {
- monitor_printf(mon, "\n");
+ monitor_hmp_printf(hmp, "\n");
}
- print_block_info(mon, info->value, info->value->inserted,
+ print_block_info(hmp, info->value, info->value->inserted,
verbose);
printed = true;
}
@@ -713,17 +712,16 @@ void hmp_info_block(MonitorHMP *hmp, const QDict *qdict)
}
if (blockdev != blockdev_list) {
- monitor_printf(mon, "\n");
+ monitor_hmp_printf(hmp, "\n");
}
- print_block_info(mon, NULL, blockdev->value, verbose);
+ print_block_info(hmp, NULL, blockdev->value, verbose);
}
qapi_free_BlockDeviceInfoList(blockdev_list);
}
void hmp_info_blockstats(MonitorHMP *hmp, const QDict *qdict)
{
- Monitor *mon = MONITOR(hmp);
BlockStatsList *stats_list, *stats;
stats_list = qmp_query_blockstats(false, false, NULL);
@@ -733,28 +731,28 @@ void hmp_info_blockstats(MonitorHMP *hmp, const QDict *qdict)
continue;
}
- monitor_printf(mon, "%s%s: idle_time_ns=%" PRId64 "\n",
- stats != stats_list ? "\n" : "",
- stats->value->device,
- stats->value->stats->idle_time_ns);
- monitor_printf(mon, " %24s %16s %24s %10s\n", "bytes",
- "operations", "total_time_ns", "merged");
- monitor_printf(mon, "Read: %24" PRId64 " %16" PRId64 " %24" PRId64
- " %10" PRId64 "\n",
- stats->value->stats->rd_bytes,
- stats->value->stats->rd_operations,
- stats->value->stats->rd_total_time_ns,
- stats->value->stats->rd_merged);
- monitor_printf(mon, "Write: %24" PRId64 " %16" PRId64 " %24" PRId64
- " %10" PRId64 "\n",
- stats->value->stats->wr_bytes,
- stats->value->stats->wr_operations,
- stats->value->stats->wr_total_time_ns,
- stats->value->stats->wr_merged);
- monitor_printf(mon, "Flush: %24s %16" PRId64 " %24" PRId64 "\n",
- "",
- stats->value->stats->flush_operations,
- stats->value->stats->flush_total_time_ns);
+ monitor_hmp_printf(hmp, "%s%s: idle_time_ns=%" PRId64 "\n",
+ stats != stats_list ? "\n" : "",
+ stats->value->device,
+ stats->value->stats->idle_time_ns);
+ monitor_hmp_printf(hmp, " %24s %16s %24s %10s\n", "bytes",
+ "operations", "total_time_ns", "merged");
+ monitor_hmp_printf(hmp, "Read: %24" PRId64 " %16" PRId64 " %24" PRId64
+ " %10" PRId64 "\n",
+ stats->value->stats->rd_bytes,
+ stats->value->stats->rd_operations,
+ stats->value->stats->rd_total_time_ns,
+ stats->value->stats->rd_merged);
+ monitor_hmp_printf(hmp, "Write: %24" PRId64 " %16" PRId64 " %24" PRId64
+ " %10" PRId64 "\n",
+ stats->value->stats->wr_bytes,
+ stats->value->stats->wr_operations,
+ stats->value->stats->wr_total_time_ns,
+ stats->value->stats->wr_merged);
+ monitor_hmp_printf(hmp, "Flush: %24s %16" PRId64 " %24" PRId64 "\n",
+ "",
+ stats->value->stats->flush_operations,
+ stats->value->stats->flush_total_time_ns);
}
qapi_free_BlockStatsList(stats_list);
@@ -762,34 +760,33 @@ void hmp_info_blockstats(MonitorHMP *hmp, const QDict *qdict)
void hmp_info_block_jobs(MonitorHMP *hmp, const QDict *qdict)
{
- Monitor *mon = MONITOR(hmp);
BlockJobInfoList *list;
list = qmp_query_block_jobs(&error_abort);
if (!list) {
- monitor_printf(mon, "No active jobs\n");
+ monitor_hmp_printf(hmp, "No active jobs\n");
return;
}
while (list) {
if (list->value->type == JOB_TYPE_STREAM) {
- monitor_printf(mon, "Streaming device %s: Completed %" PRId64
- " of %" PRId64 " bytes, speed limit %" PRId64
- " bytes/s\n",
- list->value->device,
- list->value->offset,
- list->value->len,
- list->value->speed);
+ monitor_hmp_printf(hmp, "Streaming device %s: Completed %" PRId64
+ " of %" PRId64 " bytes, speed limit %" PRId64
+ " bytes/s\n",
+ list->value->device,
+ list->value->offset,
+ list->value->len,
+ list->value->speed);
} else {
- monitor_printf(mon, "Type %s, device %s: Completed %" PRId64
- " of %" PRId64 " bytes, speed limit %" PRId64
- " bytes/s\n",
- JobType_str(list->value->type),
- list->value->device,
- list->value->offset,
- list->value->len,
- list->value->speed);
+ monitor_hmp_printf(hmp, "Type %s, device %s: Completed %" PRId64
+ " of %" PRId64 " bytes, speed limit %" PRId64
+ " bytes/s\n",
+ JobType_str(list->value->type),
+ list->value->device,
+ list->value->offset,
+ list->value->len,
+ list->value->speed);
}
list = list->next;
}
@@ -799,7 +796,6 @@ void hmp_info_block_jobs(MonitorHMP *hmp, const QDict *qdict)
void hmp_info_snapshots(MonitorHMP *hmp, const QDict *qdict)
{
- Monitor *mon = MONITOR(hmp);
BlockDriverState *bs, *bs1;
BdrvNextIterator it1;
QEMUSnapshotInfo *sn_tab, *sn;
@@ -837,7 +833,7 @@ void hmp_info_snapshots(MonitorHMP *hmp, const QDict *qdict)
nb_sns = bdrv_snapshot_list(bs, &sn_tab);
if (nb_sns < 0) {
- monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns);
+ monitor_hmp_printf(hmp, "bdrv_snapshot_list: error %d\n", nb_sns);
return;
}
@@ -866,7 +862,7 @@ void hmp_info_snapshots(MonitorHMP *hmp, const QDict *qdict)
}
if (no_snapshot) {
- monitor_printf(mon, "There is no snapshot available.\n");
+ monitor_hmp_printf(hmp, "There is no snapshot available.\n");
return;
}
@@ -889,11 +885,11 @@ void hmp_info_snapshots(MonitorHMP *hmp, const QDict *qdict)
}
}
}
- monitor_printf(mon, "List of snapshots present on all disks:\n");
+ monitor_hmp_printf(hmp, "List of snapshots present on all disks:\n");
if (total > 0) {
bdrv_snapshot_dump(NULL);
- monitor_printf(mon, "\n");
+ monitor_hmp_printf(hmp, "\n");
for (i = 0; i < total; i++) {
sn = &sn_tab[global_snapshots[i]];
/*
@@ -902,24 +898,24 @@ void hmp_info_snapshots(MonitorHMP *hmp, const QDict *qdict)
*/
pstrcpy(sn->id_str, sizeof(sn->id_str), "--");
bdrv_snapshot_dump(sn);
- monitor_printf(mon, "\n");
+ monitor_hmp_printf(hmp, "\n");
}
} else {
- monitor_printf(mon, "None\n");
+ monitor_hmp_printf(hmp, "None\n");
}
QTAILQ_FOREACH(image_entry, &image_list, next) {
if (QTAILQ_EMPTY(&image_entry->snapshots)) {
continue;
}
- monitor_printf(mon,
- "\nList of partial (non-loadable) snapshots on '%s':\n",
- image_entry->imagename);
+ monitor_hmp_printf(hmp,
+ "\nList of partial (non-loadable) snapshots on '%s':\n",
+ image_entry->imagename);
bdrv_snapshot_dump(NULL);
- monitor_printf(mon, "\n");
+ monitor_hmp_printf(hmp, "\n");
QTAILQ_FOREACH(snapshot_entry, &image_entry->snapshots, next) {
bdrv_snapshot_dump(&snapshot_entry->sn);
- monitor_printf(mon, "\n");
+ monitor_hmp_printf(hmp, "\n");
}
}
@@ -935,7 +931,7 @@ void hmp_info_snapshots(MonitorHMP *hmp, const QDict *qdict)
g_free(global_snapshots);
}
-void hmp_change_medium(Monitor *mon, const char *device, const char *target,
+void hmp_change_medium(MonitorHMP *hmp, const char *device, const char *target,
const char *arg, const char *read_only, bool force,
Error **errp)
{