mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 23:07:44 +00:00
Introduce a more convenient virCgroupNewDetectMachine
Instead of requiring drivers to use a combination of calls to virCgroupNewDetect and virCgroupIsValidMachine, combine the two into virCgroupNewDetectMachine Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
6b79a47270
commit
a45b99ead9
@ -1192,6 +1192,7 @@ virCgroupKillPainfully;
|
||||
virCgroupKillRecursive;
|
||||
virCgroupMoveTask;
|
||||
virCgroupNewDetect;
|
||||
virCgroupNewDetectMachine;
|
||||
virCgroupNewDomainPartition;
|
||||
virCgroupNewEmulator;
|
||||
virCgroupNewIgnoreError;
|
||||
|
@ -1189,16 +1189,14 @@ int virLXCProcessStart(virConnectPtr conn,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0)
|
||||
if (virCgroupNewDetectMachine(vm->def->name, "lxc",
|
||||
vm->pid, &priv->cgroup) < 0)
|
||||
goto error;
|
||||
|
||||
if (!virCgroupIsValidMachineGroup(priv->cgroup,
|
||||
vm->def->name,
|
||||
"lxc")) {
|
||||
if (!priv->cgroup) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Cgroup name is not valid for machine %s"),
|
||||
_("No valid cgroup for machine %s"),
|
||||
vm->def->name);
|
||||
virCgroupFree(&priv->cgroup);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -1399,16 +1397,14 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
|
||||
if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
|
||||
goto error;
|
||||
|
||||
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0)
|
||||
if (virCgroupNewDetectMachine(vm->def->name, "lxc",
|
||||
vm->pid, &priv->cgroup) < 0)
|
||||
goto error;
|
||||
|
||||
if (!virCgroupIsValidMachineGroup(priv->cgroup,
|
||||
vm->def->name,
|
||||
"lxc")) {
|
||||
if (!priv->cgroup) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Cgroup name is not valid for machine %s"),
|
||||
_("No valid cgroup for machine %s"),
|
||||
vm->def->name);
|
||||
virCgroupFree(&priv->cgroup);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -704,19 +704,11 @@ qemuConnectCgroup(virQEMUDriverPtr driver,
|
||||
|
||||
virCgroupFree(&priv->cgroup);
|
||||
|
||||
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0) {
|
||||
if (virCgroupNewIgnoreError())
|
||||
goto done;
|
||||
if (virCgroupNewDetectMachine(vm->def->name,
|
||||
"qemu",
|
||||
vm->pid,
|
||||
&priv->cgroup) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virCgroupIsValidMachineGroup(priv->cgroup,
|
||||
vm->def->name,
|
||||
"qemu")) {
|
||||
VIR_DEBUG("Cgroup name is not valid for machine");
|
||||
virCgroupFree(&priv->cgroup);
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
ret = 0;
|
||||
|
@ -1575,6 +1575,28 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Returns 0 on success (but @group may be NULL), -1 on fatal error
|
||||
*/
|
||||
int virCgroupNewDetectMachine(const char *name,
|
||||
const char *drivername,
|
||||
pid_t pid,
|
||||
virCgroupPtr *group)
|
||||
{
|
||||
if (virCgroupNewDetect(pid, group) < 0) {
|
||||
if (virCgroupNewIgnoreError())
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!virCgroupIsValidMachineGroup(*group, name, drivername)) {
|
||||
virCgroupFree(group);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int virCgroupNewMachine(const char *name,
|
||||
const char *drivername,
|
||||
bool privileged ATTRIBUTE_UNUSED,
|
||||
|
@ -83,6 +83,11 @@ int virCgroupNewEmulator(virCgroupPtr domain,
|
||||
int virCgroupNewDetect(pid_t pid,
|
||||
virCgroupPtr *group);
|
||||
|
||||
int virCgroupNewDetectMachine(const char *name,
|
||||
const char *drivername,
|
||||
pid_t pid,
|
||||
virCgroupPtr *group);
|
||||
|
||||
int virCgroupNewMachine(const char *name,
|
||||
const char *drivername,
|
||||
bool privileged,
|
||||
|
Loading…
Reference in New Issue
Block a user