[libvirt] [PATCH 1 of 3] Add get/set of cpu.shares to cgroup implementation

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

 



This brings get/set of U64 out of the #if 0, which looks messier than it is.

diff -r 64f19f607bc6 -r 6fb284fa200a src/cgroup.c
--- a/src/cgroup.c	Fri Oct 03 17:58:02 2008 +0000
+++ b/src/cgroup.c	Tue Oct 07 08:21:49 2008 -0700
@@ -224,26 +224,6 @@
     return rc;
 }
 
-#if 0
-/* This is included for completeness, but not yet used */
-
-static int virCgroupSetValueI64(virCgroupPtr group,
-                                const char *key,
-                                int64_t value)
-{
-    char *strval = NULL;
-    int rc;
-
-    if (asprintf(&strval, "%" PRIi64, value) == -1)
-        return -ENOMEM;
-
-    rc = virCgroupSetValueStr(group, key, strval);
-
-    VIR_FREE(strval);
-
-    return rc;
-}
-
 static int virCgroupGetValueStr(virCgroupPtr group,
                                 const char *key,
                                 char **value)
@@ -293,20 +273,21 @@
     return rc;
 }
 
-static int virCgroupGetValueU64(virCgroupPtr group,
+#if 0
+/* This is included for completeness, but not yet used */
+
+static int virCgroupSetValueI64(virCgroupPtr group,
                                 const char *key,
-                                uint64_t *value)
+                                int64_t value)
 {
     char *strval = NULL;
-    int rc = 0;
+    int rc;
 
-    rc = virCgroupGetValueStr(group, key, &strval);
-    if (rc != 0)
-        goto out;
+    if (asprintf(&strval, "%" PRIi64, value) == -1)
+        return -ENOMEM;
 
-    if (sscanf(strval, "%" SCNu64, value) != 1)
-        rc = -EINVAL;
-out:
+    rc = virCgroupSetValueStr(group, key, strval);
+
     VIR_FREE(strval);
 
     return rc;
@@ -331,6 +312,25 @@
     return rc;
 }
 #endif
+
+static int virCgroupGetValueU64(virCgroupPtr group,
+                                const char *key,
+                                uint64_t *value)
+{
+    char *strval = NULL;
+    int rc = 0;
+
+    rc = virCgroupGetValueStr(group, key, &strval);
+    if (rc != 0)
+        goto out;
+
+    if (sscanf(strval, "%" SCNu64, value) != 1)
+        rc = -EINVAL;
+out:
+    VIR_FREE(strval);
+
+    return rc;
+}
 
 static int _virCgroupInherit(const char *path,
                              const char *key)
@@ -760,3 +760,13 @@
 
     return rc;
 }
+
+int virCgroupSetCpuShares(virCgroupPtr group, unsigned long shares)
+{
+    return virCgroupSetValueU64(group, "cpu.shares", (uint64_t)shares);
+}
+
+int virCgroupGetCpuShares(virCgroupPtr group, unsigned long *shares)
+{
+    return virCgroupGetValueU64(group, "cpu.shares", (uint64_t *)shares);
+}
diff -r 64f19f607bc6 -r 6fb284fa200a src/cgroup.h
--- a/src/cgroup.h	Fri Oct 03 17:58:02 2008 +0000
+++ b/src/cgroup.h	Tue Oct 07 08:21:49 2008 -0700
@@ -36,6 +36,9 @@
                          int major,
                          int minor);
 
+int virCgroupSetCpuShares(virCgroupPtr group, unsigned long shares);
+int virCgroupGetCpuShares(virCgroupPtr group, unsigned long *shares);
+
 int virCgroupRemove(virCgroupPtr group);
 
 void virCgroupFree(virCgroupPtr *group);

--
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]