]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Add getters for cgroup block device I/O throttling
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 3 Aug 2015 13:10:20 +0000 (15:10 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Tue, 18 Aug 2015 23:25:16 +0000 (16:25 -0700)
Since now they were not needed, but I sense they will be in a short
while.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/libvirt_private.syms
src/util/vircgroup.c
src/util/vircgroup.h

index ef62a5be6bb12b18f358e257b871abda802bc612..62bd4c6d0ec19dbfaed13afa90350cd72d17bbd2 100644 (file)
@@ -1181,6 +1181,11 @@ virCgroupDenyDeviceMajor;
 virCgroupDenyDevicePath;
 virCgroupDetectMountsFromFile;
 virCgroupFree;
+virCgroupGetBlkioDeviceReadBps;
+virCgroupGetBlkioDeviceReadIops;
+virCgroupGetBlkioDeviceWeight;
+virCgroupGetBlkioDeviceWriteBps;
+virCgroupGetBlkioDeviceWriteIops;
 virCgroupGetBlkioIoDeviceServiced;
 virCgroupGetBlkioIoServiced;
 virCgroupGetBlkioWeight;
index afa85ded906120691c9c37383424bb7bf3a11971..c94512a148b9f9ce01c721bcd2bd2edd895385f3 100644 (file)
@@ -803,6 +803,39 @@ virCgroupGetValueStr(virCgroupPtr group,
 }
 
 
+static int
+virCgroupGetValueForBlkDev(virCgroupPtr group,
+                           int controller,
+                           const char *key,
+                           const char *path,
+                           char **value)
+{
+    char *prefix = NULL;
+    char *str = NULL;
+    char **lines = NULL;
+    int ret = -1;
+
+    if (virCgroupGetValueStr(group, controller, key, &str) < 0)
+        goto error;
+
+    if (!(prefix = virCgroupGetBlockDevString(path)))
+        goto error;
+
+    if (!(lines = virStringSplit(str, "\n", -1)))
+        goto error;
+
+    if (VIR_STRDUP(*value, virStringGetFirstWithPrefix(lines, prefix)) < 0)
+        goto error;
+
+    ret = 0;
+ error:
+    VIR_FREE(str);
+    VIR_FREE(prefix);
+    virStringFreeList(lines);
+    return ret;
+}
+
+
 static int
 virCgroupSetValueU64(virCgroupPtr group,
                      int controller,
@@ -2259,9 +2292,6 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group,
  * @weight: The new device weight (100-1000),
  * (10-1000) after kernel 2.6.39, or 0 to clear
  *
- * device_weight is treated as a write-only parameter, so
- * there isn't a getter counterpart.
- *
  * Returns: 0 on success, -1 on error
  */
 int
@@ -2289,6 +2319,196 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
     return ret;
 }
 
+/**
+ * virCgroupGetBlkioDeviceReadIops:
+ * @group: The cgroup to gather block io setting for
+ * @path: The path of device
+ * @riops: Returned device read iops throttle, 0 if there is none
+ *
+ * Returns: 0 on success, -1 on error
+ */
+int
+virCgroupGetBlkioDeviceReadIops(virCgroupPtr group,
+                                const char *path,
+                                unsigned int *riops)
+{
+    char *str = NULL;
+    int ret = -1;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.throttle.read_iops_device",
+                                   path,
+                                   &str) < 0)
+        goto error;
+
+    if (!str) {
+        *riops = 0;
+    } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        goto error;
+    }
+
+    ret = 0;
+ error:
+    VIR_FREE(str);
+    return ret;
+}
+
+/**
+ * virCgroupGetBlkioDeviceWriteIops:
+ * @group: The cgroup to gather block io setting for
+ * @path: The path of device
+ * @wiops: Returned device write iops throttle, 0 if there is none
+ *
+ * Returns: 0 on success, -1 on error
+ */
+int
+virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group,
+                                 const char *path,
+                                 unsigned int *wiops)
+{
+    char *str = NULL;
+    int ret = -1;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.throttle.write_iops_device",
+                                   path,
+                                   &str) < 0)
+        goto error;
+
+    if (!str) {
+        *wiops = 0;
+    } else if (virStrToLong_ui(str, NULL, 10, wiops) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        goto error;
+    }
+
+    ret = 0;
+ error:
+    VIR_FREE(str);
+    return ret;
+}
+
+/**
+ * virCgroupGetBlkioDeviceReadBps:
+ * @group: The cgroup to gather block io setting for
+ * @path: The path of device
+ * @rbps: Returned device read bps throttle, 0 if there is none
+ *
+ * Returns: 0 on success, -1 on error
+ */
+int
+virCgroupGetBlkioDeviceReadBps(virCgroupPtr group,
+                               const char *path,
+                               unsigned long long *rbps)
+{
+    char *str = NULL;
+    int ret = -1;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.throttle.read_bps_device",
+                                   path,
+                                   &str) < 0)
+        goto error;
+
+    if (!str) {
+        *rbps = 0;
+    } else if (virStrToLong_ull(str, NULL, 10, rbps) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        goto error;
+    }
+
+    ret = 0;
+ error:
+    VIR_FREE(str);
+    return ret;
+}
+
+/**
+ * virCgroupGetBlkioDeviceWriteBps:
+ * @group: The cgroup to gather block io setting for
+ * @path: The path of device
+ * @wbps: Returned device write bps throttle, 0 if there is none
+ *
+ * Returns: 0 on success, -1 on error
+ */
+int
+virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group,
+                                const char *path,
+                                unsigned long long *wbps)
+{
+    char *str = NULL;
+    int ret = -1;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.throttle.write_bps_device",
+                                   path,
+                                   &str) < 0)
+        goto error;
+
+    if (!str) {
+        *wbps = 0;
+    } else if (virStrToLong_ull(str, NULL, 10, wbps) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        goto error;
+    }
+
+    ret = 0;
+ error:
+    VIR_FREE(str);
+    return ret;
+}
+
+/**
+ * virCgroupGetBlkioDeviceWeight:
+ * @group: The cgroup to gather block io setting for
+ * @path: The path of device
+ * @weight: Returned device weight, 0 if there is none
+ *
+ * Returns: 0 on success, -1 on error
+ */
+int
+virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
+                              const char *path,
+                              unsigned int *weight)
+{
+    char *str = NULL;
+    int ret = -1;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.weight_device",
+                                   path,
+                                   &str) < 0)
+        goto error;
+
+    if (!str) {
+        *weight = 0;
+    } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        goto error;
+    }
+
+    ret = 0;
+ error:
+    VIR_FREE(str);
+    return ret;
+}
+
 
 /**
  * virCgroupSetMemory:
@@ -4204,6 +4424,60 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group ATTRIBUTE_UNUSED,
     return -1;
 }
 
+int
+virCgroupGetBlkioDeviceWeight(virCgroupPtr group ATTRIBUTE_UNUSED,
+                              const char *path ATTRIBUTE_UNUSED,
+                              const char *dev_str ATTRIBUTE_UNUSED,
+                              unsigned int weight ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+int
+virCgroupGetBlkioDeviceReadIops(virCgroupPtr group ATTRIBUTE_UNUSED,
+                                const char *path ATTRIBUTE_UNUSED,
+                                const char *dev_str ATTRIBUTE_UNUSED,
+                                unsigned int riops ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+int
+virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group ATTRIBUTE_UNUSED,
+                                 const char *path ATTRIBUTE_UNUSED,
+                                 const char *dev_str ATTRIBUTE_UNUSED,
+                                 unsigned int wiops ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+int
+virCgroupGetBlkioDeviceReadBps(virCgroupPtr group ATTRIBUTE_UNUSED,
+                               const char *path ATTRIBUTE_UNUSED,
+                               const char *dev_str ATTRIBUTE_UNUSED,
+                               unsigned long long rbps ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+int
+virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group ATTRIBUTE_UNUSED,
+                                const char *path ATTRIBUTE_UNUSED,
+                                const char *dev_str ATTRIBUTE_UNUSED,
+                                unsigned long long wbps ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
 
 int
 virCgroupSetMemory(virCgroupPtr group ATTRIBUTE_UNUSED,
index 675a1851a1c5f4e4d1cca031d5da75f7c5a75fde..63a9e1c05a1639070fcb413445f7301d23862e2b 100644 (file)
@@ -169,6 +169,26 @@ int virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group,
                                     const char *path,
                                     unsigned long long wbps);
 
+int virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
+                                  const char *path,
+                                  unsigned int *weight);
+
+int virCgroupGetBlkioDeviceReadIops(virCgroupPtr group,
+                                    const char *path,
+                                    unsigned int *riops);
+
+int virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group,
+                                     const char *path,
+                                     unsigned int *wiops);
+
+int virCgroupGetBlkioDeviceReadBps(virCgroupPtr group,
+                                   const char *path,
+                                   unsigned long long *rbps);
+
+int virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group,
+                                    const char *path,
+                                    unsigned long long *wbps);
+
 int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
 int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);