From patchwork Tue Nov 1 16:07:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 123097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CCBF8B6F85 for ; Wed, 2 Nov 2011 03:38:08 +1100 (EST) Received: from localhost ([::1]:38410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGtA-0002Jm-F3 for incoming@patchwork.ozlabs.org; Tue, 01 Nov 2011 12:08:36 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGt1-00027j-Go for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLGsw-0004kM-A3 for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:27 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:22053) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLGsv-0004jb-Nm for qemu-devel@nongnu.org; Tue, 01 Nov 2011 12:08:22 -0400 X-IronPort-AV: E=Sophos;i="4.69,438,1315195200"; d="scan'208";a="168952584" Received: from ftlpmailmx02.citrite.net ([10.13.107.66]) by FTLPIPO02.CITRIX.COM with ESMTP/TLS/RC4-MD5; 01 Nov 2011 12:08:03 -0400 Received: from smtp01.ad.xensource.com (10.219.128.104) by smtprelay.citrix.com (10.13.107.66) with Microsoft SMTP Server id 8.3.137.0; Tue, 1 Nov 2011 12:08:03 -0400 Received: from perard.uk.xensource.com (dhcp-3-28.uk.xensource.com [10.80.3.28] (may be forged)) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id pA1G7YNK014577; Tue, 1 Nov 2011 09:08:01 -0700 From: Anthony PERARD To: QEMU-devel , Stefano Stabellini Date: Tue, 1 Nov 2011 16:07:20 +0000 Message-ID: <1320163646-24291-8-git-send-email-anthony.perard@citrix.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> References: <1320163646-24291-1-git-send-email-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: Anthony PERARD , Xen Devel Subject: [Qemu-devel] [PATCH V3 07/13] libxl_qmp: Always insert a command id in the callback_list. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Because the function qmp_synchronous_send rely on the presence of the id in the callback_list. Signed-off-by: Anthony PERARD Acked-by: Ian Campbell --- tools/libxl/libxl_qmp.c | 34 ++++++++++++++++++---------------- 1 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 43c7d04..47129c3 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -213,7 +213,9 @@ static void qmp_handle_error_response(libxl__qmp_handler *qmp, resp = libxl__json_map_get("desc", resp, JSON_STRING); if (pp) { - pp->callback(qmp, NULL, pp->opaque); + if (pp->callback) { + pp->callback(qmp, NULL, pp->opaque); + } if (pp->id == qmp->wait_for_id) { /* tell that the id have been processed */ qmp->wait_for_id = 0; @@ -245,9 +247,11 @@ static int qmp_handle_response(libxl__qmp_handler *qmp, callback_id_pair *pp = qmp_get_callback_from_id(qmp, resp); if (pp) { - pp->callback(qmp, - libxl__json_map_get("return", resp, JSON_ANY), - pp->opaque); + if (pp->callback) { + pp->callback(qmp, + libxl__json_map_get("return", resp, JSON_ANY), + pp->opaque); + } if (pp->id == qmp->wait_for_id) { /* tell that the id have been processed */ qmp->wait_for_id = 0; @@ -438,6 +442,7 @@ static int qmp_send(libxl__qmp_handler *qmp, unsigned int len = 0; yajl_gen_status s; yajl_gen hand; + callback_id_pair *elm = NULL; hand = yajl_gen_alloc(&conf, NULL); if (!hand) { @@ -463,19 +468,16 @@ static int qmp_send(libxl__qmp_handler *qmp, return -1; } - if (callback) { - callback_id_pair *elm = malloc(sizeof (callback_id_pair)); - if (elm == NULL) { - LIBXL__LOG_ERRNO(qmp->ctx, LIBXL__LOG_ERROR, - "Failed to allocate a QMP callback"); - yajl_gen_free(hand); - return -1; - } - elm->id = qmp->last_id_used; - elm->callback = callback; - elm->opaque = opaque; - SIMPLEQ_INSERT_TAIL(&qmp->callback_list, elm, next); + elm = malloc(sizeof (callback_id_pair)); + if (elm == NULL) { + LIBXL__LOG_ERRNO(qmp->ctx, LIBXL__LOG_ERROR, + "Failed to allocate a QMP callback"); + goto error; } + elm->id = qmp->last_id_used; + elm->callback = callback; + elm->opaque = opaque; + SIMPLEQ_INSERT_TAIL(&qmp->callback_list, elm, next); LIBXL__LOG(qmp->ctx, LIBXL__LOG_DEBUG, "next qmp command: '%s'", buf);