aboutsummaryrefslogtreecommitdiff
path: root/block/qapi-sysemu.c
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/qapi-sysemu.c
parent8461b4d60153ba923c47b6e2f9e270c0e8d6d49c (diff)
downloadqemu-54fde4ff0621c22b15cbaaa3c74301cc0dbd1c9e.zip
qemu-54fde4ff0621c22b15cbaaa3c74301cc0dbd1c9e.tar.gz
qemu-54fde4ff0621c22b15cbaaa3c74301cc0dbd1c9e.tar.bz2
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/qapi-sysemu.c')
-rw-r--r--block/qapi-sysemu.c73
1 files changed, 25 insertions, 48 deletions
diff --git a/block/qapi-sysemu.c b/block/qapi-sysemu.c
index 680c7ee..0c7a142 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 */