mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
vircgroup: extract virCgroupV1GetAnyController
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
5e2df3d07f
commit
d6564037e8
@ -3169,19 +3169,11 @@ virCgroupPathOfAnyController(virCgroupPtr group,
|
||||
const char *name,
|
||||
char **keypath)
|
||||
{
|
||||
size_t i;
|
||||
int controller;
|
||||
|
||||
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
||||
/* Reject any controller with a placement
|
||||
* of '/' to avoid doing bad stuff to the root
|
||||
* cgroup
|
||||
*/
|
||||
if (group->controllers[i].mountPoint &&
|
||||
group->controllers[i].placement &&
|
||||
STRNEQ(group->controllers[i].placement, "/")) {
|
||||
return virCgroupPathOfController(group, i, name, keypath);
|
||||
}
|
||||
}
|
||||
controller = group->backend->getAnyController(group);
|
||||
if (controller >= 0)
|
||||
return virCgroupPathOfController(group, controller, name, keypath);
|
||||
|
||||
virReportSystemError(ENOSYS, "%s",
|
||||
_("No controllers are mounted"));
|
||||
|
@ -77,6 +77,9 @@ typedef bool
|
||||
(*virCgroupHasControllerCB)(virCgroupPtr cgroup,
|
||||
int controller);
|
||||
|
||||
typedef int
|
||||
(*virCgroupGetAnyControllerCB)(virCgroupPtr group);
|
||||
|
||||
struct _virCgroupBackend {
|
||||
virCgroupBackendType type;
|
||||
|
||||
@ -91,6 +94,7 @@ struct _virCgroupBackend {
|
||||
virCgroupStealPlacementCB stealPlacement;
|
||||
virCgroupDetectControllersCB detectControllers;
|
||||
virCgroupHasControllerCB hasController;
|
||||
virCgroupGetAnyControllerCB getAnyController;
|
||||
};
|
||||
typedef struct _virCgroupBackend virCgroupBackend;
|
||||
typedef virCgroupBackend *virCgroupBackendPtr;
|
||||
|
@ -485,6 +485,27 @@ virCgroupV1HasController(virCgroupPtr group,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virCgroupV1GetAnyController(virCgroupPtr group)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
||||
/* Reject any controller with a placement
|
||||
* of '/' to avoid doing bad stuff to the root
|
||||
* cgroup
|
||||
*/
|
||||
if (group->controllers[i].mountPoint &&
|
||||
group->controllers[i].placement &&
|
||||
STRNEQ(group->controllers[i].placement, "/")) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
virCgroupBackend virCgroupV1Backend = {
|
||||
.type = VIR_CGROUP_BACKEND_TYPE_V1,
|
||||
|
||||
@ -498,6 +519,7 @@ virCgroupBackend virCgroupV1Backend = {
|
||||
.stealPlacement = virCgroupV1StealPlacement,
|
||||
.detectControllers = virCgroupV1DetectControllers,
|
||||
.hasController = virCgroupV1HasController,
|
||||
.getAnyController = virCgroupV1GetAnyController,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user