From: Cédric Bosdonnat Date: Wed, 5 Feb 2014 14:10:17 +0000 (+0100) Subject: LXC from native: convert blkio throttle config X-Git-Tag: v1.2.2-rc1~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d58fa3f85438c0c6c5cf04b27d6c709067ca921;p=thirdparty%2Flibvirt.git LXC from native: convert blkio throttle config --- diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index f9931767e5..ee07635a0f 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -733,8 +733,12 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data) char **parts = NULL; virBlkioDevicePtr device = NULL; virDomainDefPtr def = data; + size_t i = 0; + char *path = NULL; + int ret = -1; - if (STRNEQ(name, "lxc.cgroup.blkio.device_weight") || !value->str) + if (!STRPREFIX(name, "lxc.cgroup.blkio.") || + STREQ(name, "lxc.cgroup.blkio.weight")|| !value->str) return 0; if (!(parts = lxcStringSplit(value->str))) @@ -742,32 +746,74 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data) if (!parts[0] || !parts[1]) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid blkio.device_weight value: '%s'"), - value->str); - goto error; + _("invalid %s value: '%s'"), + name, value->str); + goto cleanup; } - if (VIR_EXPAND_N(def->blkio.devices, def->blkio.ndevices, 1) < 0) - goto error; - device = &def->blkio.devices[def->blkio.ndevices - 1]; + if (virAsprintf(&path, "/dev/block/%s", parts[0]) < 0) + goto cleanup; - if (virAsprintf(&device->path, "/dev/block/%s", parts[0]) < 0) - goto error; + /* Do we already have a device definition for this path? + * Get that device or create a new one */ + for (i = 0; !device && i < def->blkio.ndevices; i++) { + if (STREQ(def->blkio.devices[i].path, path)) + device = &def->blkio.devices[i]; + } + if (!device) { + if (VIR_EXPAND_N(def->blkio.devices, def->blkio.ndevices, 1) < 0) + goto cleanup; + device = &def->blkio.devices[def->blkio.ndevices - 1]; + device->path = path; + path = NULL; + } - if (virStrToLong_ui(parts[1], NULL, 10, &device->weight) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), parts[1]); - goto error; + /* Set the value */ + if (STREQ(name, "lxc.cgroup.blkio.device_weight")) { + if (virStrToLong_ui(parts[1], NULL, 10, &device->weight) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse device weight: '%s'"), parts[1]); + goto cleanup; + } + } else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_bps_device")) { + if (virStrToLong_ull(parts[1], NULL, 10, &device->rbps) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse read_bps_device: '%s'"), + parts[1]); + goto cleanup; + } + } else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_bps_device")) { + if (virStrToLong_ull(parts[1], NULL, 10, &device->wbps) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse write_bps_device: '%s'"), + parts[1]); + goto cleanup; + } + } else if (STREQ(name, "lxc.cgroup.blkio.throttle.read_iops_device")) { + if (virStrToLong_ui(parts[1], NULL, 10, &device->riops) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse read_iops_device: '%s'"), + parts[1]); + goto cleanup; + } + } else if (STREQ(name, "lxc.cgroup.blkio.throttle.write_iops_device")) { + if (virStrToLong_ui(parts[1], NULL, 10, &device->wiops) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse write_iops_device: '%s'"), + parts[1]); + goto cleanup; + } + } else { + VIR_WARN("Unhandled blkio tune config: %s", name); } - virStringFreeList(parts); + ret = 0; - return 0; + cleanup: + virStringFreeList(parts); + VIR_FREE(path); -error: - if (parts) - virStringFreeList(parts); - return -1; + return ret; } static int diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config index 8083c71d92..b19d9a52aa 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config +++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config @@ -5,3 +5,7 @@ lxc.autodev=1 lxc.cgroup.blkio.weight = 500 lxc.cgroup.blkio.device_weight = 8:16 1000 lxc.cgroup.blkio.device_weight = 8:0 300 +lxc.cgroup.blkio.throttle.read_bps_device = 8:16 1234 +lxc.cgroup.blkio.throttle.write_bps_device = 8:16 5678 +lxc.cgroup.blkio.throttle.read_iops_device = 8:16 4321 +lxc.cgroup.blkio.throttle.write_iops_device = 8:16 8765 diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml index d2408f48ff..628798dd32 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml @@ -8,6 +8,10 @@ /dev/block/8:16 1000 + 4321 + 8765 + 1234 + 5678 /dev/block/8:0