From: Kelley Nielsen <kelleynnn@gmail.com>
To: xen-devel@lists.xensource.com
Cc: anthony.perard@citrix.com
Subject: [PATCH] opw: libxl: change remaining LIBXL_LOG to LOG in libxl_qmp.c
Date: Sat, 9 Nov 2013 20:05:51 -0800 [thread overview]
Message-ID: <20131110040551.GA15662@kelleynnn-HP-Compaq-8510w> (raw)
Code cleanup -- no functional changes
Coding style has recently been changed for libxl. The convenience
macro LOG() has been introduced, and invocations of the old macro
LIBXL__LOG() are to be replaced with it. Change all remaining
occurences of the old macro to the new one. These are in functions
that do not have a local libxl__gc *gc, so create one by calling
GC_INIT() at the top of the function and destroy it by calling
GC_FREE at the end. In functions that have multiple exits, create
a labeled set of statements at the end with GC_FREE and the
return statement, and route all exits through it with gotos.
Signed-off-by: Kelley Nielsen <kelleynnn@gmail.com>
---
tools/libxl/libxl_qmp.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 1f76d53..347ff9b 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -113,6 +113,7 @@ static int register_serials_chardev_callback(libxl__qmp_handler *qmp,
const libxl__json_object *o,
void *unused)
{
+ GC_INIT(qmp->ctx);
const libxl__json_object *obj = NULL;
const libxl__json_object *label = NULL;
const char *s = NULL;
@@ -137,20 +138,22 @@ static int register_serials_chardev_callback(libxl__qmp_handler *qmp,
s += strlen("serial");
port_number = strtol(s, &endptr, 10);
if (*s == 0 || *endptr != 0) {
- LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR,
- "Invalid serial port number: %s", s);
- return -1;
+ LOG(ERROR, "Invalid serial port number: %s", s);
+ ret = -1;
+ goto out;
}
ret = store_serial_port_info(qmp, chardev, port_number);
if (ret) {
LIBXL__LOG_ERRNO(qmp->ctx, LIBXL__LOG_ERROR,
"Failed to store serial port information"
" in xenstore");
- return ret;
+ goto out;
}
}
};
+out:
+ GC_FREE;
return ret;
}
@@ -263,6 +266,7 @@ static callback_id_pair *qmp_get_callback_from_id(libxl__qmp_handler *qmp,
static void qmp_handle_error_response(libxl__qmp_handler *qmp,
const libxl__json_object *resp)
{
+ GC_INIT(qmp->ctx);
callback_id_pair *pp = qmp_get_callback_from_id(qmp, resp);
resp = libxl__json_map_get("error", resp, JSON_MAP);
@@ -283,19 +287,20 @@ static void qmp_handle_error_response(libxl__qmp_handler *qmp,
free(pp);
}
- LIBXL__LOG(qmp->ctx, LIBXL__LOG_ERROR,
- "received an error message from QMP server: %s",
+ LOG(ERROR, "received an error message from QMP server: %s",
libxl__json_object_get_string(resp));
+ GC_FREE;
}
static int qmp_handle_response(libxl__qmp_handler *qmp,
const libxl__json_object *resp)
{
+ GC_INIT(qmp->ctx);
libxl__qmp_message_type type = LIBXL__QMP_MESSAGE_TYPE_INVALID;
+ int ret = 0;
type = qmp_response_type(qmp, resp);
- LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG,
- "message type: %s", libxl__qmp_message_type_to_string(type));
+ LOG(DEBUG, "message type: %s", libxl__qmp_message_type_to_string(type));
switch (type) {
case LIBXL__QMP_MESSAGE_TYPE_QMP:
@@ -321,17 +326,22 @@ static int qmp_handle_response(libxl__qmp_handler *qmp,
&qmp->callback_list, pp, callback_id_pair, next);
free(pp);
}
- return 0;
+ goto out;
}
case LIBXL__QMP_MESSAGE_TYPE_ERROR:
qmp_handle_error_response(qmp, resp);
- return -1;
+ ret = -1;
+ goto out;
case LIBXL__QMP_MESSAGE_TYPE_EVENT:
- return 0;
+ goto out;
case LIBXL__QMP_MESSAGE_TYPE_INVALID:
- return -1;
+ ret = -1;
+ goto out;
}
- return 0;
+
+out:
+ GC_FREE;
+ return ret;
}
/*
--
1.8.1.2
next reply other threads:[~2013-11-10 4:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-10 4:05 Kelley Nielsen [this message]
2013-11-11 12:24 ` [PATCH] opw: libxl: change remaining LIBXL_LOG to LOG in libxl_qmp.c Ian Campbell
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=20131110040551.GA15662@kelleynnn-HP-Compaq-8510w \
--to=kelleynnn@gmail.com \
--cc=anthony.perard@citrix.com \
--cc=xen-devel@lists.xensource.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).