Skip to content

Commit 54fde4f

Browse files
author
Markus Armbruster
committed
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 <[email protected]> Cc: Hanna Reitz <[email protected]> Cc: [email protected] Signed-off-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]> [Fixes for #ifndef LIBRBD_SUPPORTS_ENCRYPTION and MacOS squashed in]
1 parent 8461b4d commit 54fde4f

23 files changed

+173
-281
lines changed

block/block-backend.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ static void send_qmp_error_event(BlockBackend *blk,
18601860
BlockDriverState *bs = blk_bs(blk);
18611861

18621862
optype = is_read ? IO_OPERATION_TYPE_READ : IO_OPERATION_TYPE_WRITE;
1863-
qapi_event_send_block_io_error(blk_name(blk), !!bs,
1863+
qapi_event_send_block_io_error(blk_name(blk),
18641864
bs ? bdrv_get_node_name(bs) : NULL, optype,
18651865
action, blk_iostatus_is_enabled(blk),
18661866
error == ENOSPC, strerror(error));

block/copy-before-write.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,
432432
return -EINVAL;
433433
}
434434

435-
if (opts->has_bitmap) {
435+
if (opts->bitmap) {
436436
bitmap = block_dirty_bitmap_lookup(opts->bitmap->node,
437437
opts->bitmap->name, NULL, errp);
438438
if (!bitmap) {

block/dirty-bitmap.c

-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)
541541

542542
info->count = bdrv_get_dirty_count(bm);
543543
info->granularity = bdrv_dirty_bitmap_granularity(bm);
544-
info->has_name = !!bm->name;
545544
info->name = g_strdup(bm->name);
546545
info->recording = bdrv_dirty_bitmap_recording(bm);
547546
info->busy = bdrv_dirty_bitmap_busy(bm);

block/export/export.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
114114
ctx = bdrv_get_aio_context(bs);
115115
aio_context_acquire(ctx);
116116

117-
if (export->has_iothread) {
117+
if (export->iothread) {
118118
IOThread *iothread;
119119
AioContext *new_ctx;
120120
Error **set_context_errp;

block/export/vduse-blk.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
265265
}
266266
vblk_exp->num_queues = num_queues;
267267
vblk_exp->handler.blk = exp->blk;
268-
vblk_exp->handler.serial = g_strdup(vblk_opts->has_serial ?
269-
vblk_opts->serial : "");
268+
vblk_exp->handler.serial = g_strdup(vblk_opts->serial ?: "");
270269
vblk_exp->handler.logical_block_size = logical_block_size;
271270
vblk_exp->handler.writable = opts->writable;
272271

block/gluster.c

-3
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options,
830830
s->logfile = g_strdup(logfile ? logfile : GLUSTER_LOGFILE_DEFAULT);
831831

832832
gconf->logfile = g_strdup(s->logfile);
833-
gconf->has_logfile = true;
834833

835834
s->glfs = qemu_gluster_init(gconf, filename, options, errp);
836835
if (!s->glfs) {
@@ -917,7 +916,6 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
917916
gconf->debug = s->debug;
918917
gconf->has_debug = true;
919918
gconf->logfile = g_strdup(s->logfile);
920-
gconf->has_logfile = true;
921919

922920
/*
923921
* If 'state->bs->exact_filename' is empty, 'state->options' should contain
@@ -1162,7 +1160,6 @@ static int coroutine_fn qemu_gluster_co_create_opts(BlockDriver *drv,
11621160
if (!gconf->logfile) {
11631161
gconf->logfile = g_strdup(GLUSTER_LOGFILE_DEFAULT);
11641162
}
1165-
gconf->has_logfile = true;
11661163

11671164
ret = qemu_gluster_parse(gconf, filename, NULL, errp);
11681165
if (ret < 0) {

block/monitor/block-hmp-cmds.c

+19-29
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
241241
DriveMirror mirror = {
242242
.device = (char *)qdict_get_str(qdict, "device"),
243243
.target = (char *)filename,
244-
.has_format = !!format,
245244
.format = (char *)format,
246245
.sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
247246
.has_mode = true,
@@ -270,7 +269,6 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict)
270269
DriveBackup backup = {
271270
.device = (char *)device,
272271
.target = (char *)filename,
273-
.has_format = !!format,
274272
.format = (char *)format,
275273
.sync = full ? MIRROR_SYNC_MODE_FULL : MIRROR_SYNC_MODE_TOP,
276274
.has_mode = true,
@@ -360,9 +358,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
360358
}
361359

362360
mode = reuse ? NEW_IMAGE_MODE_EXISTING : NEW_IMAGE_MODE_ABSOLUTE_PATHS;
363-
qmp_blockdev_snapshot_sync(true, device, false, NULL,
364-
filename, false, NULL,
365-
!!format, format,
361+
qmp_blockdev_snapshot_sync(device, NULL, filename, NULL, format,
366362
true, mode, &err);
367363
end:
368364
hmp_handle_error(mon, err);
@@ -385,8 +381,7 @@ void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
385381
const char *id = qdict_get_try_str(qdict, "id");
386382
Error *err = NULL;
387383

388-
qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
389-
true, name, &err);
384+
qmp_blockdev_snapshot_delete_internal_sync(device, id, name, &err);
390385
hmp_handle_error(mon, err);
391386
}
392387

@@ -427,7 +422,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
427422
block_list = qmp_query_block(NULL);
428423

429424
for (info = block_list; info; info = info->next) {
430-
if (!info->value->has_inserted) {
425+
if (!info->value->inserted) {
431426
continue;
432427
}
433428

@@ -460,7 +455,6 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
460455

461456
NbdServerAddOptions export = {
462457
.device = (char *) device,
463-
.has_name = !!name,
464458
.name = (char *) name,
465459
.has_writable = true,
466460
.writable = writable,
@@ -495,7 +489,7 @@ void coroutine_fn hmp_block_resize(Monitor *mon, const QDict *qdict)
495489
int64_t size = qdict_get_int(qdict, "size");
496490
Error *err = NULL;
497491

498-
qmp_block_resize(true, device, false, NULL, size, &err);
492+
qmp_block_resize(device, NULL, size, &err);
499493
hmp_handle_error(mon, err);
500494
}
501495

@@ -506,11 +500,10 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)
506500
const char *base = qdict_get_try_str(qdict, "base");
507501
int64_t speed = qdict_get_try_int(qdict, "speed", 0);
508502

509-
qmp_block_stream(true, device, device, base != NULL, base, false, NULL,
510-
false, NULL, false, NULL,
511-
qdict_haskey(qdict, "speed"), speed, true,
512-
BLOCKDEV_ON_ERROR_REPORT, false, NULL, false, false, false,
513-
false, &error);
503+
qmp_block_stream(device, device, base, NULL, NULL, NULL,
504+
qdict_haskey(qdict, "speed"), speed,
505+
true, BLOCKDEV_ON_ERROR_REPORT, NULL,
506+
false, false, false, false, &error);
514507

515508
hmp_handle_error(mon, error);
516509
}
@@ -534,10 +527,8 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
534527
* version has only one, so we must decide which one to pass.
535528
*/
536529
if (blk_by_name(device)) {
537-
throttle.has_device = true;
538530
throttle.device = device;
539531
} else {
540-
throttle.has_id = true;
541532
throttle.id = device;
542533
}
543534

@@ -551,7 +542,7 @@ void hmp_eject(Monitor *mon, const QDict *qdict)
551542
const char *device = qdict_get_str(qdict, "device");
552543
Error *err = NULL;
553544

554-
qmp_eject(true, device, false, NULL, true, force, &err);
545+
qmp_eject(device, NULL, true, force, &err);
555546
hmp_handle_error(mon, err);
556547
}
557548

@@ -635,18 +626,18 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
635626
{
636627
ImageInfo *image_info;
637628

638-
assert(!info || !info->has_inserted || info->inserted == inserted);
629+
assert(!info || !info->inserted || info->inserted == inserted);
639630

640631
if (info && *info->device) {
641632
monitor_puts(mon, info->device);
642-
if (inserted && inserted->has_node_name) {
633+
if (inserted && inserted->node_name) {
643634
monitor_printf(mon, " (%s)", inserted->node_name);
644635
}
645636
} else {
646637
assert(info || inserted);
647638
monitor_puts(mon,
648-
inserted && inserted->has_node_name ? inserted->node_name
649-
: info && info->has_qdev ? info->qdev
639+
inserted && inserted->node_name ? inserted->node_name
640+
: info && info->qdev ? info->qdev
650641
: "<anonymous>");
651642
}
652643

@@ -661,7 +652,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
661652
}
662653

663654
if (info) {
664-
if (info->has_qdev) {
655+
if (info->qdev) {
665656
monitor_printf(mon, " Attached to: %s\n", info->qdev);
666657
}
667658
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,
686677
inserted->cache->direct ? ", direct" : "",
687678
inserted->cache->no_flush ? ", ignore flushes" : "");
688679

689-
if (inserted->has_backing_file) {
680+
if (inserted->backing_file) {
690681
monitor_printf(mon,
691682
" Backing file: %s "
692683
"(chain depth: %" PRId64 ")\n",
@@ -735,7 +726,7 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
735726
image_info = inserted->image;
736727
while (1) {
737728
bdrv_image_info_dump(image_info);
738-
if (image_info->has_backing_image) {
729+
if (image_info->backing_image) {
739730
image_info = image_info->backing_image;
740731
} else {
741732
break;
@@ -769,8 +760,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
769760
monitor_printf(mon, "\n");
770761
}
771762

772-
print_block_info(mon, info->value, info->value->has_inserted
773-
? info->value->inserted : NULL,
763+
print_block_info(mon, info->value, info->value->inserted,
774764
verbose);
775765
printed = true;
776766
}
@@ -784,7 +774,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
784774
/* Print node information */
785775
blockdev_list = qmp_query_named_block_nodes(false, false, NULL);
786776
for (blockdev = blockdev_list; blockdev; blockdev = blockdev->next) {
787-
assert(blockdev->value->has_node_name);
777+
assert(blockdev->value->node_name);
788778
if (device && strcmp(device, blockdev->value->node_name)) {
789779
continue;
790780
}
@@ -805,7 +795,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
805795
stats_list = qmp_query_blockstats(false, false, NULL);
806796

807797
for (stats = stats_list; stats; stats = stats->next) {
808-
if (!stats->value->has_device) {
798+
if (!stats->value->device) {
809799
continue;
810800
}
811801

0 commit comments

Comments
 (0)