mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
vircgroup: introduce virCgroupV2ValidateMachineGroup
When reconnecting to a domain we are validating the cgroup name. In case of cgroup v2 we need to validate only the new format for host without systemd '{machinename}.libvirt-{drivername}' or scope name generated by systemd. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
034ef217d7
commit
3a365ef697
@ -35,6 +35,7 @@
|
||||
#include "virfile.h"
|
||||
#include "virlog.h"
|
||||
#include "virstring.h"
|
||||
#include "virsystemd.h"
|
||||
|
||||
VIR_LOG_INIT("util.cgroup");
|
||||
|
||||
@ -89,10 +90,52 @@ virCgroupV2Available(void)
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
virCgroupV2ValidateMachineGroup(virCgroupPtr group,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
const char *drivername,
|
||||
const char *machinename)
|
||||
{
|
||||
VIR_AUTOFREE(char *) partmachinename = NULL;
|
||||
VIR_AUTOFREE(char *) scopename = NULL;
|
||||
char *tmp;
|
||||
|
||||
if (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename,
|
||||
drivername) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (virCgroupPartitionEscape(&partmachinename) < 0)
|
||||
return false;
|
||||
|
||||
if (!(scopename = virSystemdMakeScopeName(machinename, drivername,
|
||||
false))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (virCgroupPartitionEscape(&scopename) < 0)
|
||||
return false;
|
||||
|
||||
if (!(tmp = strrchr(group->unified.placement, '/')))
|
||||
return false;
|
||||
tmp++;
|
||||
|
||||
if (STRNEQ(tmp, partmachinename) &&
|
||||
STRNEQ(tmp, scopename)) {
|
||||
VIR_DEBUG("Name '%s' for unified does not match '%s' or '%s'",
|
||||
tmp, partmachinename, scopename);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virCgroupBackend virCgroupV2Backend = {
|
||||
.type = VIR_CGROUP_BACKEND_TYPE_V2,
|
||||
|
||||
.available = virCgroupV2Available,
|
||||
.validateMachineGroup = virCgroupV2ValidateMachineGroup,
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user