aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2022-11-04 17:06:52 +0100
committerMarkus Armbruster <armbru@redhat.com>2022-12-14 20:03:25 +0100
commit54fde4ff0621c22b15cbaaa3c74301cc0dbd1c9e (patch)
tree373c23134aab19ba0edf43249e7722eea1d01d14 /block
parent8461b4d60153ba923c47b6e2f9e270c0e8d6d49c (diff)
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]
Diffstat (limited to 'block')
-rw-r--r--block/block-backend.c2
-rw-r--r--block/copy-before-write.c2
-rw-r--r--block/dirty-bitmap.c1
-rw-r--r--block/export/export.c2
-rw-r--r--block/export/vduse-blk.c3
-rw-r--r--block/gluster.c3
-rw-r--r--block/monitor/block-hmp-cmds.c48
-rw-r--r--block/qapi-sysemu.c73
-rw-r--r--block/qapi.c62
-rw-r--r--block/qcow.c10
-rw-r--r--block/qcow2.c18
-rw-r--r--block/qed.c2
-rw-r--r--block/quorum.c2
-rw-r--r--block/rbd.c17
-rw-r--r--block/ssh.c2
15 files changed, 92 insertions, 155 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index d98a96ff37..bf0ea3cfed 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1860,7 +1860,7 @@ static void send_qmp_error_event(BlockBackend *blk,
BlockDriverState *bs = blk_bs(blk);
optype = is_read ? IO_OPERATION_TYPE_READ : IO_OPERATION_TYPE_WRITE;
- qapi_event_send_block_io_error(blk_name(blk), !!bs,
+ qapi_event_send_block_io_error(blk_name(blk),
bs ? bdrv_get_node_name(bs) : NULL, optype,
action, blk_iostatus_is_enabled(blk),
error == ENOSPC, strerror(error));
diff --git a/block/copy-before-write.c b/block/copy-before-write.c
index 4abaa7339e..b28ae25ec1 100644
--- a/block/copy-before-write.c
+++ b/block/copy-before-write.c
@@ -432,7 +432,7 @@ static int cbw_open(BlockDriverState *bs, QDict *options, int flags,
return -EINVAL;
}
- if (opts->has_bitmap) {
+ if (opts->bitmap) {
bitmap = block_dirty_bitmap_lookup(opts->bitmap->node,
opts->bitmap->name, NULL, errp);
if (!bitmap) {
diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c
index bf3dc0512a..9c39550698 100644
--- a/block/dirty-bitmap.c
+++ b/block/dirty-bitmap.c
@@ -541,7 +541,6 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs)
info->count = bdrv_get_dirty_count(bm);
info->granularity = bdrv_dirty_bitmap_granularity(bm);
- info->has_name = !!bm->name;
info->name = g_strdup(bm->name);
info->recording = bdrv_dirty_bitmap_recording(bm);
info->busy = bdrv_dirty_bitmap_busy(bm);
diff --git a/block/export/export.c b/block/export/export.c
index 7cc0c25c1c..28a91c9c42 100644
--- a/block/export/export.c
+++ b/block/export/export.c
@@ -114,7 +114,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp)
ctx = bdrv_get_aio_context(bs);
aio_context_acquire(ctx);
- if (export->has_iothread) {
+ if (export->iothread) {
IOThread *iothread;
AioContext *new_ctx;
Error **set_context_errp;
diff --git a/block/export/vduse-blk.c b/block/export/vduse-blk.c
index f101c24c3f..350d6fdaf0 100644
--- a/block/export/vduse-blk.c
+++ b/block/export/vduse-blk.c
@@ -265,8 +265,7 @@ static int vduse_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
}
vblk_exp->num_queues = num_queues;
vblk_exp->handler.blk = exp->blk;
- vblk_exp->handler.serial = g_strdup(vblk_opts->has_serial ?
- vblk_opts->serial : "");
+ vblk_exp->handler.serial = g_strdup(vblk_opts->serial ?: "");
vblk_exp->handler.logical_block_size = logical_block_size;
vblk_exp->handler.writable = opts->writable;
diff --git a/block/gluster.c b/block/gluster.c
index 7c90f7ba4b..7efc296399 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -830,7 +830,6 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options,
s->logfile = g_strdup(logfile ? logfile : GLUSTER_LOGFILE_DEFAULT);
gconf->logfile = g_strdup(s->logfile);
- gconf->has_logfile = true;
s->glfs = qemu_gluster_init(gconf, filename, options, errp);
if (!s->glfs) {
@@ -917,7 +916,6 @@ static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
gconf->debug = s->debug;
gconf->has_debug = true;
gconf->logfile = g_strdup(s->logfile);
- gconf->has_logfile = true;
/*
* 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,
if (!gconf->logfile) {
gconf->logfile = g_strdup(GLUSTER_LOGFILE_DEFAULT);
}
- gconf->has_logfile = true;
ret = qemu_gluster_parse(gconf, filename, NULL, errp);
if (ret < 0) {
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
index b6135e9bfe..0ff7c84039 100644
--- a/block/monitor/block-hmp-cmds.c
+++ b/block/monitor/block-hmp-cmds.c
@@ -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;
}
diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c
index 680c7ee342..0c7a1423de 100644
--- a/block/qapi-sysemu.c
+++ b/block/qapi-sysemu.c
@@ -116,8 +116,8 @@ static int do_open_tray(const char *blk_name, const char *qdev_id,
return 0;
}
-void qmp_blockdev_open_tray(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_blockdev_open_tray(const char *device,
+ const char *id,
bool has_force, bool force,
Error **errp)
{
@@ -127,9 +127,7 @@ void qmp_blockdev_open_tray(bool has_device, const char *device,
if (!has_force) {
force = false;
}
- rc = do_open_tray(has_device ? device : NULL,
- has_id ? id : NULL,
- force, &local_err);
+ rc = do_open_tray(device, id, force, &local_err);
if (rc && rc != -ENOSYS && rc != -EINPROGRESS) {
error_propagate(errp, local_err);
return;
@@ -137,16 +135,13 @@ void qmp_blockdev_open_tray(bool has_device, const char *device,
error_free(local_err);
}
-void qmp_blockdev_close_tray(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_blockdev_close_tray(const char *device,
+ const char *id,
Error **errp)
{
BlockBackend *blk;
Error *local_err = NULL;
- device = has_device ? device : NULL;
- id = has_id ? id : NULL;
-
blk = qmp_get_blk(device, id, errp);
if (!blk) {
return;
@@ -173,17 +168,14 @@ void qmp_blockdev_close_tray(bool has_device, const char *device,
}
}
-static void blockdev_remove_medium(bool has_device, const char *device,
- bool has_id, const char *id, Error **errp)
+static void blockdev_remove_medium(const char *device, const char *id,
+ Error **errp)
{
BlockBackend *blk;
BlockDriverState *bs;
AioContext *aio_context;
bool has_attached_device;
- device = has_device ? device : NULL;
- id = has_id ? id : NULL;
-
blk = qmp_get_blk(device, id, errp);
if (!blk) {
return;
@@ -232,7 +224,7 @@ out:
void qmp_blockdev_remove_medium(const char *id, Error **errp)
{
- blockdev_remove_medium(false, NULL, true, id, errp);
+ blockdev_remove_medium(NULL, id, errp);
}
static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
@@ -280,16 +272,13 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
}
}
-static void blockdev_insert_medium(bool has_device, const char *device,
- bool has_id, const char *id,
+static void blockdev_insert_medium(const char *device, const char *id,
const char *node_name, Error **errp)
{
BlockBackend *blk;
BlockDriverState *bs;
- blk = qmp_get_blk(has_device ? device : NULL,
- has_id ? id : NULL,
- errp);
+ blk = qmp_get_blk(device, id, errp);
if (!blk) {
return;
}
@@ -311,13 +300,13 @@ static void blockdev_insert_medium(bool has_device, const char *device,
void qmp_blockdev_insert_medium(const char *id, const char *node_name,
Error **errp)
{
- blockdev_insert_medium(false, NULL, true, id, node_name, errp);
+ blockdev_insert_medium(NULL, id, node_name, errp);
}
-void qmp_blockdev_change_medium(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_blockdev_change_medium(const char *device,
+ const char *id,
const char *filename,
- bool has_format, const char *format,
+ const char *format,
bool has_force, bool force,
bool has_read_only,
BlockdevChangeReadOnlyMode read_only,
@@ -331,9 +320,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
QDict *options = NULL;
Error *err = NULL;
- blk = qmp_get_blk(has_device ? device : NULL,
- has_id ? id : NULL,
- errp);
+ blk = qmp_get_blk(device, id, errp);
if (!blk) {
goto fail;
}
@@ -370,7 +357,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
detect_zeroes = blk_get_detect_zeroes_from_root_state(blk);
qdict_put_str(options, "detect-zeroes", detect_zeroes ? "on" : "off");
- if (has_format) {
+ if (format) {
qdict_put_str(options, "driver", format);
}
@@ -379,9 +366,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
goto fail;
}
- rc = do_open_tray(has_device ? device : NULL,
- has_id ? id : NULL,
- force, &err);
+ rc = do_open_tray(device, id, force, &err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, err);
goto fail;
@@ -389,7 +374,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
error_free(err);
err = NULL;
- blockdev_remove_medium(has_device, device, has_id, id, &err);
+ blockdev_remove_medium(device, id, &err);
if (err) {
error_propagate(errp, err);
goto fail;
@@ -401,7 +386,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
goto fail;
}
- qmp_blockdev_close_tray(has_device, device, has_id, id, errp);
+ qmp_blockdev_close_tray(device, id, errp);
fail:
/* If the medium has been inserted, the device has its own reference, so
@@ -410,8 +395,7 @@ fail:
bdrv_unref(medium_bs);
}
-void qmp_eject(bool has_device, const char *device,
- bool has_id, const char *id,
+void qmp_eject(const char *device, const char *id,
bool has_force, bool force, Error **errp)
{
Error *local_err = NULL;
@@ -421,16 +405,14 @@ void qmp_eject(bool has_device, const char *device,
force = false;
}
- rc = do_open_tray(has_device ? device : NULL,
- has_id ? id : NULL,
- force, &local_err);
+ rc = do_open_tray(device, id, force, &local_err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, local_err);
return;
}
error_free(local_err);
- blockdev_remove_medium(has_device, device, has_id, id, errp);
+ blockdev_remove_medium(device, id, errp);
}
/* throttling disk I/O limits */
@@ -441,9 +423,7 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)
BlockBackend *blk;
AioContext *aio_context;
- blk = qmp_get_blk(arg->has_device ? arg->device : NULL,
- arg->has_id ? arg->id : NULL,
- errp);
+ blk = qmp_get_blk(arg->device, arg->id, errp);
if (!blk) {
return;
}
@@ -516,11 +496,8 @@ void qmp_block_set_io_throttle(BlockIOThrottle *arg, Error **errp)
/* Enable I/O limits if they're not enabled yet, otherwise
* just update the throttling group. */
if (!blk_get_public(blk)->throttle_group_member.throttle_state) {
- blk_io_limits_enable(blk,
- arg->has_group ? arg->group :
- arg->has_device ? arg->device :
- arg->id);
- } else if (arg->has_group) {
+ blk_io_limits_enable(blk, arg->group ?: arg->device ?: arg->id);
+ } else if (arg->group) {
blk_io_limits_update_group(blk, arg->group);
}
/* Set the new throttling configuration */
diff --git a/block/qapi.c b/block/qapi.c
index cf557e3aea..fea808425b 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -71,13 +71,11 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
};
if (bs->node_name[0]) {
- info->has_node_name = true;
info->node_name = g_strdup(bs->node_name);
}
backing = bdrv_cow_bs(bs);
if (backing) {
- info->has_backing_file = true;
info->backing_file = g_strdup(backing->filename);
}
@@ -139,7 +137,6 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
info->has_iops_size = cfg.op_size;
info->iops_size = cfg.op_size;
- info->has_group = true;
info->group =
g_strdup(throttle_group_get_name(&blkp->throttle_group_member));
}
@@ -170,7 +167,6 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
*/
info->backing_file_depth++;
bs0 = bdrv_filter_or_cow_bs(bs0);
- (*p_image_info)->has_backing_image = true;
p_image_info = &((*p_image_info)->backing_image);
} else {
break;
@@ -301,26 +297,21 @@ void bdrv_query_image_info(BlockDriverState *bs,
qapi_free_ImageInfo(info);
goto out;
}
- info->has_format_specific = info->format_specific != NULL;
-
backing_filename = bs->backing_file;
if (backing_filename[0] != '\0') {
char *backing_filename2;
info->backing_filename = g_strdup(backing_filename);
- info->has_backing_filename = true;
backing_filename2 = bdrv_get_full_backing_filename(bs, NULL);
/* Always report the full_backing_filename if present, even if it's the
* same as backing_filename. That they are same is useful info. */
if (backing_filename2) {
info->full_backing_filename = g_strdup(backing_filename2);
- info->has_full_backing_filename = true;
}
if (bs->backing_format[0]) {
info->backing_filename_format = g_strdup(bs->backing_format);
- info->has_backing_filename_format = true;
}
g_free(backing_filename2);
}
@@ -367,7 +358,6 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
qdev = blk_get_attached_dev_id(blk);
if (qdev && *qdev) {
- info->has_qdev = true;
info->qdev = qdev;
} else {
g_free(qdev);
@@ -384,7 +374,6 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
}
if (bs && bs->drv) {
- info->has_inserted = true;
info->inserted = bdrv_block_device_info(blk, bs, false, errp);
if (info->inserted == NULL) {
goto err;
@@ -411,23 +400,26 @@ static uint64List *uint64_list(uint64_t *list, int size)
return out_list;
}
-static void bdrv_latency_histogram_stats(BlockLatencyHistogram *hist,
- bool *not_null,
- BlockLatencyHistogramInfo **info)
+static BlockLatencyHistogramInfo *
+bdrv_latency_histogram_stats(BlockLatencyHistogram *hist)
{
- *not_null = hist->bins != NULL;
- if (*not_null) {
- *info = g_new0(BlockLatencyHistogramInfo, 1);
+ BlockLatencyHistogramInfo *info;
- (*info)->boundaries = uint64_list(hist->boundaries, hist->nbins - 1);
- (*info)->bins = uint64_list(hist->bins, hist->nbins);
+ if (!hist->bins) {
+ return NULL;
}
+
+ info = g_new0(BlockLatencyHistogramInfo, 1);
+ info->boundaries = uint64_list(hist->boundaries, hist->nbins - 1);
+ info->bins = uint64_list(hist->bins, hist->nbins);
+ return info;
}
static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
{
BlockAcctStats *stats = blk_get_stats(blk);
BlockAcctTimedStats *ts = NULL;
+ BlockLatencyHistogram *hgram;
ds->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ];
ds->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE];
@@ -493,15 +485,13 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
QAPI_LIST_PREPEND(ds->timed_stats, dev_stats);
}
- bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_READ],
- &ds->has_rd_latency_histogram,
- &ds->rd_latency_histogram);
- bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_WRITE],
- &ds->has_wr_latency_histogram,
- &ds->wr_latency_histogram);
- bdrv_latency_histogram_stats(&stats->latency_histogram[BLOCK_ACCT_FLUSH],
- &ds->has_flush_latency_histogram,
- &ds->flush_latency_histogram);
+ hgram = stats->latency_histogram;
+ ds->rd_latency_histogram
+ = bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_READ]);
+ ds->wr_latency_histogram
+ = bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_WRITE]);
+ ds->flush_latency_histogram
+ = bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_FLUSH]);
}
static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
@@ -526,16 +516,12 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
}
if (bdrv_get_node_name(bs)[0]) {
- s->has_node_name = true;
s->node_name = g_strdup(bdrv_get_node_name(bs));
}
s->stats->wr_highest_offset = stat64_get(&bs->wr_highest_offset);
s->driver_specific = bdrv_get_specific_stats(bs);
- if (s->driver_specific) {
- s->has_driver_specific = true;
- }
parent_child = bdrv_primary_child(bs);
if (!parent_child ||
@@ -564,7 +550,6 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
}
}
if (parent_child) {
- s->has_parent = true;
s->parent = bdrv_query_bds_stats(parent_child->bs, blk_level);
}
@@ -575,7 +560,6 @@ static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs,
* compatibility to when we put bs0->backing here, which might
* be either)
*/
- s->has_backing = true;
s->backing = bdrv_query_bds_stats(filter_or_cow_bs, blk_level);
}
@@ -640,12 +624,10 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
aio_context_acquire(ctx);
s = bdrv_query_bds_stats(blk_bs(blk), true);
- s->has_device = true;
s->device = g_strdup(blk_name(blk));
qdev = blk_get_attached_dev_id(blk);
if (qdev && *qdev) {
- s->has_qdev = true;
s->qdev = qdev;
} else {
g_free(qdev);
@@ -822,16 +804,16 @@ void bdrv_image_info_dump(ImageInfo *info)
qemu_printf("cleanly shut down: no\n");
}
- if (info->has_backing_filename) {
+ if (info->backing_filename) {
qemu_printf("backing file: %s", info->backing_filename);
- if (!info->has_full_backing_filename) {
+ if (!info->full_backing_filename) {
qemu_printf(" (cannot determine actual path)");
} else if (strcmp(info->backing_filename,
info->full_backing_filename) != 0) {
qemu_printf(" (actual path: %s)", info->full_backing_filename);
}
qemu_printf("\n");
- if (info->has_backing_filename_format) {
+ if (info->backing_filename_format) {
qemu_printf("backing file format: %s\n",
info->backing_filename_format);
}
@@ -865,7 +847,7 @@ void bdrv_image_info_dump(ImageInfo *info)
}
}
- if (info->has_format_specific) {
+ if (info->format_specific) {
qemu_printf("Format specific information:\n");
bdrv_image_info_specific_dump(info->format_specific);
}
diff --git a/block/qcow.c b/block/qcow.c
index daa38839ab..8bffc41531 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -825,7 +825,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
return -EINVAL;
}
- if (qcow_opts->has_encrypt &&
+ if (qcow_opts->encrypt &&
qcow_opts->encrypt->format != Q_CRYPTO_BLOCK_FORMAT_QCOW)
{
error_setg(errp, "Unsupported encryption format");
@@ -853,7 +853,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
header.size = cpu_to_be64(total_size);
header_size = sizeof(header);
backing_filename_len = 0;
- if (qcow_opts->has_backing_file) {
+ if (qcow_opts->backing_file) {
if (strcmp(qcow_opts->backing_file, "fat:")) {
header.backing_file_offset = cpu_to_be64(header_size);
backing_filename_len = strlen(qcow_opts->backing_file);
@@ -861,7 +861,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
header_size += backing_filename_len;
} else {
/* special backing file for vvfat */
- qcow_opts->has_backing_file = false;
+ qcow_opts->backing_file = NULL;
}
header.cluster_bits = 9; /* 512 byte cluster to avoid copying
unmodified sectors */
@@ -876,7 +876,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
header.l1_table_offset = cpu_to_be64(header_size);
- if (qcow_opts->has_encrypt) {
+ if (qcow_opts->encrypt) {
header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);
crypto = qcrypto_block_create(qcow_opts->encrypt, "encrypt.",
@@ -895,7 +895,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
goto exit;
}
- if (qcow_opts->has_backing_file) {
+ if (qcow_opts->backing_file) {
ret = blk_co_pwrite(qcow_blk, sizeof(header), backing_filename_len,
qcow_opts->backing_file, 0);
if (ret < 0) {
diff --git a/block/qcow2.c b/block/qcow2.c
index 4d6666d3ff..941782a011 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3508,7 +3508,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
if (!qcow2_opts->has_preallocation) {
qcow2_opts->preallocation = PREALLOC_MODE_OFF;
}
- if (qcow2_opts->has_backing_file &&
+ if (qcow2_opts->backing_file &&
qcow2_opts->preallocation != PREALLOC_MODE_OFF &&
!qcow2_opts->extended_l2)
{
@@ -3517,7 +3517,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
ret = -EINVAL;
goto out;
}
- if (qcow2_opts->has_backing_fmt && !qcow2_opts->has_backing_file) {
+ if (qcow2_opts->has_backing_fmt && !qcow2_opts->backing_file) {
error_setg(errp, "Backing format cannot be used without backing file");
ret = -EINVAL;
goto out;
@@ -3558,7 +3558,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
ret = -EINVAL;
goto out;
}
- if (qcow2_opts->data_file_raw && qcow2_opts->has_backing_file) {
+ if (qcow2_opts->data_file_raw && qcow2_opts->backing_file) {
error_setg(errp, "Backing file and data-file-raw cannot be used at "
"the same time");
ret = -EINVAL;
@@ -3584,7 +3584,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
* backing file when specifying data_file_raw is an error
* anyway.
*/
- assert(!qcow2_opts->has_backing_file);
+ assert(!qcow2_opts->backing_file);
}
if (qcow2_opts->data_file) {
@@ -3752,7 +3752,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
/* Want a backing file? There you go. */
- if (qcow2_opts->has_backing_file) {
+ if (qcow2_opts->backing_file) {
const char *backing_format = NULL;
if (qcow2_opts->has_backing_fmt) {
@@ -3770,7 +3770,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
/* Want encryption? There you go. */
- if (qcow2_opts->has_encrypt) {
+ if (qcow2_opts->encrypt) {
ret = qcow2_set_up_encryption(blk_bs(blk), qcow2_opts->encrypt, errp);
if (ret < 0) {
goto out;
@@ -5195,7 +5195,6 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs,
.refcount_bits = s->refcount_bits,
.has_bitmaps = !!bitmaps,
.bitmaps = bitmaps,
- .has_data_file = !!s->image_data_file,
.data_file = g_strdup(s->image_data_file),
.has_data_file_raw = has_data_file(bs),
.data_file_raw = data_file_is_raw(bs),
@@ -5226,7 +5225,6 @@ static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs,
memset(&encrypt_info->u, 0, sizeof(encrypt_info->u));
qapi_free_QCryptoBlockInfo(encrypt_info);
- spec_info->u.qcow2.data->has_encrypt = true;
spec_info->u.qcow2.data->encrypt = qencrypt;
}
@@ -5846,7 +5844,7 @@ static int coroutine_fn qcow2_co_amend(BlockDriverState *bs,
BDRVQcow2State *s = bs->opaque;
int ret = 0;
- if (qopts->has_encrypt) {
+ if (qopts->encrypt) {
if (!s->crypto) {
error_setg(errp, "image is not encrypted, can't amend");
return -EOPNOTSUPP;
@@ -5911,7 +5909,7 @@ void qcow2_signal_corruption(BlockDriverState *bs, bool fatal, int64_t offset,
node_name = bdrv_get_node_name(bs);
qapi_event_send_block_image_corrupted(bdrv_get_device_name(bs),
- *node_name != '\0', node_name,
+ *node_name ? node_name : NULL,
message, offset >= 0, offset,
size >= 0, size,
fatal);
diff --git a/block/qed.c b/block/qed.c
index 2f36ad342c..0ab159b468 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -698,7 +698,7 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts,
goto out;
}
- if (qed_opts->has_backing_file) {
+ if (qed_opts->backing_file) {
header.features |= QED_F_BACKING_FILE;
header.backing_filename_offset = sizeof(le_header);
header.backing_filename_size = strlen(qed_opts->backing_file);
diff --git a/block/quorum.c b/block/quorum.c
index f9e6539ceb..7f21c03f1f 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -202,7 +202,7 @@ static void quorum_report_bad(QuorumOpType type, uint64_t offset,
msg = strerror(-ret);
}
- qapi_event_send_quorum_report_bad(type, !!msg, msg, node_name, start_sector,
+ qapi_event_send_quorum_report_bad(type, msg, node_name, start_sector,
end_sector - start_sector);
}
diff --git a/block/rbd.c b/block/rbd.c
index f826410f40..3aa6aae0e0 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -536,13 +536,13 @@ static int qemu_rbd_do_create(BlockdevCreateOptions *options,
int ret;
assert(options->driver == BLOCKDEV_DRIVER_RBD);
- if (opts->location->has_snapshot) {
+ if (opts->location->snapshot) {
error_setg(errp, "Can't use snapshot name for image creation");
return -EINVAL;
}
#ifndef LIBRBD_SUPPORTS_ENCRYPTION
- if (opts->has_encrypt) {
+ if (opts->encrypt) {
error_setg(errp, "RBD library does not support image encryption");
return -ENOTSUP;
}
@@ -574,7 +574,7 @@ static int qemu_rbd_do_create(BlockdevCreateOptions *options,
}
#ifdef LIBRBD_SUPPORTS_ENCRYPTION
- if (opts->has_encrypt) {
+ if (opts->encrypt) {
rbd_image_t image;
ret = rbd_open(io_ctx, opts->location->image, &image, NULL);
@@ -686,7 +686,6 @@ static int coroutine_fn qemu_rbd_co_create_opts(BlockDriver *drv,
goto exit;
}
rbd_opts->encrypt = encrypt;
- rbd_opts->has_encrypt = !!encrypt;
/*
* Caution: while qdict_get_try_str() is fine, getting non-string
@@ -697,11 +696,8 @@ static int coroutine_fn qemu_rbd_co_create_opts(BlockDriver *drv,
loc = rbd_opts->location;
loc->pool = g_strdup(qdict_get_try_str(options, "pool"));
loc->conf = g_strdup(qdict_get_try_str(options, "conf"));
- loc->has_conf = !!loc->conf;
loc->user = g_strdup(qdict_get_try_str(options, "user"));
- loc->has_user = !!loc->user;
loc->q_namespace = g_strdup(qdict_get_try_str(options, "namespace"));
- loc->has_q_namespace = !!loc->q_namespace;
loc->image = g_strdup(qdict_get_try_str(options, "image"));
keypairs = qdict_get_try_str(options, "=keyvalue-pairs");
@@ -767,7 +763,6 @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
return -EINVAL;
}
opts->key_secret = g_strdup(secretid);
- opts->has_key_secret = true;
}
mon_host = qemu_rbd_mon_host(opts, &local_err);
@@ -785,7 +780,7 @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
/* try default location when conf=NULL, but ignore failure */
r = rados_conf_read_file(*cluster, opts->conf);
- if (opts->has_conf && r < 0) {
+ if (opts->conf && r < 0) {
error_setg_errno(errp, -r, "error reading conf file %s", opts->conf);
goto failed_shutdown;
}
@@ -833,7 +828,7 @@ static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx,
}
#ifdef HAVE_RBD_NAMESPACE_EXISTS
- if (opts->has_q_namespace && strlen(opts->q_namespace) > 0) {
+ if (opts->q_namespace && strlen(opts->q_namespace) > 0) {
bool exists;
r = rbd_namespace_exists(*io_ctx, opts->q_namespace, &exists);
@@ -991,7 +986,7 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,
goto failed_open;
}
- if (opts->has_encrypt) {
+ if (opts->encrypt) {
#ifdef LIBRBD_SUPPORTS_ENCRYPTION
r = qemu_rbd_encryption_load(s->image, opts->encrypt, errp);
if (r < 0) {
diff --git a/block/ssh.c b/block/ssh.c
index 04726d4ecb..8508710f2f 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -643,7 +643,7 @@ static int connect_to_ssh(BDRVSSHState *s, BlockdevOptionsSsh *opts,
unsigned int port = 0;
int new_sock = -1;
- if (opts->has_user) {
+ if (opts->user) {
s->user = g_strdup(opts->user);
} else {
s->user = g_strdup(g_get_user_name());