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
0d190408
Unverified
Commit
0d190408
authored
May 02, 2018
by
Liza Tretyakova
Committed by
Christian Brauner
Jul 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf, confile: add parsing of a shmounts config parameter
Signed-off-by:
Liza Tretyakova
<
elizabet.tretyakova@gmail.com
>
parent
adf0ba1f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
+55
-0
conf.c
src/lxc/conf.c
+33
-0
confile.c
src/lxc/confile.c
+20
-0
confile.h
src/lxc/confile.h
+2
-0
No files found.
src/lxc/conf.c
View file @
0d190408
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include "config.h"
#include "config.h"
#include "confile.h"
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <dirent.h>
#include <dirent.h>
...
@@ -647,6 +648,30 @@ unsigned long add_required_remount_flags(const char *s, const char *d,
...
@@ -647,6 +648,30 @@ unsigned long add_required_remount_flags(const char *s, const char *d,
#endif
#endif
}
}
static
int
add_shmount_to_list
(
struct
lxc_conf
*
conf
)
{
char
new_mount
[
MAXPATHLEN
];
size_t
len_mount
;
/* Offset for the leading '/' since the path_cont
* is absolute inside the container */
int
ret
=
-
1
,
offset
=
1
;
/* +1 for the separating whitespace */
len_mount
=
strlen
(
conf
->
lxc_shmount
.
path_host
)
+
1
+
strlen
(
conf
->
lxc_shmount
.
path_cont
)
-
offset
+
sizeof
(
" none bind,create=dir 0 0"
)
-
1
;
ret
=
snprintf
(
new_mount
,
len_mount
+
1
,
"%s %s none bind,create=dir 0 0"
,
conf
->
lxc_shmount
.
path_host
,
conf
->
lxc_shmount
.
path_cont
+
offset
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len_mount
+
1
)
return
-
1
;
ret
=
add_elem_to_mount_list
(
new_mount
,
conf
);
if
(
ret
<
0
)
ERROR
(
"Failed to add new mount
\"
%s
\"
to the config"
,
new_mount
);
return
ret
;
}
static
int
lxc_mount_auto_mounts
(
struct
lxc_conf
*
conf
,
int
flags
,
struct
lxc_handler
*
handler
)
static
int
lxc_mount_auto_mounts
(
struct
lxc_conf
*
conf
,
int
flags
,
struct
lxc_handler
*
handler
)
{
{
int
i
,
r
;
int
i
,
r
;
...
@@ -783,6 +808,14 @@ static int lxc_mount_auto_mounts(struct lxc_conf *conf, int flags, struct lxc_ha
...
@@ -783,6 +808,14 @@ static int lxc_mount_auto_mounts(struct lxc_conf *conf, int flags, struct lxc_ha
}
}
}
}
if
(
flags
&
LXC_AUTO_SHMOUNTS_MASK
)
{
int
ret
=
add_shmount_to_list
(
conf
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to add shmount entry to container config"
);
return
ret
;
}
}
return
0
;
return
0
;
}
}
...
...
src/lxc/confile.c
View file @
0d190408
...
@@ -1677,6 +1677,8 @@ static int set_config_mount_auto(const char *key, const char *value,
...
@@ -1677,6 +1677,8 @@ static int set_config_mount_auto(const char *key, const char *value,
return
-
1
;
return
-
1
;
for
(
autoptr
=
autos
;;
autoptr
=
NULL
)
{
for
(
autoptr
=
autos
;;
autoptr
=
NULL
)
{
bool
is_shmounts
=
false
;
token
=
strtok_r
(
autoptr
,
"
\t
"
,
&
sptr
);
token
=
strtok_r
(
autoptr
,
"
\t
"
,
&
sptr
);
if
(
!
token
)
{
if
(
!
token
)
{
ret
=
0
;
ret
=
0
;
...
@@ -1686,6 +1688,12 @@ static int set_config_mount_auto(const char *key, const char *value,
...
@@ -1686,6 +1688,12 @@ static int set_config_mount_auto(const char *key, const char *value,
for
(
i
=
0
;
allowed_auto_mounts
[
i
].
token
;
i
++
)
{
for
(
i
=
0
;
allowed_auto_mounts
[
i
].
token
;
i
++
)
{
if
(
!
strcmp
(
allowed_auto_mounts
[
i
].
token
,
token
))
if
(
!
strcmp
(
allowed_auto_mounts
[
i
].
token
,
token
))
break
;
break
;
if
(
strcmp
(
"shmounts:"
,
allowed_auto_mounts
[
i
].
token
)
==
0
&&
strncmp
(
"shmounts:"
,
token
,
sizeof
(
"shmounts:"
)
-
1
)
==
0
)
{
is_shmounts
=
true
;
break
;
}
}
}
if
(
!
allowed_auto_mounts
[
i
].
token
)
{
if
(
!
allowed_auto_mounts
[
i
].
token
)
{
...
@@ -1695,6 +1703,14 @@ static int set_config_mount_auto(const char *key, const char *value,
...
@@ -1695,6 +1703,14 @@ static int set_config_mount_auto(const char *key, const char *value,
lxc_conf
->
auto_mounts
&=
~
allowed_auto_mounts
[
i
].
mask
;
lxc_conf
->
auto_mounts
&=
~
allowed_auto_mounts
[
i
].
mask
;
lxc_conf
->
auto_mounts
|=
allowed_auto_mounts
[
i
].
flag
;
lxc_conf
->
auto_mounts
|=
allowed_auto_mounts
[
i
].
flag
;
if
(
is_shmounts
)
{
lxc_conf
->
lxc_shmount
.
path_host
=
strdup
(
token
+
(
sizeof
(
"shmounts:"
)
-
1
));
if
(
strcmp
(
lxc_conf
->
lxc_shmount
.
path_host
,
""
)
==
0
)
{
ERROR
(
"Invalid shmounts path: empty"
);
break
;
}
lxc_conf
->
lxc_shmount
.
path_cont
=
strdup
(
"/dev/.lxc-mounts"
);
}
}
}
free
(
autos
);
free
(
autos
);
...
@@ -1726,6 +1742,10 @@ static int set_config_mount(const char *key, const char *value,
...
@@ -1726,6 +1742,10 @@ static int set_config_mount(const char *key, const char *value,
return
0
;
return
0
;
}
}
int
add_elem_to_mount_list
(
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
)
{
return
set_config_mount
(
NULL
,
value
,
lxc_conf
,
NULL
);
}
static
int
set_config_cap_keep
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_cap_keep
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
...
...
src/lxc/confile.h
View file @
0d190408
...
@@ -121,4 +121,6 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
...
@@ -121,4 +121,6 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
extern
bool
network_new_hwaddrs
(
struct
lxc_conf
*
conf
);
extern
bool
network_new_hwaddrs
(
struct
lxc_conf
*
conf
);
extern
int
add_elem_to_mount_list
(
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
);
#endif
/* __LXC_CONFILE_H */
#endif
/* __LXC_CONFILE_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