Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx> --- src/util/vircgroup.c | 83 ++-------------------------------- src/util/vircgroupbackend.h | 9 ++++ src/util/vircgrouppriv.h | 2 + src/util/vircgroupv1.c | 89 +++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 79 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index a9b67f7d53..0d93860df6 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -411,7 +411,7 @@ virCgroupDetect(virCgroupPtr group, } -static char * +char * virCgroupGetBlockDevString(const char *path) { char *ret = NULL; @@ -1339,84 +1339,9 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - VIR_AUTOFREE(char *) str1 = NULL; - VIR_AUTOFREE(char *) str2 = NULL; - VIR_AUTOFREE(char *) str3 = NULL; - char *p1 = NULL; - char *p2 = NULL; - size_t i; - - const char *value_names[] = { - "Read ", - "Write " - }; - long long *bytes_ptrs[] = { - bytes_read, - bytes_write - }; - long long *requests_ptrs[] = { - requests_read, - requests_write - }; - - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.io_service_bytes", &str1) < 0) - return -1; - - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.io_serviced", &str2) < 0) - return -1; - - if (!(str3 = virCgroupGetBlockDevString(path))) - return -1; - - if (!(p1 = strstr(str1, str3))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find byte stats for block device '%s'"), - str3); - return -1; - } - - if (!(p2 = strstr(str2, str3))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find request stats for block device '%s'"), - str3); - return -1; - } - - for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) { - if (!(p1 = strstr(p1, value_names[i]))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find byte %sstats for block device '%s'"), - value_names[i], str3); - return -1; - } - - if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_ptrs[i]) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse %sstat '%s'"), - value_names[i], p1 + strlen(value_names[i])); - return -1; - } - - if (!(p2 = strstr(p2, value_names[i]))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find request %sstats for block device '%s'"), - value_names[i], str3); - return -1; - } - - if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests_ptrs[i]) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse %sstat '%s'"), - value_names[i], p2 + strlen(value_names[i])); - return -1; - } - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioIoDeviceServiced, -1, + path, bytes_read, bytes_write, + requests_read, requests_write); } diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 90584947fd..bd78c5b937 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -144,6 +144,14 @@ typedef int long long *requests_read, long long *requests_write); +typedef int +(*virCgroupGetBlkioIoDeviceServicedCB)(virCgroupPtr group, + const char *path, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write); + struct _virCgroupBackend { virCgroupBackendType type; @@ -171,6 +179,7 @@ struct _virCgroupBackend { virCgroupSetBlkioWeightCB setBlkioWeight; virCgroupGetBlkioWeightCB getBlkioWeight; virCgroupGetBlkioIoServicedCB getBlkioIoServiced; + virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 01714370be..525c288a9a 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -80,6 +80,8 @@ int virCgroupSetValueI64(virCgroupPtr group, int virCgroupPartitionEscape(char **path); +char *virCgroupGetBlockDevString(const char *path); + int virCgroupNewPartition(const char *path, bool create, int controllers, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 4b9c03830c..206318d436 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1049,6 +1049,94 @@ virCgroupV1GetBlkioIoServiced(virCgroupPtr group, } +static int +virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group, + const char *path, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write) +{ + VIR_AUTOFREE(char *) str1 = NULL; + VIR_AUTOFREE(char *) str2 = NULL; + VIR_AUTOFREE(char *) str3 = NULL; + char *p1, *p2; + size_t i; + + const char *value_names[] = { + "Read ", + "Write " + }; + long long *bytes_ptrs[] = { + bytes_read, + bytes_write + }; + long long *requests_ptrs[] = { + requests_read, + requests_write + }; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.io_service_bytes", &str1) < 0) + return -1; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.io_serviced", &str2) < 0) + return -1; + + if (!(str3 = virCgroupGetBlockDevString(path))) + return -1; + + if (!(p1 = strstr(str1, str3))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find byte stats for block device '%s'"), + str3); + return -1; + } + + if (!(p2 = strstr(str2, str3))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find request stats for block device '%s'"), + str3); + return -1; + } + + for (i = 0; i < ARRAY_CARDINALITY(value_names); i++) { + if (!(p1 = strstr(p1, value_names[i]))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find byte %sstats for block device '%s'"), + value_names[i], str3); + return -1; + } + + if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_ptrs[i]) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse %sstat '%s'"), + value_names[i], p1 + strlen(value_names[i])); + return -1; + } + + if (!(p2 = strstr(p2, value_names[i]))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find request %sstats for block device '%s'"), + value_names[i], str3); + return -1; + } + + if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests_ptrs[i]) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse %sstat '%s'"), + value_names[i], p2 + strlen(value_names[i])); + return -1; + } + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend = { .type = VIR_CGROUP_BACKEND_TYPE_V1, @@ -1074,6 +1162,7 @@ virCgroupBackend virCgroupV1Backend = { .setBlkioWeight = virCgroupV1SetBlkioWeight, .getBlkioWeight = virCgroupV1GetBlkioWeight, .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced, + .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced, }; -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list