]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: vircgroup: introduce virCgroup(Get|Set)ValueRaw
authorPavel Hrdina <phrdina@redhat.com>
Tue, 18 Jun 2019 13:01:39 +0000 (15:01 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 21 Jun 2019 12:35:51 +0000 (14:35 +0200)
If we need to get a path of specific file and we need to check its
existence before we use it then we can reuse that path to get/set
values instead of calling the existing get/set value functions which
would be building the path again.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/vircgroup.c
src/util/vircgrouppriv.h

index f58e3364042ca24eb0e5f43236362bdab638c9d5..278453ea2fe50d42672f3b0cd3cb3755580c5a67 100644 (file)
@@ -455,28 +455,22 @@ virCgroupGetBlockDevString(const char *path)
 
 
 int
-virCgroupSetValueStr(virCgroupPtr group,
-                     int controller,
-                     const char *key,
+virCgroupSetValueRaw(const char *path,
                      const char *value)
 {
-    VIR_AUTOFREE(char *) keypath = NULL;
-    char *tmp = NULL;
+    char *tmp;
 
-    if (virCgroupPathOfController(group, controller, key, &keypath) < 0)
-        return -1;
-
-    VIR_DEBUG("Set value '%s' to '%s'", keypath, value);
-    if (virFileWriteStr(keypath, value, 0) < 0) {
+    VIR_DEBUG("Set value '%s' to '%s'", path, value);
+    if (virFileWriteStr(path, value, 0) < 0) {
         if (errno == EINVAL &&
-            (tmp = strrchr(keypath, '/'))) {
+            (tmp = strrchr(path, '/'))) {
             virReportSystemError(errno,
                                  _("Invalid value '%s' for '%s'"),
                                  value, tmp + 1);
             return -1;
         }
         virReportSystemError(errno,
-                             _("Unable to write to '%s'"), keypath);
+                             _("Unable to write to '%s'"), path);
         return -1;
     }
 
@@ -485,24 +479,18 @@ virCgroupSetValueStr(virCgroupPtr group,
 
 
 int
-virCgroupGetValueStr(virCgroupPtr group,
-                     int controller,
-                     const char *key,
+virCgroupGetValueRaw(const char *path,
                      char **value)
 {
-    VIR_AUTOFREE(char *) keypath = NULL;
     int rc;
 
     *value = NULL;
 
-    if (virCgroupPathOfController(group, controller, key, &keypath) < 0)
-        return -1;
-
-    VIR_DEBUG("Get value %s", keypath);
+    VIR_DEBUG("Get value %s", path);
 
-    if ((rc = virFileReadAll(keypath, 1024*1024, value)) < 0) {
+    if ((rc = virFileReadAll(path, 1024*1024, value)) < 0) {
         virReportSystemError(errno,
-                             _("Unable to read from '%s'"), keypath);
+                             _("Unable to read from '%s'"), path);
         return -1;
     }
 
@@ -514,6 +502,36 @@ virCgroupGetValueStr(virCgroupPtr group,
 }
 
 
+int
+virCgroupSetValueStr(virCgroupPtr group,
+                     int controller,
+                     const char *key,
+                     const char *value)
+{
+    VIR_AUTOFREE(char *) keypath = NULL;
+
+    if (virCgroupPathOfController(group, controller, key, &keypath) < 0)
+        return -1;
+
+    return virCgroupSetValueRaw(keypath, value);
+}
+
+
+int
+virCgroupGetValueStr(virCgroupPtr group,
+                     int controller,
+                     const char *key,
+                     char **value)
+{
+    VIR_AUTOFREE(char *) keypath = NULL;
+
+    if (virCgroupPathOfController(group, controller, key, &keypath) < 0)
+        return -1;
+
+    return virCgroupGetValueRaw(keypath, value);
+}
+
+
 int
 virCgroupGetValueForBlkDev(virCgroupPtr group,
                            int controller,
index 9110c7729743ab1003377421cfa673e50e7283bf..758091811e19d83e1eb8f8ee9cf7a4f8ba99811e 100644 (file)
@@ -58,6 +58,12 @@ struct _virCgroup {
     virCgroupV2Controller unified;
 };
 
+int virCgroupSetValueRaw(const char *path,
+                         const char *value);
+
+int virCgroupGetValueRaw(const char *path,
+                         char **value);
+
 int virCgroupSetValueStr(virCgroupPtr group,
                          int controller,
                          const char *key,