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
315f8a4e
Unverified
Commit
315f8a4e
authored
Feb 04, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroups: fix cgroup mounting
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
dfb71524
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
15 deletions
+68
-15
cgfsng.c
src/lxc/cgroups/cgfsng.c
+10
-9
cgroup.h
src/lxc/cgroups/cgroup.h
+1
-2
conf.c
src/lxc/conf.c
+1
-4
utils.c
src/lxc/utils.c
+52
-0
utils.h
src/lxc/utils.h
+4
-0
No files found.
src/lxc/cgroups/cgfsng.c
View file @
315f8a4e
...
@@ -45,6 +45,7 @@
...
@@ -45,6 +45,7 @@
#include "mainloop.h"
#include "mainloop.h"
#include "memory_utils.h"
#include "memory_utils.h"
#include "storage/storage.h"
#include "storage/storage.h"
#include "syscall_wrappers.h"
#include "utils.h"
#include "utils.h"
#ifndef HAVE_STRLCPY
#ifndef HAVE_STRLCPY
...
@@ -1805,11 +1806,12 @@ static inline int cg_mount_cgroup_full(int type, struct hierarchy *h,
...
@@ -1805,11 +1806,12 @@ static inline int cg_mount_cgroup_full(int type, struct hierarchy *h,
}
}
__cgfsng_ops
static
bool
cgfsng_mount
(
struct
cgroup_ops
*
ops
,
__cgfsng_ops
static
bool
cgfsng_mount
(
struct
cgroup_ops
*
ops
,
struct
lxc_handler
*
handler
,
struct
lxc_conf
*
conf
,
int
type
)
const
char
*
root
,
int
type
)
{
{
__do_free
char
*
cgroup_root
=
NULL
;
__do_free
char
*
cgroup_root
=
NULL
;
bool
has_cgns
=
false
,
wants_force_mount
=
false
;
bool
has_cgns
=
false
,
wants_force_mount
=
false
;
struct
lxc_rootfs
*
rootfs
=
&
conf
->
rootfs
;
const
char
*
root
=
rootfs
->
path
?
rootfs
->
mount
:
""
;
int
ret
;
int
ret
;
if
(
!
ops
)
if
(
!
ops
)
...
@@ -1818,7 +1820,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
...
@@ -1818,7 +1820,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
if
(
!
ops
->
hierarchies
)
if
(
!
ops
->
hierarchies
)
return
true
;
return
true
;
if
(
!
handler
||
!
handler
->
conf
)
if
(
!
conf
)
return
ret_set_errno
(
false
,
EINVAL
);
return
ret_set_errno
(
false
,
EINVAL
);
if
((
type
&
LXC_AUTO_CGROUP_MASK
)
==
0
)
if
((
type
&
LXC_AUTO_CGROUP_MASK
)
==
0
)
...
@@ -1830,7 +1832,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
...
@@ -1830,7 +1832,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
}
}
if
(
!
wants_force_mount
)
{
if
(
!
wants_force_mount
)
{
wants_force_mount
=
!
lxc_wants_cap
(
CAP_SYS_ADMIN
,
handler
->
conf
);
wants_force_mount
=
!
lxc_wants_cap
(
CAP_SYS_ADMIN
,
conf
);
/*
/*
* Most recent distro versions currently have init system that
* Most recent distro versions currently have init system that
...
@@ -1874,16 +1876,15 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
...
@@ -1874,16 +1876,15 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
* relying on RESOLVE_BENEATH so we need to skip the leading "/" in the
* relying on RESOLVE_BENEATH so we need to skip the leading "/" in the
* DEFAULT_CGROUP_MOUNTPOINT define.
* DEFAULT_CGROUP_MOUNTPOINT define.
*/
*/
ret
=
safe_mount_beneath
(
root
,
NULL
,
ret
=
mount_at
(
rootfs
->
mntpt_fd
,
NULL
,
DEFAULT_CGROUP_MOUNTPOINT_RELATIVE
,
DEFAULT_CGROUP_MOUNTPOINT_RELATIVE
,
PROTECT_OPATH_DIRECTORY
,
PROTECT_LOOKUP_BENEATH_XDEV
,
"tmpfs"
,
"tmpfs"
,
MS_NOSUID
|
MS_NODEV
|
MS_NOEXEC
|
MS_RELATIME
,
MS_NOSUID
|
MS_NODEV
|
MS_NOEXEC
|
MS_RELATIME
,
"size=10240k,mode=755"
);
"size=10240k,mode=755"
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
if
(
errno
!=
ENOSYS
)
if
(
errno
!=
ENOSYS
)
return
log_error_errno
(
false
,
errno
,
return
log_error_errno
(
false
,
errno
,
"Failed to mount tmpfs on %s"
,
"Failed to mount tmpfs on %s"
,
DEFAULT_CGROUP_MOUNTPOINT
);
DEFAULT_CGROUP_MOUNTPOINT
_RELATIVE
);
ret
=
safe_mount
(
NULL
,
cgroup_root
,
"tmpfs"
,
ret
=
safe_mount
(
NULL
,
cgroup_root
,
"tmpfs"
,
MS_NOSUID
|
MS_NODEV
|
MS_NOEXEC
|
MS_RELATIME
,
MS_NOSUID
|
MS_NODEV
|
MS_NOEXEC
|
MS_RELATIME
,
...
...
src/lxc/cgroups/cgroup.h
View file @
315f8a4e
...
@@ -172,8 +172,7 @@ struct cgroup_ops {
...
@@ -172,8 +172,7 @@ struct cgroup_ops {
bool
(
*
chown
)(
struct
cgroup_ops
*
ops
,
struct
lxc_conf
*
conf
);
bool
(
*
chown
)(
struct
cgroup_ops
*
ops
,
struct
lxc_conf
*
conf
);
bool
(
*
attach
)(
struct
cgroup_ops
*
ops
,
const
struct
lxc_conf
*
conf
,
bool
(
*
attach
)(
struct
cgroup_ops
*
ops
,
const
struct
lxc_conf
*
conf
,
const
char
*
name
,
const
char
*
lxcpath
,
pid_t
pid
);
const
char
*
name
,
const
char
*
lxcpath
,
pid_t
pid
);
bool
(
*
mount
)(
struct
cgroup_ops
*
ops
,
struct
lxc_handler
*
handler
,
bool
(
*
mount
)(
struct
cgroup_ops
*
ops
,
struct
lxc_conf
*
conf
,
int
type
);
const
char
*
root
,
int
type
);
bool
(
*
devices_activate
)(
struct
cgroup_ops
*
ops
,
bool
(
*
devices_activate
)(
struct
cgroup_ops
*
ops
,
struct
lxc_handler
*
handler
);
struct
lxc_handler
*
handler
);
bool
(
*
monitor_delegate_controllers
)(
struct
cgroup_ops
*
ops
);
bool
(
*
monitor_delegate_controllers
)(
struct
cgroup_ops
*
ops
);
...
...
src/lxc/conf.c
View file @
315f8a4e
...
@@ -734,10 +734,7 @@ static int lxc_mount_auto_mounts(struct lxc_conf *conf, int flags, struct lxc_ha
...
@@ -734,10 +734,7 @@ static int lxc_mount_auto_mounts(struct lxc_conf *conf, int flags, struct lxc_ha
if
(
flags
&
LXC_AUTO_CGROUP_FORCE
)
if
(
flags
&
LXC_AUTO_CGROUP_FORCE
)
cg_flags
|=
LXC_AUTO_CGROUP_FORCE
;
cg_flags
|=
LXC_AUTO_CGROUP_FORCE
;
if
(
!
handler
->
cgroup_ops
->
mount
(
handler
->
cgroup_ops
,
if
(
!
handler
->
cgroup_ops
->
mount
(
handler
->
cgroup_ops
,
conf
,
cg_flags
))
handler
,
rootfs
->
path
?
rootfs
->
mount
:
""
,
cg_flags
))
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount
\"
/sys/fs/cgroup
\"
"
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to mount
\"
/sys/fs/cgroup
\"
"
);
}
}
...
...
src/lxc/utils.c
View file @
315f8a4e
...
@@ -1208,6 +1208,58 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
...
@@ -1208,6 +1208,58 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
return
0
;
return
0
;
}
}
int
mount_at
(
int
dfd
,
const
char
*
src_under_dfd
,
const
char
*
dst_under_dfd
,
__u64
o_flags
,
__u64
resolve_flags
,
const
char
*
fstype
,
unsigned
int
mnt_flags
,
const
void
*
data
)
{
__do_close
int
source_fd
=
-
EBADF
,
target_fd
=
-
EBADF
;
struct
lxc_open_how
how
=
{
.
flags
=
o_flags
,
.
resolve
=
resolve_flags
,
};
int
ret
;
char
src_buf
[
LXC_PROC_PID_FD_LEN
],
dst_buf
[
LXC_PROC_PID_FD_LEN
];
if
(
dfd
<
0
)
return
ret_errno
(
EINVAL
);
if
(
!
is_empty_string
(
src_buf
)
&&
*
src_buf
==
'/'
)
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"Absolute path specified"
);
if
(
is_empty_string
(
dst_under_dfd
))
return
log_error_errno
(
-
EINVAL
,
EINVAL
,
"No target path specified"
);
if
(
!
is_empty_string
(
src_under_dfd
))
{
source_fd
=
openat2
(
dfd
,
src_under_dfd
,
&
how
,
sizeof
(
how
));
if
(
source_fd
<
0
)
return
-
errno
;
ret
=
snprintf
(
src_buf
,
sizeof
(
src_buf
),
"/proc/self/fd/%d"
,
source_fd
);
if
(
ret
<
0
||
ret
>=
sizeof
(
src_buf
))
return
-
EIO
;
}
target_fd
=
openat2
(
dfd
,
dst_under_dfd
,
&
how
,
sizeof
(
how
));
if
(
target_fd
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to open %d(%s)"
,
dfd
,
dst_under_dfd
);
ret
=
snprintf
(
dst_buf
,
sizeof
(
dst_buf
),
"/proc/self/fd/%d"
,
target_fd
);
if
(
ret
<
0
||
ret
>=
sizeof
(
dst_buf
))
return
-
EIO
;
if
(
!
is_empty_string
(
src_buf
))
ret
=
mount
(
src_buf
,
dst_buf
,
fstype
,
mnt_flags
,
data
);
else
ret
=
mount
(
NULL
,
dst_buf
,
fstype
,
mnt_flags
,
data
);
return
ret
;
}
int
open_devnull
(
void
)
int
open_devnull
(
void
)
{
{
int
fd
=
open
(
"/dev/null"
,
O_RDWR
);
int
fd
=
open
(
"/dev/null"
,
O_RDWR
);
...
...
src/lxc/utils.h
View file @
315f8a4e
...
@@ -243,5 +243,9 @@ __hidden extern int safe_mount_beneath(const char *beneath, const char *src, con
...
@@ -243,5 +243,9 @@ __hidden extern int safe_mount_beneath(const char *beneath, const char *src, con
const
char
*
fstype
,
unsigned
int
flags
,
const
void
*
data
);
const
char
*
fstype
,
unsigned
int
flags
,
const
void
*
data
);
__hidden
extern
int
safe_mount_beneath_at
(
int
beneat_fd
,
const
char
*
src
,
const
char
*
dst
,
__hidden
extern
int
safe_mount_beneath_at
(
int
beneat_fd
,
const
char
*
src
,
const
char
*
dst
,
const
char
*
fstype
,
unsigned
int
flags
,
const
void
*
data
);
const
char
*
fstype
,
unsigned
int
flags
,
const
void
*
data
);
__hidden
extern
int
mount_at
(
int
dfd
,
const
char
*
src_under_dfd
,
const
char
*
dst_under_dfd
,
__u64
o_flags
,
__u64
resolve_flags
,
const
char
*
fstype
,
unsigned
int
mnt_flags
,
const
void
*
data
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_UTILS_H */
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