QError conversions and more
cover QError conversions and more
This patch series converts monitor commands eject, change, closefd, getfd to QError.
There's a simple bonus fix in PATCH 3.
Finally, PATCH 18 puts a human-readable error description into the QMP error response. For background, see the lengthy thread ending at
http://lists.gnu.org/archive/html/qemu-devel/2009-11/msg01221.html
Series should be applied after Luiz's work.
Luiz Capitulino (2):
QError: new class for device encrypted errors
monitor: do_cont(): Don't ask for passwords
Markus Armbruster (16):
monitor: Fix double-prompt after "change vnc passwd BLA"
QError: Put error definitions in alphabetical order
QError: New QERR_DEVICE_LOCKED
QError: New QERR_DEVICE_NOT_REMOVABLE
monitor: convert do_eject() to QError
QError: New QERR_INVALID_BLOCK_FORMAT
QError: New QERR_SET_PASSWD_FAILED
QError: New QERR_VNC_SERVER_FAILED
monitor: convert do_change() to QObject, QError
QError: New QERR_FD_NOT_FOUND
monitor: convert do_closefd() to QError
QError: New QERR_FD_NOT_SUPPLIED
New QERR_INVALID_PARAMETER
QError: New QERR_TOO_MANY_FILES
monitor: convert do_getfd() to QError
QMP: add human-readable description to error response
QMP/qmp-spec.txt | 5 ++- monitor.c | 55 +++++++++++++++++++++++----------- qemu-monitor.hx | 3 +- qerror.c | 85 +++++++++++++++++++++++++++++++++++++++++++----------- qerror.h | 56 ++++++++++++++++++++++++++++------- 5 files changed, 155 insertions(+), 49 deletions(-)
PATCH 1/18 QError: new class for device encrypted errors
From: Luiz Capitulino <[email protected]>
--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -45,6 +45,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "The command %(name) has not been found", }, { + .error_fmt = QERR_DEVICE_ENCRYPTED, + .desc = "The %(device) is encrypted", + }, + { .error_fmt = QERR_DEVICE_NOT_FOUND, .desc = "The %(device) device has not been found", },
qerror.h +3 -0
@@ -41,6 +41,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_COMMAND_NOT_FOUND \ "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }" +#define QERR_DEVICE_ENCRYPTED \ + "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" +#define QERR_DEVICE_NOT_FOUND \ "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"
Signature · 1 line
1.6.2.5
PATCH 2/18 monitor: do_cont(): Don't ask for passwords
In reply to Markus ArmbrusterFrom: Luiz Capitulino <[email protected]>
The do_cont() function will ask the user to enter a password if a device is encrypted.
This is invalid under QMP, so we raise a QERR_DEVICE_ENCRYPTED error.
--- monitor.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
monitor.c +9 -1
@@ -148,7 +148,10 @@ static void monitor_read_command(Monitor *mon, int show_prompt)static int monitor_read_password (Monitor *mon,ReadLineFunc *readline_func,void *opaque) { -if (mon->rs) { +if (monitor_ctrl_mode (mon)) { +qemu_error_new (QERR_MISSING_PARAMETER ,"password" ); +return -EINVAL ; + }else if (mon->rs) {readline_start (mon->rs,"Password: " ,1 , readline_func, opaque);/* prompt is printed on return from the command handler */ return 0 ;
@@ -4188,6 +4191,11 @@ void monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,return ; } +if (monitor_ctrl_mode (mon)) { +qemu_error_new (QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs)); +return ; + } +monitor_printf (mon,"%s (%s) is encrypted.\n" ,bdrv_get_device_name (bs),bdrv_get_encrypted_filename (bs));
Signature · 1 line
1.6.2.5
PATCH 3/18 monitor: Fix double-prompt after "change vnc passwd BLA"
In reply to Markus Armbruster--- monitor.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
monitor.c +8 -3
@@ -845,12 +845,17 @@ static void do_change_block(Monitor *mon, const char *device,monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); } -static void change_vnc_password_cb (Monitor *mon,const char *password, -void *opaque) +static void change_vnc_password (Monitor *mon,const char *password) {if (vnc_display_password (NULL , password) <0 )monitor_printf (mon,"could not set VNC server password\n" ); +} + +static void change_vnc_password_cb (Monitor *mon,const char *password, +void *opaque) +{ +change_vnc_password (mon, password);monitor_read_command (mon,1 ); }
@@ -862,7 +867,7 @@ static void do_change_vnc(Monitor *mon, const char *target, const char *arg)char password[9 ];strncpy (password, arg,sizeof (password)); password[sizeof (password) -1 ] ='\0' ; -change_vnc_password_cb (mon, password,NULL ); +change_vnc_password (mon, password); }else {monitor_read_password (mon, change_vnc_password_cb,NULL ); }
Signature · 1 line
1.6.2.5
PATCH 4/18 QError: Put error definitions in alphabetical order
In reply to Markus ArmbrusterAlso fix the odd typoe and clean up whitespace.
--- qerror.c | 28 ++++++++++++++-------------- qerror.h | 30 +++++++++++++++--------------- 2 files changed, 29 insertions(+), 29 deletions(-)
qerror.c +14 -14
@@ -41,28 +41,32 @@ static const QType qerror_type = {*/ static const QErrorStringTable qerror_table[] = { { - .error_fmt =QERR_COMMAND_NOT_FOUND , - .desc ="The command %(name) has not been found" , + .error_fmt =QERR_COMMAND_NOT_FOUND , + .desc ="The command %(name) has not been found" , }, { .error_fmt =QERR_DEVICE_ENCRYPTED , .desc ="The %(device) is encrypted" , }, { + .error_fmt =QERR_DEVICE_NOT_ACTIVE , + .desc ="The %(device) device has not been activated by the guest" , + }, + { .error_fmt =QERR_DEVICE_NOT_FOUND , .desc ="The %(device) device has not been found" , }, { - .error_fmt =QERR_DEVICE_NOT_ACTIVE , - .desc ="The %(device) device has not been activated by the guest" , + .error_fmt =QERR_INVALID_PARAMETER_TYPE , + .desc ="Invalid parameter type, expected: %(expected)" , }, { - .error_fmt =QERR_INVALID_PARAMETER_TYPE , - .desc ="Invalid parameter type, expected: %(expected)" , + .error_fmt =QERR_INVALID_PASSWORD , + .desc ="The entered password is invalid" , }, { - .error_fmt =QERR_INVALID_PASSWORD , - .desc ="The entered password is invalid" , + .error_fmt =QERR_JSON_PARSING , + .desc ="Invalid JSON syntax" , }, { .error_fmt =QERR_KVM_MISSING_CAP ,
@@ -77,12 +81,8 @@ static const QErrorStringTable qerror_table[] = { .desc = "Bad QMP input object", }, { - .error_fmt = QERR_JSON_PARSING, - .desc = "Invalid JSON synaxt", - }, - { - .error_fmt = QERR_UNDEFINED_ERROR, - .desc = "An undefined error has ocurred", + .error_fmt = QERR_UNDEFINED_ERROR, + .desc = "An undefined error has ocurred", }, {} };
qerror.h +15 -15
@@ -39,36 +39,36 @@ QError *qobject_to_qerror(const QObject *obj);* QError class list */ #define QERR_COMMAND_NOT_FOUND \ - "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }" + "{ 'class': 'CommandNotFound', 'data': { 'name': %s } }"#define QERR_DEVICE_ENCRYPTED \ - "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" - -#define QERR_DEVICE_NOT_FOUND \ - "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }" + "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }"#define QERR_DEVICE_NOT_ACTIVE \ - "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }" + "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }" + +#define QERR_DEVICE_NOT_FOUND \ + "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }"#define QERR_INVALID_PARAMETER_TYPE \ - "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }" + "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }"#define QERR_INVALID_PASSWORD \ - "{ 'class': 'InvalidPassword', 'data': {} }" + "{ 'class': 'InvalidPassword', 'data': {} }" + +#define QERR_JSON_PARSING \ + "{ 'class': 'JSONParsing', 'data': {} }"#define QERR_KVM_MISSING_CAP \ - "{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }" + "{ 'class': 'KVMMissingCap', 'data': { 'capability': %s, 'feature': %s } }"#define QERR_MISSING_PARAMETER \ - "{ 'class': 'MissingParameter', 'data': { 'name': %s } }" + "{ 'class': 'MissingParameter', 'data': { 'name': %s } }"#define QERR_QMP_BAD_INPUT_OBJECT \ - "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }" - -#define QERR_JSON_PARSING \ - "{ 'class': 'JSONParsing', 'data': {} }" + "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }"#define QERR_UNDEFINED_ERROR \ - "{ 'class': 'UndefinedError', 'data': {} }" + "{ 'class': 'UndefinedError', 'data': {} }"#endif /* QERROR_H */
Signature · 1 line
1.6.2.5
PATCH 5/18 QError: New QERR_DEVICE_LOCKED
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -49,6 +49,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "The %(device) is encrypted", }, { + .error_fmt = QERR_DEVICE_LOCKED, + .desc = "Device %(device) is locked", + }, + { .error_fmt = QERR_DEVICE_NOT_ACTIVE, .desc = "The %(device) device has not been activated by the guest", },
qerror.h +3 -0
@@ -44,6 +44,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_ENCRYPTED \ "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" +#define QERR_DEVICE_LOCKED \ + "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }" +#define QERR_DEVICE_NOT_ACTIVE \ "{ 'class': 'DeviceNotActive', 'data': { 'device': %s } }"
Signature · 1 line
1.6.2.5
PATCH 6/18 QError: New QERR_DEVICE_NOT_REMOVABLE
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -61,6 +61,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "The %(device) device has not been found", }, { + .error_fmt = QERR_DEVICE_NOT_REMOVABLE, + .desc = "Device %(device) is not removable", + }, + { .error_fmt = QERR_INVALID_PARAMETER_TYPE, .desc = "Invalid parameter type, expected: %(expected)", },
qerror.h +3 -0
@@ -53,6 +53,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_NOT_FOUND \ "{ 'class': 'DeviceNotFound', 'data': { 'device': %s } }" +#define QERR_DEVICE_NOT_REMOVABLE \ + "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }" +#define QERR_INVALID_PARAMETER_TYPE \ "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }"
Signature · 1 line
1.6.2.5
PATCH 7/18 monitor: convert do_eject() to QError
In reply to Markus ArmbrusterAlso affects do_change(), because the two share eject_device().
--- monitor.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
monitor.c +4 -3
@@ -778,11 +778,12 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force)if (bdrv_is_inserted (bs)) {if (!force) {if (!bdrv_is_removable (bs)) { -monitor_printf (mon,"device is not removable\n" ); +qemu_error_new (QERR_DEVICE_NOT_REMOVABLE , +bdrv_get_device_name (bs));return -1 ; }if (bdrv_is_locked (bs)) { -monitor_printf (mon,"device is locked\n" ); +qemu_error_new (QERR_DEVICE_LOCKED ,bdrv_get_device_name (bs));return -1 ; } }
@@ -799,7 +800,7 @@ static void do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data) bs =bdrv_find (filename);if (!bs) { -monitor_printf (mon,"device not found\n" ); +qemu_error_new (QERR_DEVICE_NOT_FOUND , filename);return ; }eject_device (mon, bs, force);
Signature · 1 line
1.6.2.5
PATCH 8/18 QError: New QERR_INVALID_BLOCK_FORMAT
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -65,6 +65,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device %(device) is not removable", }, { + .error_fmt = QERR_INVALID_BLOCK_FORMAT, + .desc = "Invalid block format %(name)", + }, + { .error_fmt = QERR_INVALID_PARAMETER_TYPE, .desc = "Invalid parameter type, expected: %(expected)", },
qerror.h +3 -0
@@ -56,6 +56,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_NOT_REMOVABLE \ "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }" +#define QERR_INVALID_BLOCK_FORMAT \ + "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }" +#define QERR_INVALID_PARAMETER_TYPE \ "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }"
Signature · 1 line
1.6.2.5
PATCH 9/18 QError: New QERR_SET_PASSWD_FAILED
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -93,6 +93,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Bad QMP input object", }, { + .error_fmt = QERR_SET_PASSWD_FAILED, + .desc = "Could not set password", + }, + { .error_fmt = QERR_UNDEFINED_ERROR, .desc = "An undefined error has ocurred", },
qerror.h +3 -0
@@ -77,6 +77,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_QMP_BAD_INPUT_OBJECT \ "{ 'class': 'QMPBadInputObject', 'data': { 'expected': %s } }" +#define QERR_SET_PASSWD_FAILED \ + "{ 'class': 'SetPasswdFailed', 'data': {} }" +#define QERR_UNDEFINED_ERROR \ "{ 'class': 'UndefinedError', 'data': {} }"
Signature · 1 line
1.6.2.5
PATCH 10/18 QError: New QERR_VNC_SERVER_FAILED
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -100,6 +100,10 @@ static const QErrorStringTable qerror_table[] = { .error_fmt = QERR_UNDEFINED_ERROR, .desc = "An undefined error has ocurred", }, + { + .error_fmt = QERR_VNC_SERVER_FAILED, + .desc = "Could not start VNC server on %(target)", + }, {} };
qerror.h +3 -0
@@ -83,4 +83,7 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_UNDEFINED_ERROR \ "{ 'class': 'UndefinedError', 'data': {} }" +#define QERR_VNC_SERVER_FAILED \ + "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }" +#endif /* QERROR_H */
Signature · 1 line
1.6.2.5
PATCH 11/18 monitor: convert do_change() to QObject, QError
In reply to Markus Armbruster--- monitor.c | 19 +++++++++++-------- qemu-monitor.hx | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-)
monitor.c +11 -8
@@ -830,13 +830,13 @@ static void do_change_block(Monitor *mon, const char *device, bs =bdrv_find (device);if (!bs) { -monitor_printf (mon,"device not found\n" ); +qemu_error_new (QERR_DEVICE_NOT_FOUND , device);return ; }if (fmt) { drv =bdrv_find_whitelisted_format (fmt);if (!drv) { -monitor_printf (mon,"invalid format %s\n" , fmt); +qemu_error_new (QERR_INVALID_BLOCK_FORMAT , fmt);return ; } }
@@ -846,17 +846,17 @@ static void do_change_block(Monitor *mon, const char *device,monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); } -static void change_vnc_password (Monitor *mon,const char *password) +static void change_vnc_password (const char *password) {if (vnc_display_password (NULL , password) <0 ) -monitor_printf (mon,"could not set VNC server password\n" ); +qemu_error_new (QERR_SET_PASSWD_FAILED ); }static void change_vnc_password_cb (Monitor *mon,const char *password,void *opaque) { -change_vnc_password (mon, password); +change_vnc_password (password);monitor_read_command (mon,1 ); }
@@ -868,17 +868,20 @@ static void do_change_vnc(Monitor *mon, const char *target, const char *arg)char password[9 ];strncpy (password, arg,sizeof (password)); password[sizeof (password) -1 ] ='\0' ; -change_vnc_password (mon, password); +change_vnc_password (password); }else {monitor_read_password (mon, change_vnc_password_cb,NULL ); } }else {if (vnc_display_open (NULL , target) <0 ) -monitor_printf (mon,"could not start VNC server on %s\n" , target); +qemu_error_new (QERR_VNC_SERVER_FAILED , target); } } -static void do_change (Monitor *mon,const QDict *qdict) +/** +* do_change(): Change a removable medium, or VNC configuration +*/ +static void do_change (Monitor *mon,const QDict *qdict,QObject **ret_data) {const char *device =qdict_get_str (qdict,"device" );const char *target =qdict_get_str (qdict,"target" );
qemu-monitor.hx +2 -1
@@ -147,7 +147,8 @@ ETEXI .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]", .help = "change a removable medium, optional format", - .mhandler.cmd = do_change, + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_change, }, STEXI
Signature · 1 line
1.6.2.5
PATCH 12/18 QError: New QERR_FD_NOT_FOUND
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -65,6 +65,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Device %(device) is not removable", }, { + .error_fmt = QERR_FD_NOT_FOUND, + .desc = "Failed to find file descriptor named %(name)", + }, + { .error_fmt = QERR_INVALID_BLOCK_FORMAT, .desc = "Invalid block format %(name)", },
qerror.h +3 -0
@@ -56,6 +56,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_NOT_REMOVABLE \ "{ 'class': 'DeviceNotRemovable', 'data': { 'device': %s } }" +#define QERR_FD_NOT_FOUND \ + "{ 'class': 'fd_not_found', 'data': { 'name': %s } }" +#define QERR_INVALID_BLOCK_FORMAT \ "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }"
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [FOR 0.12 PATCH 12/18] QError: New QERR_FD_NOT_FOUND
qerror.h QError *qobject_to_qerror(const QObject *obj); · line 61
Quoted 3 lines · On Mon, 7 Dec 2009 21:37:10 +0100 Markus Armbruster <[email protected]> wrote:
qerror.h +3
-0+#define QERR_FD_NOT_FOUND \ + "{ 'class': 'fd_not_found', 'data': { 'name': %s } }" +
I think this came from your previous series of not using CamelCase?
Also happens in next patches..
[Qemu-devel] Re: [FOR 0.12 PATCH 12/18] QError: New QERR_FD_NOT_FOUND
Quoted 10 lines · Luiz Capitulino
qerror.h QError *qobject_to_qerror(const QObject *obj); · line 61
Quoted 3 lines · On Mon, 7 Dec 2009 21:37:10 +0100 Markus Armbruster <[email protected]> wrote:
qerror.h +3
-0+#define QERR_FD_NOT_FOUND \ + "{ 'class': 'fd_not_found', 'data': { 'name': %s } }" +I think this came from your previous series of not using CamelCase?
Also happens in next patches..
Rats. Fixing...
PATCH 13/18 monitor: convert do_closefd() to QError
In reply to Markus Armbruster--- monitor.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
monitor.c +1 -2
@@ -2195,8 +2195,7 @@ static void do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)return ; } -monitor_printf (mon,"Failed to find file descriptor named %s\n" , - fdname); +qemu_error_new (QERR_FD_NOT_FOUND , fdname); }static void do_loadvm (Monitor *mon,const QDict *qdict)
Signature · 1 line
1.6.2.5
PATCH 14/18 QError: New QERR_FD_NOT_SUPPLIED
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -69,6 +69,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Failed to find file descriptor named %(name)", }, { + .error_fmt = QERR_FD_NOT_SUPPLIED, + .desc = "No file descriptor supplied via SCM_RIGHTS", + }, + { .error_fmt = QERR_INVALID_BLOCK_FORMAT, .desc = "Invalid block format %(name)", },
qerror.h +3 -0
@@ -59,6 +59,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_FD_NOT_FOUND \ "{ 'class': 'fd_not_found', 'data': { 'name': %s } }" +#define QERR_FD_NOT_SUPPLIED \ + "{ 'class': 'fd_not_supplied', 'data': {} }" +#define QERR_INVALID_BLOCK_FORMAT \ "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }"
Signature · 1 line
1.6.2.5
PATCH 15/18 New QERR_INVALID_PARAMETER
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -77,6 +77,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Invalid block format %(name)", }, { + .error_fmt = QERR_INVALID_PARAMETER, + .desc = "Invalid parameter %(name)", + }, + { .error_fmt = QERR_INVALID_PARAMETER_TYPE, .desc = "Invalid parameter type, expected: %(expected)", },
qerror.h +3 -0
@@ -65,6 +65,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_INVALID_BLOCK_FORMAT \ "{ 'class': 'InvalidBlockFormat', 'data': { 'name': %s } }" +#define QERR_INVALID_PARAMETER \ + "{ 'class': 'invalid_parameter', 'data': { 'name': %s } }" +#define QERR_INVALID_PARAMETER_TYPE \ "{ 'class': 'InvalidParameterType', 'data': { 'name': %s,'expected': %s } }"
Signature · 1 line
1.6.2.5
PATCH 16/18 QError: New QERR_TOO_MANY_FILES
In reply to Markus Armbruster--- qerror.c | 4 ++++ qerror.h | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
@@ -109,6 +109,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "Could not set password", }, { + .error_fmt = QERR_TOO_MANY_FILES, + .desc = "Too many open files", + }, + { .error_fmt = QERR_UNDEFINED_ERROR, .desc = "An undefined error has ocurred", },
qerror.h +3 -0
@@ -92,6 +92,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_UNDEFINED_ERROR \ "{ 'class': 'UndefinedError', 'data': {} }" +#define QERR_TOO_MANY_FILES \ + "{ 'class': 'fd_too_many_files', 'data': {} }" +#define QERR_VNC_SERVER_FAILED \ "{ 'class': 'VNCServerFailed', 'data': { 'target': %s } }"
Signature · 1 line
1.6.2.5
PATCH 17/18 monitor: convert do_getfd() to QError
In reply to Markus Armbruster--- monitor.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
monitor.c +6 -4
@@ -2145,19 +2145,21 @@ static void do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data) fd =qemu_chr_get_msgfd (mon->chr);if (fd ==-1 ) { -monitor_printf (mon,"getfd: no file descriptor supplied via SCM_RIGHTS\n" ); +qemu_error_new (QERR_FD_NOT_SUPPLIED );return ; }if (qemu_isdigit (fdname[0 ])) { -monitor_printf (mon,"getfd: monitor names may not begin with a number\n" ); +qemu_error_new (QERR_INVALID_PARAMETER ,"fdname" );return ; } fd =dup (fd);if (fd ==-1 ) { -monitor_printf (mon,"Failed to dup() file descriptor: %s\n" , -strerror (errno)); +if (errno ==EMFILE ) +qemu_error_new (QERR_TOO_MANY_FILES ); +else +qemu_error_new (QERR_UNDEFINED_ERROR );return ; }
Signature · 1 line
1.6.2.5
PATCH 18/18 QMP: add human-readable description to error response
In reply to Markus Armbruster--- QMP/qmp-spec.txt | 5 ++++- monitor.c | 1 + qerror.c | 21 ++++++++++++++++----- qerror.h | 2 ++ 4 files changed, 23 insertions(+), 6 deletions(-)
QMP/qmp-spec.txt +4 -1
@@ -102,13 +102,16 @@ completed because of an error condition. The format is: -{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value } Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)
monitor.c +1 -0
@@ -305,6 +305,7 @@ static void monitor_protocol_emitter(Monitor *mon, QObject *data) } }else {/* error response */ +qdict_put (mon->error->error,"desc" ,qerror_human (mon->error));qdict_put (qmp,"error" , mon->error->error);QINCREF (mon->error->error);QDECREF (mon->error);
qerror.c +16 -5
@@ -283,13 +283,11 @@ static const char *append_field(QString *outstr, const QError *qerror, }/** -* qerror_print(): Print QError data +* qerror_human(): Format QError data into human-readable string. * -* This function will print the member 'desc' of the specified QError object, -* it uses qemu_error() for this, so that the output is routed to the right -* place (ie. stderr or Monitor's device). +* Formats according to member 'desc' of the specified QError object. */ -void qerror_print (const QError *qerror) +QString *qerror_human (const QError *qerror) {const char *p;QString *qstring;
@@ -309,6 +307,19 @@ void qerror_print(const QError *qerror) } } +return qstring; +} + +/** +* qerror_print(): Print QError data +* +* This function will print the member 'desc' of the specified QError object, +* it uses qemu_error() for this, so that the output is routed to the right +* place (ie. stderr or Monitor's device). +*/ +void qerror_print (const QError *qerror) +{ +QString *qstring =qerror_human (qerror);qemu_error ("%s\n" ,qstring_get_str (qstring));QDECREF (qstring); }
qerror.h +2 -0
@@ -13,6 +13,7 @@#define QERROR_H #include "qdict.h" +#include "qstring.h" #include <stdarg.h> typedef struct QErrorStringTable {
@@ -32,6 +33,7 @@ typedef struct QError {QError *qerror_new (void );QError *qerror_from_info (const char *file,int linenr,const char *func,const char *fmt,va_list *va); +QString *qerror_human (const QError *qerror);void qerror_print (const QError *qerror);QError *qobject_to_qerror (const QObject *obj);
Signature · 1 line
1.6.2.5
[Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
QMP/qmp-spec.txt completed because of an error condition. · line 116
Quoted 13 lines · On Mon, 7 Dec 2009 21:37:16 +0100 Markus Armbruster <[email protected]> wrote:
QMP/qmp-spec.txt +4
-1-{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value } Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)
As we've talked on irc, I don't agree with this change.
Basically, adding 'desc' to the standard error message introduces all
the problems we've discussed about free-form English strings.
I feel that QError is becoming the worst of all proposals.
I agree with you that it's not as easy as it should be to report errors,
but as we're targeting on Clients I was convinced that we could not have the best API internally but offer a good interface for Clients.
Now, having 'desc' as part of the standard protocol is like not having
the best API internally and offering a bad interface for Clients.
Not to mention that those strings can't be modified when the protocol
becomes stable and we're probably talking about dozens if not a hundred of strings. Ok, there isn't a reason to change them often, but it's still one more thing to maintain.
Having said that, I would agree to have 'desc' as part of debug
information. I have patches in my tree which adds CONFIG_DEBUG_QMP, if one enables it information about the error location will also be part of the error message. I would agree having 'desc' there too.
Re: [Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
Quoted 28 lines · Luiz Capitulino
QMP/qmp-spec.txt completed because of an error condition. · line 116
Quoted 13 lines · On Mon, 7 Dec 2009 21:37:16 +0100 Markus Armbruster <[email protected]> wrote:
QMP/qmp-spec.txt +4
-1-{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value } Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)As we've talked on irc, I don't agree with this change.
Basically, adding 'desc' to the standard error message introduces all
the problems we've discussed about free-form English strings.I feel that QError is becoming the worst of all proposals.
I agree with you that it's not as easy as it should be to report errors,
but as we're targeting on Clients I was convinced that we could not have the best API internally but offer a good interface for Clients.
Quoted 7 lines
Now, having 'desc' as part of the standard protocol is like not having
the best API internally and offering a bad interface for Clients.Not to mention that those strings can't be modified when the protocol
becomes stable and we're probably talking about dozens if not a hundred of strings. Ok, there isn't a reason to change them often, but it's still one more thing to maintain.
I think it is fine to declare that 'desc' strings are subject to arbitrary change. Even if QEMU includes this 'desc' I think in libvirt will end up doing its own error code -> human string conversion, simply because we need to translate the strings. So we'd only use 'desc' in any logging calls if it were present.
Quoted 5 lines
Having said that, I would agree to have 'desc' as part of debug
information. I have patches in my tree which addsCONFIG_DEBUG_QMP, if one enables it information about the error location will also be part of the error message. I would agree having 'desc' there too.
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Re: [Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
Quoted 37 lines · On Tue, 8 Dec 2009 12:25:13 +0000 "Daniel P. Berrange" <[email protected]>…
Quoted 28 lines · Luiz Capitulino
QMP/qmp-spec.txt completed because of an error condition. · line 116
Quoted 13 lines · On Mon, 7 Dec 2009 21:37:16 +0100 Markus Armbruster <[email protected]> wrote:
QMP/qmp-spec.txt +4
-1-{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value } Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)As we've talked on irc, I don't agree with this change.
Basically, adding 'desc' to the standard error message introduces all
the problems we've discussed about free-form English strings.I feel that QError is becoming the worst of all proposals.
I agree with you that it's not as easy as it should be to report errors,
but as we're targeting on Clients I was convinced that we could not have the best API internally but offer a good interface for Clients.Quoted 7 lines
Now, having 'desc' as part of the standard protocol is like not having
the best API internally and offering a bad interface for Clients.Not to mention that those strings can't be modified when the protocol
becomes stable and we're probably talking about dozens if not a hundred of strings. Ok, there isn't a reason to change them often, but it's still one more thing to maintain.
Quoted 5 lines
I think it is fine to declare that 'desc' strings are subject to arbitrary change. Even if QEMU includes this 'desc' I think in libvirt will end up doing its own error code -> human string conversion, simply because we need to translate the strings. So we'd only use 'desc' in any logging calls if it were present.
That's what we would expect from clients, but I'm not convinced that
they'll took the easy way and start using it the way they shouldn't.
Re: [Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
Quoted 40 lines · Luiz Capitulino
Quoted 37 lines · On Tue, 8 Dec 2009 12:25:13 +0000 "Daniel P. Berrange" <[email protected]>…
Quoted 35 lines · Luiz Capitulino
QMP/qmp-spec.txt completed because of an error condition. · line 116
Quoted 13 lines · On Mon, 7 Dec 2009 21:37:16 +0100 Markus Armbruster <[email protected]> wrote:
QMP/qmp-spec.txt +4
-1-{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value } Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)As we've talked on irc, I don't agree with this change.
Basically, adding 'desc' to the standard error message introduces all
the problems we've discussed about free-form English strings.I feel that QError is becoming the worst of all proposals.
I agree with you that it's not as easy as it should be to report errors,
but as we're targeting on Clients I was convinced that we could not have the best API internally but offer a good interface for Clients.Now, having 'desc' as part of the standard protocol is like not having
the best API internally and offering a bad interface for Clients.Not to mention that those strings can't be modified when the protocol
becomes stable and we're probably talking about dozens if not a hundred of strings. Ok, there isn't a reason to change them often, but it's still one more thing to maintain.
Quoted 8 lines
Quoted 5 lines
I think it is fine to declare that 'desc' strings are subject to arbitrary change. Even if QEMU includes this 'desc' I think in libvirt will end up doing its own error code -> human string conversion, simply because we need to translate the strings. So we'd only use 'desc' in any logging calls if it were present.
That's what we would expect from clients, but I'm not convinced that
they'll took the easy way and start using it the way they shouldn't.
Change a couple of common messages in every release, and they'll stop doing that real fast ;)
[Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
In reply to Luiz CapitulinoQuoted 3 lines · Luiz Capitulino
Not to mention that those strings can't be modified when the protocol
becomes stable and we're probably talking about dozens if not a hundred of strings.
I would say that there is _explicitly no promise_ of keeping these stable. You can serve
HTTP/1.1 302 You have bad taste in music
Location: http://www.britneyspears.com/
and clients will not complain. It's the same for QMP and desc.
(Disclaimer: I haven't read the entire series from Markus).
Paolo
[Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
Quoted 5 lines · Paolo Bonzini
Quoted 3 lines · Luiz Capitulino
Not to mention that those strings can't be modified when the protocol
becomes stable and we're probably talking about dozens if not a hundred of strings.
Quoted 7 lines
I would say that there is
_explicitlynopromise_of keeping these stable. You can serveHTTP/1.1 302 You have bad taste in music
Location: http://www.britneyspears.com/and clients will not complain.
And even serve later in the same session
HTTP/1.1 302 Bad taste in music you have
Location: http://www.britneyspears.com/
Quoted 1 line
It's the same for QMP and desc.
Precisely.
Quoted 1 line
(Disclaimer: I haven't read the entire series from Markus).
[Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
In reply to Luiz CapitulinoQuoted 19 lines · Luiz Capitulino
QMP/qmp-spec.txt completed because of an error condition. · line 116
Quoted 13 lines · On Mon, 7 Dec 2009 21:37:16 +0100 Markus Armbruster <[email protected]> wrote:
QMP/qmp-spec.txt +4
-1-{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value } Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)As we've talked on irc, I don't agree with this change.
Quoted 2 lines
Basically, adding 'desc' to the standard error message introduces all
the problems we've discussed about free-form English strings.
I disagree. See below.
Quoted 1 line
I feel that QError is becoming the worst of all proposals.
I'm not exactly thrilled about it either, but it could clearly be worse in many ways, so it can't be the worst of all :)
Quoted 9 lines
I agree with you that it's not as easy as it should be to report errors,
but as we're targeting on Clients I was convinced that we could not have the best API internally but offer a good interface for Clients.Now, having 'desc' as part of the standard protocol is like not having
the best API internally and offering a bad interface for Clients.Not to mention that those strings can't be modified when the protocol
becomes stable
This is incorrect. We explicitly threaten client writers that these strings are not to be interpreted, in qmp-spec.txt: "Clients should not attempt to parse this message." For me, that implies that they can change at any time. Maybe we could use even stronger language there.
Quoted 9 lines
and we're probably talking about dozens if not a hundred
of strings. Ok, there isn't a reason to change them often, but it's still one more thing to maintain.Having said that, I would agree to have 'desc' as part of debug
information. I have patches in my tree which addsCONFIG_DEBUG_QMP, if one enables it information about the error location will also be part of the error message. I would agree having 'desc' there too.
Debugging is one use for human-readable text in the error reply. But it is *not* the only use. We discussed this at length in October[*], and again in November[**]. Any new arguments?
[*] Sub-thread starting at
http://lists.gnu.org/archive/html/qemu-devel/2009-10/msg01245.html
[**] Sub-thread starting at
http://lists.gnu.org/archive/html/qemu-devel/2009-11/msg01071.html
Re: [Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
In reply to Luiz CapitulinoQuoted 21 lines · Luiz Capitulino
Quoted 4 lines · On Mon, 7 Dec 2009 21:37:16 +0100 Markus Armbruster <[email protected]> wrote:
QMP/qmp-spec.txt +2
-1-{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value }QMP/qmp-spec.txt completed because of an error condition. · line 116
Quoted 10 lines
QMP/qmp-spec.txt +2
-0Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)As we've talked on irc, I don't agree with this change.
Quoted 3 lines
Basically, adding 'desc' to the standard error message introduces all
the problems we've discussed about free-form English strings.
It's not free form English. The 'desc' string is always autogenerated based on the error object.
It's completely redundant information because you can already generate that string, but it simplifies client creation because a lazy client does not have to include the conversion table if they only care about English error output.
Regards,
Anthony Liguori
Re: [Qemu-devel] Re: [FOR 0.12 PATCH 18/18] QMP: add human-readable description to error response
Quoted 26 lines · On Tue, 08 Dec 2009 07:18:11 -0600 Anthony Liguori <[email protected]>…
Quoted 21 lines · Luiz Capitulino
Quoted 4 lines · On Mon, 7 Dec 2009 21:37:16 +0100 Markus Armbruster <[email protected]> wrote:
QMP/qmp-spec.txt +2
-1-{ "error": { "class": json-string, "data": json-value }, "id": json-value } +{ "error": { "class": json-string, "data": json-value, "desc": json-string }, + "id": json-value }QMP/qmp-spec.txt completed because of an error condition. · line 116
Quoted 10 lines
QMP/qmp-spec.txt +2
-0Where, - The "class" member contains the error class name (eg. "ServiceUnavailable") - The "data" member contains specific error data and is defined in a per-command basis, it will be an empty json-object if the error has no data +- The "desc" member is a human-readable error message. Clients should + not attempt to parse this message. - The "id" member contains the transaction identification associated with the command execution (if issued by the Client)As we've talked on irc, I don't agree with this change.
Quoted 3 lines
Basically, adding 'desc' to the standard error message introduces all
the problems we've discussed about free-form English strings.
Quoted 7 lines
It's not free form English. The 'desc' string is always autogenerated based on the error object.
It's completely redundant information because you can already generate that string, but it simplifies client creation because a lazy client does not have to include the conversion table if they only care about English error output.
I wonder if we could have a simpler design for the internal API if
we knew in advance that 'desc' would be part of the standard error message, eg. error code based.
But, as Markus said it's not the 'worst' as I've put it, let's
move forward then.
Quoted 2 lines · On Mon, 7 Dec 2009 21:36:58 +0100 Markus Armbruster <[email protected]> wrote:
This patch series converts monitor commands eject, change, closefd, getfd to QError.
Thanks a lot for this work.
Although the series is already merged, I have some comments and will
reply the patches.