提交 064024e7 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1AddTask

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 b148d080
......@@ -540,7 +540,7 @@ virCgroupSetValueU64(virCgroupPtr group,
}
static int
int
virCgroupSetValueI64(virCgroupPtr group,
int controller,
const char *key,
......@@ -668,50 +668,6 @@ virCgroupNew(pid_t pid,
}
typedef enum {
/* Adds a whole process with all threads to specific cgroup except
* to systemd named controller. */
VIR_CGROUP_TASK_PROCESS = 1 << 0,
/* Same as VIR_CGROUP_TASK_PROCESS but it also adds the task to systemd
* named controller. */
VIR_CGROUP_TASK_SYSTEMD = 1 << 1,
/* Moves only specific thread into cgroup except to systemd
* named controller. */
VIR_CGROUP_TASK_THREAD = 1 << 2,
} virCgroupTaskFlags;
static int
virCgroupAddTaskInternal(virCgroupPtr group,
pid_t pid,
unsigned int flags)
{
int ret = -1;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
/* Skip over controllers not mounted */
if (!group->controllers[i].mountPoint)
continue;
/* We must never add tasks in systemd's hierarchy
* unless we're intentionally trying to move a
* task into a systemd machine scope */
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
!(flags & VIR_CGROUP_TASK_SYSTEMD))
continue;
if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
goto cleanup;
}
ret = 0;
cleanup:
return ret;
}
/**
* virCgroupAddProcess:
*
......@@ -726,7 +682,7 @@ virCgroupAddTaskInternal(virCgroupPtr group,
int
virCgroupAddProcess(virCgroupPtr group, pid_t pid)
{
return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS);
return group->backend->addTask(group, pid, VIR_CGROUP_TASK_PROCESS);
}
/**
......@@ -743,9 +699,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid)
int
virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
{
return virCgroupAddTaskInternal(group, pid,
VIR_CGROUP_TASK_PROCESS |
VIR_CGROUP_TASK_SYSTEMD);
return group->backend->addTask(group, pid,
VIR_CGROUP_TASK_PROCESS |
VIR_CGROUP_TASK_SYSTEMD);
}
/**
......@@ -763,7 +719,7 @@ int
virCgroupAddThread(virCgroupPtr group,
pid_t pid)
{
return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD);
return group->backend->addTask(group, pid, VIR_CGROUP_TASK_THREAD);
}
......
......@@ -35,6 +35,20 @@ typedef enum {
*/
} virCgroupBackendFlags;
typedef enum {
/* Adds a whole process with all threads to specific cgroup except
* to systemd named controller. */
VIR_CGROUP_TASK_PROCESS = 1 << 0,
/* Same as VIR_CGROUP_TASK_PROCESS but it also adds the task to systemd
* named controller. */
VIR_CGROUP_TASK_SYSTEMD = 1 << 1,
/* Moves only specific thread into cgroup except to systemd
* named controller. */
VIR_CGROUP_TASK_THREAD = 1 << 2,
} virCgroupBackendTaskFlags;
typedef enum {
VIR_CGROUP_BACKEND_TYPE_V1 = 0,
VIR_CGROUP_BACKEND_TYPE_LAST,
......@@ -103,6 +117,11 @@ typedef int
typedef int
(*virCgroupRemoveCB)(virCgroupPtr group);
typedef int
(*virCgroupAddTaskCB)(virCgroupPtr group,
pid_t pid,
unsigned int flags);
struct _virCgroupBackend {
virCgroupBackendType type;
......@@ -121,6 +140,7 @@ struct _virCgroupBackend {
virCgroupPathOfControllerCB pathOfController;
virCgroupMakeGroupCB makeGroup;
virCgroupRemoveCB remove;
virCgroupAddTaskCB addTask;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;
......
......@@ -73,6 +73,11 @@ int virCgroupGetValueU64(virCgroupPtr group,
const char *key,
unsigned long long int *value);
int virCgroupSetValueI64(virCgroupPtr group,
int controller,
const char *key,
long long int value);
int virCgroupPartitionEscape(char **path);
int virCgroupNewPartition(const char *path,
......
......@@ -705,6 +705,36 @@ virCgroupV1Remove(virCgroupPtr group)
}
static int
virCgroupV1AddTask(virCgroupPtr group,
pid_t pid,
unsigned int flags)
{
int ret = -1;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
/* Skip over controllers not mounted */
if (!group->controllers[i].mountPoint)
continue;
/* We must never add tasks in systemd's hierarchy
* unless we're intentionally trying to move a
* task into a systemd machine scope */
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
!(flags & VIR_CGROUP_TASK_SYSTEMD))
continue;
if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
goto cleanup;
}
ret = 0;
cleanup:
return ret;
}
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
......@@ -722,6 +752,7 @@ virCgroupBackend virCgroupV1Backend = {
.pathOfController = virCgroupV1PathOfController,
.makeGroup = virCgroupV1MakeGroup,
.remove = virCgroupV1Remove,
.addTask = virCgroupV1AddTask,
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册