]> git.ipfire.org Git - thirdparty/libvirt.git/commit
virCgroupController: Check the enum fits into 'int'
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 27 Mar 2015 12:45:33 +0000 (13:45 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 30 Mar 2015 13:20:28 +0000 (15:20 +0200)
commit771e6e5a466364dfd9da9ce6cfa2f787084e9a15
tree10a32f4b1a9b4248240aaadefde445845fd5cbaa
parent149a62bc83166aeaf36eaf5f0cde1c55607ddde8
virCgroupController: Check the enum fits into 'int'

Throughout our code, the virCgroupController enum is used in two ways.
First as an index to an array of cgroup controllers:

struct virCgroup {
    char *path;

    struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
};

Second way is that when calling virCgroupNew() a bitmask of the enum
items can be passed to selectively detect only some controllers. For
instance:

int
virCgroupNewVcpu(virCgroupPtr domain,
                 int vcpuid,
                 bool create,
                 virCgroupPtr *group)
{
    ...
    controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
                   (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
                   (1 << VIR_CGROUP_CONTROLLER_CPUSET));

    if (virCgroupNew(-1, name, domain, controllers, group) < 0)
        goto cleanup;
}

Even though it's highly unlikely that so many new controllers will be
invented so that we would overflow when constructing the bitmask, it
doesn't hurt to check at compile time either.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/util/vircgroup.h