]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/cgroups/cgroup.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <sys/types.h>
35 #include "initutils.h"
39 lxc_log_define(cgroup
, lxc
);
41 extern struct cgroup_ops
*cgfsng_ops_init(struct lxc_conf
*conf
);
43 struct cgroup_ops
*cgroup_init(struct lxc_conf
*conf
)
45 struct cgroup_ops
*cgroup_ops
;
48 ERROR("No valid conf given");
52 cgroup_ops
= cgfsng_ops_init(conf
);
54 ERROR("Failed to initialize cgroup driver");
58 if (!cgroup_ops
->data_init(cgroup_ops
))
61 TRACE("Initialized cgroup driver %s", cgroup_ops
->driver
);
63 if (cgroup_ops
->cgroup_layout
== CGROUP_LAYOUT_LEGACY
)
64 TRACE("Running with legacy cgroup layout");
65 else if (cgroup_ops
->cgroup_layout
== CGROUP_LAYOUT_HYBRID
)
66 TRACE("Running with hybrid cgroup layout");
67 else if (cgroup_ops
->cgroup_layout
== CGROUP_LAYOUT_UNIFIED
)
68 TRACE("Running with unified cgroup layout");
70 WARN("Running with unknown cgroup layout");
75 void cgroup_exit(struct cgroup_ops
*ops
)
78 struct hierarchy
**it
;
83 for (cur
= ops
->cgroup_use
; cur
&& *cur
; cur
++)
86 free(ops
->cgroup_pattern
);
87 free(ops
->container_cgroup
);
89 for (it
= ops
->hierarchies
; it
&& *it
; it
++) {
92 for (p
= (*it
)->controllers
; p
&& *p
; p
++)
94 free((*it
)->controllers
);
96 for (p
= (*it
)->cgroup2_chown
; p
&& *p
; p
++)
98 free((*it
)->cgroup2_chown
);
100 free((*it
)->mountpoint
);
101 free((*it
)->container_base_path
);
102 free((*it
)->container_full_path
);
103 free((*it
)->monitor_full_path
);
106 free(ops
->hierarchies
);
113 #define INIT_SCOPE "/init.scope"
114 void prune_init_scope(char *cg
)
121 point
= cg
+ strlen(cg
) - strlen(INIT_SCOPE
);
125 if (strcmp(point
, INIT_SCOPE
) == 0) {