[PATCH V2 1/2] util: Add more virsysfs functions for handling resctrl sysfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extended /sys/fs/resctrl sysfs handling.

Signed-off-by: Eli Qiao <liyong.qiao@xxxxxxxxx>
---
 src/libvirt_private.syms |  11 ++++-
 src/util/virsysfs.c      | 102 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/util/virsysfs.h      |  16 ++++++++
 src/util/virsysfspriv.h  |   1 +
 4 files changed, 128 insertions(+), 2 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b551cb8..b03ad5b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2388,6 +2388,10 @@ virRandomGenerateWWN;
 virRandomInt;
 
 
+# util/virresctrl.h
+virResCtrlAvailable;
+virResCtrlInit;
+
 # util/virrotatingfile.h
 virRotatingFileReaderConsume;
 virRotatingFileReaderFree;
@@ -2626,13 +2630,18 @@ virSysfsGetCpuValueString;
 virSysfsGetCpuValueUint;
 virSysfsGetNodeValueBitmap;
 virSysfsGetNodeValueString;
+virSysfsGetResctrlInfoString;
+virSysfsGetResctrlInfoUint;
+virSysfsGetResctrlPath;
+virSysfsGetResctrlString;
+virSysfsGetResctrlUint;
 virSysfsGetSystemPath;
 virSysfsGetValueBitmap;
 virSysfsGetValueInt;
 virSysfsGetValueString;
+virSysfsSetResctrlPath;
 virSysfsSetSystemPath;
 
-
 # util/virsysinfo.h
 virSysinfoBaseBoardDefClear;
 virSysinfoBIOSDefFree;
diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c
index 7a98b48..97808be 100644
--- a/src/util/virsysfs.c
+++ b/src/util/virsysfs.c
@@ -36,8 +36,10 @@ VIR_LOG_INIT("util.sysfs");
 
 #define VIR_SYSFS_VALUE_MAXLEN 8192
 #define SYSFS_SYSTEM_PATH "/sys/devices/system"
+#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl"
 
 static const char *sysfs_system_path = SYSFS_SYSTEM_PATH;
+static const char *sysfs_resctrl_path = SYSFS_RESCTRL_PATH;
 
 
 void virSysfsSetSystemPath(const char *path)
@@ -48,13 +50,26 @@ void virSysfsSetSystemPath(const char *path)
         sysfs_system_path = SYSFS_SYSTEM_PATH;
 }
 
-
 const char *
 virSysfsGetSystemPath(void)
 {
     return sysfs_system_path;
 }
 
+void virSysfsSetResctrlPath(const char *path)
+{
+    if (path)
+        sysfs_resctrl_path  = path;
+    else
+        sysfs_resctrl_path = SYSFS_RESCTRL_PATH;
+}
+
+const char *
+virSysfsGetResctrlPath(void)
+{
+    return sysfs_resctrl_path;
+}
+
 int
 virSysfsGetValueInt(const char *file,
                     int *value)
@@ -227,3 +242,88 @@ virSysfsGetNodeValueBitmap(unsigned int node,
     VIR_FREE(path);
     return ret;
 }
+
+int
+virSysfsGetResctrlString(const char* file,
+                         char **value)
+{
+    char *path = NULL;
+    int ret = -1;
+    if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0)
+        return -1;
+
+    if (!virFileExists(path)) {
+        ret = -2;
+        goto cleanup;
+    }
+
+    if (virFileReadAll(path, VIR_SYSFS_VALUE_MAXLEN, value) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(path);
+    return ret;
+}
+
+int
+virSysfsGetResctrlUint(const char* file,
+                       unsigned int *value)
+{
+    char *path = NULL;
+    int ret = -1;
+    if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0)
+        return -1;
+
+    if (!virFileExists(path)) {
+        ret = -2;
+        goto cleanup;
+    }
+
+    ret = virFileReadValueUint(path, value);
+
+ cleanup:
+    VIR_FREE(path);
+    return ret;
+}
+
+int
+virSysfsGetResctrlInfoString(const char* file,
+                             char **value)
+{
+    char *path = NULL;
+    int ret = -1;
+    if (virAsprintf(&path, "%s/info/%s", sysfs_resctrl_path, file) < 0)
+        return -1;
+
+    if (!virFileExists(path)) {
+        ret = -2;
+        goto cleanup;
+    }
+
+    if (virFileReadAll(path, VIR_SYSFS_VALUE_MAXLEN, value) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(path);
+    return ret;
+}
+
+int
+virSysfsGetResctrlInfoUint(const char *file,
+                          unsigned int *value)
+{
+    char *path = NULL;
+    int ret = -1;
+
+    if (virAsprintf(&path, "%s/info/%s", sysfs_resctrl_path, file) < 0)
+        return -1;
+
+    ret = virFileReadValueUint(path, value);
+
+    VIR_FREE(path);
+    return ret;
+}
diff --git a/src/util/virsysfs.h b/src/util/virsysfs.h
index cd871ff..af1e786 100644
--- a/src/util/virsysfs.h
+++ b/src/util/virsysfs.h
@@ -25,6 +25,7 @@
 # include "virbitmap.h"
 
 const char * virSysfsGetSystemPath(void);
+const char * virSysfsGetResctrlPath(void);
 
 int
 virSysfsGetValueInt(const char *file,
@@ -67,4 +68,19 @@ virSysfsGetNodeValueBitmap(unsigned int cpu,
                            const char *file,
                            virBitmapPtr *value);
 
+int
+virSysfsGetResctrlString(const char* file,
+                         char **value);
+
+int
+virSysfsGetResctrlUint(const char* file,
+                       unsigned int *value);
+
+int
+virSysfsGetResctrlInfoString(const char* file,
+                             char **value);
+
+int
+virSysfsGetResctrlInfoUint(const char *file,
+                          unsigned int *value);
 #endif /* __VIR_SYSFS_H__*/
diff --git a/src/util/virsysfspriv.h b/src/util/virsysfspriv.h
index ae9f54a..bf36082 100644
--- a/src/util/virsysfspriv.h
+++ b/src/util/virsysfspriv.h
@@ -24,5 +24,6 @@
 # include "virsysfs.h"
 
 void virSysfsSetSystemPath(const char *path);
+void virSysfsSetResctrlPath(const char *path);
 
 #endif /* __VIR_SYSFS_PRIV_H__*/
-- 
1.9.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux