On 08/03/2015 10:50 AM, Martin Kletzander wrote:
Since now they were not needed, but I sense they will be in a short
while.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/libvirt_private.syms | 5 +
src/util/vircgroup.c | 277 ++++++++++++++++++++++++++++++++++++++++++++++-
src/util/vircgroup.h | 20 ++++
3 files changed, 299 insertions(+), 3 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d22bde70e17d..8803777cde80 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1175,6 +1175,11 @@ virCgroupDenyDeviceMajor;
virCgroupDenyDevicePath;
virCgroupDetectMountsFromFile;
virCgroupFree;
+virCgroupGetBlkioDeviceReadBps;
+virCgroupGetBlkioDeviceReadIops;
+virCgroupGetBlkioDeviceWeight;
+virCgroupGetBlkioDeviceWriteBps;
+virCgroupGetBlkioDeviceWriteIops;
virCgroupGetBlkioIoDeviceServiced;
virCgroupGetBlkioIoServiced;
virCgroupGetBlkioWeight;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index afa85ded9061..9d527fb8b99a 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -804,6 +804,36 @@ 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)))
+ return -1;
^^^
str is leaked. (Coverity found)
+
+ if (!(lines = virStringSplit(str, "\n", -1)))
+ goto error;
+
+ ret = VIR_STRDUP(*value, virStringGetFirstWithPrefix(lines, prefix));
^^^ can return NULL
VIR_STRDUP(*value, NULL)
??
+ error:
+ VIR_FREE(str);
+ VIR_FREE(prefix);
+ virStringFreeList(lines);
+ return ret;
+}
+
+
+static int
virCgroupSetValueU64(virCgroupPtr group,
int controller,
const char *key,
@@ -2259,9 +2289,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 +2316,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 +4421,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,
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 675a1851a1c5..63a9e1c05a16 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -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);
+
Each of these could have ATTRIBUTE_NONNULL() for arg2 and arg3, but I
also see it's not used for other virCgroupGet* API's...
John
int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb);
int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb);