[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/21] monitor: Propagate errors through qmp_check_cl
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 09/21] monitor: Propagate errors through qmp_check_client_args() |
Date: |
Tue, 2 Jun 2015 10:23:47 +0200 |
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Luiz Capitulino <address@hidden>
---
monitor.c | 65 ++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 33 insertions(+), 32 deletions(-)
diff --git a/monitor.c b/monitor.c
index 9403c2c..0afcf60 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4736,8 +4736,9 @@ static bool invalid_qmp_mode(const Monitor *mon, const
mon_cmd_t *cmd)
* the QMP_ACCEPT_UNKNOWNS flag is set, then the
* checking is skipped for it.
*/
-static int check_client_args_type(const QDict *client_args,
- const QDict *cmd_args, int flags)
+static void check_client_args_type(const QDict *client_args,
+ const QDict *cmd_args, int flags,
+ Error **errp)
{
const QDictEntry *ent;
@@ -4754,8 +4755,8 @@ static int check_client_args_type(const QDict
*client_args,
continue;
}
/* client arg doesn't exist */
- qerror_report(QERR_INVALID_PARAMETER, client_arg_name);
- return -1;
+ error_set(errp, QERR_INVALID_PARAMETER, client_arg_name);
+ return;
}
arg_type = qobject_to_qstring(obj);
@@ -4767,9 +4768,9 @@ static int check_client_args_type(const QDict
*client_args,
case 'B':
case 's':
if (qobject_type(client_arg) != QTYPE_QSTRING) {
- qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
- "string");
- return -1;
+ error_set(errp, QERR_INVALID_PARAMETER_TYPE,
+ client_arg_name, "string");
+ return;
}
break;
case 'i':
@@ -4777,25 +4778,25 @@ static int check_client_args_type(const QDict
*client_args,
case 'M':
case 'o':
if (qobject_type(client_arg) != QTYPE_QINT) {
- qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
- "int");
- return -1;
+ error_set(errp, QERR_INVALID_PARAMETER_TYPE,
+ client_arg_name, "int");
+ return;
}
break;
case 'T':
if (qobject_type(client_arg) != QTYPE_QINT &&
qobject_type(client_arg) != QTYPE_QFLOAT) {
- qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
- "number");
- return -1;
+ error_set(errp, QERR_INVALID_PARAMETER_TYPE,
+ client_arg_name, "number");
+ return;
}
break;
case 'b':
case '-':
if (qobject_type(client_arg) != QTYPE_QBOOL) {
- qerror_report(QERR_INVALID_PARAMETER_TYPE, client_arg_name,
- "bool");
- return -1;
+ error_set(errp, QERR_INVALID_PARAMETER_TYPE,
+ client_arg_name, "bool");
+ return;
}
break;
case 'O':
@@ -4814,16 +4815,15 @@ static int check_client_args_type(const QDict
*client_args,
abort();
}
}
-
- return 0;
}
/*
* - Check if the client has passed all mandatory args
* - Set special flags for argument validation
*/
-static int check_mandatory_args(const QDict *cmd_args,
- const QDict *client_args, int *flags)
+static void check_mandatory_args(const QDict *cmd_args,
+ const QDict *client_args, int *flags,
+ Error **errp)
{
const QDictEntry *ent;
@@ -4838,12 +4838,10 @@ static int check_mandatory_args(const QDict *cmd_args,
} else if (qstring_get_str(type)[0] != '-' &&
qstring_get_str(type)[1] != '?' &&
!qdict_haskey(client_args, cmd_arg_name)) {
- qerror_report(QERR_MISSING_PARAMETER, cmd_arg_name);
- return -1;
+ error_set(errp, QERR_MISSING_PARAMETER, cmd_arg_name);
+ return;
}
}
-
- return 0;
}
static QDict *qdict_from_args_type(const char *args_type)
@@ -4899,24 +4897,26 @@ out:
* 3. Each argument provided by the client must have the type expected
* by the command
*/
-static int qmp_check_client_args(const mon_cmd_t *cmd, QDict *client_args)
+static void qmp_check_client_args(const mon_cmd_t *cmd, QDict *client_args,
+ Error **errp)
{
- int flags, err;
+ Error *err = NULL;
+ int flags;
QDict *cmd_args;
cmd_args = qdict_from_args_type(cmd->args_type);
flags = 0;
- err = check_mandatory_args(cmd_args, client_args, &flags);
+ check_mandatory_args(cmd_args, client_args, &flags, &err);
if (err) {
goto out;
}
- err = check_client_args_type(client_args, cmd_args, flags);
+ check_client_args_type(client_args, cmd_args, flags, &err);
out:
+ error_propagate(errp, err);
QDECREF(cmd_args);
- return err;
}
/*
@@ -4975,7 +4975,7 @@ static QDict *qmp_check_input_obj(QObject *input_obj)
static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
{
- int err;
+ Error *local_err = NULL;
QObject *obj, *data;
QDict *input, *args;
const mon_cmd_t *cmd;
@@ -5021,8 +5021,9 @@ static void handle_qmp_command(JSONMessageParser *parser,
QList *tokens)
QINCREF(args);
}
- err = qmp_check_client_args(cmd, args);
- if (err < 0) {
+ qmp_check_client_args(cmd, args, &local_err);
+ if (local_err) {
+ qerror_report_err(local_err);
goto err_out;
}
--
1.9.3
- [Qemu-devel] [PULL 00/21] Monitor patches, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 08/21] monitor: Drop unused "new" HMP command interface, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 11/21] monitor: Propagate errors through invalid_qmp_mode(), Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 02/21] monitor: Clean up after previous commit, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 12/21] monitor: Wean monitor_protocol_emitter() off mon->error, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 05/21] monitor: Use traditional command interface for HMP drive_del, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 06/21] monitor: Use traditional command interface for HMP device_add, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 09/21] monitor: Propagate errors through qmp_check_client_args(),
Markus Armbruster <=
- [Qemu-devel] [PULL 07/21] monitor: Use trad. command interface for HMP pcie_aer_inject_error, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 03/21] monitor: Improve and document client_migrate_info protocol error, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 04/21] monitor: Convert client_migrate_info to QAPI, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 01/21] monitor: Drop broken, unused asynchronous command interface, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 13/21] monitor: Inline monitor_has_error() into its only caller, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 20/21] monitor: Rename monitor_ctrl_mode() to monitor_is_qmp(), Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 21/21] monitor: Change return type of monitor_cur_is_qmp() to bool, Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 10/21] monitor: Propagate errors through qmp_check_input_obj(), Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 16/21] monitor: Rename monitor_control_read(), monitor_control_event(), Markus Armbruster, 2015/06/02
- [Qemu-devel] [PULL 15/21] monitor: Rename handle_user_command() to handle_hmp_command(), Markus Armbruster, 2015/06/02