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
51c8368a
Unverified
Commit
51c8368a
authored
Apr 07, 2020
by
Christian Brauner
Committed by
GitHub
Apr 07, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3359 from Blub/legacy-devices-isolation-change
cgroup isolation: handle devices cgroup early
parents
d8ccf906
432faf20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
17 deletions
+56
-17
cgfsng.c
src/lxc/cgroups/cgfsng.c
+50
-16
start.c
src/lxc/start.c
+6
-1
No files found.
src/lxc/cgroups/cgfsng.c
View file @
51c8368a
...
@@ -1154,11 +1154,12 @@ static int mkdir_eexist_on_last(const char *dir, mode_t mode)
...
@@ -1154,11 +1154,12 @@ static int mkdir_eexist_on_last(const char *dir, mode_t mode)
return
0
;
return
0
;
}
}
static
bool
cgroup_tree_create
(
struct
hierarchy
*
h
,
const
char
*
cgroup_tree
,
static
bool
cgroup_tree_create
(
struct
cgroup_ops
*
ops
,
struct
lxc_conf
*
conf
,
struct
hierarchy
*
h
,
const
char
*
cgroup_tree
,
const
char
*
cgroup_leaf
,
bool
payload
,
const
char
*
cgroup_leaf
,
bool
payload
,
const
char
*
cgroup_limit_dir
)
const
char
*
cgroup_limit_dir
)
{
{
__do_free
char
*
path
=
NULL
;
__do_free
char
*
path
=
NULL
,
*
limit_path
=
NULL
;
int
ret
,
ret_cpuset
;
int
ret
,
ret_cpuset
;
path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgroup_leaf
,
NULL
);
path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgroup_leaf
,
NULL
);
...
@@ -1169,6 +1170,37 @@ static bool cgroup_tree_create(struct hierarchy *h, const char *cgroup_tree,
...
@@ -1169,6 +1170,37 @@ static bool cgroup_tree_create(struct hierarchy *h, const char *cgroup_tree,
if
(
ret_cpuset
<
0
)
if
(
ret_cpuset
<
0
)
return
log_error_errno
(
false
,
errno
,
"Failed to handle legacy cpuset controller"
);
return
log_error_errno
(
false
,
errno
,
"Failed to handle legacy cpuset controller"
);
if
(
payload
&&
cgroup_limit_dir
)
{
/* with isolation both parts need to not already exist */
limit_path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgroup_limit_dir
,
NULL
);
ret
=
mkdir_eexist_on_last
(
limit_path
,
0755
);
if
(
ret
<
0
)
return
log_error_errno
(
false
,
errno
,
"Failed to create %s limiting cgroup"
,
limit_path
);
h
->
cgfd_limit
=
lxc_open_dirfd
(
limit_path
);
if
(
h
->
cgfd_limit
<
0
)
return
log_error_errno
(
false
,
errno
,
"Failed to open %s"
,
path
);
h
->
container_limit_path
=
move_ptr
(
limit_path
);
/*
* With isolation the devices legacy cgroup needs to be
* iinitialized early, as it typically contains an 'a' (all)
* line, which is not possible once a subdirectory has been
* created.
*/
if
(
string_in_list
(
h
->
controllers
,
"devices"
))
{
ret
=
ops
->
setup_limits_legacy
(
ops
,
conf
,
true
);
if
(
ret
<
0
)
return
ret
;
}
}
ret
=
mkdir_eexist_on_last
(
path
,
0755
);
ret
=
mkdir_eexist_on_last
(
path
,
0755
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
/*
/*
...
@@ -1185,16 +1217,10 @@ static bool cgroup_tree_create(struct hierarchy *h, const char *cgroup_tree,
...
@@ -1185,16 +1217,10 @@ static bool cgroup_tree_create(struct hierarchy *h, const char *cgroup_tree,
if
(
h
->
cgfd_con
<
0
)
if
(
h
->
cgfd_con
<
0
)
return
log_error_errno
(
false
,
errno
,
"Failed to open %s"
,
path
);
return
log_error_errno
(
false
,
errno
,
"Failed to open %s"
,
path
);
h
->
container_full_path
=
move_ptr
(
path
);
h
->
container_full_path
=
move_ptr
(
path
);
if
(
cgroup_limit_dir
)
{
if
(
h
->
cgfd_limit
<
0
)
path
=
must_make_path
(
h
->
mountpoint
,
h
->
container_base_path
,
cgroup_limit_dir
,
NULL
);
h
->
cgfd_limit
=
lxc_open_dirfd
(
path
);
if
(
h
->
cgfd_limit
<
0
)
return
log_error_errno
(
false
,
errno
,
"Failed to open %s"
,
path
);
h
->
container_limit_path
=
move_ptr
(
path
);
}
else
{
h
->
container_limit_path
=
h
->
container_full_path
;
h
->
cgfd_limit
=
h
->
cgfd_con
;
h
->
cgfd_limit
=
h
->
cgfd_con
;
}
if
(
!
h
->
container_limit_path
)
h
->
container_limit_path
=
h
->
container_full_path
;
}
else
{
}
else
{
h
->
cgfd_mon
=
lxc_open_dirfd
(
path
);
h
->
cgfd_mon
=
lxc_open_dirfd
(
path
);
if
(
h
->
cgfd_mon
<
0
)
if
(
h
->
cgfd_mon
<
0
)
...
@@ -1321,7 +1347,9 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
...
@@ -1321,7 +1347,9 @@ __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
sprintf
(
suffix
,
"-%d"
,
idx
);
sprintf
(
suffix
,
"-%d"
,
idx
);
for
(
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
for
(
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
if
(
cgroup_tree_create
(
ops
->
hierarchies
[
i
],
cgroup_tree
,
monitor_cgroup
,
false
,
NULL
))
if
(
cgroup_tree_create
(
ops
,
handler
->
conf
,
ops
->
hierarchies
[
i
],
cgroup_tree
,
monitor_cgroup
,
false
,
NULL
))
continue
;
continue
;
ERROR
(
"Failed to create cgroup
\"
%s
\"
"
,
ops
->
hierarchies
[
i
]
->
monitor_full_path
?:
"(null)"
);
ERROR
(
"Failed to create cgroup
\"
%s
\"
"
,
ops
->
hierarchies
[
i
]
->
monitor_full_path
?:
"(null)"
);
...
@@ -1381,9 +1409,14 @@ __cgfsng_ops static inline bool cgfsng_payload_create(struct cgroup_ops *ops,
...
@@ -1381,9 +1409,14 @@ __cgfsng_ops static inline bool cgfsng_payload_create(struct cgroup_ops *ops,
if
(
!
limiting_cgroup
)
if
(
!
limiting_cgroup
)
return
ret_set_errno
(
false
,
ENOMEM
);
return
ret_set_errno
(
false
,
ENOMEM
);
container_cgroup
=
must_make_path
(
limiting_cgroup
,
if
(
conf
->
cgroup_meta
.
namespace_dir
)
{
conf
->
cgroup_meta
.
namespace_dir
,
container_cgroup
=
must_make_path
(
limiting_cgroup
,
NULL
);
conf
->
cgroup_meta
.
namespace_dir
,
NULL
);
}
else
{
/* explicit paths but without isolation */
container_cgroup
=
move_ptr
(
limiting_cgroup
);
}
}
else
if
(
conf
->
cgroup_meta
.
dir
)
{
}
else
if
(
conf
->
cgroup_meta
.
dir
)
{
cgroup_tree
=
conf
->
cgroup_meta
.
dir
;
cgroup_tree
=
conf
->
cgroup_meta
.
dir
;
container_cgroup
=
must_concat
(
&
len
,
cgroup_tree
,
"/"
,
container_cgroup
=
must_concat
(
&
len
,
cgroup_tree
,
"/"
,
...
@@ -1417,7 +1450,8 @@ __cgfsng_ops static inline bool cgfsng_payload_create(struct cgroup_ops *ops,
...
@@ -1417,7 +1450,8 @@ __cgfsng_ops static inline bool cgfsng_payload_create(struct cgroup_ops *ops,
sprintf
(
suffix
,
"-%d"
,
idx
);
sprintf
(
suffix
,
"-%d"
,
idx
);
for
(
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
for
(
i
=
0
;
ops
->
hierarchies
[
i
];
i
++
)
{
if
(
cgroup_tree_create
(
ops
->
hierarchies
[
i
],
cgroup_tree
,
if
(
cgroup_tree_create
(
ops
,
handler
->
conf
,
ops
->
hierarchies
[
i
],
cgroup_tree
,
container_cgroup
,
true
,
container_cgroup
,
true
,
limiting_cgroup
))
limiting_cgroup
))
continue
;
continue
;
...
...
src/lxc/start.c
View file @
51c8368a
...
@@ -1784,7 +1784,12 @@ static int lxc_spawn(struct lxc_handler *handler)
...
@@ -1784,7 +1784,12 @@ static int lxc_spawn(struct lxc_handler *handler)
if
(
ret
<
0
)
if
(
ret
<
0
)
goto
out_delete_net
;
goto
out_delete_net
;
if
(
!
cgroup_ops
->
setup_limits_legacy
(
cgroup_ops
,
handler
->
conf
,
true
))
{
/*
* with isolation the limiting devices cgroup was already setup, so
* only setup devices here if we have no namespace directory
*/
if
(
!
handler
->
conf
->
cgroup_meta
.
namespace_dir
&&
!
cgroup_ops
->
setup_limits_legacy
(
cgroup_ops
,
handler
->
conf
,
true
))
{
ERROR
(
"Failed to setup legacy device cgroup controller limits"
);
ERROR
(
"Failed to setup legacy device cgroup controller limits"
);
goto
out_delete_net
;
goto
out_delete_net
;
}
}
...
...
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