Move virGetCgroupValueRaw from vircgroup.c, so that we can call it more appropriately at any where. And change it to a more generic name virGetValueRaw. Replace virGetCgroupValueRaw by virGetValueRaw in cgroup data obtain. Signed-off-by: Yang Fei <yangfei85@xxxxxxxxxx> --- src/util/vircgroup.c | 29 ++--------------------------- src/util/vircgrouppriv.h | 3 --- src/util/vircgroupv1.c | 5 +++-- src/util/vircgroupv2.c | 5 +++-- src/util/virutil.c | 23 +++++++++++++++++++++++ src/util/virutil.h | 3 +++ 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 65a81e8d6f..80a06c78b9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -48,6 +48,7 @@ #include "virtypedparam.h" #include "virhostcpu.h" #include "virthread.h" +#include "virutil.h" VIR_LOG_INIT("util.cgroup"); @@ -539,31 +540,6 @@ virCgroupSetValueRaw(const char *path, return 0; } - -int -virCgroupGetValueRaw(const char *path, - char **value) -{ - int rc; - - *value = NULL; - - VIR_DEBUG("Get value %s", path); - - if ((rc = virFileReadAll(path, 1024*1024, value)) < 0) { - virReportSystemError(errno, - _("Unable to read from '%s'"), path); - return -1; - } - - /* Terminated with '\n' has sometimes harmful effects to the caller */ - if (rc > 0 && (*value)[rc - 1] == '\n') - (*value)[rc - 1] = '\0'; - - return 0; -} - - int virCgroupSetValueStr(virCgroup *group, int controller, @@ -590,10 +566,9 @@ virCgroupGetValueStr(virCgroup *group, if (virCgroupPathOfController(group, controller, key, &keypath) < 0) return -1; - return virCgroupGetValueRaw(keypath, value); + return virGetValueRaw(keypath, value); } - int virCgroupGetValueForBlkDev(const char *str, const char *path, diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index caf7ed84db..627308d995 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -76,9 +76,6 @@ int virCgroupSetValueDBus(const char *unitName, int virCgroupSetValueRaw(const char *path, const char *value); -int virCgroupGetValueRaw(const char *path, - char **value); - int virCgroupSetValueStr(virCgroup *group, int controller, const char *key, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 8a04bb2e4a..2a40de51a0 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -42,6 +42,7 @@ #include "virerror.h" #include "viralloc.h" #include "virthread.h" +#include "virutil.h" VIR_LOG_INIT("util.cgroup"); @@ -1042,7 +1043,7 @@ virCgroupV1GetBlkioWeight(virCgroup *group, return -1; } - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; if (virStrToLong_ui(value, NULL, 10, weight) < 0) { @@ -1297,7 +1298,7 @@ virCgroupV1GetBlkioDeviceWeight(virCgroup *group, return -1; } - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 8881d3a88a..1c444d58f2 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -41,6 +41,7 @@ #include "virlog.h" #include "virstring.h" #include "virsystemd.h" +#include "virutil.h" VIR_LOG_INIT("util.cgroup"); @@ -701,7 +702,7 @@ virCgroupV2GetBlkioWeight(virCgroup *group, return -1; } - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; if ((tmp = strstr(value, "default "))) { @@ -907,7 +908,7 @@ virCgroupV2GetBlkioDeviceWeight(virCgroup *group, return -1; } - if (virCgroupGetValueRaw(path, &value) < 0) + if (virGetValueRaw(path, &value) < 0) return -1; if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) diff --git a/src/util/virutil.c b/src/util/virutil.c index 311cbbf93a..c0d25fe247 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1936,3 +1936,26 @@ virPipeNonBlock(int fds[2]) { return virPipeImpl(fds, true, true); } + +int +virGetValueRaw(const char *path, + char **value) +{ + int rc; + + *value = NULL; + + VIR_DEBUG("Get value %s", path); + + if ((rc = virFileReadAll(path, 1024*1024, value)) < 0) { + virReportSystemError(errno, + _("Unable to read from '%s'"), path); + return -1; + } + + /* Terminated with '\n' has sometimes harmful effects to the caller */ + if (rc > 0 && (*value)[rc - 1] == '\n') + (*value)[rc - 1] = '\0'; + + return 0; +} diff --git a/src/util/virutil.h b/src/util/virutil.h index 854b494890..851b421476 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -225,3 +225,6 @@ int virPipeQuiet(int fds[2]); * Returns: -1 on error, 0 on success */ int virPipeNonBlock(int fds[2]); + +int virGetValueRaw(const char *path, + char **value); -- 2.23.0