From: Jacek Konieczny <jajcus@jajcus.net>
To: xen-devel@lists.xen.org
Cc: Ian Campbell <Ian.Campbell@citrix.com>,
Jacek Konieczny <jajcus@jajcus.net>
Subject: [PATCH] libxenstat: handle renamed VIFs
Date: Wed, 21 May 2014 14:37:38 +0200 [thread overview]
Message-ID: <1400675858-4528-1-git-send-email-jajcus@jajcus.net> (raw)
Before trying to parse network interface name as 'vif*.*'
try to get the domid and network number from sysfs.
Fixes xentop output for domains with VIF renamed through the
'vifname' xl option.
Signed-off-by: Jacek Konieczny <jajcus@jajcus.net>
---
tools/xenstat/libxenstat/src/xenstat_linux.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/tools/xenstat/libxenstat/src/xenstat_linux.c b/tools/xenstat/libxenstat/src/xenstat_linux.c
index 24335e1..20a5d91 100644
--- a/tools/xenstat/libxenstat/src/xenstat_linux.c
+++ b/tools/xenstat/libxenstat/src/xenstat_linux.c
@@ -233,6 +233,29 @@ int parseNetDevLine(char *line, char *iface, unsigned long long *rxBytes, unsign
return 0;
}
+/* Find out the domid and network number given an interface name.
+ * Return 1 on success. */
+static int get_iface_domid_network(const char *iface, unsigned int *domid_p, unsigned int *netid_p)
+{
+ char nodename_path[48];
+ FILE * nodename_file;
+ int ret;
+
+ snprintf(nodename_path, 48, "/sys/class/net/%s/device/nodename", iface);
+ nodename_file = fopen(nodename_path, "r");
+ if (nodename_file != NULL) {
+ ret = fscanf(nodename_file, "backend/vif/%u/%u", domid_p, netid_p);
+ fclose(nodename_file);
+ if (ret == 2)
+ return 1;
+ }
+
+ if (sscanf(iface, "vif%u.%u", domid_p, netid_p) == 2)
+ return 1;
+
+ return 0;
+}
+
/* Collect information about networks */
int xenstat_collect_networks(xenstat_node * node)
{
@@ -309,8 +332,7 @@ int xenstat_collect_networks(xenstat_node * node)
}
}
else /* Otherwise we need to preserve old behaviour */
- if (strstr(iface, "vif") != NULL) {
- sscanf(iface, "vif%u.%u", &domid, &net.id);
+ if (get_iface_domid_network(iface, &domid, &net.id)) {
net.tbytes = txBytes;
net.tpackets = txPackets;
--
1.9.0
reply other threads:[~2014-05-21 12:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1400675858-4528-1-git-send-email-jajcus@jajcus.net \
--to=jajcus@jajcus.net \
--cc=Ian.Campbell@citrix.com \
--cc=xen-devel@lists.xen.org \
/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).