[libvirt] [PATCH 2/2]blkio: change the minimum weight according to kernel version

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Tue Oct 8 08:38:55 UTC 2013


From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>

kernel had changed the minimum weight of device blkio from
100 to 10 in commit df457f845e5449be2e7d96668791f789b3770ac7.
So we should to use new blkio weight range after 2.6.39.

libvirt should follow kernel according to
kernel version.

Signed-off-by: Gao feng <gaofeng at cn.fujitsu.com>
Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 src/util/vircgroup.c | 44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 498bc20..fa3b67e 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -57,6 +57,8 @@
 
 #define VIR_FROM_THIS VIR_FROM_CGROUP
 
+#define BLKIO_WEIGHT_DEVICE_RANGE_CHANGED_VERSION "2.6.39"
+
 #if defined(__linux__) && defined(HAVE_GETMNTENT_R) && \
     defined(_DIRENT_HAVE_D_TYPE) && defined(_SC_CLK_TCK)
 # define VIR_CGROUP_SUPPORTED
@@ -1820,11 +1822,20 @@ virCgroupPathOfController(virCgroupPtr group,
 int
 virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
 {
-    if (weight > 1000 || weight < 100) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("weight '%u' must be in range (100, 1000)"),
-                       weight);
-        return -1;
+    if (virCgroupVersionCheck(BLKIO_WEIGHT_DEVICE_RANGE_CHANGED_VERSION)) {
+        if (weight > 1000 || weight < 10) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("weight '%u' must be in range (10, 1000)"),
+                           weight);
+            return -1;
+        }
+    } else {
+        if (weight > 1000 || weight < 100) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("weight '%u' must be in range (100, 1000)"),
+                           weight);
+            return -1;
+        }
     }
 
     return virCgroupSetValueU64(group,
@@ -1861,7 +1872,8 @@ virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
  *
  * @group: The cgroup to change io device weight device for
  * @path: The device with a weight to alter
- * @weight: The new device weight (100-1000), or 0 to clear
+ * @weight: The new device weight (100-1000) or
+ * (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.
@@ -1877,11 +1889,21 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
     struct stat sb;
     int ret;
 
-    if (weight && (weight > 1000 || weight < 100)) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("weight '%u' must be in range (100, 1000)"),
-                       weight);
-        return -1;
+    if (virCgroupVersionCheck(BLKIO_WEIGHT_DEVICE_RANGE_CHANGED_VERSION)) {
+        if (weight &&
+            (weight > 1000 || weight < 10)) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("weight '%u' must be in range (10, 1000)"),
+                           weight);
+            return -1;
+        }
+    } else {
+        if (weight && (weight > 1000 || weight < 100)) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("weight '%u' must be in range (100, 1000)"),
+                           weight);
+            return -1;
+        }
     }
 
     if (stat(path, &sb) < 0) {
-- 
1.8.2.1




More information about the libvir-list mailing list