Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
635e7bac
Unverified
Commit
635e7bac
authored
Feb 05, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree-wide: make use of new_mount_api() where it makes sense
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
87545854
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
52 deletions
+54
-52
cgfsng.c
src/lxc/cgroups/cgfsng.c
+30
-24
conf.c
src/lxc/conf.c
+24
-28
No files found.
src/lxc/cgroups/cgfsng.c
View file @
635e7bac
...
...
@@ -1785,8 +1785,26 @@ static int __cg_mount_direct(int type, struct hierarchy *h,
fstype
=
"cgroup"
;
}
fd_fs
=
fs_prepare
(
fstype
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
{
if
(
new_mount_api
())
{
fd_fs
=
fs_prepare
(
fstype
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to prepare filesystem context for %s"
,
fstype
);
if
(
!
is_unified_hierarchy
(
h
))
{
for
(
const
char
**
it
=
(
const
char
**
)
h
->
controllers
;
it
&&
*
it
;
it
++
)
{
if
(
strncmp
(
*
it
,
"name="
,
STRLITERALLEN
(
"name="
))
==
0
)
ret
=
fs_set_property
(
fd_fs
,
"name"
,
*
it
+
STRLITERALLEN
(
"name="
));
else
ret
=
fs_set_property
(
fd_fs
,
*
it
,
""
);
if
(
ret
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to add %s controller to cgroup filesystem context %d(dev)"
,
*
it
,
fd_fs
);
}
}
ret
=
fs_attach
(
fd_fs
,
dfd_mnt_cgroupfs
,
hierarchy_mnt
,
PROTECT_OPATH_DIRECTORY
,
PROTECT_LOOKUP_BENEATH
,
flags
);
}
else
{
__do_free
char
*
controllers
=
NULL
,
*
target
=
NULL
;
unsigned
int
old_flags
=
0
;
const
char
*
rootfs_mnt
;
...
...
@@ -1804,21 +1822,6 @@ static int __cg_mount_direct(int type, struct hierarchy *h,
target
=
must_make_path
(
rootfs_mnt
,
DEFAULT_CGROUP_MOUNTPOINT
,
hierarchy_mnt
,
NULL
);
ret
=
safe_mount
(
NULL
,
target
,
fstype
,
old_flags
,
controllers
,
rootfs_mnt
);
}
else
{
if
(
!
is_unified_hierarchy
(
h
))
{
for
(
const
char
**
it
=
(
const
char
**
)
h
->
controllers
;
it
&&
*
it
;
it
++
)
{
if
(
strncmp
(
*
it
,
"name="
,
STRLITERALLEN
(
"name="
))
==
0
)
ret
=
fs_set_property
(
fd_fs
,
"name"
,
*
it
+
STRLITERALLEN
(
"name="
));
else
ret
=
fs_set_property
(
fd_fs
,
*
it
,
""
);
if
(
ret
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to add %s controller to cgroup filesystem context %d(dev)"
,
*
it
,
fd_fs
);
}
}
ret
=
fs_attach
(
fd_fs
,
dfd_mnt_cgroupfs
,
hierarchy_mnt
,
PROTECT_OPATH_DIRECTORY
,
PROTECT_LOOKUP_BENEATH
,
flags
);
}
if
(
ret
<
0
)
return
log_error_errno
(
ret
,
errno
,
"Failed to mount %s filesystem onto %d(%s)"
,
...
...
@@ -1928,13 +1931,11 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
* relying on RESOLVE_BENEATH so we need to skip the leading "/" in the
* DEFAULT_CGROUP_MOUNTPOINT define.
*/
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
{
cgroup_root
=
must_make_path
(
rootfs_mnt
,
DEFAULT_CGROUP_MOUNTPOINT
,
NULL
);
ret
=
safe_mount
(
NULL
,
cgroup_root
,
"tmpfs"
,
MS_NOSUID
|
MS_NODEV
|
MS_NOEXEC
|
MS_RELATIME
,
"size=10240k,mode=755"
,
rootfs_mnt
);
}
else
{
if
(
new_mount_api
())
{
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create new filesystem context for tmpfs"
);
ret
=
fs_set_property
(
fd_fs
,
"mode"
,
"0755"
);
if
(
ret
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to mount tmpfs onto %d(dev)"
,
fd_fs
);
...
...
@@ -1947,6 +1948,11 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
PROTECT_OPATH_DIRECTORY
,
PROTECT_LOOKUP_BENEATH_XDEV
,
MOUNT_ATTR_NOSUID
|
MOUNT_ATTR_NODEV
|
MOUNT_ATTR_NOEXEC
|
MOUNT_ATTR_RELATIME
);
}
else
{
cgroup_root
=
must_make_path
(
rootfs_mnt
,
DEFAULT_CGROUP_MOUNTPOINT
,
NULL
);
ret
=
safe_mount
(
NULL
,
cgroup_root
,
"tmpfs"
,
MS_NOSUID
|
MS_NODEV
|
MS_NOEXEC
|
MS_RELATIME
,
"size=10240k,mode=755"
,
rootfs_mnt
);
}
if
(
ret
<
0
)
return
log_error_errno
(
false
,
errno
,
"Failed to mount tmpfs on %s"
,
...
...
src/lxc/conf.c
View file @
635e7bac
...
...
@@ -1077,20 +1077,11 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
goto
reset_umask
;
}
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
{
__do_free
char
*
fallback_path
=
NULL
;
sprintf
(
mount_options
,
"size=%zu,mode=755"
,
tmpfs_size
);
DEBUG
(
"Using mount options: %s"
,
mount_options
);
if
(
new_mount_api
())
{
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to prepare filesystem context for tmpfs"
);
if
(
path
)
{
fallback_path
=
must_make_path
(
path
,
"/dev"
,
NULL
);
ret
=
safe_mount
(
"none"
,
fallback_path
,
"tmpfs"
,
0
,
mount_options
,
path
);
}
else
{
ret
=
safe_mount
(
"none"
,
"dev"
,
"tmpfs"
,
0
,
mount_options
,
NULL
);
}
}
else
{
sprintf
(
mount_options
,
"%zu"
,
tmpfs_size
);
ret
=
fs_set_property
(
fd_fs
,
"mode"
,
"0755"
);
...
...
@@ -1102,6 +1093,18 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
return
log_error_errno
(
-
errno
,
errno
,
"Failed to mount tmpfs onto %d(dev)"
,
fd_fs
);
ret
=
fs_attach
(
fd_fs
,
rootfs
->
dfd_mnt
,
"dev"
,
PROTECT_OPATH_DIRECTORY
,
PROTECT_LOOKUP_BENEATH
,
0
);
}
else
{
__do_free
char
*
fallback_path
=
NULL
;
sprintf
(
mount_options
,
"size=%zu,mode=755"
,
tmpfs_size
);
DEBUG
(
"Using mount options: %s"
,
mount_options
);
if
(
path
)
{
fallback_path
=
must_make_path
(
path
,
"/dev"
,
NULL
);
ret
=
safe_mount
(
"none"
,
fallback_path
,
"tmpfs"
,
0
,
mount_options
,
path
);
}
else
{
ret
=
safe_mount
(
"none"
,
"dev"
,
"tmpfs"
,
0
,
mount_options
,
NULL
);
}
}
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to mount tmpfs on
\"
%s
\"
"
,
path
);
...
...
@@ -1217,23 +1220,16 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
device_path
))
return
ret_errno
(
EIO
);
ret
=
fd_bind_mount
(
rootfs
->
dfd_host
,
device_path
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
rootfs
->
dfd_dev
,
device
->
name
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH
,
0
,
false
);
if
(
ret
<
0
)
{
if
(
new_mount_api
())
{
ret
=
fd_bind_mount
(
rootfs
->
dfd_host
,
device_path
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
rootfs
->
dfd_dev
,
device
->
name
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH
,
0
,
false
);
}
else
{
char
path
[
PATH_MAX
];
if
(
errno
!=
ENOSYS
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to mount %d(%s) to %d(%s)"
,
rootfs
->
dfd_host
,
device_path
,
rootfs
->
dfd_dev
,
device
->
name
);
ret
=
snprintf
(
device_path
,
sizeof
(
device_path
),
"/dev/%s"
,
device
->
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
device_path
))
return
ret_errno
(
EIO
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment