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
a1786b03
Unverified
Commit
a1786b03
authored
Jan 20, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cgroups: reduce delta
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
35b5e050
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
30 deletions
+34
-30
cgfs.c
src/lxc/cgroups/cgfs.c
+9
-6
cgmanager.c
src/lxc/cgroups/cgmanager.c
+21
-21
cgroup.c
src/lxc/cgroups/cgroup.c
+3
-2
cgroup.h
src/lxc/cgroups/cgroup.h
+1
-1
No files found.
src/lxc/cgroups/cgfs.c
View file @
a1786b03
...
@@ -1804,7 +1804,9 @@ static char **subsystems_from_mount_options(const char *mount_options,
...
@@ -1804,7 +1804,9 @@ static char **subsystems_from_mount_options(const char *mount_options,
goto
out_free
;
goto
out_free
;
result
[
result_count
+
1
]
=
NULL
;
result
[
result_count
+
1
]
=
NULL
;
if
(
strncmp
(
token
,
"name="
,
5
)
&&
!
lxc_string_in_array
(
token
,
(
const
char
**
)
kernel_list
))
{
if
(
strncmp
(
token
,
"name="
,
5
)
&&
!
lxc_string_in_array
(
token
,
(
const
char
**
)
kernel_list
))
{
// this is eg 'systemd' but the mount will be 'name=systemd'
/* this is eg 'systemd' but the mount will be
* 'name=systemd'
*/
result
[
result_count
]
=
malloc
(
strlen
(
token
)
+
6
);
result
[
result_count
]
=
malloc
(
strlen
(
token
)
+
6
);
if
(
result
[
result_count
])
if
(
result
[
result_count
])
sprintf
(
result
[
result_count
],
"name=%s"
,
token
);
sprintf
(
result
[
result_count
],
"name=%s"
,
token
);
...
@@ -2072,9 +2074,10 @@ static bool cgroup_devices_has_allow_or_deny(struct cgfs_data *d,
...
@@ -2072,9 +2074,10 @@ static bool cgroup_devices_has_allow_or_deny(struct cgfs_data *d,
NULL
NULL
};
};
// XXX FIXME if users could use something other than 'lxc.devices.deny = a'.
/* XXX FIXME if users could use something other than 'lxc.devices.deny =
// not sure they ever do, but they *could*
* a'. not sure they ever do, but they *could* right now, I'm assuming
// right now, I'm assuming they do NOT
* they do NOT
*/
if
(
!
for_allow
&&
strcmp
(
v
,
"a"
)
!=
0
&&
strcmp
(
v
,
"a *:* rwm"
)
!=
0
)
if
(
!
for_allow
&&
strcmp
(
v
,
"a"
)
!=
0
&&
strcmp
(
v
,
"a *:* rwm"
)
!=
0
)
return
false
;
return
false
;
...
@@ -2344,7 +2347,7 @@ struct cgroup_ops *cgfs_ops_init(void)
...
@@ -2344,7 +2347,7 @@ struct cgroup_ops *cgfs_ops_init(void)
return
&
cgfs_ops
;
return
&
cgfs_ops
;
}
}
static
void
*
cgfs_init
(
const
char
*
name
)
static
void
*
cgfs_init
(
struct
lxc_handler
*
handler
)
{
{
struct
cgfs_data
*
d
;
struct
cgfs_data
*
d
;
...
@@ -2353,7 +2356,7 @@ static void *cgfs_init(const char *name)
...
@@ -2353,7 +2356,7 @@ static void *cgfs_init(const char *name)
return
NULL
;
return
NULL
;
memset
(
d
,
0
,
sizeof
(
*
d
));
memset
(
d
,
0
,
sizeof
(
*
d
));
d
->
name
=
strdup
(
name
);
d
->
name
=
strdup
(
handler
->
name
);
if
(
!
d
->
name
)
if
(
!
d
->
name
)
goto
err1
;
goto
err1
;
...
...
src/lxc/cgroups/cgmanager.c
View file @
a1786b03
...
@@ -141,7 +141,7 @@ static bool cgm_dbus_connect(void)
...
@@ -141,7 +141,7 @@ static bool cgm_dbus_connect(void)
cgm_lock
();
cgm_lock
();
if
(
!
dbus_threads_initialized
)
{
if
(
!
dbus_threads_initialized
)
{
/
/ tell dbus to do struct locking for thread safety
/
* tell dbus to do struct locking for thread safety */
dbus_threads_init_default
();
dbus_threads_init_default
();
dbus_threads_initialized
=
true
;
dbus_threads_initialized
=
true
;
}
}
...
@@ -171,7 +171,7 @@ static bool cgm_dbus_connect(void)
...
@@ -171,7 +171,7 @@ static bool cgm_dbus_connect(void)
return
false
;
return
false
;
}
}
/
/ get the api version
/
* get the api version */
if
(
cgmanager_get_api_version_sync
(
NULL
,
cgroup_manager
,
&
api_version
)
!=
0
)
{
if
(
cgmanager_get_api_version_sync
(
NULL
,
cgroup_manager
,
&
api_version
)
!=
0
)
{
NihError
*
nerr
;
NihError
*
nerr
;
nerr
=
nih_error_get
();
nerr
=
nih_error_get
();
...
@@ -545,7 +545,7 @@ static void cgm_remove_cgroup(const char *controller, const char *path)
...
@@ -545,7 +545,7 @@ static void cgm_remove_cgroup(const char *controller, const char *path)
INFO
(
"cgroup removal attempt: %s:%s did not exist"
,
controller
,
path
);
INFO
(
"cgroup removal attempt: %s:%s did not exist"
,
controller
,
path
);
}
}
static
void
*
cgm_init
(
const
char
*
name
)
static
void
*
cgm_init
(
struct
lxc_handler
*
handler
)
{
{
struct
cgm_data
*
d
;
struct
cgm_data
*
d
;
...
@@ -559,7 +559,7 @@ static void *cgm_init(const char *name)
...
@@ -559,7 +559,7 @@ static void *cgm_init(const char *name)
}
}
memset
(
d
,
0
,
sizeof
(
*
d
));
memset
(
d
,
0
,
sizeof
(
*
d
));
d
->
name
=
strdup
(
name
);
d
->
name
=
strdup
(
handler
->
name
);
if
(
!
d
->
name
)
{
if
(
!
d
->
name
)
{
cgm_dbus_disconnect
();
cgm_dbus_disconnect
();
goto
err1
;
goto
err1
;
...
@@ -567,7 +567,7 @@ static void *cgm_init(const char *name)
...
@@ -567,7 +567,7 @@ static void *cgm_init(const char *name)
d
->
cgroup_pattern
=
lxc_global_config_value
(
"lxc.cgroup.pattern"
);
d
->
cgroup_pattern
=
lxc_global_config_value
(
"lxc.cgroup.pattern"
);
/
/ cgm_create immediately gets called so keep the connection open
/
* cgm_create immediately gets called so keep the connection open */
return
d
;
return
d
;
err1:
err1:
...
@@ -625,10 +625,10 @@ static inline bool cgm_create(void *hdata)
...
@@ -625,10 +625,10 @@ static inline bool cgm_create(void *hdata)
if
(
!
d
)
if
(
!
d
)
return
false
;
return
false
;
// XXX we should send a hint to the cgmanager that when these
// cgroups become empty they should be deleted. Requires a cgmanager
// extension
/* XXX we should send a hint to the cgmanager that when these cgroups
* become empty they should be deleted. Requires a cgmanager extension.
*/
memset
(
result
,
0
,
MAXPATHLEN
);
memset
(
result
,
0
,
MAXPATHLEN
);
tmp
=
lxc_string_replace
(
"%n"
,
d
->
name
,
d
->
cgroup_pattern
);
tmp
=
lxc_string_replace
(
"%n"
,
d
->
name
,
d
->
cgroup_pattern
);
if
(
!
tmp
)
if
(
!
tmp
)
...
@@ -644,7 +644,7 @@ static inline bool cgm_create(void *hdata)
...
@@ -644,7 +644,7 @@ static inline bool cgm_create(void *hdata)
while
(
*
tmp
==
'/'
)
while
(
*
tmp
==
'/'
)
tmp
++
;
tmp
++
;
again:
again:
if
(
index
==
100
)
{
/
/ turn this into a warn later
if
(
index
==
100
)
{
/
* turn this into a warn later */
ERROR
(
"cgroup error? 100 cgroups with this name already running"
);
ERROR
(
"cgroup error? 100 cgroups with this name already running"
);
goto
bad
;
goto
bad
;
}
}
...
@@ -667,7 +667,7 @@ again:
...
@@ -667,7 +667,7 @@ again:
if
(
existed
==
1
)
if
(
existed
==
1
)
goto
next
;
goto
next
;
}
}
/
/ success
/
* success */
cgroup_path
=
strdup
(
tmp
);
cgroup_path
=
strdup
(
tmp
);
if
(
!
cgroup_path
)
{
if
(
!
cgroup_path
)
{
cleanup_cgroups
(
tmp
);
cleanup_cgroups
(
tmp
);
...
@@ -952,7 +952,7 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
...
@@ -952,7 +952,7 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
close
(
p
[
1
]);
close
(
p
[
1
]);
return
-
1
;
return
-
1
;
}
}
if
(
!
pid
)
/
/ do_cgm_get exits
if
(
!
pid
)
/
* do_cgm_get exits */
do_cgm_get
(
name
,
lxcpath
,
filename
,
p
[
1
],
len
&&
value
);
do_cgm_get
(
name
,
lxcpath
,
filename
,
p
[
1
],
len
&&
value
);
close
(
p
[
1
]);
close
(
p
[
1
]);
ret
=
read
(
p
[
0
],
&
newlen
,
sizeof
(
newlen
));
ret
=
read
(
p
[
0
],
&
newlen
,
sizeof
(
newlen
));
...
@@ -967,12 +967,12 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
...
@@ -967,12 +967,12 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
goto
out
;
goto
out
;
}
}
memset
(
value
,
0
,
len
);
memset
(
value
,
0
,
len
);
if
(
newlen
<
0
)
{
/
/ child is reporting an error
if
(
newlen
<
0
)
{
/
* child is reporting an error */
close
(
p
[
0
]);
close
(
p
[
0
]);
ret
=
-
1
;
ret
=
-
1
;
goto
out
;
goto
out
;
}
}
if
(
newlen
==
0
)
{
/
/ empty read
if
(
newlen
==
0
)
{
/
* empty read */
close
(
p
[
0
]);
close
(
p
[
0
]);
ret
=
0
;
ret
=
0
;
goto
out
;
goto
out
;
...
@@ -988,7 +988,7 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
...
@@ -988,7 +988,7 @@ static int cgm_get(const char *filename, char *value, size_t len, const char *na
value
[
len
-
1
]
=
'\0'
;
value
[
len
-
1
]
=
'\0'
;
newlen
=
len
-
1
;
newlen
=
len
-
1
;
}
else
if
(
newlen
+
1
<
len
)
{
}
else
if
(
newlen
+
1
<
len
)
{
/
/ cgmanager doesn't add eol to last entry
/
* cgmanager doesn't add eol to last entry */
value
[
newlen
++
]
=
'\n'
;
value
[
newlen
++
]
=
'\n'
;
value
[
newlen
]
=
'\0'
;
value
[
newlen
]
=
'\0'
;
}
}
...
@@ -1002,7 +1002,7 @@ out:
...
@@ -1002,7 +1002,7 @@ out:
static
void
do_cgm_set
(
const
char
*
name
,
const
char
*
lxcpath
,
const
char
*
filename
,
const
char
*
value
,
int
outp
)
static
void
do_cgm_set
(
const
char
*
name
,
const
char
*
lxcpath
,
const
char
*
filename
,
const
char
*
value
,
int
outp
)
{
{
char
*
controller
,
*
key
,
*
cgroup
=
NULL
;
char
*
controller
,
*
key
,
*
cgroup
=
NULL
;
int
retval
=
0
;
/
/ value we are sending to the parent over outp
int
retval
=
0
;
/
* value we are sending to the parent over outp */
int
ret
;
int
ret
;
char
*
cglast
;
char
*
cglast
;
...
@@ -1088,7 +1088,7 @@ static int cgm_set(const char *filename, const char *value, const char *name, co
...
@@ -1088,7 +1088,7 @@ static int cgm_set(const char *filename, const char *value, const char *name, co
close
(
p
[
0
]);
close
(
p
[
0
]);
return
-
1
;
return
-
1
;
}
}
if
(
!
pid
)
/
/ do_cgm_set exits
if
(
!
pid
)
/
* do_cgm_set exits */
do_cgm_set
(
name
,
lxcpath
,
filename
,
value
,
p
[
1
]);
do_cgm_set
(
name
,
lxcpath
,
filename
,
value
,
p
[
1
]);
close
(
p
[
1
]);
close
(
p
[
1
]);
ret
=
read
(
p
[
0
],
&
v
,
sizeof
(
v
));
ret
=
read
(
p
[
0
],
&
v
,
sizeof
(
v
));
...
@@ -1333,7 +1333,7 @@ static bool collect_subsystems(void)
...
@@ -1333,7 +1333,7 @@ static bool collect_subsystems(void)
size_t
sz
=
0
;
size_t
sz
=
0
;
FILE
*
f
=
NULL
;
FILE
*
f
=
NULL
;
if
(
subsystems
)
/
/ already initialized
if
(
subsystems
)
/
* already initialized */
return
true
;
return
true
;
subsystems_inone
=
malloc
(
2
*
sizeof
(
char
*
));
subsystems_inone
=
malloc
(
2
*
sizeof
(
char
*
));
...
@@ -1444,7 +1444,7 @@ struct cgroup_ops *cgm_ops_init(void)
...
@@ -1444,7 +1444,7 @@ struct cgroup_ops *cgm_ops_init(void)
if
(
api_version
<
CGM_SUPPORTS_MULT_CONTROLLERS
)
if
(
api_version
<
CGM_SUPPORTS_MULT_CONTROLLERS
)
cgm_all_controllers_same
=
false
;
cgm_all_controllers_same
=
false
;
/
/ if root, try to escape to root cgroup
/
* if root, try to escape to root cgroup */
if
(
geteuid
()
==
0
&&
!
cgm_escape
(
NULL
))
{
if
(
geteuid
()
==
0
&&
!
cgm_escape
(
NULL
))
{
free_subsystems
();
free_subsystems
();
return
NULL
;
return
NULL
;
...
@@ -1507,7 +1507,7 @@ static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool
...
@@ -1507,7 +1507,7 @@ static bool cgm_setup_limits(void *hdata, struct lxc_list *cgroup_settings, bool
cg
=
iterator
->
elem
;
cg
=
iterator
->
elem
;
if
(
do_devices
!=
!
strncmp
(
"devices"
,
cg
->
subsystem
,
7
))
if
(
do_devices
!=
!
strncmp
(
"devices"
,
cg
->
subsystem
,
7
))
continue
;
continue
;
if
(
strlen
(
cg
->
subsystem
)
>
100
)
/
/ i smell a rat
if
(
strlen
(
cg
->
subsystem
)
>
100
)
/
* i smell a rat */
goto
out
;
goto
out
;
strcpy
(
controller
,
cg
->
subsystem
);
strcpy
(
controller
,
cg
->
subsystem
);
p
=
strchr
(
controller
,
'.'
);
p
=
strchr
(
controller
,
'.'
);
...
@@ -1564,7 +1564,7 @@ static bool cgm_chown(void *hdata, struct lxc_conf *conf)
...
@@ -1564,7 +1564,7 @@ static bool cgm_chown(void *hdata, struct lxc_conf *conf)
}
}
/*
/*
* TODO: this should be re-written to use the get_config_item("lxc.id
_
map")
* TODO: this should be re-written to use the get_config_item("lxc.idmap")
* cmd api instead of getting the idmap from c->lxc_conf. The reason is
* cmd api instead of getting the idmap from c->lxc_conf. The reason is
* that the id_maps may be different if the container was started with a
* that the id_maps may be different if the container was started with a
* -f or -s argument.
* -f or -s argument.
...
@@ -1653,7 +1653,7 @@ static bool cgm_mount_cgroup(void *hdata, const char *root, int type)
...
@@ -1653,7 +1653,7 @@ static bool cgm_mount_cgroup(void *hdata, const char *root, int type)
return
cgm_bind_dir
(
root
,
CGMANAGER_LOWER_SOCK
);
return
cgm_bind_dir
(
root
,
CGMANAGER_LOWER_SOCK
);
if
(
dir_exists
(
CGMANAGER_UPPER_SOCK
))
if
(
dir_exists
(
CGMANAGER_UPPER_SOCK
))
return
cgm_bind_dir
(
root
,
CGMANAGER_UPPER_SOCK
);
return
cgm_bind_dir
(
root
,
CGMANAGER_UPPER_SOCK
);
/
/ Host doesn't have cgmanager running? Then how did we get here?
/
* Host doesn't have cgmanager running? Then how did we get here? */
return
false
;
return
false
;
}
}
...
...
src/lxc/cgroups/cgroup.c
View file @
a1786b03
...
@@ -65,7 +65,7 @@ bool cgroup_init(struct lxc_handler *handler)
...
@@ -65,7 +65,7 @@ bool cgroup_init(struct lxc_handler *handler)
if
(
ops
)
{
if
(
ops
)
{
INFO
(
"cgroup driver %s initing for %s"
,
ops
->
name
,
handler
->
name
);
INFO
(
"cgroup driver %s initing for %s"
,
ops
->
name
,
handler
->
name
);
handler
->
cgroup_data
=
ops
->
init
(
handler
->
name
);
handler
->
cgroup_data
=
ops
->
init
(
handler
);
}
}
return
handler
->
cgroup_data
!=
NULL
;
return
handler
->
cgroup_data
!=
NULL
;
...
@@ -209,7 +209,8 @@ int lxc_cgroup_get(const char *filename, char *value, size_t len,
...
@@ -209,7 +209,8 @@ int lxc_cgroup_get(const char *filename, char *value, size_t len,
return
-
1
;
return
-
1
;
}
}
void
cgroup_disconnect
(
void
)
{
void
cgroup_disconnect
(
void
)
{
if
(
ops
&&
ops
->
disconnect
)
if
(
ops
&&
ops
->
disconnect
)
ops
->
disconnect
();
ops
->
disconnect
();
}
}
...
...
src/lxc/cgroups/cgroup.h
View file @
a1786b03
...
@@ -41,7 +41,7 @@ typedef enum {
...
@@ -41,7 +41,7 @@ typedef enum {
struct
cgroup_ops
{
struct
cgroup_ops
{
const
char
*
name
;
const
char
*
name
;
void
*
(
*
init
)(
const
char
*
name
);
void
*
(
*
init
)(
struct
lxc_handler
*
handler
);
void
(
*
destroy
)(
void
*
hdata
,
struct
lxc_conf
*
conf
);
void
(
*
destroy
)(
void
*
hdata
,
struct
lxc_conf
*
conf
);
bool
(
*
create
)(
void
*
hdata
);
bool
(
*
create
)(
void
*
hdata
);
bool
(
*
enter
)(
void
*
hdata
,
pid_t
pid
);
bool
(
*
enter
)(
void
*
hdata
,
pid_t
pid
);
...
...
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