mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
New cgroups API for atomically creating machine cgroups
Instead of requiring one API call to create a cgroup and another to add a task to it, introduce a new API virCgroupNewMachine which does both jobs at once. This will facilitate the later code to talk to systemd to achieve this job which is also atomic. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
4e5f0dd2d3
commit
b333330aa5
@ -1195,6 +1195,7 @@ virCgroupNewDetect;
|
|||||||
virCgroupNewDomainPartition;
|
virCgroupNewDomainPartition;
|
||||||
virCgroupNewEmulator;
|
virCgroupNewEmulator;
|
||||||
virCgroupNewIgnoreError;
|
virCgroupNewIgnoreError;
|
||||||
|
virCgroupNewMachine;
|
||||||
virCgroupNewPartition;
|
virCgroupNewPartition;
|
||||||
virCgroupNewSelf;
|
virCgroupNewSelf;
|
||||||
virCgroupNewVcpu;
|
virCgroupNewVcpu;
|
||||||
|
@ -1565,6 +1565,57 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int virCgroupNewMachine(const char *name,
|
||||||
|
const char *drivername,
|
||||||
|
bool privileged ATTRIBUTE_UNUSED,
|
||||||
|
const unsigned char *uuid ATTRIBUTE_UNUSED,
|
||||||
|
const char *rootdir ATTRIBUTE_UNUSED,
|
||||||
|
pid_t pidleader ATTRIBUTE_UNUSED,
|
||||||
|
bool isContainer ATTRIBUTE_UNUSED,
|
||||||
|
const char *partition,
|
||||||
|
int controllers,
|
||||||
|
virCgroupPtr *group)
|
||||||
|
{
|
||||||
|
virCgroupPtr parent = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
*group = NULL;
|
||||||
|
|
||||||
|
if (virCgroupNewPartition(partition,
|
||||||
|
STREQ(partition, "/machine"),
|
||||||
|
controllers,
|
||||||
|
&parent) < 0) {
|
||||||
|
if (virCgroupNewIgnoreError())
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virCgroupNewDomainPartition(parent,
|
||||||
|
drivername,
|
||||||
|
name,
|
||||||
|
true,
|
||||||
|
group) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virCgroupAddTask(*group, pidleader) < 0) {
|
||||||
|
virErrorPtr saved = virSaveLastError();
|
||||||
|
virCgroupRemove(*group);
|
||||||
|
virCgroupFree(group);
|
||||||
|
if (saved) {
|
||||||
|
virSetError(saved);
|
||||||
|
virFreeError(saved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virCgroupFree(&parent);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool virCgroupNewIgnoreError(void)
|
bool virCgroupNewIgnoreError(void)
|
||||||
{
|
{
|
||||||
if (virLastErrorIsSystemErrno(ENXIO) ||
|
if (virLastErrorIsSystemErrno(ENXIO) ||
|
||||||
|
@ -83,6 +83,19 @@ int virCgroupNewEmulator(virCgroupPtr domain,
|
|||||||
int virCgroupNewDetect(pid_t pid,
|
int virCgroupNewDetect(pid_t pid,
|
||||||
virCgroupPtr *group);
|
virCgroupPtr *group);
|
||||||
|
|
||||||
|
int virCgroupNewMachine(const char *name,
|
||||||
|
const char *drivername,
|
||||||
|
bool privileged,
|
||||||
|
const unsigned char *uuid,
|
||||||
|
const char *rootdir,
|
||||||
|
pid_t pidleader,
|
||||||
|
bool isContainer,
|
||||||
|
const char *partition,
|
||||||
|
int controllers,
|
||||||
|
virCgroupPtr *group)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
||||||
|
ATTRIBUTE_NONNULL(4);
|
||||||
|
|
||||||
bool virCgroupNewIgnoreError(void);
|
bool virCgroupNewIgnoreError(void);
|
||||||
|
|
||||||
int virCgroupPathOfController(virCgroupPtr group,
|
int virCgroupPathOfController(virCgroupPtr group,
|
||||||
|
Loading…
Reference in New Issue
Block a user