Skip to content

Commit 720a3c1

Browse files
committed
lxc: assume fsopen/open_tree/mount_setattr syscalls are supported
fsopen and open_tree were added in 5.2 mount_setattr in 5.12 Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
1 parent fc7adb3 commit 720a3c1

2 files changed

Lines changed: 104 additions & 225 deletions

File tree

src/lxc/cgroups/cgfsng.c

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,44 +1844,24 @@ static int __cgroupfs_mount(int cgroup_automount_type, struct hierarchy *h,
18441844
if (!is_unified_hierarchy(h))
18451845
return ret_errno(EOPNOTSUPP);
18461846

1847-
if (can_use_mount_api()) {
1848-
fd_fs = fs_prepare(fstype, -EBADF, "", 0, 0);
1849-
if (fd_fs < 0)
1850-
return log_error_errno(-errno, errno, "Failed to prepare filesystem context for %s", fstype);
1851-
1852-
if (!is_unified_hierarchy(h)) {
1853-
for (const char **it = (const char **)h->controllers; it && *it; it++) {
1854-
if (strnequal(*it, "name=", STRLITERALLEN("name=")))
1855-
ret = fs_set_property(fd_fs, "name", *it + STRLITERALLEN("name="));
1856-
else
1857-
ret = fs_set_property(fd_fs, *it, "");
1858-
if (ret < 0)
1859-
return log_error_errno(-errno, errno, "Failed to add %s controller to cgroup filesystem context %d(dev)", *it, fd_fs);
1860-
}
1861-
}
1862-
1863-
ret = fs_attach(fd_fs, dfd_mnt_cgroupfs, hierarchy_mnt,
1864-
PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_BENEATH,
1865-
flags);
1866-
} else {
1867-
__do_free char *controllers = NULL, *target = NULL;
1868-
unsigned int old_flags = 0;
1869-
const char *rootfs_mnt;
1870-
1871-
if (!is_unified_hierarchy(h)) {
1872-
controllers = lxc_string_join(",", (const char **)h->controllers, false);
1873-
if (!controllers)
1874-
return ret_errno(ENOMEM);
1847+
fd_fs = fs_prepare(fstype, -EBADF, "", 0, 0);
1848+
if (fd_fs < 0)
1849+
return log_error_errno(-errno, errno, "Failed to prepare filesystem context for %s", fstype);
1850+
1851+
if (!is_unified_hierarchy(h)) {
1852+
for (const char **it = (const char **)h->controllers; it && *it; it++) {
1853+
if (strnequal(*it, "name=", STRLITERALLEN("name=")))
1854+
ret = fs_set_property(fd_fs, "name", *it + STRLITERALLEN("name="));
1855+
else
1856+
ret = fs_set_property(fd_fs, *it, "");
1857+
if (ret < 0)
1858+
return log_error_errno(-errno, errno, "Failed to add %s controller to cgroup filesystem context %d(dev)", *it, fd_fs);
18751859
}
1876-
1877-
rootfs_mnt = get_rootfs_mnt(rootfs);
1878-
ret = mnt_attributes_old(flags, &old_flags);
1879-
if (ret)
1880-
return log_error_errno(-EINVAL, EINVAL, "Unsupported mount properties specified");
1881-
1882-
target = must_make_path(rootfs_mnt, DEFAULT_CGROUP_MOUNTPOINT, hierarchy_mnt, NULL);
1883-
ret = safe_mount(NULL, target, fstype, old_flags, controllers, rootfs_mnt);
18841860
}
1861+
1862+
ret = fs_attach(fd_fs, dfd_mnt_cgroupfs, hierarchy_mnt,
1863+
PROTECT_OPATH_DIRECTORY, PROTECT_LOOKUP_BENEATH,
1864+
flags);
18851865
if (ret < 0)
18861866
return log_error_errno(ret, errno, "Failed to mount %s filesystem onto %d(%s)",
18871867
fstype, dfd_mnt_cgroupfs, maybe_empty(hierarchy_mnt));

0 commit comments

Comments
 (0)