Skip to contentSkip to conversation

libxenstat: handle renamed VIFs

PATCH Superseded Jacek Konieczny 1 participant 1 message May 21, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxenstat: handle renamed VIFs

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.

---
 tools/xenstat/libxenstat/src/xenstat_linux.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
tools/xenstat/libxenstat/src/xenstat_linux.c +24 -2
index 24335e1..20a5d91 100644
@@ -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;
Signature · 1 line
1.9.0