src/libvirt_private.syms | 4 ++ src/util/virsysfs.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++- src/util/virsysfs.h | 15 ++++++++ 3 files changed, 116 insertions(+), 1 deletion(-)
Extended /sys/fs/resctrl sysfs handling.
Signed-off-by: Eli Qiao <liyong.qiao@intel.com>
---
src/libvirt_private.syms | 4 ++
src/util/virsysfs.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++-
src/util/virsysfs.h | 15 ++++++++
3 files changed, 116 insertions(+), 1 deletion(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b551cb8..e07ae79 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2631,6 +2631,10 @@ virSysfsGetValueBitmap;
virSysfsGetValueInt;
virSysfsGetValueString;
virSysfsSetSystemPath;
+virSysfsGetResctrlString;
+virSysfsGetResctrlUint;
+virSysfsGetResctrlInfoString;
+virSysfsGetResCtrInfoUint;
# util/virsysinfo.h
diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c
index 7a98b48..d1be289 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,84 @@ virSysfsGetNodeValueBitmap(unsigned int node,
VIR_FREE(path);
return ret;
}
+
+int
+virSysfsGetResctrlString(const char* file,
+ char **value)
+{
+ chat *path = NULL;
+ int ret = -1;
+ if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0)
+ 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)
+{
+ chat *path = NULL;
+ int ret = -1;
+ if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0)
+ if (!virFileExists(path)) {
+ ret = -2;
+ goto cleanup;
+ }
+
+ ret = virFileReadValueUint(path, value);
+
+ cleanup:
+ VIR_FREE(path);
+ return ret;
+}
+
+int
+virSysfsGetResctrlInfoString(const char* file,
+ char **value)
+{
+ chat *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
+virSysfsGetResCtrInfoUint(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..81a27c2 100644
--- a/src/util/virsysfs.h
+++ b/src/util/virsysfs.h
@@ -67,4 +67,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
+virSysfsGetResCtrInfoUint(const char *file,
+ unsigned int *value);
#endif /* __VIR_SYSFS_H__*/
--
1.9.1
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Wed, Mar 29, 2017 at 05:44:36PM +0800, Eli Qiao wrote: >Extended /sys/fs/resctrl sysfs handling. > This looks good, few notes below. >Signed-off-by: Eli Qiao <liyong.qiao@intel.com> >--- > src/libvirt_private.syms | 4 ++ > src/util/virsysfs.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++- > src/util/virsysfs.h | 15 ++++++++ > 3 files changed, 116 insertions(+), 1 deletion(-) > >diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms >index b551cb8..e07ae79 100644 >--- a/src/libvirt_private.syms >+++ b/src/libvirt_private.syms >@@ -2631,6 +2631,10 @@ virSysfsGetValueBitmap; > virSysfsGetValueInt; > virSysfsGetValueString; > virSysfsSetSystemPath; >+virSysfsGetResctrlString; >+virSysfsGetResctrlUint; >+virSysfsGetResctrlInfoString; >+virSysfsGetResCtrInfoUint; > This will not pass the tests. > > # util/virsysinfo.h >diff --git a/src/util/virsysfs.c b/src/util/virsysfs.c >index 7a98b48..d1be289 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; >+} >+ This will not compile (no previous declaration) > int > virSysfsGetValueInt(const char *file, > int *value) >@@ -227,3 +242,84 @@ virSysfsGetNodeValueBitmap(unsigned int node, > VIR_FREE(path); > return ret; > } >+ >+int >+virSysfsGetResctrlString(const char* file, >+ char **value) >+{ >+ chat *path = NULL; >+ int ret = -1; Some empty line here ... >+ if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0) ... and there would be nice to read. >+ 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) >+{ >+ chat *path = NULL; >+ int ret = -1; >+ if (virAsprintf(&path, "%s/%s", sysfs_resctrl_path, file) < 0) >+ if (!virFileExists(path)) { >+ ret = -2; >+ goto cleanup; >+ } >+ >+ ret = virFileReadValueUint(path, value); >+ >+ cleanup: >+ VIR_FREE(path); >+ return ret; >+} >+ >+int >+virSysfsGetResctrlInfoString(const char* file, >+ char **value) >+{ >+ chat *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 >+virSysfsGetResCtrInfoUint(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..81a27c2 100644 >--- a/src/util/virsysfs.h >+++ b/src/util/virsysfs.h >@@ -67,4 +67,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 >+virSysfsGetResCtrInfoUint(const char *file, >+ unsigned int *value); > #endif /* __VIR_SYSFS_H__*/ >-- >1.9.1 > -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2024 Red Hat, Inc.