diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 064b99dceb9dc9c4f173f22ba8fb8c1ba62b46cb..97258917bc20c2ce0a8fe91b088b60fa186f3302 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -949,10 +949,33 @@ static int virCgroupV1SetBlkioWeight(virCgroupPtr group, unsigned int weight) { - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", - weight); + VIR_AUTOFREE(char *) path = NULL; + VIR_AUTOFREE(char *) value = NULL; + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.bfq.weight", &path) < 0) { + return -1; + } + + if (!virFileExists(path)) { + VIR_FREE(path); + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight", &path) < 0) { + return -1; + } + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for bfq or cfq scheduler")); + return -1; + } + + if (virAsprintf(&value, "%u", weight) < 0) + return -1; + + return virCgroupSetValueRaw(path, value); } @@ -960,14 +983,40 @@ static int virCgroupV1GetBlkioWeight(virCgroupPtr group, unsigned int *weight) { - unsigned long long tmp; - int ret; - ret = virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", &tmp); - if (ret == 0) - *weight = tmp; - return ret; + VIR_AUTOFREE(char *) path = NULL; + VIR_AUTOFREE(char *) value = NULL; + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.bfq.weight", &path) < 0) { + return -1; + } + + if (!virFileExists(path)) { + VIR_FREE(path); + + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight", &path) < 0) { + return -1; + } + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for bfq or cfq scheduler")); + return -1; + } + + if (virCgroupGetValueRaw(path, &value) < 0) + return -1; + + if (virStrToLong_ui(value, NULL, 10, weight) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + value); + return -1; + } + + return 0; } @@ -1156,41 +1205,58 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group, static int virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int weight) { VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) blkstr = NULL; + VIR_AUTOFREE(char *) path = NULL; - if (!(blkstr = virCgroupGetBlockDevString(path))) + if (!(blkstr = virCgroupGetBlockDevString(devPath))) return -1; if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) return -1; - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - str); + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", &path) < 0) { + return -1; + } + + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for cfq scheduler")); + return -1; + } + + return virCgroupSetValueRaw(path, str); } static int virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group, - const char *path, + const char *devPath, unsigned int *weight) { VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) value = NULL; + VIR_AUTOFREE(char *) path = NULL; - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - &value) < 0) { + if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", &path) < 0) { return -1; } - if (virCgroupGetValueForBlkDev(value, path, &str) < 0) + if (!virFileExists(path)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("blkio device weight is valid only for cfq scheduler")); + return -1; + } + + if (virCgroupGetValueRaw(path, &value) < 0) + return -1; + + if (virCgroupGetValueForBlkDev(value, devPath, &str) < 0) return -1; if (!str) {