mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +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;
|
virCgroupKillRecursive;
|
||||||
virCgroupMoveTask;
|
virCgroupMoveTask;
|
||||||
virCgroupNewDetect;
|
virCgroupNewDetect;
|
||||||
|
virCgroupNewDetectMachine;
|
||||||
virCgroupNewDomainPartition;
|
virCgroupNewDomainPartition;
|
||||||
virCgroupNewEmulator;
|
virCgroupNewEmulator;
|
||||||
virCgroupNewIgnoreError;
|
virCgroupNewIgnoreError;
|
||||||
|
@ -1189,16 +1189,14 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0)
|
if (virCgroupNewDetectMachine(vm->def->name, "lxc",
|
||||||
|
vm->pid, &priv->cgroup) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!virCgroupIsValidMachineGroup(priv->cgroup,
|
if (!priv->cgroup) {
|
||||||
vm->def->name,
|
|
||||||
"lxc")) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cgroup name is not valid for machine %s"),
|
_("No valid cgroup for machine %s"),
|
||||||
vm->def->name);
|
vm->def->name);
|
||||||
virCgroupFree(&priv->cgroup);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1399,16 +1397,14 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
|
|||||||
if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
|
if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0)
|
if (virCgroupNewDetectMachine(vm->def->name, "lxc",
|
||||||
|
vm->pid, &priv->cgroup) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!virCgroupIsValidMachineGroup(priv->cgroup,
|
if (!priv->cgroup) {
|
||||||
vm->def->name,
|
|
||||||
"lxc")) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Cgroup name is not valid for machine %s"),
|
_("No valid cgroup for machine %s"),
|
||||||
vm->def->name);
|
vm->def->name);
|
||||||
virCgroupFree(&priv->cgroup);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,19 +704,11 @@ qemuConnectCgroup(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
virCgroupFree(&priv->cgroup);
|
virCgroupFree(&priv->cgroup);
|
||||||
|
|
||||||
if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0) {
|
if (virCgroupNewDetectMachine(vm->def->name,
|
||||||
if (virCgroupNewIgnoreError())
|
"qemu",
|
||||||
goto done;
|
vm->pid,
|
||||||
|
&priv->cgroup) < 0)
|
||||||
goto cleanup;
|
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:
|
done:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -1575,6 +1575,28 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
#endif
|
#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,
|
int virCgroupNewMachine(const char *name,
|
||||||
const char *drivername,
|
const char *drivername,
|
||||||
bool privileged ATTRIBUTE_UNUSED,
|
bool privileged ATTRIBUTE_UNUSED,
|
||||||
|
@ -83,6 +83,11 @@ int virCgroupNewEmulator(virCgroupPtr domain,
|
|||||||
int virCgroupNewDetect(pid_t pid,
|
int virCgroupNewDetect(pid_t pid,
|
||||||
virCgroupPtr *group);
|
virCgroupPtr *group);
|
||||||
|
|
||||||
|
int virCgroupNewDetectMachine(const char *name,
|
||||||
|
const char *drivername,
|
||||||
|
pid_t pid,
|
||||||
|
virCgroupPtr *group);
|
||||||
|
|
||||||
int virCgroupNewMachine(const char *name,
|
int virCgroupNewMachine(const char *name,
|
||||||
const char *drivername,
|
const char *drivername,
|
||||||
bool privileged,
|
bool privileged,
|
||||||
|
Loading…
Reference in New Issue
Block a user