Re: [PATCH v2 14/18] LXC from native: add lxc.cgroup.blkio.* mapping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 30, 2014 at 10:56:02AM +0100, Cédric Bosdonnat wrote:
> ---
>  src/lxc/lxc_native.c                               | 63 ++++++++++++++++++++++
>  tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config |  7 +++
>  tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml    | 35 ++++++++++++
>  tests/lxcconf2xmltest.c                            |  1 +
>  4 files changed, 106 insertions(+)
>  create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config
>  create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml

ACK

> 
> diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
> index e0a4769..346dbba 100644
> --- a/src/lxc/lxc_native.c
> +++ b/src/lxc/lxc_native.c
> @@ -692,6 +692,65 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
>      return 0;
>  }
>  
> +static int
> +lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data)
> +{
> +    char **parts = NULL;
> +    virBlkioDevicePtr device = NULL;
> +    virDomainDefPtr def = data;
> +
> +    if (STRNEQ(name, "lxc.cgroup.blkio.device_weight") || !value->str)
> +        return 0;
> +
> +    if ((!(parts = lxcStringSplit(value->str)) && (!parts[0] || !parts[1]))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("invalid blkio.device_weight value: '%s'"),
> +                       value->str);
> +        goto error;
> +    }
> +
> +    if (VIR_EXPAND_N(def->blkio.devices, def->blkio.ndevices, 1) < 0)
> +        goto error;
> +    device = &def->blkio.devices[def->blkio.ndevices - 1];
> +
> +    if (virAsprintf(&device->path, "/dev/block/%s", parts[0]) < 0)
> +        goto error;
> +
> +    if (virStrToLong_ui(parts[1], NULL, 10, &device->weight) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to parse integer: '%s'"), parts[1]);
> +        goto error;
> +    }
> +
> +    virStringFreeList(parts);
> +
> +    return 0;
> +
> +error:
> +    if (parts)
> +        virStringFreeList(parts);
> +    return -1;
> +}
> +
> +static int
> +lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties)
> +{
> +    virConfValuePtr value;
> +
> +    if ((value = virConfGetValue(properties, "lxc.cgroup.blkio.weight")) &&
> +            value->str && virStrToLong_ui(value->str, NULL, 10,
> +                                          &def->blkio.weight) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("failed to parse integer: '%s'"), value->str);
> +        return -1;
> +    }
> +
> +    if (virConfWalk(properties, lxcBlkioDeviceWalkCallback, def) < 0)
> +        return -1;
> +
> +    return 0;
> +}
> +
>  virDomainDefPtr
>  lxcParseConfigString(const char *config)
>  {
> @@ -776,6 +835,10 @@ lxcParseConfigString(const char *config)
>      if (lxcSetCpusetTune(vmdef, properties) < 0)
>          goto error;
>  
> +    /* lxc.cgroup.blkio.* */
> +    if (lxcSetBlkioTune(vmdef, properties) < 0)
> +        goto error;
> +
>      goto cleanup;
>  
>  error:
> diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config
> new file mode 100644
> index 0000000..8083c71
> --- /dev/null
> +++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.config
> @@ -0,0 +1,7 @@
> +lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
> +lxc.utsname = migrate_test
> +lxc.autodev=1
> +
> +lxc.cgroup.blkio.weight = 500
> +lxc.cgroup.blkio.device_weight = 8:16	1000
> +lxc.cgroup.blkio.device_weight = 8:0    300
> diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
> new file mode 100644
> index 0000000..d2408f4
> --- /dev/null
> +++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
> @@ -0,0 +1,35 @@
> +<domain type='lxc'>
> +  <name>migrate_test</name>
> +  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
> +  <memory unit='KiB'>65536</memory>
> +  <currentMemory unit='KiB'>0</currentMemory>
> +  <blkiotune>
> +    <weight>500</weight>
> +    <device>
> +      <path>/dev/block/8:16</path>
> +      <weight>1000</weight>
> +    </device>
> +    <device>
> +      <path>/dev/block/8:0</path>

Hmm, I don't think this is correct. The libvirt XML takes block
paths like /dev/sda, rather than relative sysfs block paths.

If this works, it is by luck rather than by design.

Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]