Skip to content

Commit 85d8cee

Browse files
Add --enable-nsdelegate flag to mount cgroups2 with nsdelegate option
1 parent 554d8dc commit 85d8cee

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/bindings.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct lxcfs_opts {
120120
bool swap_off;
121121
bool use_pidfd;
122122
bool use_cfs;
123+
bool use_nsdelegate;
123124
/*
124125
* Ideally we'd version by size but because of backwards compatability
125126
* and the use of bool instead of explicited __u32 and __u64 we can't.
@@ -130,10 +131,11 @@ struct lxcfs_opts {
130131
};
131132

132133
typedef enum lxcfs_opt_t {
133-
LXCFS_SWAP_ON = 0,
134-
LXCFS_PIDFD_ON = 1,
135-
LXCFS_CFS_ON = 2,
136-
LXCFS_OPTS_MAX = LXCFS_CFS_ON,
134+
LXCFS_SWAP_ON = 0,
135+
LXCFS_PIDFD_ON = 1,
136+
LXCFS_CFS_ON = 2,
137+
LXCFS_NSDELEGATE_ON = 3,
138+
LXCFS_OPTS_MAX = LXCFS_NSDELEGATE_ON,
137139
} lxcfs_opt_t;
138140

139141

@@ -164,6 +166,8 @@ static inline bool lxcfs_has_opt(struct lxcfs_opts *opts, lxcfs_opt_t opt)
164166
return opts->use_pidfd;
165167
case LXCFS_CFS_ON:
166168
return opts->use_cfs;
169+
case LXCFS_NSDELEGATE_ON:
170+
return opts->use_nsdelegate;
167171
}
168172

169173
return false;

src/cgroups/cgfsng.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <sys/types.h>
3131
#include <unistd.h>
3232

33+
#include "../bindings.h"
3334
#include "../macro.h"
3435
#include "../memory_utils.h"
3536
#include "../utils.h"
@@ -401,6 +402,12 @@ static int __cg_mount_direct(struct hierarchy *h, const char *controllerpath)
401402
{
402403
__do_free char *controllers = NULL;
403404
char *fstype = "cgroup2";
405+
const char *mount_opts = NULL;
406+
407+
const bool use_nsdelegate = lxcfs_has_opt(fuse_get_context()->private_data, LXCFS_NSDELEGATE_ON);
408+
if (use_nsdelegate) {
409+
mount_opts = "nsdelegate";
410+
}
404411
unsigned long flags = 0;
405412
int ret;
406413

@@ -414,9 +421,10 @@ static int __cg_mount_direct(struct hierarchy *h, const char *controllerpath)
414421
if (!controllers)
415422
return -ENOMEM;
416423
fstype = "cgroup";
424+
mount_opts = controllers;
417425
}
418426

419-
ret = mount("cgroup", controllerpath, fstype, flags, controllers);
427+
ret = mount("cgroup", controllerpath, fstype, flags, mount_opts);
420428
if (ret < 0)
421429
return -1;
422430

src/lxcfs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ static void usage(void)
12431243
lxcfs_info(" --enable-cfs Enable CPU virtualization via CPU shares");
12441244
lxcfs_info(" --enable-pidfd Use pidfd for process tracking");
12451245
lxcfs_info(" --enable-cgroup Enable cgroup emulation code");
1246+
lxcfs_info(" --enable-nsdelegate Enable cgroup nsdelegate mount option");
12461247
lxcfs_info(" --runtime-dir=DIR Path to use as the runtime directory.");
12471248
lxcfs_info(" Default is %s", DEFAULT_RUNTIME_PATH);
12481249
exit(EXIT_FAILURE);
@@ -1294,6 +1295,7 @@ static const struct option long_options[] = {
12941295
{"enable-cfs", no_argument, 0, 0 },
12951296
{"enable-pidfd", no_argument, 0, 0 },
12961297
{"enable-cgroup", no_argument, 0, 0 },
1298+
{"enable-nsdelegate", no_argument, 0, 0 },
12971299

12981300
{"pidfile", required_argument, 0, 'p' },
12991301
{"runtime-dir", required_argument, 0, 0 },
@@ -1367,6 +1369,7 @@ int main(int argc, char *argv[])
13671369
opts->swap_off = false;
13681370
opts->use_pidfd = false;
13691371
opts->use_cfs = false;
1372+
opts->use_nsdelegate = false;
13701373
opts->version = 2;
13711374

13721375
while ((c = getopt_long(argc, argv, "dulfhvso:p:", long_options, &idx)) != -1) {
@@ -1378,6 +1381,8 @@ int main(int argc, char *argv[])
13781381
opts->use_cfs = true;
13791382
else if (strcmp(long_options[idx].name, "enable-cgroup") == 0)
13801383
cgroup_is_enabled = true;
1384+
else if (strcmp(long_options[idx].name, "enable-nsdelegate") == 0)
1385+
opts->use_nsdelegate = true;
13811386
else if (strcmp(long_options[idx].name, "runtime-dir") == 0)
13821387
runtime_path_arg = optarg;
13831388
else

0 commit comments

Comments
 (0)