From nobody Fri May 3 06:57:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498139104694547.1031251218401; Thu, 22 Jun 2017 06:45:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB2F87F40C; Thu, 22 Jun 2017 13:44:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 370F85D967; Thu, 22 Jun 2017 13:44:58 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 869431833033; Thu, 22 Jun 2017 13:44:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MDiqBK002319 for ; Thu, 22 Jun 2017 09:44:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C03565E80; Thu, 22 Jun 2017 13:44:52 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF1F865E86 for ; Thu, 22 Jun 2017 13:44:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB2F87F40C Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AB2F87F40C From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 15:44:46 +0200 Message-Id: <3ffa576449eb6aab61a2f436f6613617d2367e62.1498139086.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virNetDevOpenvswitchInterfaceStats: Be more forgiving when fetching stats X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 22 Jun 2017 13:45:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1461270 When fetching stats for a vhost-user type of interface, we run couple of ovs-vsctl commands and parse their output. However, not all stats exist at all times, for instance "rx_dropped" or "tx_errors" can be missing. Thing is, we ask for a bulk of statistics and if one of them is missing an error is reported instead of returning the rest. Since we ignore errors, we fail to set statistics. Fix this by asking for each piece alone. Signed-off-by: Michal Privoznik --- src/util/virnetdevopenvswitch.c | 96 +++++++++++++++----------------------= ---- 1 file changed, 34 insertions(+), 62 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index 8f7215e06..6848f65b7 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -317,14 +317,8 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, { virCommandPtr cmd =3D NULL; char *output; - long long rx_bytes; - long long rx_packets; - long long tx_bytes; - long long tx_packets; - long long rx_errs; - long long rx_drop; - long long tx_errs; - long long tx_drop; + char *tmp; + bool gotStats =3D false; int ret =3D -1; =20 /* Just ensure the interface exists in ovs */ @@ -340,67 +334,45 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname, goto cleanup; } =20 - VIR_FREE(output); - virCommandFree(cmd); - - cmd =3D virCommandNew(OVSVSCTL); - virNetDevOpenvswitchAddTimeout(cmd); - virCommandAddArgList(cmd, "get", "Interface", ifname, - "statistics:rx_bytes", - "statistics:rx_packets", - "statistics:tx_bytes", - "statistics:tx_packets", NULL); - virCommandSetOutputBuffer(cmd, &output); - - if (virCommandRun(cmd, NULL) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Interface doesn't have statistics")); - goto cleanup; - } +#define GET_STAT(name, member) = \ + do { = \ + VIR_FREE(output); = \ + virCommandFree(cmd); = \ + cmd =3D virCommandNew(OVSVSCTL); = \ + virNetDevOpenvswitchAddTimeout(cmd); = \ + virCommandAddArgList(cmd, "get", "Interface", ifname, = \ + "statistics:" name, NULL); = \ + virCommandSetOutputBuffer(cmd, &output); = \ + if (virCommandRun(cmd, NULL) < 0) { = \ + stats->member =3D -1; = \ + } else { = \ + if (virStrToLong_ll(output, &tmp, 10, &stats->member) < 0 || = \ + *tmp !=3D '\n') { = \ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", = \ + _("Fail to parse ovs-vsctl output")); = \ + goto cleanup; = \ + } = \ + gotStats =3D true; = \ + } = \ + } while (0) =20 /* The TX/RX fields appear to be swapped here * because this is the host view. */ - if (sscanf(output, "%lld\n%lld\n%lld\n%lld\n", - &tx_bytes, &tx_packets, &rx_bytes, &rx_packets) !=3D 4) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Fail to parse ovs-vsctl output")); - goto cleanup; - } + GET_STAT("rx_bytes", tx_bytes); + GET_STAT("rx_packets", tx_packets); + GET_STAT("rx_errors", tx_errs); + GET_STAT("rx_dropped", tx_drop); + GET_STAT("tx_bytes", rx_bytes); + GET_STAT("tx_packets", rx_packets); + GET_STAT("tx_errors", rx_errs); + GET_STAT("tx_dropped", rx_drop); =20 - stats->rx_bytes =3D rx_bytes; - stats->rx_packets =3D rx_packets; - stats->tx_bytes =3D tx_bytes; - stats->tx_packets =3D tx_packets; - - VIR_FREE(output); - virCommandFree(cmd); - - cmd =3D virCommandNew(OVSVSCTL); - virNetDevOpenvswitchAddTimeout(cmd); - virCommandAddArgList(cmd, "get", "Interface", ifname, - "statistics:rx_errors", - "statistics:rx_dropped", - "statistics:tx_errors", - "statistics:tx_dropped", NULL); - virCommandSetOutputBuffer(cmd, &output); - if (virCommandRun(cmd, NULL) < 0) { - /* This interface don't have errors or dropped, so set them to 0 */ - stats->rx_errs =3D 0; - stats->rx_drop =3D 0; - stats->tx_errs =3D 0; - stats->tx_drop =3D 0; - } else if (sscanf(output, "%lld\n%lld\n%lld\n%lld\n", - &tx_errs, &tx_drop, &rx_errs, &rx_drop) =3D=3D 4) { - stats->rx_errs =3D rx_errs; - stats->rx_drop =3D rx_drop; - stats->tx_errs =3D tx_errs; - stats->tx_drop =3D tx_drop; - ret =3D 0; - } else { + if (!gotStats) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Fail to parse ovs-vsctl output")); + _("Interface doesn't have statistics")); goto cleanup; } + ret =3D 0; =20 cleanup: --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list