All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 09/20] monitor: Propagate errors through qmp_check_client_args()
Date: Thu, 28 May 2015 15:03:54 -0400	[thread overview]
Message-ID: <20150528150354.7684f7b1@redhat.com> (raw)
In-Reply-To: <1432653655-30745-10-git-send-email-armbru@redhat.com>

On Tue, 26 May 2015 17:20:44 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>  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;

I'd go from qerror_report() to error_setg(), but it's fine if you're
saving this for a different series. I won't make this comment on the
next patches, as this seems to be your intention.

>  }
>  
>  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;
>      }
>  

  reply	other threads:[~2015-05-28 19:13 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26 15:20 [Qemu-devel] [PATCH v2 00/20] monitor: Wean core off QError, and other cleanups Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 01/20] monitor: Drop broken, unused asynchronous command interface Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 02/20] monitor: Clean up after previous commit Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 03/20] monitor: Improve and document client_migrate_info protocol error Markus Armbruster
2015-05-27 14:30   ` Gerd Hoffmann
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 04/20] monitor: Convert client_migrate_info to QAPI Markus Armbruster
2015-05-28 18:39   ` Luiz Capitulino
2015-05-29  8:12     ` Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 05/20] monitor: Use traditional command interface for HMP drive_del Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 06/20] monitor: Use traditional command interface for HMP device_add Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 07/20] monitor: Use trad. command interface for HMP pcie_aer_inject_error Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 08/20] monitor: Drop unused "new" HMP command interface Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 09/20] monitor: Propagate errors through qmp_check_client_args() Markus Armbruster
2015-05-28 19:03   ` Luiz Capitulino [this message]
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 10/20] monitor: Propagate errors through qmp_check_input_obj() Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 11/20] monitor: Wean monitor_protocol_emitter() off mon->error Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 12/20] monitor: Inline monitor_has_error() into its only caller Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 13/20] monitor: Limit QError use to command handlers Markus Armbruster
2015-05-28 19:35   ` Luiz Capitulino
2015-05-29  8:17     ` Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 14/20] monitor: Rename handle_user_command() to handle_hmp_command() Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 15/20] monitor: Rename monitor_control_read(), monitor_control_event() Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 16/20] monitor: Unbox Monitor member mc and rename to qmp Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 17/20] monitor: Drop do_qmp_capabilities()'s superfluous QMP check Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 18/20] monitor: Turn int command_mode into bool in_command_mode Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 19/20] monitor: Rename monitor_ctrl_mode() to monitor_is_qmp() Markus Armbruster
2015-05-26 15:20 ` [Qemu-devel] [PATCH v2 20/20] monitor: Change return type of monitor_cur_is_qmp() to bool Markus Armbruster
2015-05-28 19:42 ` [Qemu-devel] [PATCH v2 00/20] monitor: Wean core off QError, and other cleanups Luiz Capitulino
2015-05-29  8:21   ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150528150354.7684f7b1@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.