提交 b148d080 编写于 作者: P Pavel Hrdina

vircgroup: extract virCgroupV1Remove

Reviewed-by: NFabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 152c0f0b
...@@ -2919,7 +2919,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) ...@@ -2919,7 +2919,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
} }
static int int
virCgroupRemoveRecursively(char *grppath) virCgroupRemoveRecursively(char *grppath)
{ {
DIR *grpdir; DIR *grpdir;
...@@ -2982,38 +2982,7 @@ virCgroupRemoveRecursively(char *grppath) ...@@ -2982,38 +2982,7 @@ virCgroupRemoveRecursively(char *grppath)
int int
virCgroupRemove(virCgroupPtr group) virCgroupRemove(virCgroupPtr group)
{ {
int rc = 0; return group->backend->remove(group);
size_t i;
VIR_DEBUG("Removing cgroup %s", group->path);
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
VIR_AUTOFREE(char *) grppath = NULL;
/* Skip over controllers not mounted */
if (!group->controllers[i].mountPoint)
continue;
/* We must never rmdir() in systemd's hierarchy */
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
continue;
/* Don't delete the root group, if we accidentally
ended up in it for some reason */
if (STREQ(group->controllers[i].placement, "/"))
continue;
if (virCgroupPathOfController(group,
i,
NULL,
&grppath) != 0)
continue;
VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath);
rc = virCgroupRemoveRecursively(grppath);
}
VIR_DEBUG("Done removing cgroup %s", group->path);
return rc;
} }
......
...@@ -100,6 +100,9 @@ typedef int ...@@ -100,6 +100,9 @@ typedef int
bool create, bool create,
unsigned int flags); unsigned int flags);
typedef int
(*virCgroupRemoveCB)(virCgroupPtr group);
struct _virCgroupBackend { struct _virCgroupBackend {
virCgroupBackendType type; virCgroupBackendType type;
...@@ -117,6 +120,7 @@ struct _virCgroupBackend { ...@@ -117,6 +120,7 @@ struct _virCgroupBackend {
virCgroupGetAnyControllerCB getAnyController; virCgroupGetAnyControllerCB getAnyController;
virCgroupPathOfControllerCB pathOfController; virCgroupPathOfControllerCB pathOfController;
virCgroupMakeGroupCB makeGroup; virCgroupMakeGroupCB makeGroup;
virCgroupRemoveCB remove;
}; };
typedef struct _virCgroupBackend virCgroupBackend; typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr; typedef virCgroupBackend *virCgroupBackendPtr;
......
...@@ -88,4 +88,6 @@ int virCgroupNewDomainPartition(virCgroupPtr partition, ...@@ -88,4 +88,6 @@ int virCgroupNewDomainPartition(virCgroupPtr partition,
virCgroupPtr *group) virCgroupPtr *group)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
int virCgroupRemoveRecursively(char *grppath);
#endif /* __VIR_CGROUP_PRIV_H__ */ #endif /* __VIR_CGROUP_PRIV_H__ */
...@@ -667,6 +667,44 @@ virCgroupV1MakeGroup(virCgroupPtr parent, ...@@ -667,6 +667,44 @@ virCgroupV1MakeGroup(virCgroupPtr parent,
} }
static int
virCgroupV1Remove(virCgroupPtr group)
{
int rc = 0;
size_t i;
VIR_DEBUG("Removing cgroup %s", group->path);
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
VIR_AUTOFREE(char *) grppath = NULL;
/* Skip over controllers not mounted */
if (!group->controllers[i].mountPoint)
continue;
/* We must never rmdir() in systemd's hierarchy */
if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
continue;
/* Don't delete the root group, if we accidentally
ended up in it for some reason */
if (STREQ(group->controllers[i].placement, "/"))
continue;
if (virCgroupV1PathOfController(group,
i,
NULL,
&grppath) != 0)
continue;
VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath);
rc = virCgroupRemoveRecursively(grppath);
}
VIR_DEBUG("Done removing cgroup %s", group->path);
return rc;
}
virCgroupBackend virCgroupV1Backend = { virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1, .type = VIR_CGROUP_BACKEND_TYPE_V1,
...@@ -683,6 +721,7 @@ virCgroupBackend virCgroupV1Backend = { ...@@ -683,6 +721,7 @@ virCgroupBackend virCgroupV1Backend = {
.getAnyController = virCgroupV1GetAnyController, .getAnyController = virCgroupV1GetAnyController,
.pathOfController = virCgroupV1PathOfController, .pathOfController = virCgroupV1PathOfController,
.makeGroup = virCgroupV1MakeGroup, .makeGroup = virCgroupV1MakeGroup,
.remove = virCgroupV1Remove,
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册