When using a hierarchy of cgroups we might want to add tasks just to the children cgroups but never to the parent. To make sure we do not use a parent cgroup by accident add a mechanism that lets us assert a correct implementation in cases we want such a hierarchy. i.e. for qemu cpusets we want all tasks in /vcpuX or /emulator, not in /. Signed-off-by: Henning Schild <henning.schild@xxxxxxxxxxx> --- src/libvirt_private.syms | 2 ++ src/util/vircgroup.c | 19 +++++++++++++++++++ src/util/vircgroup.h | 3 +++ src/util/vircgrouppriv.h | 1 + 4 files changed, 25 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 83f6e2c..cf93d06 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1201,6 +1201,7 @@ virCgroupDenyDeviceMajor; virCgroupDenyDevicePath; virCgroupDetectMountsFromFile; virCgroupFree; +virCgroupGetAssertEmpty; virCgroupGetBlkioDeviceReadBps; virCgroupGetBlkioDeviceReadIops; virCgroupGetBlkioDeviceWeight; @@ -1245,6 +1246,7 @@ virCgroupNewThread; virCgroupPathOfController; virCgroupRemove; virCgroupRemoveRecursively; +virCgroupSetAssertEmpty; virCgroupSetBlkioDeviceReadBps; virCgroupSetBlkioDeviceReadIops; virCgroupSetBlkioDeviceWeight; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0b65238..ad46dfc 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1197,6 +1197,15 @@ virCgroupAddTaskController(virCgroupPtr group, pid_t pid, int controller) return -1; } + if(group->assert_empty & (1 << controller)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Controller '%s' is not supposed to contain any" + " tasks. group=%s pid=%d\n"), + virCgroupControllerTypeToString(controller), + group->path, pid); + return -1; + } + return virCgroupSetValueU64(group, controller, "tasks", (unsigned long long)pid); } @@ -1246,6 +1255,16 @@ virCgroupAddTaskStrController(virCgroupPtr group, return rc; } +void +virCgroupSetAssertEmpty(virCgroupPtr group, int mask) { + group->assert_empty = mask; +} + +int +virCgroupGetAssertEmpty(virCgroupPtr group) { + return group->assert_empty; +} + /** * virCgroupMoveTask: diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index 63a9e1c..f244c24 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -131,6 +131,9 @@ int virCgroupAddTaskController(virCgroupPtr group, pid_t pid, int controller); +void virCgroupSetAssertEmpty(virCgroupPtr group, int mask); +int virCgroupGetAssertEmpty(virCgroupPtr group); + int virCgroupMoveTask(virCgroupPtr src_group, virCgroupPtr dest_group); diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 722863e..944d6ae 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -44,6 +44,7 @@ struct virCgroupController { struct virCgroup { char *path; + int assert_empty; struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; }; -- 2.4.10 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list