2 * lxc: linux Container library
4 * Copyright © 2016 Canonical Ltd.
7 * Serge Hallyn <serge.hallyn@ubuntu.com>
8 * Christian Brauner <christian.brauner@ubuntu.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 * cgfs-ng.c: this is a new, simplified implementation of a filesystem
27 * cgroup backend. The original cgfs.c was designed to be as flexible
28 * as possible. It would try to find cgroup filesystems no matter where
29 * or how you had them mounted, and deduce the most usable mount for
32 * This new implementation assumes that cgroup filesystems are mounted
33 * under /sys/fs/cgroup/clist where clist is either the controller, or
34 * a comma-separated list of controllers.
44 #include <linux/kdev_t.h>
45 #include <linux/types.h>
50 #include <sys/types.h>
55 #include "cgroup_utils.h"
61 #include "memory_utils.h"
62 #include "storage/storage.h"
66 #include "include/strlcpy.h"
70 #include "include/strlcat.h"
73 lxc_log_define(cgfsng
, cgroup
);
75 static void free_string_list(char **clist
)
82 for (i
= 0; clist
[i
]; i
++)
88 /* Given a pointer to a null-terminated array of pointers, realloc to add one
89 * entry, and point the new entry to NULL. Do not fail. Return the index to the
90 * second-to-last entry - that is, the one which is now available for use
91 * (keeping the list null-terminated).
93 static int append_null_to_list(void ***list
)
98 for (; (*list
)[newentry
]; newentry
++)
101 *list
= must_realloc(*list
, (newentry
+ 2) * sizeof(void **));
102 (*list
)[newentry
+ 1] = NULL
;
106 /* Given a null-terminated array of strings, check whether @entry is one of the
109 static bool string_in_list(char **list
, const char *entry
)
116 for (i
= 0; list
[i
]; i
++)
117 if (strcmp(list
[i
], entry
) == 0)
123 /* Return a copy of @entry prepending "name=", i.e. turn "systemd" into
124 * "name=systemd". Do not fail.
126 static char *cg_legacy_must_prefix_named(char *entry
)
132 prefixed
= must_realloc(NULL
, len
+ 6);
134 memcpy(prefixed
, "name=", STRLITERALLEN("name="));
135 memcpy(prefixed
+ STRLITERALLEN("name="), entry
, len
);
136 prefixed
[len
+ 5] = '\0';
141 /* Append an entry to the clist. Do not fail. @clist must be NULL the first time
144 * We also handle named subsystems here. Any controller which is not a kernel
145 * subsystem, we prefix "name=". Any which is both a kernel and named subsystem,
146 * we refuse to use because we're not sure which we have here.
147 * (TODO: We could work around this in some cases by just remounting to be
148 * unambiguous, or by comparing mountpoint contents with current cgroup.)
150 * The last entry will always be NULL.
152 static void must_append_controller(char **klist
, char **nlist
, char ***clist
,
158 if (string_in_list(klist
, entry
) && string_in_list(nlist
, entry
)) {
159 ERROR("Refusing to use ambiguous controller \"%s\"", entry
);
160 ERROR("It is both a named and kernel subsystem");
164 newentry
= append_null_to_list((void ***)clist
);
166 if (strncmp(entry
, "name=", 5) == 0)
167 copy
= must_copy_string(entry
);
168 else if (string_in_list(klist
, entry
))
169 copy
= must_copy_string(entry
);
171 copy
= cg_legacy_must_prefix_named(entry
);
173 (*clist
)[newentry
] = copy
;
176 /* Given a handler's cgroup data, return the struct hierarchy for the controller
177 * @c, or NULL if there is none.
179 struct hierarchy
*get_hierarchy(struct cgroup_ops
*ops
, const char *controller
)
185 if (!ops
->hierarchies
) {
186 TRACE("There are no useable cgroup controllers");
190 for (i
= 0; ops
->hierarchies
[i
]; i
++) {
192 /* This is the empty unified hierarchy. */
193 if (ops
->hierarchies
[i
]->controllers
&&
194 !ops
->hierarchies
[i
]->controllers
[0])
195 return ops
->hierarchies
[i
];
200 if (string_in_list(ops
->hierarchies
[i
]->controllers
, controller
))
201 return ops
->hierarchies
[i
];
205 WARN("There is no useable %s controller", controller
);
207 WARN("There is no empty unified cgroup hierarchy");
212 #define BATCH_SIZE 50
213 static void batch_realloc(char **mem
, size_t oldlen
, size_t newlen
)
215 int newbatches
= (newlen
/ BATCH_SIZE
) + 1;
216 int oldbatches
= (oldlen
/ BATCH_SIZE
) + 1;
218 if (!*mem
|| newbatches
> oldbatches
) {
219 *mem
= must_realloc(*mem
, newbatches
* BATCH_SIZE
);
223 static void append_line(char **dest
, size_t oldlen
, char *new, size_t newlen
)
225 size_t full
= oldlen
+ newlen
;
227 batch_realloc(dest
, oldlen
, full
+ 1);
229 memcpy(*dest
+ oldlen
, new, newlen
+ 1);
232 /* Slurp in a whole file */
233 static char *read_file(const char *fnam
)
235 __do_free
char *line
= NULL
;
236 __do_fclose
FILE *f
= NULL
;
239 size_t len
= 0, fulllen
= 0;
241 f
= fopen(fnam
, "r");
244 while ((linelen
= getline(&line
, &len
, f
)) != -1) {
245 append_line(&buf
, fulllen
, line
, linelen
);
251 /* Taken over modified from the kernel sources. */
252 #define NBITS 32 /* bits in uint32_t */
253 #define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d))
254 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, NBITS)
256 static void set_bit(unsigned bit
, uint32_t *bitarr
)
258 bitarr
[bit
/ NBITS
] |= (1 << (bit
% NBITS
));
261 static void clear_bit(unsigned bit
, uint32_t *bitarr
)
263 bitarr
[bit
/ NBITS
] &= ~(1 << (bit
% NBITS
));
266 static bool is_set(unsigned bit
, uint32_t *bitarr
)
268 return (bitarr
[bit
/ NBITS
] & (1 << (bit
% NBITS
))) != 0;
271 /* Create cpumask from cpulist aka turn:
279 static uint32_t *lxc_cpumask(char *buf
, size_t nbits
)
285 arrlen
= BITS_TO_LONGS(nbits
);
286 bitarr
= calloc(arrlen
, sizeof(uint32_t));
290 lxc_iterate_parts(token
, buf
, ",") {
295 start
= strtoul(token
, NULL
, 0);
297 range
= strchr(token
, '-');
299 end
= strtoul(range
+ 1, NULL
, 0);
301 if (!(start
<= end
)) {
312 set_bit(start
++, bitarr
);
318 /* Turn cpumask into simple, comma-separated cpulist. */
319 static char *lxc_cpumask_to_cpulist(uint32_t *bitarr
, size_t nbits
)
323 char **cpulist
= NULL
;
324 char numstr
[INTTYPE_TO_STRLEN(size_t)] = {0};
326 for (i
= 0; i
<= nbits
; i
++) {
327 if (!is_set(i
, bitarr
))
330 ret
= snprintf(numstr
, sizeof(numstr
), "%zu", i
);
331 if (ret
< 0 || (size_t)ret
>= sizeof(numstr
)) {
332 lxc_free_array((void **)cpulist
, free
);
336 ret
= lxc_append_string(&cpulist
, numstr
);
338 lxc_free_array((void **)cpulist
, free
);
346 return lxc_string_join(",", (const char **)cpulist
, false);
349 static ssize_t
get_max_cpus(char *cpulist
)
352 char *maxcpus
= cpulist
;
355 c1
= strrchr(maxcpus
, ',');
359 c2
= strrchr(maxcpus
, '-');
373 cpus
= strtoul(c1
, NULL
, 0);
380 #define __ISOL_CPUS "/sys/devices/system/cpu/isolated"
381 static bool cg_legacy_filter_and_set_cpus(char *path
, bool am_initialized
)
383 __do_free
char *cpulist
= NULL
, *fpath
= NULL
, *isolcpus
= NULL
,
385 __do_free
uint32_t *isolmask
= NULL
, *possmask
= NULL
;
390 ssize_t maxisol
= 0, maxposs
= 0;
391 bool bret
= false, flipped_bit
= false;
393 lastslash
= strrchr(path
, '/');
395 ERROR("Failed to detect \"/\" in \"%s\"", path
);
400 fpath
= must_make_path(path
, "cpuset.cpus", NULL
);
401 posscpus
= read_file(fpath
);
403 SYSERROR("Failed to read file \"%s\"", fpath
);
407 /* Get maximum number of cpus found in possible cpuset. */
408 maxposs
= get_max_cpus(posscpus
);
409 if (maxposs
< 0 || maxposs
>= INT_MAX
- 1)
412 if (!file_exists(__ISOL_CPUS
)) {
413 /* This system doesn't expose isolated cpus. */
414 DEBUG("The path \""__ISOL_CPUS
"\" to read isolated cpus from does not exist");
415 /* No isolated cpus but we weren't already initialized by
416 * someone. We should simply copy the parents cpuset.cpus
419 if (!am_initialized
) {
420 DEBUG("Copying cpu settings of parent cgroup");
424 /* No isolated cpus but we were already initialized by someone.
425 * Nothing more to do for us.
430 isolcpus
= read_file(__ISOL_CPUS
);
432 SYSERROR("Failed to read file \""__ISOL_CPUS
"\"");
435 if (!isdigit(isolcpus
[0])) {
436 TRACE("No isolated cpus detected");
437 /* No isolated cpus but we weren't already initialized by
438 * someone. We should simply copy the parents cpuset.cpus
441 if (!am_initialized
) {
442 DEBUG("Copying cpu settings of parent cgroup");
446 /* No isolated cpus but we were already initialized by someone.
447 * Nothing more to do for us.
452 /* Get maximum number of cpus found in isolated cpuset. */
453 maxisol
= get_max_cpus(isolcpus
);
454 if (maxisol
< 0 || maxisol
>= INT_MAX
- 1)
457 if (maxposs
< maxisol
)
461 possmask
= lxc_cpumask(posscpus
, maxposs
);
463 ERROR("Failed to create cpumask for possible cpus");
467 isolmask
= lxc_cpumask(isolcpus
, maxposs
);
469 ERROR("Failed to create cpumask for isolated cpus");
473 for (i
= 0; i
<= maxposs
; i
++) {
474 if (!is_set(i
, isolmask
) || !is_set(i
, possmask
))
478 clear_bit(i
, possmask
);
482 DEBUG("No isolated cpus present in cpuset");
485 DEBUG("Removed isolated cpus from cpuset");
487 cpulist
= lxc_cpumask_to_cpulist(possmask
, maxposs
);
489 ERROR("Failed to create cpu list");
495 fpath
= must_make_path(path
, "cpuset.cpus", NULL
);
496 ret
= lxc_write_to_file(fpath
, cpulist
, strlen(cpulist
), false, 0666);
497 if (cpulist
== posscpus
)
500 SYSERROR("Failed to write cpu list to \"%s\"", fpath
);
507 /* Copy contents of parent(@path)/@file to @path/@file */
508 static bool copy_parent_file(char *path
, char *file
)
510 __do_free
char *child_path
= NULL
, *parent_path
= NULL
, *value
= NULL
;
514 char *lastslash
= NULL
;
516 lastslash
= strrchr(path
, '/');
518 ERROR("Failed to detect \"/\" in \"%s\"", path
);
523 parent_path
= must_make_path(path
, file
, NULL
);
524 len
= lxc_read_from_file(parent_path
, NULL
, 0);
528 value
= must_realloc(NULL
, len
+ 1);
529 ret
= lxc_read_from_file(parent_path
, value
, len
);
534 child_path
= must_make_path(path
, file
, NULL
);
535 ret
= lxc_write_to_file(child_path
, value
, len
, false, 0666);
537 SYSERROR("Failed to write \"%s\" to file \"%s\"", value
, child_path
);
541 SYSERROR("Failed to read file \"%s\"", child_path
);
545 /* Initialize the cpuset hierarchy in first directory of @gname and set
546 * cgroup.clone_children so that children inherit settings. Since the
547 * h->base_path is populated by init or ourselves, we know it is already
550 static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy
*h
, char *cgname
)
552 __do_free
char *cgpath
= NULL
, *clonechildrenpath
= NULL
;
557 if (!string_in_list(h
->controllers
, "cpuset"))
562 slash
= strchr(cgname
, '/');
566 cgpath
= must_make_path(h
->mountpoint
, h
->container_base_path
, cgname
, NULL
);
570 ret
= mkdir(cgpath
, 0755);
572 if (errno
!= EEXIST
) {
573 SYSERROR("Failed to create directory \"%s\"", cgpath
);
578 clonechildrenpath
= must_make_path(cgpath
, "cgroup.clone_children", NULL
);
579 /* unified hierarchy doesn't have clone_children */
580 if (!file_exists(clonechildrenpath
))
583 ret
= lxc_read_from_file(clonechildrenpath
, &v
, 1);
585 SYSERROR("Failed to read file \"%s\"", clonechildrenpath
);
589 /* Make sure any isolated cpus are removed from cpuset.cpus. */
590 if (!cg_legacy_filter_and_set_cpus(cgpath
, v
== '1')) {
591 SYSERROR("Failed to remove isolated cpus");
595 /* Already set for us by someone else. */
597 DEBUG("\"cgroup.clone_children\" was already set to \"1\"");
601 /* copy parent's settings */
602 if (!copy_parent_file(cgpath
, "cpuset.mems")) {
603 SYSERROR("Failed to copy \"cpuset.mems\" settings");
607 ret
= lxc_write_to_file(clonechildrenpath
, "1", 1, false, 0666);
609 /* Set clone_children so children inherit our settings */
610 SYSERROR("Failed to write 1 to \"%s\"", clonechildrenpath
);
617 /* Given two null-terminated lists of strings, return true if any string is in
620 static bool controller_lists_intersect(char **l1
, char **l2
)
627 for (i
= 0; l1
[i
]; i
++) {
628 if (string_in_list(l2
, l1
[i
]))
635 /* For a null-terminated list of controllers @clist, return true if any of those
636 * controllers is already listed the null-terminated list of hierarchies @hlist.
637 * Realistically, if one is present, all must be present.
639 static bool controller_list_is_dup(struct hierarchy
**hlist
, char **clist
)
646 for (i
= 0; hlist
[i
]; i
++)
647 if (controller_lists_intersect(hlist
[i
]->controllers
, clist
))
653 /* Return true if the controller @entry is found in the null-terminated list of
654 * hierarchies @hlist.
656 static bool controller_found(struct hierarchy
**hlist
, char *entry
)
663 for (i
= 0; hlist
[i
]; i
++)
664 if (string_in_list(hlist
[i
]->controllers
, entry
))
670 /* Return true if all of the controllers which we require have been found. The
671 * required list is freezer and anything in lxc.cgroup.use.
673 static bool all_controllers_found(struct cgroup_ops
*ops
)
676 struct hierarchy
**hlist
= ops
->hierarchies
;
678 if (!ops
->cgroup_use
)
681 for (cur
= ops
->cgroup_use
; cur
&& *cur
; cur
++)
682 if (!controller_found(hlist
, *cur
)) {
683 ERROR("No %s controller mountpoint found", *cur
);
690 /* Get the controllers from a mountinfo line There are other ways we could get
691 * this info. For lxcfs, field 3 is /cgroup/controller-list. For cgroupfs, we
692 * could parse the mount options. But we simply assume that the mountpoint must
693 * be /sys/fs/cgroup/controller-list
695 static char **cg_hybrid_get_controllers(char **klist
, char **nlist
, char *line
,
698 /* The fourth field is /sys/fs/cgroup/comma-delimited-controller-list
699 * for legacy hierarchies.
703 char *p
= line
, *sep
= ",";
706 for (i
= 0; i
< 4; i
++) {
713 /* Note, if we change how mountinfo works, then our caller will need to
714 * verify /sys/fs/cgroup/ in this field.
716 if (strncmp(p
, "/sys/fs/cgroup/", 15) != 0) {
717 ERROR("Found hierarchy not under /sys/fs/cgroup: \"%s\"", p
);
724 ERROR("Corrupt mountinfo");
729 if (type
== CGROUP_SUPER_MAGIC
) {
730 __do_free
char *dup
= NULL
;
732 /* strdup() here for v1 hierarchies. Otherwise
733 * lxc_iterate_parts() will destroy mountpoints such as
734 * "/sys/fs/cgroup/cpu,cpuacct".
736 dup
= must_copy_string(p
);
740 lxc_iterate_parts (tok
, dup
, sep
)
741 must_append_controller(klist
, nlist
, &aret
, tok
);
748 static char **cg_unified_make_empty_controller(void)
753 newentry
= append_null_to_list((void ***)&aret
);
754 aret
[newentry
] = NULL
;
758 static char **cg_unified_get_controllers(const char *file
)
760 __do_free
char *buf
= NULL
;
765 buf
= read_file(file
);
769 lxc_iterate_parts(tok
, buf
, sep
) {
773 newentry
= append_null_to_list((void ***)&aret
);
774 copy
= must_copy_string(tok
);
775 aret
[newentry
] = copy
;
781 static struct hierarchy
*add_hierarchy(struct hierarchy
***h
, char **clist
, char *mountpoint
,
782 char *container_base_path
, int type
)
784 struct hierarchy
*new;
787 new = must_realloc(NULL
, sizeof(*new));
788 new->controllers
= clist
;
789 new->mountpoint
= mountpoint
;
790 new->container_base_path
= container_base_path
;
791 new->container_full_path
= NULL
;
792 new->monitor_full_path
= NULL
;
794 new->cgroup2_chown
= NULL
;
796 newentry
= append_null_to_list((void ***)h
);
797 (*h
)[newentry
] = new;
801 /* Get a copy of the mountpoint from @line, which is a line from
802 * /proc/self/mountinfo.
804 static char *cg_hybrid_get_mountpoint(char *line
)
809 char *p
= line
, *sret
= NULL
;
811 for (i
= 0; i
< 4; i
++) {
818 if (strncmp(p
, "/sys/fs/cgroup/", 15) != 0)
821 p2
= strchr(p
+ 15, ' ');
827 sret
= must_realloc(NULL
, len
+ 1);
828 memcpy(sret
, p
, len
);
833 /* Given a multi-line string, return a null-terminated copy of the current line. */
834 static char *copy_to_eol(char *p
)
836 char *p2
= strchr(p
, '\n'), *sret
;
843 sret
= must_realloc(NULL
, len
+ 1);
844 memcpy(sret
, p
, len
);
849 /* cgline: pointer to character after the first ':' in a line in a \n-terminated
850 * /proc/self/cgroup file. Check whether controller c is present.
852 static bool controller_in_clist(char *cgline
, char *c
)
854 __do_free
char *tmp
= NULL
;
858 eol
= strchr(cgline
, ':');
863 tmp
= must_realloc(NULL
, len
+ 1);
864 memcpy(tmp
, cgline
, len
);
867 lxc_iterate_parts(tok
, tmp
, ",")
868 if (strcmp(tok
, c
) == 0)
874 /* @basecginfo is a copy of /proc/$$/cgroup. Return the current cgroup for
877 static char *cg_hybrid_get_current_cgroup(char *basecginfo
, char *controller
,
880 char *p
= basecginfo
;
883 bool is_cgv2_base_cgroup
= false;
885 /* cgroup v2 entry in "/proc/<pid>/cgroup": "0::/some/path" */
886 if ((type
== CGROUP2_SUPER_MAGIC
) && (*p
== '0'))
887 is_cgv2_base_cgroup
= true;
894 if (is_cgv2_base_cgroup
|| (controller
&& controller_in_clist(p
, controller
))) {
899 return copy_to_eol(p
);
909 static void must_append_string(char ***list
, char *entry
)
914 newentry
= append_null_to_list((void ***)list
);
915 copy
= must_copy_string(entry
);
916 (*list
)[newentry
] = copy
;
919 static int get_existing_subsystems(char ***klist
, char ***nlist
)
921 __do_free
char *line
= NULL
;
922 __do_fclose
FILE *f
= NULL
;
925 f
= fopen("/proc/self/cgroup", "r");
929 while (getline(&line
, &len
, f
) != -1) {
931 p
= strchr(line
, ':');
940 /* If the kernel has cgroup v2 support, then /proc/self/cgroup
941 * contains an entry of the form:
945 * In this case we use "cgroup2" as controller name.
948 must_append_string(klist
, "cgroup2");
952 lxc_iterate_parts(tok
, p
, ",") {
953 if (strncmp(tok
, "name=", 5) == 0)
954 must_append_string(nlist
, tok
);
956 must_append_string(klist
, tok
);
963 static void trim(char *s
)
968 while ((len
> 1) && (s
[len
- 1] == '\n'))
972 static void lxc_cgfsng_print_hierarchies(struct cgroup_ops
*ops
)
975 struct hierarchy
**it
;
977 if (!ops
->hierarchies
) {
978 TRACE(" No hierarchies found");
982 TRACE(" Hierarchies:");
983 for (i
= 0, it
= ops
->hierarchies
; it
&& *it
; it
++, i
++) {
987 TRACE(" %d: base_cgroup: %s", i
, (*it
)->container_base_path
? (*it
)->container_base_path
: "(null)");
988 TRACE(" mountpoint: %s", (*it
)->mountpoint
? (*it
)->mountpoint
: "(null)");
989 TRACE(" controllers:");
990 for (j
= 0, cit
= (*it
)->controllers
; cit
&& *cit
; cit
++, j
++)
991 TRACE(" %d: %s", j
, *cit
);
995 static void lxc_cgfsng_print_basecg_debuginfo(char *basecginfo
, char **klist
,
1001 TRACE("basecginfo is:");
1002 TRACE("%s", basecginfo
);
1004 for (k
= 0, it
= klist
; it
&& *it
; it
++, k
++)
1005 TRACE("kernel subsystem %d: %s", k
, *it
);
1007 for (k
= 0, it
= nlist
; it
&& *it
; it
++, k
++)
1008 TRACE("named subsystem %d: %s", k
, *it
);
1011 static int cgroup_rmdir(struct hierarchy
**hierarchies
,
1012 const char *container_cgroup
)
1016 if (!container_cgroup
|| !hierarchies
)
1019 for (i
= 0; hierarchies
[i
]; i
++) {
1021 struct hierarchy
*h
= hierarchies
[i
];
1023 if (!h
->container_full_path
)
1026 ret
= recursive_destroy(h
->container_full_path
);
1028 WARN("Failed to destroy \"%s\"", h
->container_full_path
);
1030 free(h
->container_full_path
);
1031 h
->container_full_path
= NULL
;
1037 struct generic_userns_exec_data
{
1038 struct hierarchy
**hierarchies
;
1039 const char *container_cgroup
;
1040 struct lxc_conf
*conf
;
1041 uid_t origuid
; /* target uid in parent namespace */
1045 static int cgroup_rmdir_wrapper(void *data
)
1048 struct generic_userns_exec_data
*arg
= data
;
1049 uid_t nsuid
= (arg
->conf
->root_nsuid_map
!= NULL
) ? 0 : arg
->conf
->init_uid
;
1050 gid_t nsgid
= (arg
->conf
->root_nsgid_map
!= NULL
) ? 0 : arg
->conf
->init_gid
;
1052 ret
= setresgid(nsgid
, nsgid
, nsgid
);
1054 SYSERROR("Failed to setresgid(%d, %d, %d)", (int)nsgid
,
1055 (int)nsgid
, (int)nsgid
);
1059 ret
= setresuid(nsuid
, nsuid
, nsuid
);
1061 SYSERROR("Failed to setresuid(%d, %d, %d)", (int)nsuid
,
1062 (int)nsuid
, (int)nsuid
);
1066 ret
= setgroups(0, NULL
);
1067 if (ret
< 0 && errno
!= EPERM
) {
1068 SYSERROR("Failed to setgroups(0, NULL)");
1072 return cgroup_rmdir(arg
->hierarchies
, arg
->container_cgroup
);
1075 __cgfsng_ops
static void cgfsng_payload_destroy(struct cgroup_ops
*ops
,
1076 struct lxc_handler
*handler
)
1079 struct generic_userns_exec_data wrap
;
1081 if (!ops
->hierarchies
)
1085 wrap
.container_cgroup
= ops
->container_cgroup
;
1086 wrap
.hierarchies
= ops
->hierarchies
;
1087 wrap
.conf
= handler
->conf
;
1089 if (handler
->conf
&& !lxc_list_empty(&handler
->conf
->id_map
))
1090 ret
= userns_exec_1(handler
->conf
, cgroup_rmdir_wrapper
, &wrap
,
1091 "cgroup_rmdir_wrapper");
1093 ret
= cgroup_rmdir(ops
->hierarchies
, ops
->container_cgroup
);
1095 WARN("Failed to destroy cgroups");
1100 __cgfsng_ops
static void cgfsng_monitor_destroy(struct cgroup_ops
*ops
,
1101 struct lxc_handler
*handler
)
1104 struct lxc_conf
*conf
= handler
->conf
;
1105 char pidstr
[INTTYPE_TO_STRLEN(pid_t
)];
1107 if (!ops
->hierarchies
)
1110 len
= snprintf(pidstr
, sizeof(pidstr
), "%d", handler
->monitor_pid
);
1111 if (len
< 0 || (size_t)len
>= sizeof(pidstr
))
1114 for (int i
= 0; ops
->hierarchies
[i
]; i
++) {
1115 __do_free
char *pivot_path
= NULL
;
1118 char pivot_cgroup
[] = PIVOT_CGROUP
;
1119 struct hierarchy
*h
= ops
->hierarchies
[i
];
1121 if (!h
->monitor_full_path
)
1124 if (conf
&& conf
->cgroup_meta
.dir
)
1125 pivot_path
= must_make_path(h
->mountpoint
,
1126 h
->container_base_path
,
1127 conf
->cgroup_meta
.dir
,
1129 "cgroup.procs", NULL
);
1131 pivot_path
= must_make_path(h
->mountpoint
,
1132 h
->container_base_path
,
1134 "cgroup.procs", NULL
);
1136 chop
= strrchr(pivot_path
, '/');
1141 * Make sure not to pass in the ro string literal PIVOT_CGROUP
1144 if (!cg_legacy_handle_cpuset_hierarchy(h
, pivot_cgroup
)) {
1145 WARN("Failed to handle legacy cpuset controller");
1149 ret
= mkdir_p(pivot_path
, 0755);
1150 if (ret
< 0 && errno
!= EEXIST
) {
1151 SYSWARN("Failed to create cgroup \"%s\"\n", pivot_path
);
1158 /* Move ourselves into the pivot cgroup to delete our own
1161 ret
= lxc_write_to_file(pivot_path
, pidstr
, len
, false, 0666);
1163 SYSWARN("Failed to move monitor %s to \"%s\"\n", pidstr
, pivot_path
);
1167 ret
= recursive_destroy(h
->monitor_full_path
);
1169 WARN("Failed to destroy \"%s\"", h
->monitor_full_path
);
1173 static bool cg_unified_create_cgroup(struct hierarchy
*h
, char *cgname
)
1175 __do_free
char *add_controllers
= NULL
, *cgroup
= NULL
;
1176 size_t i
, parts_len
;
1178 size_t full_len
= 0;
1179 char **parts
= NULL
;
1182 if (h
->version
!= CGROUP2_SUPER_MAGIC
)
1185 if (!h
->controllers
)
1188 /* For now we simply enable all controllers that we have detected by
1189 * creating a string like "+memory +pids +cpu +io".
1190 * TODO: In the near future we might want to support "-<controller>"
1191 * etc. but whether supporting semantics like this make sense will need
1194 for (it
= h
->controllers
; it
&& *it
; it
++) {
1195 full_len
+= strlen(*it
) + 2;
1196 add_controllers
= must_realloc(add_controllers
, full_len
+ 1);
1198 if (h
->controllers
[0] == *it
)
1199 add_controllers
[0] = '\0';
1201 (void)strlcat(add_controllers
, "+", full_len
+ 1);
1202 (void)strlcat(add_controllers
, *it
, full_len
+ 1);
1204 if ((it
+ 1) && *(it
+ 1))
1205 (void)strlcat(add_controllers
, " ", full_len
+ 1);
1208 parts
= lxc_string_split(cgname
, '/');
1212 parts_len
= lxc_array_len((void **)parts
);
1216 cgroup
= must_make_path(h
->mountpoint
, h
->container_base_path
, NULL
);
1217 for (i
= 0; i
< parts_len
; i
++) {
1219 __do_free
char *target
= NULL
;
1221 cgroup
= must_append_path(cgroup
, parts
[i
], NULL
);
1222 target
= must_make_path(cgroup
, "cgroup.subtree_control", NULL
);
1223 ret
= lxc_write_to_file(target
, add_controllers
, full_len
, false, 0666);
1225 SYSERROR("Could not enable \"%s\" controllers in the "
1226 "unified cgroup \"%s\"", add_controllers
, cgroup
);
1234 lxc_free_array((void **)parts
, free
);
1238 static int mkdir_eexist_on_last(const char *dir
, mode_t mode
)
1240 const char *tmp
= dir
;
1241 const char *orig
= dir
;
1244 orig_len
= strlen(dir
);
1246 __do_free
char *makeme
;
1250 dir
= tmp
+ strspn(tmp
, "/");
1251 tmp
= dir
+ strcspn(dir
, "/");
1254 cur_len
= dir
- orig
;
1255 makeme
= strndup(orig
, cur_len
);
1259 ret
= mkdir(makeme
, mode
);
1261 if ((errno
!= EEXIST
) || (orig_len
== cur_len
)) {
1262 SYSERROR("Failed to create directory \"%s\"", makeme
);
1266 } while (tmp
!= dir
);
1271 static bool monitor_create_path_for_hierarchy(struct hierarchy
*h
, char *cgname
)
1275 if (!cg_legacy_handle_cpuset_hierarchy(h
, cgname
)) {
1276 ERROR("Failed to handle legacy cpuset controller");
1280 h
->monitor_full_path
= must_make_path(h
->mountpoint
, h
->container_base_path
, cgname
, NULL
);
1281 ret
= mkdir_eexist_on_last(h
->monitor_full_path
, 0755);
1283 ERROR("Failed to create cgroup \"%s\"", h
->monitor_full_path
);
1287 return cg_unified_create_cgroup(h
, cgname
);
1290 static bool container_create_path_for_hierarchy(struct hierarchy
*h
, char *cgname
)
1294 if (!cg_legacy_handle_cpuset_hierarchy(h
, cgname
)) {
1295 ERROR("Failed to handle legacy cpuset controller");
1299 h
->container_full_path
= must_make_path(h
->mountpoint
, h
->container_base_path
, cgname
, NULL
);
1300 ret
= mkdir_eexist_on_last(h
->container_full_path
, 0755);
1302 ERROR("Failed to create cgroup \"%s\"", h
->container_full_path
);
1306 return cg_unified_create_cgroup(h
, cgname
);
1309 static void remove_path_for_hierarchy(struct hierarchy
*h
, char *cgname
, bool monitor
)
1315 full_path
= h
->monitor_full_path
;
1317 full_path
= h
->container_full_path
;
1319 ret
= rmdir(full_path
);
1321 SYSERROR("Failed to rmdir(\"%s\") from failed creation attempt", full_path
);
1326 h
->monitor_full_path
= NULL
;
1328 h
->container_full_path
= NULL
;
1331 __cgfsng_ops
static inline bool cgfsng_monitor_create(struct cgroup_ops
*ops
,
1332 struct lxc_handler
*handler
)
1334 __do_free
char *monitor_cgroup
= NULL
;
1338 struct lxc_conf
*conf
= handler
->conf
;
1343 if (!ops
->hierarchies
)
1346 if (conf
->cgroup_meta
.dir
)
1347 tmp
= lxc_string_join("/",
1348 (const char *[]){conf
->cgroup_meta
.dir
,
1349 ops
->monitor_pattern
,
1350 handler
->name
, NULL
},
1353 tmp
= must_make_path(ops
->monitor_pattern
, handler
->name
, NULL
);
1357 len
= strlen(tmp
) + 5; /* leave room for -NNN\0 */
1358 monitor_cgroup
= must_realloc(tmp
, len
);
1359 offset
= monitor_cgroup
+ len
- 5;
1364 int ret
= snprintf(offset
, 5, "-%d", idx
);
1365 if (ret
< 0 || (size_t)ret
>= 5)
1369 for (i
= 0; ops
->hierarchies
[i
]; i
++) {
1370 if (!monitor_create_path_for_hierarchy(ops
->hierarchies
[i
],
1372 ERROR("Failed to create cgroup \"%s\"",
1373 ops
->hierarchies
[i
]->monitor_full_path
);
1374 for (int j
= 0; j
< i
; j
++)
1375 remove_path_for_hierarchy(ops
->hierarchies
[j
],
1383 } while (ops
->hierarchies
[i
] && idx
> 0 && idx
< 1000);
1388 INFO("The monitor process uses \"%s\" as cgroup", monitor_cgroup
);
1392 /* Try to create the same cgroup in all hierarchies. Start with cgroup_pattern;
1393 * next cgroup_pattern-1, -2, ..., -999.
1395 __cgfsng_ops
static inline bool cgfsng_payload_create(struct cgroup_ops
*ops
,
1396 struct lxc_handler
*handler
)
1398 __do_free
char *container_cgroup
= NULL
, *tmp
= NULL
;
1403 struct lxc_conf
*conf
= handler
->conf
;
1405 if (ops
->container_cgroup
)
1411 if (!ops
->hierarchies
)
1414 if (conf
->cgroup_meta
.dir
)
1415 tmp
= lxc_string_join("/", (const char *[]){conf
->cgroup_meta
.dir
, handler
->name
, NULL
}, false);
1417 tmp
= lxc_string_replace("%n", handler
->name
, ops
->cgroup_pattern
);
1419 ERROR("Failed expanding cgroup name pattern");
1423 len
= strlen(tmp
) + 5; /* leave room for -NNN\0 */
1424 container_cgroup
= must_realloc(NULL
, len
);
1425 (void)strlcpy(container_cgroup
, tmp
, len
);
1426 offset
= container_cgroup
+ len
- 5;
1430 int ret
= snprintf(offset
, 5, "-%d", idx
);
1431 if (ret
< 0 || (size_t)ret
>= 5)
1435 for (i
= 0; ops
->hierarchies
[i
]; i
++) {
1436 if (!container_create_path_for_hierarchy(ops
->hierarchies
[i
],
1437 container_cgroup
)) {
1438 ERROR("Failed to create cgroup \"%s\"",
1439 ops
->hierarchies
[i
]->container_full_path
);
1440 for (int j
= 0; j
< i
; j
++)
1441 remove_path_for_hierarchy(ops
->hierarchies
[j
],
1448 } while (ops
->hierarchies
[i
] && idx
> 0 && idx
< 1000);
1453 INFO("The container process uses \"%s\" as cgroup", container_cgroup
);
1454 ops
->container_cgroup
= move_ptr(container_cgroup
);
1458 __cgfsng_ops
static bool __do_cgroup_enter(struct cgroup_ops
*ops
, pid_t pid
,
1462 char pidstr
[INTTYPE_TO_STRLEN(pid_t
)];
1464 if (!ops
->hierarchies
)
1467 len
= snprintf(pidstr
, sizeof(pidstr
), "%d", pid
);
1468 if (len
< 0 || (size_t)len
>= sizeof(pidstr
))
1471 for (int i
= 0; ops
->hierarchies
[i
]; i
++) {
1473 __do_free
char *path
= NULL
;
1476 path
= must_make_path(ops
->hierarchies
[i
]->monitor_full_path
,
1477 "cgroup.procs", NULL
);
1479 path
= must_make_path(ops
->hierarchies
[i
]->container_full_path
,
1480 "cgroup.procs", NULL
);
1481 ret
= lxc_write_to_file(path
, pidstr
, len
, false, 0666);
1483 SYSERROR("Failed to enter cgroup \"%s\"", path
);
1491 __cgfsng_ops
static bool cgfsng_monitor_enter(struct cgroup_ops
*ops
, pid_t pid
)
1493 return __do_cgroup_enter(ops
, pid
, true);
1496 static bool cgfsng_payload_enter(struct cgroup_ops
*ops
, pid_t pid
)
1498 return __do_cgroup_enter(ops
, pid
, false);
1501 static int chowmod(char *path
, uid_t chown_uid
, gid_t chown_gid
,
1506 ret
= chown(path
, chown_uid
, chown_gid
);
1508 SYSWARN("Failed to chown(%s, %d, %d)", path
, (int)chown_uid
, (int)chown_gid
);
1512 ret
= chmod(path
, chmod_mode
);
1514 SYSWARN("Failed to chmod(%s, %d)", path
, (int)chmod_mode
);
1521 /* chgrp the container cgroups to container group. We leave
1522 * the container owner as cgroup owner. So we must make the
1523 * directories 775 so that the container can create sub-cgroups.
1525 * Also chown the tasks and cgroup.procs files. Those may not
1526 * exist depending on kernel version.
1528 static int chown_cgroup_wrapper(void *data
)
1532 struct generic_userns_exec_data
*arg
= data
;
1533 uid_t nsuid
= (arg
->conf
->root_nsuid_map
!= NULL
) ? 0 : arg
->conf
->init_uid
;
1534 gid_t nsgid
= (arg
->conf
->root_nsgid_map
!= NULL
) ? 0 : arg
->conf
->init_gid
;
1536 ret
= setresgid(nsgid
, nsgid
, nsgid
);
1538 SYSERROR("Failed to setresgid(%d, %d, %d)",
1539 (int)nsgid
, (int)nsgid
, (int)nsgid
);
1543 ret
= setresuid(nsuid
, nsuid
, nsuid
);
1545 SYSERROR("Failed to setresuid(%d, %d, %d)",
1546 (int)nsuid
, (int)nsuid
, (int)nsuid
);
1550 ret
= setgroups(0, NULL
);
1551 if (ret
< 0 && errno
!= EPERM
) {
1552 SYSERROR("Failed to setgroups(0, NULL)");
1556 destuid
= get_ns_uid(arg
->origuid
);
1557 if (destuid
== LXC_INVALID_UID
)
1560 for (i
= 0; arg
->hierarchies
[i
]; i
++) {
1561 __do_free
char *fullpath
= NULL
;
1562 char *path
= arg
->hierarchies
[i
]->container_full_path
;
1564 ret
= chowmod(path
, destuid
, nsgid
, 0775);
1568 /* Failures to chown() these are inconvenient but not
1569 * detrimental We leave these owned by the container launcher,
1570 * so that container root can write to the files to attach. We
1571 * chmod() them 664 so that container systemd can write to the
1572 * files (which systemd in wily insists on doing).
1575 if (arg
->hierarchies
[i
]->version
== CGROUP_SUPER_MAGIC
) {
1576 fullpath
= must_make_path(path
, "tasks", NULL
);
1577 (void)chowmod(fullpath
, destuid
, nsgid
, 0664);
1580 fullpath
= must_make_path(path
, "cgroup.procs", NULL
);
1581 (void)chowmod(fullpath
, destuid
, nsgid
, 0664);
1583 if (arg
->hierarchies
[i
]->version
!= CGROUP2_SUPER_MAGIC
)
1586 for (char **p
= arg
->hierarchies
[i
]->cgroup2_chown
; p
&& *p
; p
++) {
1587 fullpath
= must_make_path(path
, *p
, NULL
);
1588 (void)chowmod(fullpath
, destuid
, nsgid
, 0664);
1595 __cgfsng_ops
static bool cgfsng_chown(struct cgroup_ops
*ops
,
1596 struct lxc_conf
*conf
)
1598 struct generic_userns_exec_data wrap
;
1600 if (lxc_list_empty(&conf
->id_map
))
1603 if (!ops
->hierarchies
)
1606 wrap
.origuid
= geteuid();
1608 wrap
.hierarchies
= ops
->hierarchies
;
1611 if (userns_exec_1(conf
, chown_cgroup_wrapper
, &wrap
,
1612 "chown_cgroup_wrapper") < 0) {
1613 ERROR("Error requesting cgroup chown in new user namespace");
1620 /* cgroup-full:* is done, no need to create subdirs */
1621 static bool cg_mount_needs_subdirs(int type
)
1623 if (type
>= LXC_AUTO_CGROUP_FULL_RO
)
1629 /* After $rootfs/sys/fs/container/controller/the/cg/path has been created,
1630 * remount controller ro if needed and bindmount the cgroupfs onto
1631 * control/the/cg/path.
1633 static int cg_legacy_mount_controllers(int type
, struct hierarchy
*h
,
1634 char *controllerpath
, char *cgpath
,
1635 const char *container_cgroup
)
1637 __do_free
char *sourcepath
= NULL
;
1638 int ret
, remount_flags
;
1639 int flags
= MS_BIND
;
1641 if (type
== LXC_AUTO_CGROUP_RO
|| type
== LXC_AUTO_CGROUP_MIXED
) {
1642 ret
= mount(controllerpath
, controllerpath
, "cgroup", MS_BIND
, NULL
);
1644 SYSERROR("Failed to bind mount \"%s\" onto \"%s\"",
1645 controllerpath
, controllerpath
);
1649 remount_flags
= add_required_remount_flags(controllerpath
,
1651 flags
| MS_REMOUNT
);
1652 ret
= mount(controllerpath
, controllerpath
, "cgroup",
1653 remount_flags
| MS_REMOUNT
| MS_BIND
| MS_RDONLY
,
1656 SYSERROR("Failed to remount \"%s\" ro", controllerpath
);
1660 INFO("Remounted %s read-only", controllerpath
);
1663 sourcepath
= must_make_path(h
->mountpoint
, h
->container_base_path
,
1664 container_cgroup
, NULL
);
1665 if (type
== LXC_AUTO_CGROUP_RO
)
1668 ret
= mount(sourcepath
, cgpath
, "cgroup", flags
, NULL
);
1670 SYSERROR("Failed to mount \"%s\" onto \"%s\"", h
->controllers
[0], cgpath
);
1673 INFO("Mounted \"%s\" onto \"%s\"", h
->controllers
[0], cgpath
);
1675 if (flags
& MS_RDONLY
) {
1676 remount_flags
= add_required_remount_flags(sourcepath
, cgpath
,
1677 flags
| MS_REMOUNT
);
1678 ret
= mount(sourcepath
, cgpath
, "cgroup", remount_flags
, NULL
);
1680 SYSERROR("Failed to remount \"%s\" ro", cgpath
);
1683 INFO("Remounted %s read-only", cgpath
);
1686 INFO("Completed second stage cgroup automounts for \"%s\"", cgpath
);
1690 /* __cg_mount_direct
1692 * Mount cgroup hierarchies directly without using bind-mounts. The main
1693 * uses-cases are mounting cgroup hierarchies in cgroup namespaces and mounting
1694 * cgroups for the LXC_AUTO_CGROUP_FULL option.
1696 static int __cg_mount_direct(int type
, struct hierarchy
*h
,
1697 const char *controllerpath
)
1700 __do_free
char *controllers
= NULL
;
1701 char *fstype
= "cgroup2";
1702 unsigned long flags
= 0;
1707 flags
|= MS_RELATIME
;
1709 if (type
== LXC_AUTO_CGROUP_RO
|| type
== LXC_AUTO_CGROUP_FULL_RO
)
1712 if (h
->version
!= CGROUP2_SUPER_MAGIC
) {
1713 controllers
= lxc_string_join(",", (const char **)h
->controllers
, false);
1719 ret
= mount("cgroup", controllerpath
, fstype
, flags
, controllers
);
1721 SYSERROR("Failed to mount \"%s\" with cgroup filesystem type %s", controllerpath
, fstype
);
1725 DEBUG("Mounted \"%s\" with cgroup filesystem type %s", controllerpath
, fstype
);
1729 static inline int cg_mount_in_cgroup_namespace(int type
, struct hierarchy
*h
,
1730 const char *controllerpath
)
1732 return __cg_mount_direct(type
, h
, controllerpath
);
1735 static inline int cg_mount_cgroup_full(int type
, struct hierarchy
*h
,
1736 const char *controllerpath
)
1738 if (type
< LXC_AUTO_CGROUP_FULL_RO
|| type
> LXC_AUTO_CGROUP_FULL_MIXED
)
1741 return __cg_mount_direct(type
, h
, controllerpath
);
1744 __cgfsng_ops
static bool cgfsng_mount(struct cgroup_ops
*ops
,
1745 struct lxc_handler
*handler
,
1746 const char *root
, int type
)
1748 __do_free
char *tmpfspath
= NULL
;
1750 bool has_cgns
= false, retval
= false, wants_force_mount
= false;
1752 if (!ops
->hierarchies
)
1755 if ((type
& LXC_AUTO_CGROUP_MASK
) == 0)
1758 if (type
& LXC_AUTO_CGROUP_FORCE
) {
1759 type
&= ~LXC_AUTO_CGROUP_FORCE
;
1760 wants_force_mount
= true;
1763 if (!wants_force_mount
){
1764 if (!lxc_list_empty(&handler
->conf
->keepcaps
))
1765 wants_force_mount
= !in_caplist(CAP_SYS_ADMIN
, &handler
->conf
->keepcaps
);
1767 wants_force_mount
= in_caplist(CAP_SYS_ADMIN
, &handler
->conf
->caps
);
1770 has_cgns
= cgns_supported();
1771 if (has_cgns
&& !wants_force_mount
)
1774 if (type
== LXC_AUTO_CGROUP_NOSPEC
)
1775 type
= LXC_AUTO_CGROUP_MIXED
;
1776 else if (type
== LXC_AUTO_CGROUP_FULL_NOSPEC
)
1777 type
= LXC_AUTO_CGROUP_FULL_MIXED
;
1780 tmpfspath
= must_make_path(root
, "/sys/fs/cgroup", NULL
);
1781 ret
= safe_mount(NULL
, tmpfspath
, "tmpfs",
1782 MS_NOSUID
| MS_NODEV
| MS_NOEXEC
| MS_RELATIME
,
1783 "size=10240k,mode=755", root
);
1787 for (i
= 0; ops
->hierarchies
[i
]; i
++) {
1788 __do_free
char *controllerpath
= NULL
, *path2
= NULL
;
1789 struct hierarchy
*h
= ops
->hierarchies
[i
];
1790 char *controller
= strrchr(h
->mountpoint
, '/');
1796 controllerpath
= must_make_path(tmpfspath
, controller
, NULL
);
1797 if (dir_exists(controllerpath
))
1800 ret
= mkdir(controllerpath
, 0755);
1802 SYSERROR("Error creating cgroup path: %s", controllerpath
);
1806 if (has_cgns
&& wants_force_mount
) {
1807 /* If cgroup namespaces are supported but the container
1808 * will not have CAP_SYS_ADMIN after it has started we
1809 * need to mount the cgroups manually.
1811 ret
= cg_mount_in_cgroup_namespace(type
, h
, controllerpath
);
1818 ret
= cg_mount_cgroup_full(type
, h
, controllerpath
);
1822 if (!cg_mount_needs_subdirs(type
))
1825 path2
= must_make_path(controllerpath
, h
->container_base_path
,
1826 ops
->container_cgroup
, NULL
);
1827 ret
= mkdir_p(path2
, 0755);
1831 ret
= cg_legacy_mount_controllers(type
, h
, controllerpath
,
1832 path2
, ops
->container_cgroup
);
1842 static int recursive_count_nrtasks(char *dirname
)
1844 __do_free
char *path
= NULL
;
1845 __do_closedir
DIR *dir
= NULL
;
1846 struct dirent
*direntp
;
1849 dir
= opendir(dirname
);
1853 while ((direntp
= readdir(dir
))) {
1856 if (!strcmp(direntp
->d_name
, ".") ||
1857 !strcmp(direntp
->d_name
, ".."))
1860 path
= must_make_path(dirname
, direntp
->d_name
, NULL
);
1862 if (lstat(path
, &mystat
))
1865 if (!S_ISDIR(mystat
.st_mode
))
1868 count
+= recursive_count_nrtasks(path
);
1871 path
= must_make_path(dirname
, "cgroup.procs", NULL
);
1872 ret
= lxc_count_file_lines(path
);
1879 __cgfsng_ops
static int cgfsng_nrtasks(struct cgroup_ops
*ops
)
1881 __do_free
char *path
= NULL
;
1884 if (!ops
->container_cgroup
|| !ops
->hierarchies
)
1887 path
= must_make_path(ops
->hierarchies
[0]->container_full_path
, NULL
);
1888 count
= recursive_count_nrtasks(path
);
1892 /* Only root needs to escape to the cgroup of its init. */
1893 __cgfsng_ops
static bool cgfsng_escape(const struct cgroup_ops
*ops
,
1894 struct lxc_conf
*conf
)
1898 if (conf
->cgroup_meta
.relative
|| geteuid() || !ops
->hierarchies
)
1901 for (i
= 0; ops
->hierarchies
[i
]; i
++) {
1903 __do_free
char *fullpath
= NULL
;
1905 fullpath
= must_make_path(ops
->hierarchies
[i
]->mountpoint
,
1906 ops
->hierarchies
[i
]->container_base_path
,
1907 "cgroup.procs", NULL
);
1908 ret
= lxc_write_to_file(fullpath
, "0", 2, false, 0666);
1910 SYSERROR("Failed to escape to cgroup \"%s\"", fullpath
);
1918 __cgfsng_ops
static int cgfsng_num_hierarchies(struct cgroup_ops
*ops
)
1922 if (!ops
->hierarchies
)
1925 for (; ops
->hierarchies
[i
]; i
++)
1931 __cgfsng_ops
static bool cgfsng_get_hierarchies(struct cgroup_ops
*ops
, int n
, char ***out
)
1935 if (!ops
->hierarchies
)
1938 /* sanity check n */
1939 for (i
= 0; i
< n
; i
++)
1940 if (!ops
->hierarchies
[i
])
1943 *out
= ops
->hierarchies
[i
]->controllers
;
1948 #define THAWED "THAWED"
1949 #define THAWED_LEN (strlen(THAWED))
1951 /* TODO: If the unified cgroup hierarchy grows a freezer controller this needs
1954 __cgfsng_ops
static bool cgfsng_unfreeze(struct cgroup_ops
*ops
)
1957 __do_free
char *fullpath
= NULL
;
1958 struct hierarchy
*h
;
1960 h
= get_hierarchy(ops
, "freezer");
1964 fullpath
= must_make_path(h
->container_full_path
, "freezer.state", NULL
);
1965 ret
= lxc_write_to_file(fullpath
, THAWED
, THAWED_LEN
, false, 0666);
1972 __cgfsng_ops
static const char *cgfsng_get_cgroup(struct cgroup_ops
*ops
,
1973 const char *controller
)
1975 struct hierarchy
*h
;
1977 h
= get_hierarchy(ops
, controller
);
1979 WARN("Failed to find hierarchy for controller \"%s\"",
1980 controller
? controller
: "(null)");
1984 return h
->container_full_path
? h
->container_full_path
+ strlen(h
->mountpoint
) : NULL
;
1987 /* Given a cgroup path returned from lxc_cmd_get_cgroup_path, build a full path,
1988 * which must be freed by the caller.
1990 static inline char *build_full_cgpath_from_monitorpath(struct hierarchy
*h
,
1992 const char *filename
)
1994 return must_make_path(h
->mountpoint
, inpath
, filename
, NULL
);
1997 /* Technically, we're always at a delegation boundary here (This is especially
1998 * true when cgroup namespaces are available.). The reasoning is that in order
1999 * for us to have been able to start a container in the first place the root
2000 * cgroup must have been a leaf node. Now, either the container's init system
2001 * has populated the cgroup and kept it as a leaf node or it has created
2002 * subtrees. In the former case we will simply attach to the leaf node we
2003 * created when we started the container in the latter case we create our own
2004 * cgroup for the attaching process.
2006 static int __cg_unified_attach(const struct hierarchy
*h
, const char *name
,
2007 const char *lxcpath
, const char *pidstr
,
2008 size_t pidstr_len
, const char *controller
)
2010 __do_free
char *base_path
= NULL
, *container_cgroup
= NULL
,
2014 int fret
= -1, idx
= 0;
2016 container_cgroup
= lxc_cmd_get_cgroup_path(name
, lxcpath
, controller
);
2018 if (!container_cgroup
)
2021 base_path
= must_make_path(h
->mountpoint
, container_cgroup
, NULL
);
2022 full_path
= must_make_path(base_path
, "cgroup.procs", NULL
);
2023 /* cgroup is populated */
2024 ret
= lxc_write_to_file(full_path
, pidstr
, pidstr_len
, false, 0666);
2025 if (ret
< 0 && errno
!= EBUSY
)
2031 len
= strlen(base_path
) + STRLITERALLEN("/lxc-1000") +
2032 STRLITERALLEN("/cgroup-procs");
2033 full_path
= must_realloc(NULL
, len
+ 1);
2036 ret
= snprintf(full_path
, len
+ 1, "%s/lxc-%d",
2039 ret
= snprintf(full_path
, len
+ 1, "%s/lxc", base_path
);
2040 if (ret
< 0 || (size_t)ret
>= len
+ 1)
2043 ret
= mkdir_p(full_path
, 0755);
2044 if (ret
< 0 && errno
!= EEXIST
)
2047 (void)strlcat(full_path
, "/cgroup.procs", len
+ 1);
2048 ret
= lxc_write_to_file(full_path
, pidstr
, len
, false, 0666);
2052 /* this is a non-leaf node */
2057 } while (idx
< 1000);
2067 __cgfsng_ops
static bool cgfsng_attach(struct cgroup_ops
*ops
, const char *name
,
2068 const char *lxcpath
, pid_t pid
)
2071 char pidstr
[INTTYPE_TO_STRLEN(pid_t
)];
2073 if (!ops
->hierarchies
)
2076 len
= snprintf(pidstr
, sizeof(pidstr
), "%d", pid
);
2077 if (len
< 0 || (size_t)len
>= sizeof(pidstr
))
2080 for (i
= 0; ops
->hierarchies
[i
]; i
++) {
2081 __do_free
char *path
= NULL
;
2082 char *fullpath
= NULL
;
2083 struct hierarchy
*h
= ops
->hierarchies
[i
];
2085 if (h
->version
== CGROUP2_SUPER_MAGIC
) {
2086 ret
= __cg_unified_attach(h
, name
, lxcpath
, pidstr
, len
,
2094 path
= lxc_cmd_get_cgroup_path(name
, lxcpath
, h
->controllers
[0]);
2099 fullpath
= build_full_cgpath_from_monitorpath(h
, path
, "cgroup.procs");
2100 ret
= lxc_write_to_file(fullpath
, pidstr
, len
, false, 0666);
2102 SYSERROR("Failed to attach %d to %s", (int)pid
, fullpath
);
2110 /* Called externally (i.e. from 'lxc-cgroup') to query cgroup limits. Here we
2111 * don't have a cgroup_data set up, so we ask the running container through the
2112 * commands API for the cgroup path.
2114 __cgfsng_ops
static int cgfsng_get(struct cgroup_ops
*ops
, const char *filename
,
2115 char *value
, size_t len
, const char *name
,
2116 const char *lxcpath
)
2118 __do_free
char *path
= NULL
;
2119 __do_free
char *controller
= NULL
;
2121 struct hierarchy
*h
;
2124 controller
= must_copy_string(filename
);
2125 p
= strchr(controller
, '.');
2129 path
= lxc_cmd_get_cgroup_path(name
, lxcpath
, controller
);
2134 h
= get_hierarchy(ops
, controller
);
2136 __do_free
char *fullpath
= NULL
;
2138 fullpath
= build_full_cgpath_from_monitorpath(h
, path
, filename
);
2139 ret
= lxc_read_from_file(fullpath
, value
, len
);
2145 /* Called externally (i.e. from 'lxc-cgroup') to set new cgroup limits. Here we
2146 * don't have a cgroup_data set up, so we ask the running container through the
2147 * commands API for the cgroup path.
2149 __cgfsng_ops
static int cgfsng_set(struct cgroup_ops
*ops
,
2150 const char *filename
, const char *value
,
2151 const char *name
, const char *lxcpath
)
2153 __do_free
char *path
= NULL
;
2154 __do_free
char *controller
= NULL
;
2156 struct hierarchy
*h
;
2159 controller
= must_copy_string(filename
);
2160 p
= strchr(controller
, '.');
2164 path
= lxc_cmd_get_cgroup_path(name
, lxcpath
, controller
);
2169 h
= get_hierarchy(ops
, controller
);
2171 __do_free
char *fullpath
= NULL
;
2173 fullpath
= build_full_cgpath_from_monitorpath(h
, path
, filename
);
2174 ret
= lxc_write_to_file(fullpath
, value
, strlen(value
), false, 0666);
2180 /* take devices cgroup line
2182 * and convert it to a valid
2183 * type major:minor mode
2184 * line. Return <0 on error. Dest is a preallocated buffer long enough to hold
2187 static int convert_devpath(const char *invalue
, char *dest
)
2189 __do_free
char *path
= NULL
;
2192 unsigned long minor
, major
;
2197 path
= must_copy_string(invalue
);
2199 /* Read path followed by mode. Ignore any trailing text.
2200 * A ' # comment' would be legal. Technically other text is not
2201 * legal, we could check for that if we cared to.
2203 for (n_parts
= 1, p
= path
; *p
; p
++) {
2225 ret
= stat(path
, &sb
);
2229 mode_t m
= sb
.st_mode
& S_IFMT
;
2238 ERROR("Unsupported device type %i for \"%s\"", m
, path
);
2243 major
= MAJOR(sb
.st_rdev
);
2244 minor
= MINOR(sb
.st_rdev
);
2245 ret
= snprintf(dest
, 50, "%c %lu:%lu %s", type
, major
, minor
, mode
);
2246 if (ret
< 0 || ret
>= 50) {
2247 ERROR("Error on configuration value \"%c %lu:%lu %s\" (max 50 "
2248 "chars)", type
, major
, minor
, mode
);
2249 ret
= -ENAMETOOLONG
;
2258 /* Called from setup_limits - here we have the container's cgroup_data because
2259 * we created the cgroups.
2261 static int cg_legacy_set_data(struct cgroup_ops
*ops
, const char *filename
,
2264 __do_free
char *controller
= NULL
;
2265 __do_free
char *fullpath
= NULL
;
2267 /* "b|c <2^64-1>:<2^64-1> r|w|m" = 47 chars max */
2268 char converted_value
[50];
2269 struct hierarchy
*h
;
2272 controller
= must_copy_string(filename
);
2273 p
= strchr(controller
, '.');
2277 if (strcmp("devices.allow", filename
) == 0 && value
[0] == '/') {
2278 ret
= convert_devpath(value
, converted_value
);
2281 value
= converted_value
;
2284 h
= get_hierarchy(ops
, controller
);
2286 ERROR("Failed to setup limits for the \"%s\" controller. "
2287 "The controller seems to be unused by \"cgfsng\" cgroup "
2288 "driver or not enabled on the cgroup hierarchy",
2294 fullpath
= must_make_path(h
->container_full_path
, filename
, NULL
);
2295 ret
= lxc_write_to_file(fullpath
, value
, strlen(value
), false, 0666);
2299 static bool __cg_legacy_setup_limits(struct cgroup_ops
*ops
,
2300 struct lxc_list
*cgroup_settings
,
2303 __do_free
struct lxc_list
*sorted_cgroup_settings
= NULL
;
2304 struct lxc_list
*iterator
, *next
;
2305 struct lxc_cgroup
*cg
;
2308 if (lxc_list_empty(cgroup_settings
))
2311 if (!ops
->hierarchies
)
2314 sorted_cgroup_settings
= sort_cgroup_settings(cgroup_settings
);
2315 if (!sorted_cgroup_settings
)
2318 lxc_list_for_each(iterator
, sorted_cgroup_settings
) {
2319 cg
= iterator
->elem
;
2321 if (do_devices
== !strncmp("devices", cg
->subsystem
, 7)) {
2322 if (cg_legacy_set_data(ops
, cg
->subsystem
, cg
->value
)) {
2323 if (do_devices
&& (errno
== EACCES
|| errno
== EPERM
)) {
2324 WARN("Failed to set \"%s\" to \"%s\"",
2325 cg
->subsystem
, cg
->value
);
2328 WARN("Failed to set \"%s\" to \"%s\"",
2329 cg
->subsystem
, cg
->value
);
2332 DEBUG("Set controller \"%s\" set to \"%s\"",
2333 cg
->subsystem
, cg
->value
);
2338 INFO("Limits for the legacy cgroup hierarchies have been setup");
2340 lxc_list_for_each_safe(iterator
, sorted_cgroup_settings
, next
) {
2341 lxc_list_del(iterator
);
2348 static bool __cg_unified_setup_limits(struct cgroup_ops
*ops
,
2349 struct lxc_list
*cgroup_settings
)
2351 struct lxc_list
*iterator
;
2352 struct hierarchy
*h
= ops
->unified
;
2354 if (lxc_list_empty(cgroup_settings
))
2360 lxc_list_for_each(iterator
, cgroup_settings
) {
2361 __do_free
char *fullpath
= NULL
;
2363 struct lxc_cgroup
*cg
= iterator
->elem
;
2365 fullpath
= must_make_path(h
->container_full_path
, cg
->subsystem
, NULL
);
2366 ret
= lxc_write_to_file(fullpath
, cg
->value
, strlen(cg
->value
), false, 0666);
2368 SYSERROR("Failed to set \"%s\" to \"%s\"",
2369 cg
->subsystem
, cg
->value
);
2372 TRACE("Set \"%s\" to \"%s\"", cg
->subsystem
, cg
->value
);
2375 INFO("Limits for the unified cgroup hierarchy have been setup");
2379 __cgfsng_ops
static bool cgfsng_setup_limits(struct cgroup_ops
*ops
,
2380 struct lxc_conf
*conf
,
2385 bret
= __cg_legacy_setup_limits(ops
, &conf
->cgroup
, do_devices
);
2389 return __cg_unified_setup_limits(ops
, &conf
->cgroup2
);
2392 static bool cgroup_use_wants_controllers(const struct cgroup_ops
*ops
,
2395 char **cur_ctrl
, **cur_use
;
2397 if (!ops
->cgroup_use
)
2400 for (cur_ctrl
= controllers
; cur_ctrl
&& *cur_ctrl
; cur_ctrl
++) {
2403 for (cur_use
= ops
->cgroup_use
; cur_use
&& *cur_use
; cur_use
++) {
2404 if (strcmp(*cur_use
, *cur_ctrl
) != 0)
2420 static void cg_unified_delegate(char ***delegate
)
2422 __do_free
char *tmp
= NULL
;
2424 char *standard
[] = {"cgroup.subtree_control", "cgroup.threads", NULL
};
2426 tmp
= read_file("/sys/kernel/cgroup/delegate");
2428 for (char **p
= standard
; p
&& *p
; p
++) {
2429 idx
= append_null_to_list((void ***)delegate
);
2430 (*delegate
)[idx
] = must_copy_string(*p
);
2434 lxc_iterate_parts (token
, tmp
, " \t\n") {
2436 * We always need to chown this for both cgroup and
2439 if (strcmp(token
, "cgroup.procs") == 0)
2442 idx
= append_null_to_list((void ***)delegate
);
2443 (*delegate
)[idx
] = must_copy_string(token
);
2448 /* At startup, parse_hierarchies finds all the info we need about cgroup
2449 * mountpoints and current cgroups, and stores it in @d.
2451 static bool cg_hybrid_init(struct cgroup_ops
*ops
, bool relative
,
2454 __do_free
char *basecginfo
= NULL
;
2455 __do_free
char *line
= NULL
;
2456 __do_fclose
FILE *f
= NULL
;
2459 char **klist
= NULL
, **nlist
= NULL
;
2461 /* Root spawned containers escape the current cgroup, so use init's
2462 * cgroups as our base in that case.
2464 if (!relative
&& (geteuid() == 0))
2465 basecginfo
= read_file("/proc/1/cgroup");
2467 basecginfo
= read_file("/proc/self/cgroup");
2471 ret
= get_existing_subsystems(&klist
, &nlist
);
2473 ERROR("Failed to retrieve available legacy cgroup controllers");
2477 f
= fopen("/proc/self/mountinfo", "r");
2479 ERROR("Failed to open \"/proc/self/mountinfo\"");
2483 lxc_cgfsng_print_basecg_debuginfo(basecginfo
, klist
, nlist
);
2485 while (getline(&line
, &len
, f
) != -1) {
2488 struct hierarchy
*new;
2489 char *base_cgroup
= NULL
, *mountpoint
= NULL
;
2490 char **controller_list
= NULL
;
2492 type
= get_cgroup_version(line
);
2496 if (type
== CGROUP2_SUPER_MAGIC
&& ops
->unified
)
2499 if (ops
->cgroup_layout
== CGROUP_LAYOUT_UNKNOWN
) {
2500 if (type
== CGROUP2_SUPER_MAGIC
)
2501 ops
->cgroup_layout
= CGROUP_LAYOUT_UNIFIED
;
2502 else if (type
== CGROUP_SUPER_MAGIC
)
2503 ops
->cgroup_layout
= CGROUP_LAYOUT_LEGACY
;
2504 } else if (ops
->cgroup_layout
== CGROUP_LAYOUT_UNIFIED
) {
2505 if (type
== CGROUP_SUPER_MAGIC
)
2506 ops
->cgroup_layout
= CGROUP_LAYOUT_HYBRID
;
2507 } else if (ops
->cgroup_layout
== CGROUP_LAYOUT_LEGACY
) {
2508 if (type
== CGROUP2_SUPER_MAGIC
)
2509 ops
->cgroup_layout
= CGROUP_LAYOUT_HYBRID
;
2512 controller_list
= cg_hybrid_get_controllers(klist
, nlist
, line
, type
);
2513 if (!controller_list
&& type
== CGROUP_SUPER_MAGIC
)
2516 if (type
== CGROUP_SUPER_MAGIC
)
2517 if (controller_list_is_dup(ops
->hierarchies
, controller_list
))
2520 mountpoint
= cg_hybrid_get_mountpoint(line
);
2522 ERROR("Failed parsing mountpoint from \"%s\"", line
);
2526 if (type
== CGROUP_SUPER_MAGIC
)
2527 base_cgroup
= cg_hybrid_get_current_cgroup(basecginfo
, controller_list
[0], CGROUP_SUPER_MAGIC
);
2529 base_cgroup
= cg_hybrid_get_current_cgroup(basecginfo
, NULL
, CGROUP2_SUPER_MAGIC
);
2531 ERROR("Failed to find current cgroup");
2536 prune_init_scope(base_cgroup
);
2537 if (type
== CGROUP2_SUPER_MAGIC
)
2538 writeable
= test_writeable_v2(mountpoint
, base_cgroup
);
2540 writeable
= test_writeable_v1(mountpoint
, base_cgroup
);
2544 if (type
== CGROUP2_SUPER_MAGIC
) {
2545 char *cgv2_ctrl_path
;
2547 cgv2_ctrl_path
= must_make_path(mountpoint
, base_cgroup
,
2548 "cgroup.controllers",
2551 controller_list
= cg_unified_get_controllers(cgv2_ctrl_path
);
2552 free(cgv2_ctrl_path
);
2553 if (!controller_list
) {
2554 controller_list
= cg_unified_make_empty_controller();
2555 TRACE("No controllers are enabled for "
2556 "delegation in the unified hierarchy");
2560 /* Exclude all controllers that cgroup use does not want. */
2561 if (!cgroup_use_wants_controllers(ops
, controller_list
))
2564 new = add_hierarchy(&ops
->hierarchies
, controller_list
, mountpoint
, base_cgroup
, type
);
2565 if (type
== CGROUP2_SUPER_MAGIC
&& !ops
->unified
) {
2567 cg_unified_delegate(&new->cgroup2_chown
);
2574 free_string_list(controller_list
);
2579 free_string_list(klist
);
2580 free_string_list(nlist
);
2582 TRACE("Writable cgroup hierarchies:");
2583 lxc_cgfsng_print_hierarchies(ops
);
2585 /* verify that all controllers in cgroup.use and all crucial
2586 * controllers are accounted for
2588 if (!all_controllers_found(ops
))
2594 static int cg_is_pure_unified(void)
2600 ret
= statfs("/sys/fs/cgroup", &fs
);
2604 if (is_fs_type(&fs
, CGROUP2_SUPER_MAGIC
))
2605 return CGROUP2_SUPER_MAGIC
;
2610 /* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */
2611 static char *cg_unified_get_current_cgroup(bool relative
)
2613 __do_free
char *basecginfo
= NULL
;
2617 if (!relative
&& (geteuid() == 0))
2618 basecginfo
= read_file("/proc/1/cgroup");
2620 basecginfo
= read_file("/proc/self/cgroup");
2624 base_cgroup
= strstr(basecginfo
, "0::/");
2626 goto cleanup_on_err
;
2628 base_cgroup
= base_cgroup
+ 3;
2629 copy
= copy_to_eol(base_cgroup
);
2631 goto cleanup_on_err
;
2640 static int cg_unified_init(struct cgroup_ops
*ops
, bool relative
,
2643 __do_free
char *subtree_path
= NULL
;
2647 struct hierarchy
*new;
2648 char *base_cgroup
= NULL
;
2650 ret
= cg_is_pure_unified();
2651 if (ret
== -ENOMEDIUM
)
2654 if (ret
!= CGROUP2_SUPER_MAGIC
)
2657 base_cgroup
= cg_unified_get_current_cgroup(relative
);
2660 prune_init_scope(base_cgroup
);
2662 /* We assume that we have already been given controllers to delegate
2663 * further down the hierarchy. If not it is up to the user to delegate
2666 mountpoint
= must_copy_string("/sys/fs/cgroup");
2667 subtree_path
= must_make_path(mountpoint
, base_cgroup
,
2668 "cgroup.subtree_control", NULL
);
2669 delegatable
= cg_unified_get_controllers(subtree_path
);
2671 delegatable
= cg_unified_make_empty_controller();
2672 if (!delegatable
[0])
2673 TRACE("No controllers are enabled for delegation");
2675 /* TODO: If the user requested specific controllers via lxc.cgroup.use
2676 * we should verify here. The reason I'm not doing it right is that I'm
2677 * not convinced that lxc.cgroup.use will be the future since it is a
2678 * global property. I much rather have an option that lets you request
2679 * controllers per container.
2682 new = add_hierarchy(&ops
->hierarchies
, delegatable
, mountpoint
, base_cgroup
, CGROUP2_SUPER_MAGIC
);
2684 cg_unified_delegate(&new->cgroup2_chown
);
2686 ops
->cgroup_layout
= CGROUP_LAYOUT_UNIFIED
;
2687 return CGROUP2_SUPER_MAGIC
;
2690 static bool cg_init(struct cgroup_ops
*ops
, struct lxc_conf
*conf
)
2694 bool relative
= conf
->cgroup_meta
.relative
;
2696 tmp
= lxc_global_config_value("lxc.cgroup.use");
2698 __do_free
char *pin
= NULL
;
2701 pin
= must_copy_string(tmp
);
2704 lxc_iterate_parts(cur
, chop
, ",")
2705 must_append_string(&ops
->cgroup_use
, cur
);
2708 ret
= cg_unified_init(ops
, relative
, !lxc_list_empty(&conf
->id_map
));
2712 if (ret
== CGROUP2_SUPER_MAGIC
)
2715 return cg_hybrid_init(ops
, relative
, !lxc_list_empty(&conf
->id_map
));
2718 __cgfsng_ops
static bool cgfsng_data_init(struct cgroup_ops
*ops
)
2720 const char *cgroup_pattern
;
2722 /* copy system-wide cgroup information */
2723 cgroup_pattern
= lxc_global_config_value("lxc.cgroup.pattern");
2724 if (!cgroup_pattern
) {
2725 /* lxc.cgroup.pattern is only NULL on error. */
2726 ERROR("Failed to retrieve cgroup pattern");
2729 ops
->cgroup_pattern
= must_copy_string(cgroup_pattern
);
2730 ops
->monitor_pattern
= MONITOR_CGROUP
;
2735 struct cgroup_ops
*cgfsng_ops_init(struct lxc_conf
*conf
)
2737 struct cgroup_ops
*cgfsng_ops
;
2739 cgfsng_ops
= malloc(sizeof(struct cgroup_ops
));
2743 memset(cgfsng_ops
, 0, sizeof(struct cgroup_ops
));
2744 cgfsng_ops
->cgroup_layout
= CGROUP_LAYOUT_UNKNOWN
;
2746 if (!cg_init(cgfsng_ops
, conf
)) {
2751 cgfsng_ops
->data_init
= cgfsng_data_init
;
2752 cgfsng_ops
->payload_destroy
= cgfsng_payload_destroy
;
2753 cgfsng_ops
->monitor_destroy
= cgfsng_monitor_destroy
;
2754 cgfsng_ops
->monitor_create
= cgfsng_monitor_create
;
2755 cgfsng_ops
->monitor_enter
= cgfsng_monitor_enter
;
2756 cgfsng_ops
->payload_create
= cgfsng_payload_create
;
2757 cgfsng_ops
->payload_enter
= cgfsng_payload_enter
;
2758 cgfsng_ops
->escape
= cgfsng_escape
;
2759 cgfsng_ops
->num_hierarchies
= cgfsng_num_hierarchies
;
2760 cgfsng_ops
->get_hierarchies
= cgfsng_get_hierarchies
;
2761 cgfsng_ops
->get_cgroup
= cgfsng_get_cgroup
;
2762 cgfsng_ops
->get
= cgfsng_get
;
2763 cgfsng_ops
->set
= cgfsng_set
;
2764 cgfsng_ops
->unfreeze
= cgfsng_unfreeze
;
2765 cgfsng_ops
->setup_limits
= cgfsng_setup_limits
;
2766 cgfsng_ops
->driver
= "cgfsng";
2767 cgfsng_ops
->version
= "1.0.0";
2768 cgfsng_ops
->attach
= cgfsng_attach
;
2769 cgfsng_ops
->chown
= cgfsng_chown
;
2770 cgfsng_ops
->mount
= cgfsng_mount
;
2771 cgfsng_ops
->nrtasks
= cgfsng_nrtasks
;