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
5b9912ab
Unverified
Commit
5b9912ab
authored
Feb 12, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'tanyifeng-support_mount_propagation' into lxc/master
parents
b251b0fe
d840039e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
6 deletions
+80
-6
lxc.container.conf.sgml.in
doc/lxc.container.conf.sgml.in
+3
-2
conf.c
src/lxc/conf.c
+77
-4
No files found.
doc/lxc.container.conf.sgml.in
View file @
5b9912ab
...
@@ -1059,10 +1059,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
...
@@ -1059,10 +1059,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</term>
</term>
<listitem>
<listitem>
<para>
<para>
s
pecify a mount point corresponding to a line in the
S
pecify a mount point corresponding to a line in the
fstab format.
fstab format.
Moreover lxc add two options to mount.
Moreover lxc supports mount propagation, such as rslave or
rprivate, and adds three additional mount options.
<option>optional</option> don't fail if mount does not work.
<option>optional</option> don't fail if mount does not work.
<option>create=dir</option> or <option>create=file</option>
<option>create=dir</option> or <option>create=file</option>
to create dir (or file) when the point will be mounted.
to create dir (or file) when the point will be mounted.
...
...
src/lxc/conf.c
View file @
5b9912ab
...
@@ -193,6 +193,18 @@ static struct mount_opt mount_opt[] = {
...
@@ -193,6 +193,18 @@ static struct mount_opt mount_opt[] = {
{
NULL
,
0
,
0
},
{
NULL
,
0
,
0
},
};
};
static
struct
mount_opt
propagation_opt
[]
=
{
{
"private"
,
0
,
MS_PRIVATE
},
{
"shared"
,
0
,
MS_SHARED
},
{
"slave"
,
0
,
MS_SLAVE
},
{
"unbindable"
,
0
,
MS_UNBINDABLE
},
{
"rprivate"
,
0
,
MS_PRIVATE
|
MS_REC
},
{
"rshared"
,
0
,
MS_SHARED
|
MS_REC
},
{
"rslave"
,
0
,
MS_SLAVE
|
MS_REC
},
{
"runbindable"
,
0
,
MS_UNBINDABLE
|
MS_REC
},
{
NULL
,
0
,
0
},
};
#if HAVE_LIBCAP
#if HAVE_LIBCAP
static
struct
caps_opt
caps_opt
[]
=
{
static
struct
caps_opt
caps_opt
[]
=
{
{
"chown"
,
CAP_CHOWN
},
{
"chown"
,
CAP_CHOWN
},
...
@@ -1773,6 +1785,46 @@ int parse_mntopts(const char *mntopts, unsigned long *mntflags,
...
@@ -1773,6 +1785,46 @@ int parse_mntopts(const char *mntopts, unsigned long *mntflags,
return
0
;
return
0
;
}
}
static
void
parse_propagationopt
(
char
*
opt
,
unsigned
long
*
flags
)
{
struct
mount_opt
*
mo
;
/* If opt is found in propagation_opt, set or clear flags. */
for
(
mo
=
&
propagation_opt
[
0
];
mo
->
name
!=
NULL
;
mo
++
)
{
if
(
strncmp
(
opt
,
mo
->
name
,
strlen
(
mo
->
name
))
==
0
)
{
if
(
mo
->
clear
)
*
flags
&=
~
mo
->
flag
;
else
*
flags
|=
mo
->
flag
;
return
;
}
}
}
static
int
parse_propagationopts
(
const
char
*
mntopts
,
unsigned
long
*
pflags
)
{
char
*
s
;
char
*
p
,
*
saveptr
=
NULL
;
*
pflags
=
0L
;
if
(
!
mntopts
)
return
0
;
s
=
strdup
(
mntopts
);
if
(
!
s
)
{
SYSERROR
(
"Failed to allocate memory"
);
return
-
ENOMEM
;
}
for
(
p
=
strtok_r
(
s
,
","
,
&
saveptr
);
p
!=
NULL
;
p
=
strtok_r
(
NULL
,
","
,
&
saveptr
))
parse_propagationopt
(
p
,
pflags
);
free
(
s
);
return
0
;
}
static
void
null_endofword
(
char
*
word
)
static
void
null_endofword
(
char
*
word
)
{
{
while
(
*
word
&&
*
word
!=
' '
&&
*
word
!=
'\t'
)
while
(
*
word
&&
*
word
!=
' '
&&
*
word
!=
'\t'
)
...
@@ -1800,8 +1852,8 @@ static char *get_field(char *src, int nfields)
...
@@ -1800,8 +1852,8 @@ static char *get_field(char *src, int nfields)
static
int
mount_entry
(
const
char
*
fsname
,
const
char
*
target
,
static
int
mount_entry
(
const
char
*
fsname
,
const
char
*
target
,
const
char
*
fstype
,
unsigned
long
mountflags
,
const
char
*
fstype
,
unsigned
long
mountflags
,
const
char
*
data
,
bool
optional
,
bool
dev
,
unsigned
long
pflags
,
const
char
*
data
,
bool
optional
,
bool
relative
,
const
char
*
rootfs
)
bool
dev
,
bool
relative
,
const
char
*
rootfs
)
{
{
int
ret
;
int
ret
;
char
srcbuf
[
MAXPATHLEN
];
char
srcbuf
[
MAXPATHLEN
];
...
@@ -1893,6 +1945,23 @@ static int mount_entry(const char *fsname, const char *target,
...
@@ -1893,6 +1945,23 @@ static int mount_entry(const char *fsname, const char *target,
}
}
}
}
if
(
pflags
)
{
ret
=
mount
(
NULL
,
target
,
NULL
,
pflags
,
NULL
);
if
(
ret
<
0
)
{
if
(
optional
)
{
INFO
(
"%s - Failed to change mount propagation "
"for
\"
%s
\"
(optional)"
,
strerror
(
errno
),
target
);
return
0
;
}
else
{
SYSERROR
(
"Failed to change mount propagation "
"for
\"
%s
\"
(optional)"
,
target
);
return
-
1
;
}
}
DEBUG
(
"Changed mount propagation for
\"
%s
\"
"
,
target
);
}
#ifdef HAVE_STATVFS
#ifdef HAVE_STATVFS
skipremount:
skipremount:
#endif
#endif
...
@@ -1984,7 +2053,7 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
...
@@ -1984,7 +2053,7 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
const
char
*
lxc_path
)
const
char
*
lxc_path
)
{
{
int
ret
;
int
ret
;
unsigned
long
mntflags
;
unsigned
long
mntflags
,
pflags
;
char
*
mntdata
;
char
*
mntdata
;
bool
dev
,
optional
,
relative
;
bool
dev
,
optional
,
relative
;
char
*
rootfs_path
=
NULL
;
char
*
rootfs_path
=
NULL
;
...
@@ -2006,12 +2075,16 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
...
@@ -2006,12 +2075,16 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
}
}
cull_mntent_opt
(
mntent
);
cull_mntent_opt
(
mntent
);
ret
=
parse_propagationopts
(
mntent
->
mnt_opts
,
&
pflags
);
if
(
ret
<
0
)
return
-
1
;
ret
=
parse_mntopts
(
mntent
->
mnt_opts
,
&
mntflags
,
&
mntdata
);
ret
=
parse_mntopts
(
mntent
->
mnt_opts
,
&
mntflags
,
&
mntdata
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
-
1
;
return
-
1
;
ret
=
mount_entry
(
mntent
->
mnt_fsname
,
path
,
mntent
->
mnt_type
,
mntflags
,
ret
=
mount_entry
(
mntent
->
mnt_fsname
,
path
,
mntent
->
mnt_type
,
mntflags
,
mntdata
,
optional
,
dev
,
relative
,
rootfs_path
);
pflags
,
mntdata
,
optional
,
dev
,
relative
,
rootfs_path
);
free
(
mntdata
);
free
(
mntdata
);
return
ret
;
return
ret
;
...
...
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