]>
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
;
47 cgroup_ops
= cgfsng_ops_init(conf
);
49 ERROR("Failed to initialize cgroup driver");
53 if (!cgroup_ops
->data_init(cgroup_ops
))
56 TRACE("Initialized cgroup driver %s", cgroup_ops
->driver
);
58 if (cgroup_ops
->cgroup_layout
== CGROUP_LAYOUT_LEGACY
)
59 TRACE("Running with legacy cgroup layout");
60 else if (cgroup_ops
->cgroup_layout
== CGROUP_LAYOUT_HYBRID
)
61 TRACE("Running with hybrid cgroup layout");
62 else if (cgroup_ops
->cgroup_layout
== CGROUP_LAYOUT_UNIFIED
)
63 TRACE("Running with unified cgroup layout");
65 WARN("Running with unknown cgroup layout");
70 void cgroup_exit(struct cgroup_ops
*ops
)
73 struct hierarchy
**it
;
78 for (cur
= ops
->cgroup_use
; cur
&& *cur
; cur
++)
81 free(ops
->cgroup_pattern
);
82 free(ops
->container_cgroup
);
84 for (it
= ops
->hierarchies
; it
&& *it
; it
++) {
87 for (p
= (*it
)->controllers
; p
&& *p
; p
++)
89 free((*it
)->controllers
);
91 for (p
= (*it
)->cgroup2_chown
; p
&& *p
; p
++)
93 free((*it
)->cgroup2_chown
);
95 free((*it
)->mountpoint
);
96 free((*it
)->container_base_path
);
97 free((*it
)->container_full_path
);
98 free((*it
)->monitor_full_path
);
101 free(ops
->hierarchies
);
108 #define INIT_SCOPE "/init.scope"
109 void prune_init_scope(char *cg
)
116 point
= cg
+ strlen(cg
) - strlen(INIT_SCOPE
);
120 if (strcmp(point
, INIT_SCOPE
) == 0) {