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
fe70edee
Unverified
Commit
fe70edee
authored
Dec 09, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroups: flatten hierarchy
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
e340fefe
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
25 additions
and
31 deletions
+25
-31
cgfsng.c
src/lxc/cgroups/cgfsng.c
+0
-0
cgroup.h
src/lxc/cgroups/cgroup.h
+7
-6
initutils.c
src/lxc/initutils.c
+1
-1
apparmor.c
src/lxc/lsm/apparmor.c
+4
-4
start.c
src/lxc/start.c
+2
-1
string_utils.c
src/lxc/string_utils.c
+3
-1
string_utils.h
src/lxc/string_utils.h
+1
-1
utils.h
src/lxc/utils.h
+0
-7
cgpath.c
src/tests/cgpath.c
+7
-10
No files found.
src/lxc/cgroups/cgfsng.c
View file @
fe70edee
This diff is collapsed.
Click to expand it.
src/lxc/cgroups/cgroup.h
View file @
fe70edee
...
@@ -7,10 +7,14 @@
...
@@ -7,10 +7,14 @@
#include <stddef.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/types.h>
#include "macro.h"
#define DEFAULT_CGROUP_MOUNTPOINT "/sys/fs/cgroup"
#define DEFAULT_CGROUP_MOUNTPOINT "/sys/fs/cgroup"
#define PAYLOAD_CGROUP "lxc.payload"
#define DEFAULT_PAYLOAD_CGROUP_PREFIX "lxc.payload."
#define MONITOR_CGROUP "lxc.monitor"
#define DEFAULT_MONITOR_CGROUP_PREFIX "lxc.monitor."
#define PIVOT_CGROUP "lxc.pivot"
#define CGROUP_CREATE_RETRY "-NNNN"
#define CGROUP_CREATE_RETRY_LEN (STRLITERALLEN(CGROUP_CREATE_RETRY))
#define CGROUP_PIVOT "lxc.pivot"
struct
lxc_handler
;
struct
lxc_handler
;
struct
lxc_conf
;
struct
lxc_conf
;
...
@@ -90,9 +94,6 @@ struct cgroup_ops {
...
@@ -90,9 +94,6 @@ struct cgroup_ops {
char
*
container_cgroup
;
char
*
container_cgroup
;
char
*
monitor_cgroup
;
char
*
monitor_cgroup
;
/* Static memory, do not free.*/
const
char
*
monitor_pattern
;
/* @hierarchies
/* @hierarchies
* - A NULL-terminated array of struct hierarchy, one per legacy
* - A NULL-terminated array of struct hierarchy, one per legacy
* hierarchy. No duplicates. First sufficient, writeable mounted
* hierarchy. No duplicates. First sufficient, writeable mounted
...
...
src/lxc/initutils.c
View file @
fe70edee
...
@@ -84,7 +84,7 @@ const char *lxc_global_config_value(const char *option_name)
...
@@ -84,7 +84,7 @@ const char *lxc_global_config_value(const char *option_name)
sprintf
(
user_config_path
,
"%s/.config/lxc/lxc.conf"
,
user_home
);
sprintf
(
user_config_path
,
"%s/.config/lxc/lxc.conf"
,
user_home
);
sprintf
(
user_default_config_path
,
"%s/.config/lxc/default.conf"
,
user_home
);
sprintf
(
user_default_config_path
,
"%s/.config/lxc/default.conf"
,
user_home
);
sprintf
(
user_lxc_path
,
"%s/.local/share/lxc/"
,
user_home
);
sprintf
(
user_lxc_path
,
"%s/.local/share/lxc/"
,
user_home
);
user_cgroup_pattern
=
strdup
(
"
lxc.payload/
%n"
);
user_cgroup_pattern
=
strdup
(
"%n"
);
}
}
else
{
else
{
user_config_path
=
strdup
(
LXC_GLOBAL_CONF
);
user_config_path
=
strdup
(
LXC_GLOBAL_CONF
);
...
...
src/lxc/lsm/apparmor.c
View file @
fe70edee
...
@@ -510,7 +510,7 @@ static inline char *apparmor_dir(const char *ctname, const char *lxcpath)
...
@@ -510,7 +510,7 @@ static inline char *apparmor_dir(const char *ctname, const char *lxcpath)
static
inline
char
*
apparmor_profile_full
(
const
char
*
ctname
,
const
char
*
lxcpath
)
static
inline
char
*
apparmor_profile_full
(
const
char
*
ctname
,
const
char
*
lxcpath
)
{
{
return
shorten_apparmor_name
(
must_concat
(
"lxc-"
,
ctname
,
"_<"
,
lxcpath
,
">"
,
NULL
));
return
shorten_apparmor_name
(
must_concat
(
NULL
,
"lxc-"
,
ctname
,
"_<"
,
lxcpath
,
">"
,
NULL
));
}
}
/* Like apparmor_profile_full() but with slashes replaced by hyphens */
/* Like apparmor_profile_full() but with slashes replaced by hyphens */
...
@@ -639,7 +639,7 @@ static char *get_apparmor_profile_content(struct lxc_conf *conf, const char *lxc
...
@@ -639,7 +639,7 @@ static char *get_apparmor_profile_content(struct lxc_conf *conf, const char *lxc
profile_name_full
=
apparmor_profile_full
(
conf
->
name
,
lxcpath
);
profile_name_full
=
apparmor_profile_full
(
conf
->
name
,
lxcpath
);
profile
=
must_concat
(
profile
=
must_concat
(
NULL
,
"#include <tunables/global>
\n
"
"#include <tunables/global>
\n
"
"profile
\"
"
,
profile_name_full
,
"
\"
flags=(attach_disconnected,mediate_deleted) {
\n
"
,
"profile
\"
"
,
profile_name_full
,
"
\"
flags=(attach_disconnected,mediate_deleted) {
\n
"
,
NULL
);
NULL
);
...
@@ -663,7 +663,7 @@ static char *get_apparmor_profile_content(struct lxc_conf *conf, const char *lxc
...
@@ -663,7 +663,7 @@ static char *get_apparmor_profile_content(struct lxc_conf *conf, const char *lxc
STRARRAYLEN
(
AA_PROFILE_STACKING_BASE
));
STRARRAYLEN
(
AA_PROFILE_STACKING_BASE
));
namespace
=
apparmor_namespace
(
conf
->
name
,
lxcpath
);
namespace
=
apparmor_namespace
(
conf
->
name
,
lxcpath
);
temp
=
must_concat
(
" change_profile ->
\"
:"
,
namespace
,
":*
\"
,
\n
"
temp
=
must_concat
(
NULL
,
" change_profile ->
\"
:"
,
namespace
,
":*
\"
,
\n
"
" change_profile ->
\"
:"
,
namespace
,
"://*
\"
,
\n
"
,
" change_profile ->
\"
:"
,
namespace
,
"://*
\"
,
\n
"
,
NULL
);
NULL
);
free
(
namespace
);
free
(
namespace
);
...
@@ -682,7 +682,7 @@ static char *get_apparmor_profile_content(struct lxc_conf *conf, const char *lxc
...
@@ -682,7 +682,7 @@ static char *get_apparmor_profile_content(struct lxc_conf *conf, const char *lxc
if
(
!
aa_can_stack
||
aa_is_stacked
)
{
if
(
!
aa_can_stack
||
aa_is_stacked
)
{
char
*
temp
;
char
*
temp
;
temp
=
must_concat
(
" change_profile ->
\"
"
,
temp
=
must_concat
(
NULL
,
" change_profile ->
\"
"
,
profile_name_full
,
"
\"
,
\n
"
,
NULL
);
profile_name_full
,
"
\"
,
\n
"
,
NULL
);
must_append_sized
(
&
profile
,
&
size
,
temp
,
strlen
(
temp
));
must_append_sized
(
&
profile
,
&
size
,
temp
,
strlen
(
temp
));
free
(
temp
);
free
(
temp
);
...
...
src/lxc/start.c
View file @
fe70edee
...
@@ -1820,8 +1820,9 @@ static int lxc_spawn(struct lxc_handler *handler)
...
@@ -1820,8 +1820,9 @@ static int lxc_spawn(struct lxc_handler *handler)
goto
out_delete_net
;
goto
out_delete_net
;
}
}
if
(
!
cgroup_ops
->
payload_enter
(
cgroup_ops
,
handler
))
if
(
!
cgroup_ops
->
payload_enter
(
cgroup_ops
,
handler
))
{
goto
out_delete_net
;
goto
out_delete_net
;
}
if
(
!
cgroup_ops
->
payload_delegate_controllers
(
cgroup_ops
))
{
if
(
!
cgroup_ops
->
payload_delegate_controllers
(
cgroup_ops
))
{
ERROR
(
"Failed to delegate controllers to payload cgroup"
);
ERROR
(
"Failed to delegate controllers to payload cgroup"
);
...
...
src/lxc/string_utils.c
View file @
fe70edee
...
@@ -730,7 +730,7 @@ int lxc_safe_long_long(const char *numstr, long long int *converted)
...
@@ -730,7 +730,7 @@ int lxc_safe_long_long(const char *numstr, long long int *converted)
return
0
;
return
0
;
}
}
char
*
must_concat
(
const
char
*
first
,
...)
char
*
must_concat
(
size_t
*
len
,
const
char
*
first
,
...)
{
{
va_list
args
;
va_list
args
;
char
*
cur
,
*
dest
;
char
*
cur
,
*
dest
;
...
@@ -751,6 +751,8 @@ char *must_concat(const char *first, ...)
...
@@ -751,6 +751,8 @@ char *must_concat(const char *first, ...)
va_end
(
args
);
va_end
(
args
);
dest
[
cur_len
]
=
'\0'
;
dest
[
cur_len
]
=
'\0'
;
if
(
len
)
*
len
=
cur_len
;
return
dest
;
return
dest
;
}
}
...
...
src/lxc/string_utils.h
View file @
fe70edee
...
@@ -79,7 +79,7 @@ extern int parse_byte_size_string(const char *s, int64_t *converted);
...
@@ -79,7 +79,7 @@ extern int parse_byte_size_string(const char *s, int64_t *converted);
* Concatenate all passed-in strings into one path. Do not fail. If any piece
* Concatenate all passed-in strings into one path. Do not fail. If any piece
* is not prefixed with '/', add a '/'.
* is not prefixed with '/', add a '/'.
*/
*/
__attribute__
((
sentinel
))
extern
char
*
must_concat
(
const
char
*
first
,
...);
__attribute__
((
sentinel
))
extern
char
*
must_concat
(
size_t
*
len
,
const
char
*
first
,
...);
__attribute__
((
sentinel
))
extern
char
*
must_make_path
(
const
char
*
first
,
...);
__attribute__
((
sentinel
))
extern
char
*
must_make_path
(
const
char
*
first
,
...);
__attribute__
((
sentinel
))
extern
char
*
must_append_path
(
char
*
first
,
...);
__attribute__
((
sentinel
))
extern
char
*
must_append_path
(
char
*
first
,
...);
...
...
src/lxc/utils.h
View file @
fe70edee
...
@@ -199,13 +199,6 @@ extern int run_command(char *buf, size_t buf_size, int (*child_fn)(void *),
...
@@ -199,13 +199,6 @@ extern int run_command(char *buf, size_t buf_size, int (*child_fn)(void *),
extern
int
run_command_status
(
char
*
buf
,
size_t
buf_size
,
int
(
*
child_fn
)(
void
*
),
extern
int
run_command_status
(
char
*
buf
,
size_t
buf_size
,
int
(
*
child_fn
)(
void
*
),
void
*
args
);
void
*
args
);
/* Concatenate all passed-in strings into one path. Do not fail. If any piece
* is not prefixed with '/', add a '/'.
*/
__attribute__
((
sentinel
))
extern
char
*
must_concat
(
const
char
*
first
,
...);
__attribute__
((
sentinel
))
extern
char
*
must_make_path
(
const
char
*
first
,
...);
__attribute__
((
sentinel
))
extern
char
*
must_append_path
(
char
*
first
,
...);
/* return copy of string @entry; do not fail. */
/* return copy of string @entry; do not fail. */
extern
char
*
must_copy_string
(
const
char
*
entry
);
extern
char
*
must_copy_string
(
const
char
*
entry
);
...
...
src/tests/cgpath.c
View file @
fe70edee
...
@@ -46,11 +46,9 @@
...
@@ -46,11 +46,9 @@
/*
/*
* test_running_container: test cgroup functions against a running container
* test_running_container: test cgroup functions against a running container
*
*
* @group : name of the container group or NULL for default "lxc"
* @name : name of the container
* @name : name of the container
*/
*/
static
int
test_running_container
(
const
char
*
lxcpath
,
static
int
test_running_container
(
const
char
*
lxcpath
,
const
char
*
name
)
const
char
*
group
,
const
char
*
name
)
{
{
int
ret
=
-
1
;
int
ret
=
-
1
;
struct
lxc_container
*
c
=
NULL
;
struct
lxc_container
*
c
=
NULL
;
...
@@ -59,7 +57,7 @@ static int test_running_container(const char *lxcpath,
...
@@ -59,7 +57,7 @@ static int test_running_container(const char *lxcpath,
char
value
[
NAME_MAX
],
value_save
[
NAME_MAX
];
char
value
[
NAME_MAX
],
value_save
[
NAME_MAX
];
struct
cgroup_ops
*
cgroup_ops
;
struct
cgroup_ops
*
cgroup_ops
;
sprintf
(
relpath
,
"%s/%s"
,
group
?
group
:
"lxc.payload
"
,
name
);
sprintf
(
relpath
,
DEFAULT_PAYLOAD_CGROUP_PREFIX
"%s
"
,
name
);
if
((
c
=
lxc_container_new
(
name
,
lxcpath
))
==
NULL
)
{
if
((
c
=
lxc_container_new
(
name
,
lxcpath
))
==
NULL
)
{
TSTERR
(
"container %s couldn't instantiate"
,
name
);
TSTERR
(
"container %s couldn't instantiate"
,
name
);
...
@@ -128,8 +126,7 @@ err1:
...
@@ -128,8 +126,7 @@ err1:
return
ret
;
return
ret
;
}
}
static
int
test_container
(
const
char
*
lxcpath
,
static
int
test_container
(
const
char
*
lxcpath
,
const
char
*
name
,
const
char
*
group
,
const
char
*
name
,
const
char
*
template
)
const
char
*
template
)
{
{
int
ret
;
int
ret
;
...
@@ -165,7 +162,7 @@ static int test_container(const char *lxcpath,
...
@@ -165,7 +162,7 @@ static int test_container(const char *lxcpath,
goto
out3
;
goto
out3
;
}
}
ret
=
test_running_container
(
lxcpath
,
group
,
name
);
ret
=
test_running_container
(
lxcpath
,
name
);
c
->
stop
(
c
);
c
->
stop
(
c
);
out3:
out3:
...
@@ -195,17 +192,17 @@ int main()
...
@@ -195,17 +192,17 @@ int main()
* the container ourselves because valgrind gets confused by lxc's
* the container ourselves because valgrind gets confused by lxc's
* internal calls to clone.
* internal calls to clone.
*/
*/
if
(
test_running_container
(
NULL
,
NULL
,
"bb01"
)
<
0
)
if
(
test_running_container
(
NULL
,
"bb01"
)
<
0
)
goto
out
;
goto
out
;
printf
(
"Running container cgroup tests...Passed
\n
"
);
printf
(
"Running container cgroup tests...Passed
\n
"
);
#else
#else
if
(
test_container
(
NULL
,
NULL
,
MYNAME
,
"busybox"
)
<
0
)
if
(
test_container
(
NULL
,
MYNAME
,
"busybox"
)
<
0
)
goto
out
;
goto
out
;
printf
(
"Container creation tests...Passed
\n
"
);
printf
(
"Container creation tests...Passed
\n
"
);
if
(
test_container
(
"/var/lib/lxctest2"
,
NULL
,
MYNAME
,
"busybox"
)
<
0
)
if
(
test_container
(
"/var/lib/lxctest2"
,
MYNAME
,
"busybox"
)
<
0
)
goto
out
;
goto
out
;
printf
(
"Container creation with LXCPATH tests...Passed
\n
"
);
printf
(
"Container creation with LXCPATH tests...Passed
\n
"
);
...
...
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