]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: extract virCgroupV1GetBlkioIoDeviceServiced
authorPavel Hrdina <phrdina@redhat.com>
Fri, 17 Aug 2018 13:30:21 +0000 (15:30 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Sep 2018 11:40:22 +0000 (13:40 +0200)
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroup.c
src/util/vircgroupbackend.h
src/util/vircgrouppriv.h
src/util/vircgroupv1.c

index a9c0a4d3bed74d45cd98ee8fee102ed20aa42a0e..a4816d699b43985bf0202b076a1be291aae5e0a2 100644 (file)
@@ -405,7 +405,7 @@ virCgroupDetect(virCgroupPtr group,
 }
 
 
-static char *
+char *
 virCgroupGetBlockDevString(const char *path)
 {
     char *ret = NULL;
@@ -1333,84 +1333,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);
 }
 
 
index 585a2eb353a10ebb6b4fb23441edd06588eb6bc3..e16d631a0f7175f82465aca3bff44f68f32afd78 100644 (file)
@@ -152,6 +152,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;
 
@@ -179,6 +187,7 @@ struct _virCgroupBackend {
     virCgroupSetBlkioWeightCB setBlkioWeight;
     virCgroupGetBlkioWeightCB getBlkioWeight;
     virCgroupGetBlkioIoServicedCB getBlkioIoServiced;
+    virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
index 01714370be7a0bbc02f1b250bf52cfff17e2c762..525c288a9a7087cf245e8154937c9360df25a091 100644 (file)
@@ -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,
index 70a6fc5d8334bd1cf4033d52f3c887e4cd0a4cca..0d876c8f76c381e562c3a69016e31b117bf07965 100644 (file)
@@ -1048,6 +1048,95 @@ 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 = 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;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -1073,6 +1162,7 @@ virCgroupBackend virCgroupV1Backend = {
     .setBlkioWeight = virCgroupV1SetBlkioWeight,
     .getBlkioWeight = virCgroupV1GetBlkioWeight,
     .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
+    .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
 };