From patchwork Fri Jan 15 16:07:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 8042981 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 579F5BEEE5 for ; Fri, 15 Jan 2016 16:10:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C54120459 for ; Fri, 15 Jan 2016 16:10:32 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5ECEC2040F for ; Fri, 15 Jan 2016 16:10:31 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aK6ug-0000I6-K2; Fri, 15 Jan 2016 16:07:46 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aK6uf-0000Ht-1R for xen-devel@lists.xen.org; Fri, 15 Jan 2016 16:07:45 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 77/9C-03235-05919965; Fri, 15 Jan 2016 16:07:44 +0000 X-Env-Sender: jgross@suse.com X-Msg-Ref: server-7.tower-206.messagelabs.com!1452874063!15907036!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9981 invoked from network); 15 Jan 2016 16:07:44 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-7.tower-206.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 15 Jan 2016 16:07:44 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BBBADAAC1; Fri, 15 Jan 2016 16:07:42 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xen.org, Ian.Campbell@citrix.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, wei.liu2@citrix.com Date: Fri, 15 Jan 2016 17:07:39 +0100 Message-Id: <1452874059-21099-1-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.2 Cc: Juergen Gross Subject: [Xen-devel] [PATCH v3] xenstat: handle more than 1024 domains X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP get_domain_ids() in libxenstat used by read_attributes_qdisk() is limited to 1024 domains. Remove that limit. Signed-off-by: Juergen Gross Acked-by: Ian Campbell --- V3: Obey 80 character line length limit as requested by Ian Campbell. In order to not have to wrap so many lines just carve out the loop body into a sub-function. As this changes the patch structure, drop the Reviewed-by tag of Wei. Signed-off-by: Juergen Gross --- tools/xenstat/libxenstat/src/xenstat_qmp.c | 79 ++++++++++++++---------------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/tools/xenstat/libxenstat/src/xenstat_qmp.c b/tools/xenstat/libxenstat/src/xenstat_qmp.c index 5e261af..c12929a 100644 --- a/tools/xenstat/libxenstat/src/xenstat_qmp.c +++ b/tools/xenstat/libxenstat/src/xenstat_qmp.c @@ -356,18 +356,6 @@ static int qmp_connect(char *path) return s; } -/* Get up to 1024 active domains */ -static xc_domaininfo_t *get_domain_ids(xc_interface *xc_handle, int *num_doms) -{ - xc_domaininfo_t *dominfo; - - dominfo = calloc(1024, sizeof(xc_domaininfo_t)); - if (dominfo == NULL) - return NULL; - *num_doms = xc_domain_getinfolist(xc_handle, 0, 1024, dominfo); - return dominfo; -} - /* Gather the qdisk statistics by querying QMP Resources: http://wiki.qemu.org/QMP and qmp-commands.hx from the qemu code QMP Syntax for entering command mode. This command must be issued before @@ -394,48 +382,57 @@ static xc_domaininfo_t *get_domain_ids(xc_interface *xc_handle, int *num_doms) } }]} */ -void read_attributes_qdisk(xenstat_node * node) +static void read_attributes_qdisk_dom(xenstat_node *node, domid_t domain) { char *cmd_mode = "{ \"execute\": \"qmp_capabilities\" }"; char *query_blockstats_cmd = "{ \"execute\": \"query-blockstats\" }"; - xc_domaininfo_t *dominfo = NULL; unsigned char *qmp_stats, *val; char path[80]; - int i, qfd, num_doms; + int qfd; - dominfo = get_domain_ids(node->handle->xc_handle, &num_doms); - if (dominfo == NULL) + /* Verify that qdisk disks are used with this VM */ + snprintf(path, sizeof(path),"/local/domain/0/backend/qdisk/%i", domain); + val = xs_read(node->handle->xshandle, XBT_NULL, path, NULL); + if (val == NULL) return; + free(val); - for (i=0; ihandle->xshandle, XBT_NULL, path, NULL)) == NULL) - continue; - free(val); - - /* Connect to this VMs QMP socket */ - snprintf(path, sizeof(path), "/var/run/xen/qmp-libxenstat-%i", dominfo[i].domain); - if ((qfd = qmp_connect(path)) < 0) { - continue; - } + /* Connect to this VMs QMP socket */ + snprintf(path, sizeof(path), "/var/run/xen/qmp-libxenstat-%i", domain); + if ((qfd = qmp_connect(path)) < 0) + return; - /* First enable QMP capabilities so that we can query for data */ - if ((qmp_stats = qmp_query(qfd, cmd_mode)) != NULL) { + /* First enable QMP capabilities so that we can query for data */ + if ((qmp_stats = qmp_query(qfd, cmd_mode)) != NULL) { + free(qmp_stats); + /* Query QMP for this VMs blockstats */ + qmp_stats = qmp_query(qfd, query_blockstats_cmd); + if (qmp_stats != NULL) { + qmp_parse_stats(node, domain, qmp_stats, qfd); free(qmp_stats); - /* Query QMP for this VMs blockstats */ - if ((qmp_stats = qmp_query(qfd, query_blockstats_cmd)) != NULL) { - qmp_parse_stats(node, dominfo[i].domain, qmp_stats, qfd); - free(qmp_stats); - } } - close(qfd); } + close(qfd); +} + +void read_attributes_qdisk(xenstat_node * node) +{ + xc_domaininfo_t dominfo[1024]; + int i, num_doms; + domid_t next_domid = 0; + + for (;;) { + num_doms = xc_domain_getinfolist(node->handle->xc_handle, + next_domid, 1024, dominfo); + if (num_doms <= 0) + return; - free(dominfo); + for (i = 0; i < num_doms; i++) + if (dominfo[i].domain > 0) + read_attributes_qdisk_dom(node, dominfo[i].domain); + + next_domid = dominfo[num_doms - 1].domain + 1; + } } #else /* !HAVE_YAJL_V2 */