Reduce usage of QERR_ macros further
cover Reduce usage of QERR_ macros further
Philippe posted "[PATCH v2 00/22] qapi: Kill 'qapi/qmp/qerror.h' for good" a couple of months ago. I cherry-picked just its simplest parts for now.
Markus Armbruster (1):
error: Drop superfluous #include "qapi/qmp/qerror.h"
Philippe Mathieu-Daudé (9):
qapi: Inline and remove QERR_BUS_NO_HOTPLUG definition
qapi: Inline and remove QERR_DEVICE_HAS_NO_MEDIUM definition
qapi: Inline and remove QERR_DEVICE_NO_HOTPLUG definition
qapi: Inline and remove QERR_INVALID_PARAMETER definition
qapi: Inline QERR_INVALID_PARAMETER_TYPE definition (constant value)
qapi: Inline and remove QERR_INVALID_PARAMETER_TYPE definition
qapi: Correct error message for 'vcpu_dirty_limit' parameter
qapi: Inline and remove QERR_MIGRATION_ACTIVE definition
qapi: Inline and remove QERR_PROPERTY_VALUE_BAD definition
include/qapi/qmp/qerror.h | 21 --------------------- backends/iommufd.c | 1 - block/snapshot.c | 7 ++++--- blockdev.c | 2 +- chardev/char-fe.c | 1 - hw/core/qdev-properties.c | 3 +-- hw/core/qdev.c | 4 ++-- hw/ppc/spapr_pci.c | 5 ++--- migration/migration.c | 2 +- migration/options.c | 9 ++++----- migration/savevm.c | 2 +- qapi/opts-visitor.c | 2 +- qapi/qobject-input-visitor.c | 32 ++++++++++++++++---------------- qapi/string-input-visitor.c | 8 ++++---- qom/object.c | 16 ++++++++++------ system/qdev-monitor.c | 10 ++++++---- system/rtc.c | 1 - util/qemu-option.c | 10 +++++----- scripts/qapi/visit.py | 5 ++--- 19 files changed, 60 insertions(+), 81 deletions(-)
Signature · 1 line
2.44.0
PATCH 1/10 error: Drop superfluous #include "qapi/qmp/qerror.h"
--- backends/iommufd.c | 1 - chardev/char-fe.c | 1 - system/rtc.c | 1 - 3 files changed, 3 deletions(-)
backends/iommufd.c +0 -1
@@ -13,7 +13,6 @@#include "qemu/osdep.h" #include "sysemu/iommufd.h" #include "qapi/error.h" -#include "qapi/qmp/qerror.h" #include "qemu/module.h" #include "qom/object_interfaces.h" #include "qemu/error-report.h"
chardev/char-fe.c +0 -1
@@ -24,7 +24,6 @@#include "qemu/osdep.h" #include "qemu/error-report.h" #include "qapi/error.h" -#include "qapi/qmp/qerror.h" #include "sysemu/replay.h" #include "chardev/char-fe.h"
system/rtc.c +0 -1
@@ -25,7 +25,6 @@#include "qemu/osdep.h" #include "qemu/cutils.h" #include "qapi/error.h" -#include "qapi/qmp/qerror.h" #include "qemu/error-report.h" #include "qemu/option.h" #include "qemu/timer.h"
Signature · 1 line
2.44.0
Re: [PATCH 01/10] error: Drop superfluous #include "qapi/qmp/qerror.h"
Quoted 11 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:34 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 01/10] error: Drop superfluous #include "qapi/qmp/qerror.h"Signed-off-by Markus Armbruster <[email protected]>--- backends/iommufd.c | 1 - chardev/char-fe.c | 1 - system/rtc.c | 1 - 3 files changed, 3 deletions(-)
PATCH 2/10 qapi: Inline and remove QERR_BUS_NO_HOTPLUG definition
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98
("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Mechanical transformation using sed, and manual cleanup.
--- include/qapi/qmp/qerror.h | 3 --- hw/ppc/spapr_pci.c | 5 ++--- system/qdev-monitor.c | 8 +++++--- 3 files changed, 7 insertions(+), 9 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -17,9 +17,6 @@* add new ones! */ -#define QERR_BUS_NO_HOTPLUG \ - "Bus '%s' does not support hotplugging" -#define QERR_DEVICE_HAS_NO_MEDIUM \ "Device '%s' has no medium"
hw/ppc/spapr_pci.c +2 -3
@@ -39,7 +39,6 @@#include "trace.h" #include "qemu/error-report.h" #include "qemu/module.h" -#include "qapi/qmp/qerror.h" #include "hw/ppc/fdt.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pci_bus.h"
@@ -1554,7 +1553,7 @@ static void spapr_pci_pre_plug(HotplugHandler *plug_handler,* we need to let them know it's not enabled */ if (plugged_dev->hotplugged) { -error_setg (errp,QERR_BUS_NO_HOTPLUG , +error_setg (errp,"Bus '%s' does not support hotplugging" , phb->parent_obj.bus->qbus.name);return ; }
@@ -1675,7 +1674,7 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler,SpaprDrc *drc =drc_from_dev (phb, pdev);if (!phb->dr_enabled) { -error_setg (errp,QERR_BUS_NO_HOTPLUG , +error_setg (errp,"Bus '%s' does not support hotplugging" , phb->parent_obj.bus->qbus.name);return ; }
system/qdev-monitor.c +5 -3
@@ -661,7 +661,8 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,if (qdev_should_hide_device (opts, from_json, errp)) {if (bus && !qbus_is_hotpluggable (bus)) { -error_setg (errp,QERR_BUS_NO_HOTPLUG , bus->name); +error_setg (errp,"Bus '%s' does not support hotplugging" , + bus->name); }return NULL ; }else if (*errp) {
@@ -669,7 +670,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, }if (phase_check (PHASE_MACHINE_READY ) && bus && !qbus_is_hotpluggable (bus)) { -error_setg (errp,QERR_BUS_NO_HOTPLUG , bus->name); +error_setg (errp,"Bus '%s' does not support hotplugging" , bus->name);return NULL ; }
@@ -911,7 +912,8 @@ void qdev_unplug(DeviceState *dev, Error **errp) }if (dev->parent_bus && !qbus_is_hotpluggable (dev->parent_bus)) { -error_setg (errp,QERR_BUS_NO_HOTPLUG , dev->parent_bus->name); +error_setg (errp,"Bus '%s' does not support hotplugging" , + dev->parent_bus->name);return ; }
Signature · 1 line
2.44.0
Re: [PATCH 02/10] qapi: Inline and remove QERR_BUS_NO_HOTPLUG definition
Quoted 17 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:35 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 02/10] qapi: Inline and removeQERR_BUS_NO_HOTPLUG
definitionFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98
("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Mechanical transformation using sed, and manual cleanup.
Quoted 9 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- include/qapi/qmp/qerror.h | 3 --- hw/ppc/spapr_pci.c | 5 ++--- system/qdev-monitor.c | 8 +++++--- 3 files changed, 7 insertions(+), 9 deletions(-)
PATCH 3/10 qapi: Inline and remove QERR_DEVICE_HAS_NO_MEDIUM definition
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98
("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Mechanical transformation using sed, and manual cleanup.
--- include/qapi/qmp/qerror.h | 3 --- block/snapshot.c | 7 ++++--- blockdev.c | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -17,9 +17,6 @@* add new ones! */ -#define QERR_DEVICE_HAS_NO_MEDIUM \ - "Device '%s' has no medium" -#define QERR_DEVICE_NO_HOTPLUG \ "Device '%s' does not support hotplugging"
block/snapshot.c +4 -3
@@ -28,7 +28,6 @@#include "block/qdict.h" #include "qapi/error.h" #include "qapi/qmp/qdict.h" -#include "qapi/qmp/qerror.h" #include "qapi/qmp/qstring.h" #include "qemu/option.h" #include "sysemu/block-backend.h"
@@ -359,7 +358,8 @@ int bdrv_snapshot_delete(BlockDriverState *bs,GLOBAL_STATE_CODE ();if (!drv) { -error_setg (errp,QERR_DEVICE_HAS_NO_MEDIUM ,bdrv_get_device_name (bs)); +error_setg (errp,"Device '%s' has no medium" , +bdrv_get_device_name (bs));return -ENOMEDIUM ; }if (!snapshot_id && !name) {
@@ -437,7 +437,8 @@ int bdrv_snapshot_load_tmp(BlockDriverState *bs,GRAPH_RDLOCK_GUARD_MAINLOOP ();if (!drv) { -error_setg (errp,QERR_DEVICE_HAS_NO_MEDIUM ,bdrv_get_device_name (bs)); +error_setg (errp,"Device '%s' has no medium" , +bdrv_get_device_name (bs));return -ENOMEDIUM ; }if (!snapshot_id && !name) {
blockdev.c +1 -1
@@ -1395,7 +1395,7 @@ static void external_snapshot_action(TransactionAction *action,bdrv_drained_begin (state->old_bs);if (!bdrv_is_inserted (state->old_bs)) { -error_setg (errp,QERR_DEVICE_HAS_NO_MEDIUM , device); +error_setg (errp,"Device '%s' has no medium" , device);return ; }
Signature · 1 line
2.44.0
Re: [PATCH 03/10] qapi: Inline and remove QERR_DEVICE_HAS_NO_MEDIUM definition
Quoted 17 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:36 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 03/10] qapi: Inline and removeQERR_DEVICE_HAS_NO_MEDIUM
definitionFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98
("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Mechanical transformation using sed, and manual cleanup.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- include/qapi/qmp/qerror.h | 3 --- block/snapshot.c | 7 ++++--- blockdev.c | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-)
PATCH 4/10 qapi: Inline and remove QERR_DEVICE_NO_HOTPLUG definition
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98
("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Mechanical transformation using sed, and manual cleanup.
--- include/qapi/qmp/qerror.h | 3 --- hw/core/qdev.c | 4 ++-- system/qdev-monitor.c | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -17,9 +17,6 @@* add new ones! */ -#define QERR_DEVICE_NO_HOTPLUG \ - "Device '%s' does not support hotplugging" -#define QERR_INVALID_PARAMETER \ "Invalid parameter '%s'"
hw/core/qdev.c +2 -2
@@ -29,7 +29,6 @@#include "qapi/error.h" #include "qapi/qapi-events-qdev.h" #include "qapi/qmp/qdict.h" -#include "qapi/qmp/qerror.h" #include "qapi/visitor.h" #include "qemu/error-report.h" #include "qemu/option.h"
@@ -479,7 +478,8 @@ static void device_set_realized(Object *obj, bool value, Error **errp)static int unattached_count;if (dev->hotplugged && !dc->hotpluggable) { -error_setg (errp,QERR_DEVICE_NO_HOTPLUG ,object_get_typename (obj)); +error_setg (errp,"Device '%s' does not support hotplugging" , +object_get_typename (obj));return ; }
system/qdev-monitor.c +1 -1
@@ -918,7 +918,7 @@ void qdev_unplug(DeviceState *dev, Error **errp) }if (!dc->hotpluggable) { -error_setg (errp,QERR_DEVICE_NO_HOTPLUG , +error_setg (errp,"Device '%s' does not support hotplugging" ,object_get_typename (OBJECT (dev)));return ; }
Signature · 1 line
2.44.0
Re: [PATCH 04/10] qapi: Inline and remove QERR_DEVICE_NO_HOTPLUG definition
Quoted 17 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:37 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 04/10] qapi: Inline and removeQERR_DEVICE_NO_HOTPLUG
definitionFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98
("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Mechanical transformation using sed, and manual cleanup.
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- include/qapi/qmp/qerror.h | 3 --- hw/core/qdev.c | 4 ++-- system/qdev-monitor.c | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-)
PATCH 5/10 qapi: Inline and remove QERR_INVALID_PARAMETER definition
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98
("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Mechanical transformation using:
$ sed -i -e "s/QERR_INVALID_PARAMETER,/\"Invalid parameter '%s'\",/" \
$(git grep -lw QERR_INVALID_PARAMETER)Manually simplify qemu_opts_create(), and remove the macro definition in include/qapi/qmp/qerror.h.
--- include/qapi/qmp/qerror.h | 3 --- qapi/opts-visitor.c | 2 +- util/qemu-option.c | 10 +++++----- 3 files changed, 6 insertions(+), 9 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -17,9 +17,6 @@* add new ones! */ -#define QERR_INVALID_PARAMETER \ - "Invalid parameter '%s'" -#define QERR_INVALID_PARAMETER_TYPE \ "Invalid parameter type for '%s', expected: %s"
qapi/opts-visitor.c +1 -1
@@ -184,7 +184,7 @@ opts_check_struct(Visitor *v, Error **errp)const QemuOpt *first; first =g_queue_peek_head (any); -error_setg (errp,QERR_INVALID_PARAMETER , first->name); +error_setg (errp,"Invalid parameter '%s'" , first->name);return false; }return true;
util/qemu-option.c +5 -5
@@ -498,7 +498,7 @@ static bool opt_validate(QemuOpt *opt, Error **errp) desc =find_desc_by_name (list->desc, opt->name);if (!desc && !opts_accepts_any (list)) { -error_setg (errp,QERR_INVALID_PARAMETER , opt->name); +error_setg (errp,"Invalid parameter '%s'" , opt->name);return false; }
@@ -531,7 +531,7 @@ bool qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val, desc =find_desc_by_name (list->desc, name);if (!desc && !opts_accepts_any (list)) { -error_setg (errp,QERR_INVALID_PARAMETER , name); +error_setg (errp,"Invalid parameter '%s'" , name);return false; }
@@ -554,7 +554,7 @@ bool qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val, desc =find_desc_by_name (list->desc, name);if (!desc && !opts_accepts_any (list)) { -error_setg (errp,QERR_INVALID_PARAMETER , name); +error_setg (errp,"Invalid parameter '%s'" , name);return false; }
@@ -612,7 +612,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,if (list->merge_lists) {if (id) { -error_setg (errp,QERR_INVALID_PARAMETER ,"id" ); +error_setg (errp,"Invalid parameter 'id'" );return NULL ; } opts =qemu_opts_find (list,NULL );
@@ -1103,7 +1103,7 @@ bool qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp) QTAILQ_FOREACH(opt, &opts->head, next) { opt->desc =find_desc_by_name (desc, opt->name);if (!opt->desc) { -error_setg (errp,QERR_INVALID_PARAMETER , opt->name); +error_setg (errp,"Invalid parameter '%s'" , opt->name);return false; }
Signature · 1 line
2.44.0
Re: [PATCH 05/10] qapi: Inline and remove QERR_INVALID_PARAMETER definition
Quoted 23 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:38 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 05/10] qapi: Inline and removeQERR_INVALID_PARAMETER
definitionFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98
("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Mechanical transformation using:
$ sed -i -e "s/QERR_INVALID_PARAMETER,/\"Invalid parameter '%s'\",/" \ $(git grep -lw QERR_INVALID_PARAMETER)Manually simplify
qemu_opts_create(), and remove the macro definition ininclude/qapi/qmp/qerror.h.
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- include/qapi/qmp/qerror.h | 3 --- qapi/opts-visitor.c | 2 +- util/qemu-option.c | 10 +++++----- 3 files changed, 6 insertions(+), 9 deletions(-)
PATCH 6/10 qapi: Inline QERR_INVALID_PARAMETER_TYPE definition (constant value)
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98
("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Mechanical transformation using the following
coccinelle semantic patch:
@match@
expression errp;
expression param;
constant value;
@@
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, param, value);
@script:python strformat depends on match@
value << match.value;
fixedfmt; // new var
@@
fixedfmt = f'"Invalid parameter type for \'%s\', expected: {value[1:-1]}"'
coccinelle.fixedfmt = cocci.make_ident(fixedfmt)
@replace@
expression match.errp;
expression match.param;
constant match.value;
identifier strformat.fixedfmt;
@@
- error_setg(errp, QERR_INVALID_PARAMETER_TYPE, param, value);
+ error_setg(errp, fixedfmt, param);--- qapi/qobject-input-visitor.c | 32 ++++++++++++++++---------------- qapi/string-input-visitor.c | 8 ++++---- qom/object.c | 12 ++++++++---- 3 files changed, 28 insertions(+), 24 deletions(-)
qapi/qobject-input-visitor.c +16 -16
@@ -288,8 +288,8 @@ static bool qobject_input_start_struct(Visitor *v, const char *name, void **obj,return false; }if (qobject_type (qobj) !=QTYPE_QDICT ) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"object" ); +error_setg (errp,"Invalid parameter type for '%s', expected: object" , +full_name (qiv, name));return false; }
@@ -326,8 +326,8 @@ static bool qobject_input_start_list(Visitor *v, const char *name,return false; }if (qobject_type (qobj) !=QTYPE_QLIST ) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"array" ); +error_setg (errp,"Invalid parameter type for '%s', expected: array" , +full_name (qiv, name));return false; }
@@ -405,8 +405,8 @@ static bool qobject_input_type_int64(Visitor *v, const char *name, int64_t *obj, } qnum =qobject_to (QNum, qobj);if (!qnum || !qnum_get_try_int (qnum, obj)) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"integer" ); +error_setg (errp,"Invalid parameter type for '%s', expected: integer" , +full_name (qiv, name));return false; }return true;
@@ -494,8 +494,8 @@ static bool qobject_input_type_bool(Visitor *v, const char *name, bool *obj, } qbool =qobject_to (QBool, qobj);if (!qbool) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"boolean" ); +error_setg (errp,"Invalid parameter type for '%s', expected: boolean" , +full_name (qiv, name));return false; }
@@ -534,8 +534,8 @@ static bool qobject_input_type_str(Visitor *v, const char *name, char **obj, } qstr =qobject_to (QString, qobj);if (!qstr) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"string" ); +error_setg (errp,"Invalid parameter type for '%s', expected: string" , +full_name (qiv, name));return false; }
@@ -565,8 +565,8 @@ static bool qobject_input_type_number(Visitor *v, const char *name, double *obj, } qnum =qobject_to (QNum, qobj);if (!qnum) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"number" ); +error_setg (errp,"Invalid parameter type for '%s', expected: number" , +full_name (qiv, name));return false; }
@@ -587,8 +587,8 @@ static bool qobject_input_type_number_keyval(Visitor *v, const char *name,if (qemu_strtod_finite (str,NULL , &val)) {/* TODO report -ERANGE more nicely */ -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"number" ); +error_setg (errp,"Invalid parameter type for '%s', expected: number" , +full_name (qiv, name));return false; }
@@ -623,8 +623,8 @@ static bool qobject_input_type_null(Visitor *v, const char *name, }if (qobject_type (qobj) !=QTYPE_QNULL ) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , -full_name (qiv, name),"null" ); +error_setg (errp,"Invalid parameter type for '%s', expected: null" , +full_name (qiv, name));return false; } *obj =qnull ();
qapi/string-input-visitor.c +4 -4
@@ -353,8 +353,8 @@ static bool parse_type_number(Visitor *v, const char *name, double *obj,assert (siv->lm ==LM_NONE );if (qemu_strtod_finite (siv->string,NULL , &val)) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , name ? name :"null" , -"number" ); +error_setg (errp,"Invalid parameter type for '%s', expected: number" , + name ? name :"null" );return false; }
@@ -371,8 +371,8 @@ static bool parse_type_null(Visitor *v, const char *name, QNull **obj, *obj =NULL ;if (siv->string[0 ]) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , name ? name :"null" , -"null" ); +error_setg (errp,"Invalid parameter type for '%s', expected: null" , + name ? name :"null" );return false; }
qom/object.c +8 -4
@@ -1495,7 +1495,8 @@ char *object_property_get_str(Object *obj, const char *name, } qstring =qobject_to (QString, ret);if (!qstring) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , name,"string" ); +error_setg (errp,"Invalid parameter type for '%s', expected: string" , + name); retval =NULL ; }else { retval =g_strdup (qstring_get_str (qstring));
@@ -1556,7 +1557,8 @@ bool object_property_get_bool(Object *obj, const char *name, } qbool =qobject_to (QBool, ret);if (!qbool) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , name,"boolean" ); +error_setg (errp,"Invalid parameter type for '%s', expected: boolean" , + name); retval = false; }else { retval =qbool_get_bool (qbool);
@@ -1589,7 +1591,8 @@ int64_t object_property_get_int(Object *obj, const char *name, qnum =qobject_to (QNum, ret);if (!qnum || !qnum_get_try_int (qnum, &retval)) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , name,"int" ); +error_setg (errp,"Invalid parameter type for '%s', expected: int" , + name); retval =-1 ; }
@@ -1663,7 +1666,8 @@ uint64_t object_property_get_uint(Object *obj, const char *name, } qnum =qobject_to (QNum, ret);if (!qnum || !qnum_get_try_uint (qnum, &retval)) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , name,"uint" ); +error_setg (errp,"Invalid parameter type for '%s', expected: uint" , + name); retval =0 ; }
Signature · 1 line
2.44.0
Re: [PATCH 06/10] qapi: Inline QERR_INVALID_PARAMETER_TYPE definition (constant value)
Quoted 41 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:39 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 06/10] qapi: InlineQERR_INVALID_PARAMETER_TYPEdefinition
(constant value)From: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98
("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Mechanical transformation using the following
coccinelle semantic patch:@match@ expression errp; expression param; constant value; @@ error_setg(errp, QERR_INVALID_PARAMETER_TYPE, param, value); @script:python strformat depends on match@ value << match.value; fixedfmt; // new var @@ fixedfmt = f'"Invalid parameter type for \'%s\', expected: {value[1:-1]}"' coccinelle.fixedfmt = cocci.make_ident(fixedfmt) @replace@ expression match.errp; expression match.param; constant match.value; identifier strformat.fixedfmt; @@ - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, param, value); + error_setg(errp, fixedfmt, param);
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- qapi/qobject-input-visitor.c | 32 ++++++++++++++++---------------- qapi/string-input-visitor.c | 8 ++++---- qom/object.c | 12 ++++++++---- 3 files changed, 28 insertions(+), 24 deletions(-)
PATCH 7/10 qapi: Inline and remove QERR_INVALID_PARAMETER_TYPE definition
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98
("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Manual changes (escaping the format in qapi/visit.py).
--- include/qapi/qmp/qerror.h | 3 --- qom/object.c | 4 ++-- scripts/qapi/visit.py | 5 ++--- 3 files changed, 4 insertions(+), 8 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -17,9 +17,6 @@* add new ones! */ -#define QERR_INVALID_PARAMETER_TYPE \ - "Invalid parameter type for '%s', expected: %s" -#define QERR_INVALID_PARAMETER_VALUE \ "Parameter '%s' expects %s"
qom/object.c +2 -2
@@ -23,7 +23,6 @@#include "qapi/qobject-input-visitor.h" #include "qapi/forward-visitor.h" #include "qapi/qapi-builtin-visit.h" -#include "qapi/qmp/qerror.h" #include "qapi/qmp/qjson.h" #include "trace.h"
@@ -1912,7 +1911,8 @@ static Object *object_resolve_link(Object *obj, const char *name, }else if (!target) { target =object_resolve_path (path, &ambiguous);if (target || ambiguous) { -error_setg (errp,QERR_INVALID_PARAMETER_TYPE , name, target_type); +error_setg (errp,"Invalid parameter type for '%s', expected: %s" , + name, target_type); }else {error_set (errp,ERROR_CLASS_DEVICE_NOT_FOUND ,"Device '%s' not found" , path);
scripts/qapi/visit.py +2 -3
@@ -278,8 +278,8 @@ def gen_visit_alternate(name: str, variants: QAPISchemaVariants) -> str: abort(); default: assert(visit_is_input(v)); - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", - "%(name)s"); + error_setg(errp, "Invalid parameter type for '%%s', expected: %(name)s", + name ? name : "null"); /* Avoid passing invalid *obj to qapi_free_%(c_name)s() */ g_free(*obj); *obj = NULL;
@@ -356,7 +356,6 @@ def _begin_user_module(self, name: str) -> None: self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/error.h" -#include "qapi/qmp/qerror.h" #include "%(visit)s.h" ''', visit=visit))
Signature · 1 line
2.44.0
Re: [PATCH 07/10] qapi: Inline and remove QERR_INVALID_PARAMETER_TYPE definition
Quoted 17 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:40 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 07/10] qapi: Inline and removeQERR_INVALID_PARAMETER_TYPE
definitionFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98
("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Manual changes (escaping the format in
qapi/visit.py).
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- include/qapi/qmp/qerror.h | 3 --- qom/object.c | 4 ++-- scripts/qapi/visit.py | 5 ++--- 3 files changed, 4 insertions(+), 8 deletions(-)
PATCH 8/10 qapi: Correct error message for 'vcpu_dirty_limit' parameter
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
QERR_INVALID_PARAMETER_VALUE is defined as:
#define QERR_INVALID_PARAMETER_VALUE \
"Parameter '%s' expects %s"The current error is formatted as:
"Parameter 'vcpu_dirty_limit' expects is invalid, it must greater then 1 MB/s"
Replace by:
"Parameter 'vcpu_dirty_limit' is invalid, it must greater than 1 MB/s"
--- migration/options.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
migration/options.c +2 -3
@@ -1264,9 +1264,8 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)if (params->has_vcpu_dirty_limit && (params->vcpu_dirty_limit <1 )) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE , -"vcpu_dirty_limit" , -"is invalid, it must greater then 1 MB/s" ); +error_setg (errp,"Parameter 'vcpu_dirty_limit' is invalid," +" it must greater than 1 MB/s" );return false; }
Signature · 1 line
2.44.0
Re: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit' parameter
Quoted 12 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:41 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit'
parameterFrom: Philippe Mathieu-Daudé <[email protected]>
QERR_INVALID_PARAMETER_VALUEis defined as:#define QERR_INVALID_PARAMETER_VALUE \ "Parameter '%s' expects %s"
Quoted 7 lines
The current error is formatted as:
"Parameter '
vcpu_dirty_limit' expects is invalid, it must greater then 1 MB/s"Replace by:
"Parameter '
vcpu_dirty_limit' is invalid, it must greater than 1 MB/s"
Is there a grammar error here? Maybe
s/it must greater/it must be greater/
Quoted 13 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Juan Quintela <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- migration/options.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)migration/options.c +0
-0@@ -1264,9 +1264,8 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1271
Quoted 10 lines
migration/options.c +2
-3if (params->has_vcpu_dirty_limit && (params->vcpu_dirty_limit <1 )) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE , -"vcpu_dirty_limit" , -"is invalid, it must greater then 1 MB/s" ); +error_setg (errp,"Parameter 'vcpu_dirty_limit' is invalid," +" it must greater than 1 MB/s" );return false; }
Otherwise,
Re: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit' parameter
Quoted 17 lines · Zhao Liu
Quoted 16 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:41 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit'
parameterFrom: Philippe Mathieu-Daudé <[email protected]>
QERR_INVALID_PARAMETER_VALUEis defined as:#define QERR_INVALID_PARAMETER_VALUE \ "Parameter '%s' expects %s"The current error is formatted as:
"Parameter '
vcpu_dirty_limit' expects is invalid, it must greater then 1 MB/s"
Quoted 7 lines
Quoted 3 lines
Replace by:
"Parameter '
vcpu_dirty_limit' is invalid, it must greater than 1 MB/s"Is there a grammar error here? Maybe
s/it must greater/it must be greater/
Oops indeed!
Quoted 14 lines
Quoted 14 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Juan Quintela <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- migration/options.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)migration/options.c +0
-0@@ -1264,9 +1264,8 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
Quoted 7 lines
migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1268
Quoted 7 lines
migration/options.c +2
-3if (params->has_vcpu_dirty_limit && (params->vcpu_dirty_limit <1 )) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE , -"vcpu_dirty_limit" , -"is invalid, it must greater then 1 MB/s" ); +error_setg (errp,"Parameter 'vcpu_dirty_limit' is invalid," +" it must greater than 1 MB/s" );
So s/it must greater/it must be greater/ :)
Quoted 8 lines
migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1271
Quoted 3 lines
migration/options.c +0
-0return false; }Otherwise,
Reviewed-by Zhao Liu <[email protected]>
Re: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit' parameter
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Zhao Liu
Quoted 16 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:41 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit'
parameterFrom: Philippe Mathieu-Daudé <[email protected]>
QERR_INVALID_PARAMETER_VALUEis defined as:#define QERR_INVALID_PARAMETER_VALUE \ "Parameter '%s' expects %s"The current error is formatted as:
"Parameter '
vcpu_dirty_limit' expects is invalid, it must greater then 1 MB/s"
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Replace by:
"Parameter '
vcpu_dirty_limit' is invalid, it must greater than 1 MB/s"Is there a grammar error here? Maybe
s/it must greater/it must be greater/Oops indeed!
What about dropping "is invalid, "? I.e. go with
"Parameter 'vcpu_dirty_limit' must be greater than 1 MB/s"
Quoted 28 lines
Quoted 7 lines
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Juan Quintela <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- migration/options.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)Quoted 12 lines
migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1267
Quoted 12 lines
migration/options.c +2
-3@@ -1264,9 +1264,8 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)if (params->has_vcpu_dirty_limit && (params->vcpu_dirty_limit <1 )) { -error_setg (errp,QERR_INVALID_PARAMETER_VALUE , -"vcpu_dirty_limit" , -"is invalid, it must greater then 1 MB/s" ); +error_setg (errp,"Parameter 'vcpu_dirty_limit' is invalid," +" it must greater than 1 MB/s" );So s/it must greater/it must be greater/ :)
Quoted 6 lines
migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1271
Quoted 3 lines
migration/options.c +0
-0return false; }Otherwise,
Reviewed-by Zhao Liu <[email protected]>
Re: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit' parameter
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · Philippe Mathieu-Daudé
Quoted 21 lines · Zhao Liu
Quoted 19 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:41 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 08/10] qapi: Correct error message for 'vcpu_dirty_limit'
parameterFrom: Philippe Mathieu-Daudé <[email protected]>
QERR_INVALID_PARAMETER_VALUEis defined as:#define
QERR_INVALID_PARAMETER_VALUE\
"Parameter '%s' expects %s"The current error is formatted as:
"Parameter '
vcpu_dirty_limit' expects is invalid, it must greater then 1 MB/s"Replace by:
"Parameter '
vcpu_dirty_limit' is invalid, it must greater than 1 MB/s"
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Is there a grammar error here? Maybe
s/it must greater/it must be greater/Oops indeed!
What about dropping "is invalid, "? I.e. go with
"Parameter '
vcpu_dirty_limit' must be greater than 1 MB/s"
Yes.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Juan Quintela <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- migration/options.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
PATCH 9/10 qapi: Inline and remove QERR_MIGRATION_ACTIVE definition
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98 ("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Mechanical transformation using sed, manually removing the definition in include/qapi/qmp/qerror.h.
--- include/qapi/qmp/qerror.h | 3 --- migration/migration.c | 2 +- migration/options.c | 4 ++-- migration/savevm.c | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -23,9 +23,6 @@#define QERR_IO_ERROR \ "An IO error has occurred" -#define QERR_MIGRATION_ACTIVE \ - "There's a migration process in progress" -#define QERR_MISSING_PARAMETER \ "Parameter '%s' is missing"
migration/migration.c +1 -1
@@ -1961,7 +1961,7 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc, }if (migration_is_running (s->state)) { -error_setg (errp,QERR_MIGRATION_ACTIVE ); +error_setg (errp,"There's a migration process in progress" );return false; }
migration/options.c +2 -2
@@ -682,7 +682,7 @@ bool migrate_cap_set(int cap, bool value, Error **errp)bool new_caps[MIGRATION_CAPABILITY__MAX ];if (migration_is_running (s->state)) { -error_setg (errp,QERR_MIGRATION_ACTIVE ); +error_setg (errp,"There's a migration process in progress" );return false; }
@@ -726,7 +726,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,bool new_caps[MIGRATION_CAPABILITY__MAX ];if (migration_is_running (s->state) ||migration_in_colo_state ()) { -error_setg (errp,QERR_MIGRATION_ACTIVE ); +error_setg (errp,"There's a migration process in progress" );return ; }
migration/savevm.c +1 -1
@@ -1706,7 +1706,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)MigrationStatus status;if (migration_is_running (ms->state)) { -error_setg (errp,QERR_MIGRATION_ACTIVE ); +error_setg (errp,"There's a migration process in progress" );return -EINVAL ; }
Signature · 1 line
2.44.0
Re: [PATCH 09/10] qapi: Inline and remove QERR_MIGRATION_ACTIVE definition
Quoted 21 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:42 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 09/10] qapi: Inline and removeQERR_MIGRATION_ACTIVE
definitionFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Mechanical transformation using sed, manually removing the definition in
include/qapi/qmp/qerror.h.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Juan Quintela <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 6 lines
--- include/qapi/qmp/qerror.h | 3 --- migration/migration.c | 2 +- migration/options.c | 4 ++-- migration/savevm.c | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-)
PATCH 10/10 qapi: Inline and remove QERR_PROPERTY_VALUE_BAD definition
In reply to Markus ArmbrusterFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit 4629ed1e98
("qerror: Finally unused, clean up"), from 2015:
/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/
Manual change. Remove the definition ininclude/qapi/qmp/qerror.h.
--- include/qapi/qmp/qerror.h | 3 --- hw/core/qdev-properties.c | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-)
include/qapi/qmp/qerror.h +0 -3
@@ -26,9 +26,6 @@#define QERR_MISSING_PARAMETER \ "Parameter '%s' is missing" -#define QERR_PROPERTY_VALUE_BAD \ - "Property '%s.%s' doesn't take value '%s'" -#define QERR_PROPERTY_VALUE_OUT_OF_RANGE \ "Property %s.%s doesn't take value %" PRId64 " (minimum: %" PRId64 ", maximum: %" PRId64 ")"
hw/core/qdev-properties.c +1 -2
@@ -2,7 +2,6 @@#include "hw/qdev-properties.h" #include "qapi/error.h" #include "qapi/qapi-types-misc.h" -#include "qapi/qmp/qerror.h" #include "qapi/qmp/qlist.h" #include "qemu/ctype.h" #include "qemu/error-report.h"
@@ -792,7 +791,7 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,break ;default :case -EINVAL : -error_setg (errp,QERR_PROPERTY_VALUE_BAD , +error_setg (errp,"Property '%s.%s' doesn't take value '%s'" ,object_get_typename (obj), name, value);break ;case -ENOENT :
Signature · 1 line
2.44.0
Re: [PATCH 10/10] qapi: Inline and remove QERR_PROPERTY_VALUE_BAD definition
Quoted 18 lines · Markus Armbruster
Date: Tue, 12 Mar 2024 15:13:43 +0100
From: Markus Armbruster <[email protected]>
Subject: [PATCH 10/10] qapi: Inline and removeQERR_PROPERTY_VALUE_BAD
definitionFrom: Philippe Mathieu-Daudé <[email protected]>
Address the comment added in commit
4629ed1e98
("qerror: Finally unused, clean up"), from 2015:/*
* These macros will go away, please don't use
* in new code, and do not add new ones!
*/Manual change. Remove the definition in
include/qapi/qmp/qerror.h.
Quoted 6 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- include/qapi/qmp/qerror.h | 3 --- hw/core/qdev-properties.c | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-)
Markus Armbruster
AppliedQuoted 6 lines · Markus Armbruster
Philippe posted "[PATCH v2 00/22] qapi: Kill '
qapi/qmp/qerror.h' for good" a couple of months ago. I cherry-picked just its simplest parts for now.Markus Armbruster (1):
error: Drop superfluous #include "qapi/qmp/qerror.h"
Queued for 9.1 with PATCH 08's new error message fixed. Thanks!