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:
Daniel P. Berrange 2013-07-18 16:55:37 +01:00
parent 4e5f0dd2d3
commit b333330aa5
3 changed files with 65 additions and 0 deletions

View File

@ -1195,6 +1195,7 @@ virCgroupNewDetect;
virCgroupNewDomainPartition;
virCgroupNewEmulator;
virCgroupNewIgnoreError;
virCgroupNewMachine;
virCgroupNewPartition;
virCgroupNewSelf;
virCgroupNewVcpu;

View File

@ -1565,6 +1565,57 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
}
#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)
{
if (virLastErrorIsSystemErrno(ENXIO) ||

View File

@ -83,6 +83,19 @@ int virCgroupNewEmulator(virCgroupPtr domain,
int virCgroupNewDetect(pid_t pid,
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);
int virCgroupPathOfController(virCgroupPtr group,