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
e855f214
Commit
e855f214
authored
Feb 03, 2016
by
Serge Hallyn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #799 from brauner/2016-02-03/aufs_mkdir_to_lxcaufs
move and rename mount_entry_create_aufs_dirs()
parents
cefbc615
1d52bdf7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
65 deletions
+122
-65
lxcaufs.c
src/lxc/bdev/lxcaufs.c
+99
-0
lxcaufs.h
src/lxc/bdev/lxcaufs.h
+18
-0
conf.c
src/lxc/conf.c
+5
-65
No files found.
src/lxc/bdev/lxcaufs.c
View file @
e855f214
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include "bdev.h"
#include "bdev.h"
#include "log.h"
#include "log.h"
#include "lxcaufs.h"
#include "lxcrsync.h"
#include "lxcrsync.h"
#include "utils.h"
#include "utils.h"
...
@@ -312,3 +313,101 @@ int aufs_umount(struct bdev *bdev)
...
@@ -312,3 +313,101 @@ int aufs_umount(struct bdev *bdev)
return
-
22
;
return
-
22
;
return
umount
(
bdev
->
dest
);
return
umount
(
bdev
->
dest
);
}
}
char
*
aufs_get_rootfs
(
const
char
*
rootfs_path
,
size_t
*
rootfslen
)
{
char
*
rootfsdir
=
NULL
;
char
*
s1
=
NULL
;
char
*
s2
=
NULL
;
char
*
s3
=
NULL
;
if
(
!
rootfs_path
||
!
rootfslen
)
return
NULL
;
s1
=
strdup
(
rootfs_path
);
if
(
!
s1
)
return
NULL
;
if
((
s2
=
strstr
(
s1
,
":/"
)))
{
s2
=
s2
+
1
;
if
((
s3
=
strstr
(
s2
,
":/"
)))
*
s3
=
'\0'
;
rootfsdir
=
strdup
(
s2
);
if
(
!
rootfsdir
)
{
free
(
s1
);
return
NULL
;
}
}
if
(
!
rootfsdir
)
rootfsdir
=
s1
;
else
free
(
s1
);
*
rootfslen
=
strlen
(
rootfsdir
);
return
rootfsdir
;
}
int
aufs_mkdir
(
const
struct
mntent
*
mntent
,
const
struct
lxc_rootfs
*
rootfs
,
const
char
*
lxc_name
,
const
char
*
lxc_path
)
{
char
lxcpath
[
MAXPATHLEN
];
char
*
rootfsdir
=
NULL
;
char
*
scratch
=
NULL
;
char
*
tmp
=
NULL
;
char
*
upperdir
=
NULL
;
char
**
opts
=
NULL
;
int
fret
=
-
1
;
int
ret
=
0
;
size_t
arrlen
=
0
;
size_t
i
;
size_t
len
=
0
;
size_t
rootfslen
=
0
;
/* Since we use all of these to check whether the user has given us a
* sane absolute path to create the directories needed for overlay
* lxc.mount.entry entries we consider any of these missing fatal. */
if
(
!
rootfs
||
!
rootfs
->
path
||
!
lxc_name
||
!
lxc_path
)
goto
err
;
opts
=
lxc_string_split
(
mntent
->
mnt_opts
,
','
);
if
(
opts
)
arrlen
=
lxc_array_len
((
void
**
)
opts
);
else
goto
err
;
for
(
i
=
0
;
i
<
arrlen
;
i
++
)
{
if
(
strstr
(
opts
[
i
],
"br="
)
&&
(
strlen
(
opts
[
i
])
>
(
len
=
strlen
(
"br="
))))
tmp
=
opts
[
i
]
+
len
;
}
if
(
!
tmp
)
goto
err
;
upperdir
=
strtok_r
(
tmp
,
":="
,
&
scratch
);
if
(
!
upperdir
)
goto
err
;
ret
=
snprintf
(
lxcpath
,
MAXPATHLEN
,
"%s/%s"
,
lxc_path
,
lxc_name
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
goto
err
;
rootfsdir
=
aufs_get_rootfs
(
rootfs
->
path
,
&
rootfslen
);
if
(
!
rootfsdir
)
goto
err
;
/* We neither allow users to create upperdirs outside the containerdir
* nor inside the rootfs. The latter might be debatable. */
if
((
strncmp
(
upperdir
,
lxcpath
,
strlen
(
lxcpath
))
==
0
)
&&
(
strncmp
(
upperdir
,
rootfsdir
,
rootfslen
)
!=
0
))
if
(
mkdir_p
(
upperdir
,
0755
)
<
0
)
{
WARN
(
"Failed to create upperdir"
);
}
fret
=
0
;
err:
free
(
rootfsdir
);
lxc_free_array
((
void
**
)
opts
,
free
);
return
fret
;
}
src/lxc/bdev/lxcaufs.h
View file @
e855f214
...
@@ -27,6 +27,12 @@
...
@@ -27,6 +27,12 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdint.h>
#include <stdint.h>
#if IS_BIONIC
#include <../include/lxcmntent.h>
#else
#include <mntent.h>
#endif
/* defined in bdev.h */
/* defined in bdev.h */
struct
bdev
;
struct
bdev
;
...
@@ -49,4 +55,16 @@ int aufs_detect(const char *path);
...
@@ -49,4 +55,16 @@ int aufs_detect(const char *path);
int
aufs_mount
(
struct
bdev
*
bdev
);
int
aufs_mount
(
struct
bdev
*
bdev
);
int
aufs_umount
(
struct
bdev
*
bdev
);
int
aufs_umount
(
struct
bdev
*
bdev
);
/*
* Get rootfs path for aufs backed containers. Allocated memory must be freed
* by caller.
*/
char
*
aufs_get_rootfs
(
const
char
*
rootfs_path
,
size_t
*
rootfslen
);
/*
* Create directories for aufs mounts.
*/
int
aufs_mkdir
(
const
struct
mntent
*
mntent
,
const
struct
lxc_rootfs
*
rootfs
,
const
char
*
lxc_name
,
const
char
*
lxc_path
);
#endif
/* __LXC_AUFS_H */
#endif
/* __LXC_AUFS_H */
src/lxc/conf.c
View file @
e855f214
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
* License along with this library; if not, write to the Free Software
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#define _GNU_SOURCE
#include "config.h"
#include "config.h"
#include <stdio.h>
#include <stdio.h>
...
@@ -36,6 +38,7 @@
...
@@ -36,6 +38,7 @@
#include <pwd.h>
#include <pwd.h>
#include <grp.h>
#include <grp.h>
#include <time.h>
#include <time.h>
#ifdef HAVE_STATVFS
#ifdef HAVE_STATVFS
#include <sys/statvfs.h>
#include <sys/statvfs.h>
#endif
#endif
...
@@ -72,6 +75,7 @@
...
@@ -72,6 +75,7 @@
#include "log.h"
#include "log.h"
#include "caps.h"
/* for lxc_caps_last_cap() */
#include "caps.h"
/* for lxc_caps_last_cap() */
#include "bdev/bdev.h"
#include "bdev/bdev.h"
#include "bdev/lxcaufs.h"
#include "bdev/lxcoverlay.h"
#include "bdev/lxcoverlay.h"
#include "cgroup.h"
#include "cgroup.h"
#include "lxclock.h"
#include "lxclock.h"
...
@@ -1726,70 +1730,6 @@ static void cull_mntent_opt(struct mntent *mntent)
...
@@ -1726,70 +1730,6 @@ static void cull_mntent_opt(struct mntent *mntent)
}
}
}
}
static
int
mount_entry_create_aufs_dirs
(
const
struct
mntent
*
mntent
,
const
struct
lxc_rootfs
*
rootfs
,
const
char
*
lxc_name
,
const
char
*
lxc_path
)
{
char
lxcpath
[
MAXPATHLEN
];
char
*
rootfsdir
=
NULL
;
char
*
scratch
=
NULL
;
char
*
tmp
=
NULL
;
char
*
upperdir
=
NULL
;
char
**
opts
=
NULL
;
int
fret
=
-
1
;
int
ret
=
0
;
size_t
arrlen
=
0
;
size_t
i
;
size_t
len
=
0
;
size_t
rootfslen
=
0
;
/* Since we use all of these to check whether the user has given us a
* sane absolute path to create the directories needed for overlay
* lxc.mount.entry entries we consider any of these missing fatal. */
if
(
!
rootfs
||
!
rootfs
->
path
||
!
lxc_name
||
!
lxc_path
)
goto
err
;
opts
=
lxc_string_split
(
mntent
->
mnt_opts
,
','
);
if
(
opts
)
arrlen
=
lxc_array_len
((
void
**
)
opts
);
else
goto
err
;
for
(
i
=
0
;
i
<
arrlen
;
i
++
)
{
if
(
strstr
(
opts
[
i
],
"br="
)
&&
(
strlen
(
opts
[
i
])
>
(
len
=
strlen
(
"br="
))))
tmp
=
opts
[
i
]
+
len
;
}
if
(
!
tmp
)
goto
err
;
upperdir
=
strtok_r
(
tmp
,
":="
,
&
scratch
);
if
(
!
upperdir
)
goto
err
;
ret
=
snprintf
(
lxcpath
,
MAXPATHLEN
,
"%s/%s"
,
lxc_path
,
lxc_name
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
goto
err
;
rootfsdir
=
ovl_get_rootfs
(
rootfs
->
path
,
&
rootfslen
);
if
(
!
rootfsdir
)
goto
err
;
/* We neither allow users to create upperdirs outside the containerdir
* nor inside the rootfs. The latter might be debatable. */
if
((
strncmp
(
upperdir
,
lxcpath
,
strlen
(
lxcpath
))
==
0
)
&&
(
strncmp
(
upperdir
,
rootfsdir
,
rootfslen
)
!=
0
))
if
(
mkdir_p
(
upperdir
,
0755
)
<
0
)
{
WARN
(
"Failed to create upperdir"
);
}
fret
=
0
;
err:
free
(
rootfsdir
);
lxc_free_array
((
void
**
)
opts
,
free
);
return
fret
;
}
static
int
mount_entry_create_dir_file
(
const
struct
mntent
*
mntent
,
static
int
mount_entry_create_dir_file
(
const
struct
mntent
*
mntent
,
const
char
*
path
,
const
struct
lxc_rootfs
*
rootfs
,
const
char
*
path
,
const
struct
lxc_rootfs
*
rootfs
,
const
char
*
lxc_name
,
const
char
*
lxc_path
)
const
char
*
lxc_name
,
const
char
*
lxc_path
)
...
@@ -1802,7 +1742,7 @@ static int mount_entry_create_dir_file(const struct mntent *mntent,
...
@@ -1802,7 +1742,7 @@ static int mount_entry_create_dir_file(const struct mntent *mntent,
if
(
ovl_mkdir
(
mntent
,
rootfs
,
lxc_name
,
lxc_path
)
<
0
)
if
(
ovl_mkdir
(
mntent
,
rootfs
,
lxc_name
,
lxc_path
)
<
0
)
return
-
1
;
return
-
1
;
}
else
if
(
strncmp
(
mntent
->
mnt_type
,
"aufs"
,
4
)
==
0
)
{
}
else
if
(
strncmp
(
mntent
->
mnt_type
,
"aufs"
,
4
)
==
0
)
{
if
(
mount_entry_create_aufs_dirs
(
mntent
,
rootfs
,
lxc_name
,
lxc_path
)
<
0
)
if
(
aufs_mkdir
(
mntent
,
rootfs
,
lxc_name
,
lxc_path
)
<
0
)
return
-
1
;
return
-
1
;
}
}
...
...
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