[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 5/7] libxl_qmp, Return the callback return code in qmp_next.



On Fri, 2011-10-07 at 13:10 +0100, Anthony PERARD wrote:
> So, if there is an error in the answer given by QEMU, the function
> qmp_synchronous_send while know.
                       "will"

> 
> Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
> ---
>  tools/libxl/libxl_qmp.c |   14 ++++++++------
>  1 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
> index 1594a4f..cd3e4e4 100644
> --- a/tools/libxl/libxl_qmp.c
> +++ b/tools/libxl/libxl_qmp.c
> @@ -233,6 +233,7 @@ static int qmp_handle_response(libxl__qmp_handler *qmp,
>                                 const libxl__json_object *resp)
>  {
>      libxl__qmp_message_type type = LIBXL__QMP_MESSAGE_TYPE_INVALID;
> +    int rc = 0;
>  
>      type = qmp_response_type(qmp, resp);
>      LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG,
> @@ -241,14 +242,14 @@ static int qmp_handle_response(libxl__qmp_handler *qmp,
>      switch (type) {
>      case LIBXL__QMP_MESSAGE_TYPE_QMP:
>          /* On the greeting message from the server, enable QMP capabilities 
> */
> -        enable_qmp_capabilities(qmp);
> +        rc = enable_qmp_capabilities(qmp);
>          break;
>      case LIBXL__QMP_MESSAGE_TYPE_RETURN: {
>          callback_id_pair *pp = qmp_get_callback_from_id(qmp, resp);
>  
>          if (pp) {
>              if (pp->callback) {
> -                pp->callback(qmp,
> +                rc = pp->callback(qmp,
>                               libxl__json_map_get("return", resp, JSON_ANY),
>                               pp->opaque);
>              }
> @@ -263,13 +264,13 @@ static int qmp_handle_response(libxl__qmp_handler *qmp,
>      }
>      case LIBXL__QMP_MESSAGE_TYPE_ERROR:
>          qmp_handle_error_response(qmp, resp);
> -        break;
> +        return -1;

A mixture or "return -1" and a rc variable returned at the outermost
level is a bit odd. You should either always set rc and fall through or
always return at the end of each case.

>      case LIBXL__QMP_MESSAGE_TYPE_EVENT:
>          break;
>      case LIBXL__QMP_MESSAGE_TYPE_INVALID:
>          return -1;
>      }
> -    return 0;
> +    return rc;
>  }
>  
>  /*
> @@ -358,6 +359,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler 
> *qmp)
>  
>      char *incomplete = NULL;
>      size_t incomplete_size = 0;
> +    int rc = 0;
>  
>      do {
>          fd_set rfds;
> @@ -416,7 +418,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler 
> *qmp)
>                  s = end + 2;
>  
>                  if (o) {
> -                    qmp_handle_response(qmp, o);
> +                    rc = qmp_handle_response(qmp, o);

If rc now indicates error do we need to bail straight away or need to
keep going around this loop? (Or is it certain we will immediately fall
out of the loop after this?)

>                      libxl__json_object_free(gc, o);
>                  } else {
>                      LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR,
> @@ -429,7 +431,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler 
> *qmp)
>          } while (s < s_end);
>     } while (s < s_end);
>  
> -    return 1;
> +    return rc;
>  }
>  
>  static int qmp_send(libxl__qmp_handler *qmp,



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.