af_xdp: fix NUMA node parsing 22/29522/3
authorBenoît Ganne <bganne@cisco.com>
Mon, 19 Oct 2020 07:49:09 +0000 (09:49 +0200)
committerDamjan Marion <dmarion@me.com>
Wed, 21 Oct 2020 11:05:37 +0000 (11:05 +0000)
Non-NUMA systems might report -1 as NUMA node.

Type: fix

Change-Id: I092c817ea670009d6f530cc70ad13d45e15fd363
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/plugins/af_xdp/device.c

index 9bca41c..c750e8d 100644 (file)
@@ -22,6 +22,7 @@
 #include <vlib/vlib.h>
 #include <vlib/unix/unix.h>
 #include <vlib/pci/pci.h>
+#include <vppinfra/linux/sysfs.h>
 #include <vppinfra/unix.h>
 #include <vnet/ethernet/ethernet.h>
 #include "af_xdp.h"
@@ -260,21 +261,18 @@ err0:
 static int
 af_xdp_get_numa (const char *ifname)
 {
-  FILE *fptr;
+  char *path;
+  clib_error_t *err;
   int numa;
-  char *s;
 
-  s = (char *) format (0, "/sys/class/net/%s/device/numa_node%c", ifname, 0);
-  fptr = fopen (s, "rb");
-  vec_free (s);
-
-  if (!fptr)
-    return 0;
-
-  if (fscanf (fptr, "%d\n", &numa) != 1)
+  path =
+    (char *) format (0, "/sys/class/net/%s/device/numa_node%c", ifname, 0);
+  err = clib_sysfs_read (path, "%d", &numa);
+  if (err || numa < 0)
     numa = 0;
 
-  fclose (fptr);
+  clib_error_free (err);
+  vec_free (path);
   return numa;
 }