qapi block: Elide redundant has_FOO in generated C
The has_FOO for pointer-valued FOO are redundant, except for arrays. They are also a nuisance to work with. Recent commit "qapi: Start to elide redundant has_FOO in generated C" provided the means to elide them step by step. This is the step for qapi/block*.json. Said commit explains the transformation in more detail. There is one instance of the invariant violation mentioned there: qcow2_signal_corruption() passes false, "" when node_name is an empty string. Take care to pass NULL then. The previous two commits cleaned up two more. Additionally, helper bdrv_latency_histogram_stats() loses its output parameters and returns a value instead. Cc: Kevin Wolf <kwolf@redhat.com> Cc: Hanna Reitz <hreitz@redhat.com> Cc: qemu-block@nongnu.org Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20221104160712.3005652-11-armbru@redhat.com> [Fixes for #ifndef LIBRBD_SUPPORTS_ENCRYPTION and MacOS squashed in]
This commit is contained in:
@@ -241,7 +241,6 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
|
||||
DriveMirror mirror = {
|
||||
.device = (char *)qdict_get_str(qdict, "device"),
|
||||
.target = (char *)filename,
|
||||
.has_format = !!format,
|
||||
.format = (char *)format,
|
||||
.sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
|
||||
.has_mode = true,
|
||||
@@ -270,7 +269,6 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict)
|
||||
DriveBackup backup = {
|
||||
.device = (char *)device,
|
||||
.target = (char *)filename,
|
||||
.has_format = !!format,
|
||||
.format = (char *)format,
|
||||
.sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
|
||||
.has_mode = true,
|
||||
@@ -360,9 +358,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
|
||||
}
|
||||
|
||||
mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
|
||||
qmp_blockdev_snapshot_sync(true, device, false, NULL,
|
||||
filename, false, NULL,
|
||||
!!format, format,
|
||||
qmp_blockdev_snapshot_sync(device, NULL, filename, NULL, format,
|
||||
true, mode, &err);
|
||||
end:
|
||||
hmp_handle_error(mon, err);
|
||||
@@ -385,8 +381,7 @@ void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
|
||||
const char *id = qdict_get_try_str(qdict, "id");
|
||||
Error *err = NULL;
|
||||
|
||||
qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
|
||||
true, name, &err);
|
||||
qmp_blockdev_snapshot_delete_internal_sync(device, id, name, &err);
|
||||
hmp_handle_error(mon, err);
|
||||
}
|
||||
|
||||
@@ -427,7 +422,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
|
||||
block_list = qmp_query_block(NULL);
|
||||
|
||||
for (info = block_list; info; info = info->next) {
|
||||
if (!info->value->has_inserted) {
|
||||
if (!info->value->inserted) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -460,7 +455,6 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
|
||||
|
||||
NbdServerAddOptions export = {
|
||||
.device = (char *) device,
|
||||
.has_name = !!name,
|
||||
.name = (char *) name,
|
||||
.has_writable = true,
|
||||
.writable = writable,
|
||||
@@ -495,7 +489,7 @@ void coroutine_fn hmp_block_resize(Monitor *mon, const QDict *qdict)
|
||||
int64_t size = qdict_get_int(qdict, "size");
|
||||
Error *err = NULL;
|
||||
|
||||
qmp_block_resize(true, device, false, NULL, size, &err);
|
||||
qmp_block_resize(device, NULL, size, &err);
|
||||
hmp_handle_error(mon, err);
|
||||
}
|
||||
|
||||
@@ -506,11 +500,10 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)
|
||||
const char *base = qdict_get_try_str(qdict, "base");
|
||||
int64_t speed = qdict_get_try_int(qdict, "speed", 0);
|
||||
|
||||
qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
|
||||
false, NULL, false, NULL,
|
||||
qdict_haskey(qdict, "speed"), speed, true,
|
||||
BLOCKDEV_ON_ERROR_REPORT, false, NULL, false, false, false,
|
||||
false, &error);
|
||||
qmp_block_stream(device, device, base, NULL, NULL, NULL,
|
||||
qdict_haskey(qdict, "speed"), speed,
|
||||
true, BLOCKDEV_ON_ERROR_REPORT, NULL,
|
||||
false, false, false, false, &error);
|
||||
|
||||
hmp_handle_error(mon, error);
|
||||
}
|
||||
@@ -534,10 +527,8 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
|
||||
* version has only one, so we must decide which one to pass.
|
||||
*/
|
||||
if (blk_by_name(device)) {
|
||||
throttle.has_device = true;
|
||||
throttle.device = device;
|
||||
} else {
|
||||
throttle.has_id = true;
|
||||
throttle.id = device;
|
||||
}
|
||||
|
||||
@@ -551,7 +542,7 @@ void hmp_eject(Monitor *mon, const QDict *qdict)
|
||||
const char *device = qdict_get_str(qdict, "device");
|
||||
Error *err = NULL;
|
||||
|
||||
qmp_eject(true, device, false, NULL, true, force, &err);
|
||||
qmp_eject(device, NULL, true, force, &err);
|
||||
hmp_handle_error(mon, err);
|
||||
}
|
||||
|
||||
@@ -635,18 +626,18 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
|
||||
{
|
||||
ImageInfo *image_info;
|
||||
|
||||
assert(!info || !info->has_inserted || info->inserted == inserted);
|
||||
assert(!info || !info->inserted || info->inserted == inserted);
|
||||
|
||||
if (info && *info->device) {
|
||||
monitor_puts(mon, info->device);
|
||||
if (inserted && inserted->has_node_name) {
|
||||
if (inserted && inserted->node_name) {
|
||||
monitor_printf(mon, " (%s)", inserted->node_name);
|
||||
}
|
||||
} else {
|
||||
assert(info || inserted);
|
||||
monitor_puts(mon,
|
||||
inserted && inserted->has_node_name ? inserted->node_name
|
||||
: info && info->has_qdev ? info->qdev
|
||||
inserted && inserted->node_name ? inserted->node_name
|
||||
: info && info->qdev ? info->qdev
|
||||
: "<anonymous>");
|
||||
}
|
||||
|
||||
@@ -661,7 +652,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
|
||||
}
|
||||
|
||||
if (info) {
|
||||
if (info->has_qdev) {
|
||||
if (info->qdev) {
|
||||
monitor_printf(mon, " Attached to: %s\n", info->qdev);
|
||||
}
|
||||
if (info->has_io_status && info->io_status != BLOCK_DEVICE_IO_STATUS_OK) {
|
||||
@@ -686,7 +677,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
|
||||
inserted->cache->direct ? ", direct" : "",
|
||||
inserted->cache->no_flush ? ", ignore flushes" : "");
|
||||
|
||||
if (inserted->has_backing_file) {
|
||||
if (inserted->backing_file) {
|
||||
monitor_printf(mon,
|
||||
" Backing file: %s "
|
||||
"(chain depth: %" PRId64 ")\n",
|
||||
@@ -735,7 +726,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
|
||||
image_info = inserted->image;
|
||||
while (1) {
|
||||
bdrv_image_info_dump(image_info);
|
||||
if (image_info->has_backing_image) {
|
||||
if (image_info->backing_image) {
|
||||
image_info = image_info->backing_image;
|
||||
} else {
|
||||
break;
|
||||
@@ -769,8 +760,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
|
||||
monitor_printf(mon, "\n");
|
||||
}
|
||||
|
||||
print_block_info(mon, info->value, info->value->has_inserted
|
||||
? info->value->inserted : NULL,
|
||||
print_block_info(mon, info->value, info->value->inserted,
|
||||
verbose);
|
||||
printed = true;
|
||||
}
|
||||
@@ -784,7 +774,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
|
||||
/* Print node information */
|
||||
blockdev_list = qmp_query_named_block_nodes(false, false, NULL);
|
||||
for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
|
||||
assert(blockdev->value->has_node_name);
|
||||
assert(blockdev->value->node_name);
|
||||
if (device && strcmp(device, blockdev->value->node_name)) {
|
||||
continue;
|
||||
}
|
||||
@@ -805,7 +795,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
|
||||
stats_list = qmp_query_blockstats(false, false, NULL);
|
||||
|
||||
for (stats = stats_list; stats; stats = stats->next) {
|
||||
if (!stats->value->has_device) {
|
||||
if (!stats->value->device) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user