qerror: add check-qerror.sh to verify alphabetical order
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/3 qerror: add check-qerror.sh to verify alphabetical order
We're supposed to keep qerror definitions and table entries in alphabetical order. In practice this is not checked.
I haven't found a nice way to integrate this into the makefile yet but we can at least have this script which verifies that qerrors are in alphabetical order.
--- qerror.c | 3 +-- qerror.h | 2 +- scripts/check-qerror.sh | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 scripts/check-qerror.sh
qerror.c +1 -2
@@ -40,8 +40,7 @@ static const QType qerror_type = {* "running out of foo: %(foo)%%" * * Please keep the entries in alphabetical order. -* Use "sed -n '/^static.*qerror_table\[\]/,/^};/s/QERR_/&/gp' qerror.c | sort -c" -* to check. +* Use scripts/check-qerror.sh to check. */ static const QErrorStringTable qerror_table[] = { {
qerror.h +1 -1
@@ -49,7 +49,7 @@ QError *qobject_to_qerror(const QObject *obj);/* * QError class list * Please keep the definitions in alphabetical order. -* Use "grep '^#define QERR_' qerror.h | sort -c" to check. +* Use scripts/check-qerror.sh to check. */ #define QERR_BAD_BUS_FOR_DEVICE \ "{ 'class': 'BadBusForDevice', 'data': { 'device': %s, 'bad_bus_type': %s } }"
scripts/check-qerror.sh new file +22 -0
@@ -0,0 +1,22 @@ +#!/bin/sh +# This script verifies that qerror definitions and table entries are +# alphabetically ordered. + +check_order() { + errmsg=$1 + shift + + # sort -C verifies order but does not print a message. sort -c does print a + # message. These options are both in POSIX. + if ! "$@" | sort -C; then + echo "$errmsg" + "$@" | sort -c + exit 1 + fi + return 0 +} + +check_order 'Definitions in qerror.h must be in alphabetical order:' \ + grep '^#define QERR_' qerror.h +check_order 'Entries in qerror.c:qerror_table must be in alphabetical order:' \ + sed -n '/^static.*qerror_table\[\]/,/^};/s/QERR_/&/gp' qerror.c
Signature · 1 line
1.7.7.3
Quoted 8 lines · On Wed, 4 Jan 2012 22:23:32 +0000 Stefan Hajnoczi…
We're supposed to keep qerror definitions and table entries in alphabetical order. In practice this is not checked.
I haven't found a nice way to integrate this into the makefile yet but we can at least have this script which verifies that qerrors are in alphabetical order.
Signed-off-by Stefan Hajnoczi <[email protected]>
I've applied these two patches plus v1 2/2, is this correct?
Quoted 62 lines
--- qerror.c | 3 +-- qerror.h | 2 +- scripts/check-qerror.sh | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 scripts/check-qerror.shqerror.c +1
-2@@ -40,8 +40,7 @@ static const QType qerror_type = {* "running out of foo: %(foo)%%" * * Please keep the entries in alphabetical order. -* Use "sed -n '/^static.*qerror_table\[\]/,/^};/s/QERR_/&/gp' qerror.c | sort -c" -* to check. +* Use scripts/check-qerror.sh to check. */ static const QErrorStringTable qerror_table[] = { {qerror.h +1
-1@@ -49,7 +49,7 @@ QError *qobject_to_qerror(const QObject *obj);/* * QError class list * Please keep the definitions in alphabetical order. -* Use "grep '^#define QERR_' qerror.h | sort -c" to check. +* Use scripts/check-qerror.sh to check. */ #define QERR_BAD_BUS_FOR_DEVICE \ "{ 'class': 'BadBusForDevice', 'data': { 'device': %s, 'bad_bus_type': %s } }"scripts/check-qerror.sh new file +22
-0@@ -0,0 +1,22 @@ +#!/bin/sh +# This script verifies that qerror definitions and table entries are +# alphabetically ordered. + +check_order() { + errmsg=$1 + shift + + # sort -C verifies order but does not print a message. sort -c does print a + # message. These options are both in POSIX. + if ! "$@" | sort -C; then + echo "$errmsg" + "$@" | sort -c + exit 1 + fi + return 0 +} + +check_order 'Definitions in qerror.h must be in alphabetical order:' \ + grep '^#define QERR_' qerror.h +check_order 'Entries in qerror.c:qerror_table must be in alphabetical order:' \ + sed -n '/^static.*qerror_table\[\]/,/^};/s/QERR_/&/gp' qerror.c
Quoted 6 lines · Luiz Capitulino
Quoted 3 lines · On Wed, 4 Jan 2012 22:23:32 +0000 Stefan Hajnoczi…
We're supposed to keep qerror definitions and table entries in alphabetical order. In practice this is not checked.
Quoted 7 lines
Quoted 5 lines
I haven't found a nice way to integrate this into the makefile yet but we can at least have this script which verifies that qerrors are in alphabetical order.
Signed-off-by Stefan Hajnoczi <[email protected]>I've applied these two patches plus v1 2/2, is this correct?
Yes, v1 2/3 is unchanged. Normally I send the entire series out, I'm not sure why the email went missing this time.
Thanks!
Stefan
PATCH v2 3/3 block: use proper qerrors in qmp_block_resize
In reply to a message not in the archiveLet's report specific errors so that management tools and users can identify the problem.
Two new qerrors are needed:
* QERR_DEVICE_HAS_NO_MEDIUM for ENOMEDIUM
* QERR_DEVICE_IS_READ_ONLY for EACCES
--- blockdev.c | 26 ++++++++++++++++++-------- qapi-schema.json | 7 +++++-- qerror.c | 8 ++++++++ qerror.h | 6 ++++++ 4 files changed, 37 insertions(+), 10 deletions(-)
blockdev.c +18 -8
@@ -841,11 +841,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)return 0 ; } -/* -* XXX: replace the QERR_UNDEFINED_ERROR errors with real values once the -* existing QERR_ macro mess is cleaned up. A good example for better -* error reports can be found in the qemu-img resize code. -*/ void qmp_block_resize (const char *device,int64_t size,Error **errp) {BlockDriverState *bs;
@@ -857,12 +852,27 @@ void qmp_block_resize(const char *device, int64_t size, Error **errp) }if (size <0 ) { -error_set (errp,QERR_UNDEFINED_ERROR ); +error_set (errp,QERR_INVALID_PARAMETER_VALUE ,"size" ,"a >0 size" );return ; } -if (bdrv_truncate (bs, size)) { +switch (bdrv_truncate (bs, size)) { +case 0 : +break ; +case -ENOMEDIUM : +error_set (errp,QERR_DEVICE_HAS_NO_MEDIUM , device); +break ; +case -ENOTSUP : +error_set (errp,QERR_UNSUPPORTED ); +break ; +case -EACCES : +error_set (errp,QERR_DEVICE_IS_READ_ONLY , device); +break ; +case -EBUSY : +error_set (errp,QERR_DEVICE_IN_USE , device); +break ; +default :error_set (errp,QERR_UNDEFINED_ERROR ); -return ; +break ; } }
qapi-schema.json +5 -2
@@ -1064,8 +1064,11 @@ # # Returns: nothing on success # If @device is not a valid block device, DeviceNotFound -# -# Notes: This command returns UndefinedError in a number of error conditions. +# If @size is negative, InvalidParameterValue +# If the block device has no medium inserted, DeviceHasNoMedium +# If the block device does not support resize, Unsupported +# If the block device is read-only, DeviceIsReadOnly +# If a long-running operation is using the device, DeviceInUse # # Since: 0.14.0 ##
qerror.c +8 -0
@@ -80,6 +80,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Migration is disabled when using feature '%(feature)' in device '%(device)'", }, { + .error_fmt = QERR_DEVICE_HAS_NO_MEDIUM, + .desc = "Device '%(device)' has no medium", + }, + { .error_fmt = QERR_DEVICE_INIT_FAILED, .desc = "Device '%(device)' could not be initialized", },
@@ -88,6 +92,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device '%(device)' is in use", }, { + .error_fmt = QERR_DEVICE_IS_READ_ONLY, + .desc = "Device '%(device)' is read only", + }, + { .error_fmt = QERR_DEVICE_LOCKED, .desc = "Device '%(device)' is locked", },
qerror.h +6 -0
@@ -81,12 +81,18 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_FEATURE_BLOCKS_MIGRATION \ "{ 'class': 'DeviceFeatureBlocksMigration', 'data': { 'device': %s, 'feature': %s } }" +#define QERR_DEVICE_HAS_NO_MEDIUM \ + "{ 'class': 'DeviceHasNoMedium', 'data': { 'device': %s } }" +#define QERR_DEVICE_INIT_FAILED \ "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }"#define QERR_DEVICE_IN_USE \ "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }" +#define QERR_DEVICE_IS_READ_ONLY \ + "{ 'class': 'DeviceIsReadOnly', 'data': { 'device': %s } }" +#define QERR_DEVICE_LOCKED \ "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"
Signature · 1 line
1.7.7.3