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
69dd1636
Unverified
Commit
69dd1636
authored
Aug 15, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "overlay: simplify and adapt to "overlay""
This reverts commit
7f79cc4c
. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
16811e0b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
105 deletions
+72
-105
bdev.c
src/lxc/bdev/bdev.c
+5
-10
lxcoverlay.c
src/lxc/bdev/lxcoverlay.c
+45
-89
lxcoverlay.h
src/lxc/bdev/lxcoverlay.h
+1
-1
storage_utils.c
src/lxc/bdev/storage_utils.c
+0
-2
conf.c
src/lxc/conf.c
+18
-0
lxccontainer.c
src/lxc/lxccontainer.c
+3
-3
No files found.
src/lxc/bdev/bdev.c
View file @
69dd1636
...
...
@@ -194,7 +194,6 @@ static const struct bdev_type bdevs[] = {
{
.
name
=
"btrfs"
,
.
ops
=
&
btrfs_ops
,
},
{
.
name
=
"dir"
,
.
ops
=
&
dir_ops
,
},
{
.
name
=
"aufs"
,
.
ops
=
&
aufs_ops
,
},
{
.
name
=
"overlay"
,
.
ops
=
&
ovl_ops
,
},
{
.
name
=
"overlayfs"
,
.
ops
=
&
ovl_ops
,
},
{
.
name
=
"loop"
,
.
ops
=
&
loop_ops
,
},
{
.
name
=
"nbd"
,
.
ops
=
&
nbd_ops
,
},
...
...
@@ -375,11 +374,10 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
*/
if
(
!
bdevtype
&&
!
keepbdevtype
&&
snap
&&
strcmp
(
orig
->
type
,
"dir"
)
==
0
)
bdevtype
=
"overlay"
;
bdevtype
=
"overlay
fs
"
;
if
(
am_unpriv
()
&&
!
unpriv_snap_allowed
(
orig
,
bdevtype
,
snap
,
maybe_snap
))
{
ERROR
(
"Unsupported snapshot type
\"
%s
\"
for unprivileged users"
,
bdevtype
?
bdevtype
:
"(null)"
);
ERROR
(
"Unsupported snapshot type for unprivileged users"
);
bdev_put
(
orig
);
return
NULL
;
}
...
...
@@ -387,8 +385,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
*
needs_rdep
=
0
;
if
(
bdevtype
&&
strcmp
(
orig
->
type
,
"dir"
)
==
0
&&
(
strcmp
(
bdevtype
,
"aufs"
)
==
0
||
strcmp
(
bdevtype
,
"overlayfs"
)
==
0
||
strcmp
(
bdevtype
,
"overlay"
)
==
0
))
{
strcmp
(
bdevtype
,
"overlayfs"
)
==
0
))
{
*
needs_rdep
=
1
;
}
else
if
(
snap
&&
strcmp
(
orig
->
type
,
"lvm"
)
==
0
&&
!
lvm_is_thin_volume
(
orig
->
src
))
{
...
...
@@ -414,10 +411,8 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
goto
err
;
}
if
(
!
strcmp
(
new
->
type
,
"overlay"
)
||
!
strcmp
(
new
->
type
,
"overlayfs"
))
src_no_prefix
=
ovl_get_lower
(
new
->
src
);
else
src_no_prefix
=
lxc_storage_get_path
(
new
->
src
,
new
->
type
);
src_no_prefix
=
lxc_storage_get_path
(
new
->
src
,
new
->
type
);
if
(
am_unpriv
()
&&
chown_mapped_root
(
src_no_prefix
,
c0
->
lxc_conf
)
<
0
)
WARN
(
"Failed to update ownership of %s"
,
new
->
dest
);
...
...
src/lxc/bdev/lxcoverlay.c
View file @
69dd1636
...
...
@@ -34,7 +34,6 @@
#include "lxccontainer.h"
#include "lxcoverlay.h"
#include "lxcrsync.h"
#include "storage_utils.h"
#include "utils.h"
lxc_log_define
(
lxcoverlay
,
lxc
);
...
...
@@ -42,6 +41,10 @@ lxc_log_define(lxcoverlay, lxc);
static
char
*
ovl_name
;
static
char
*
ovl_version
[]
=
{
"overlay"
,
"overlayfs"
};
/* defined in lxccontainer.c: needs to become common helper */
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
const
char
*
oldpath
,
const
char
*
lxcpath
);
static
char
*
ovl_detect_name
(
void
);
static
int
ovl_do_rsync
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
struct
lxc_conf
*
conf
);
...
...
@@ -58,18 +61,16 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
char
*
src
;
if
(
!
snap
)
{
ERROR
(
"overlay is only for snapshot clones"
);
ERROR
(
"overlay
fs
is only for snapshot clones"
);
return
-
22
;
}
if
(
!
orig
->
src
||
!
orig
->
dest
)
return
-
1
;
new
->
dest
=
lxc_string_join
(
"/"
,
(
const
char
*
[]){
lxcpath
,
cname
,
"rootfs"
,
NULL
},
false
);
new
->
dest
=
dir_new_path
(
orig
->
dest
,
oldname
,
cname
,
oldpath
,
lxcpath
);
if
(
!
new
->
dest
)
return
-
1
;
if
(
mkdir_p
(
new
->
dest
,
0755
)
<
0
)
return
-
1
;
...
...
@@ -142,11 +143,11 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
free
(
delta
);
return
-
ENOMEM
;
}
ret
=
snprintf
(
new
->
src
,
len
,
"overlay:%s:%s"
,
src
,
delta
);
ret
=
snprintf
(
new
->
src
,
len
,
"overlay
fs
:%s:%s"
,
src
,
delta
);
free
(
delta
);
if
(
ret
<
0
||
ret
>=
len
)
return
-
1
;
}
else
if
(
!
strcmp
(
orig
->
type
,
"overlayfs"
)
||
!
strcmp
(
orig
->
type
,
"overlay"
)
)
{
return
-
ENOMEM
;
}
else
if
(
strcmp
(
orig
->
type
,
"overlayfs"
)
==
0
)
{
/*
* What exactly do we want to do here? I think we want to use
* the original lowerdir, with a private delta which is
...
...
@@ -155,44 +156,26 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
char
*
osrc
,
*
odelta
,
*
nsrc
,
*
ndelta
,
*
work
;
char
*
lastslash
;
int
len
,
ret
,
lastslashidx
;
osrc
=
strdup
(
orig
->
src
);
if
(
!
osrc
)
{
SYSERROR
(
"Failed to duplicate
\"
%s
\"
"
,
orig
->
src
);
if
(
!
(
osrc
=
strdup
(
orig
->
src
)))
return
-
22
;
}
nsrc
=
strchr
(
osrc
,
':'
)
+
1
;
if
((
nsrc
!=
osrc
+
8
)
&&
(
nsrc
!=
osrc
+
10
))
{
free
(
osrc
);
ERROR
(
"Detected
\"
:
\"
in
\"
%s
\"
at wrong position"
,
osrc
);
return
-
22
;
}
odelta
=
strchr
(
nsrc
,
':'
);
if
(
!
odelta
)
{
if
(
nsrc
!=
osrc
+
10
||
(
odelta
=
strchr
(
nsrc
,
':'
))
==
NULL
)
{
free
(
osrc
);
ERROR
(
"Failed to find
\"
:
\"
in
\"
%s
\"
"
,
nsrc
);
return
-
22
;
}
*
odelta
=
'\0'
;
odelta
++
;
ndelta
=
lxc_string_join
(
"/"
,
(
const
char
*
[]){
lxcpath
,
cname
,
"rootfs"
,
NULL
},
false
);
if
(
!
ndelta
)
{
ndelta
=
dir_new_path
(
odelta
,
oldname
,
cname
,
oldpath
,
lxcpath
);
if
(
!
ndelta
)
{
free
(
osrc
);
ERROR
(
"Failed to create new path"
);
return
-
ENOMEM
;
}
ret
=
mkdir
(
ndelta
,
0755
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
{
}
if
((
ret
=
mkdir
(
ndelta
,
0755
))
<
0
&&
errno
!=
EEXIST
)
{
SYSERROR
(
"error: mkdir %s"
,
ndelta
);
free
(
osrc
);
free
(
ndelta
);
SYSERROR
(
"Failed to create
\"
%s
\"
"
,
ndelta
);
return
-
1
;
}
if
(
am_unpriv
()
&&
chown_mapped_root
(
ndelta
,
conf
)
<
0
)
WARN
(
"Failed to update ownership of %s"
,
ndelta
);
...
...
@@ -204,7 +187,6 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
if
(
!
lastslash
)
{
free
(
osrc
);
free
(
ndelta
);
ERROR
(
"Failed to detect
\"
/
\"
in
\"
%s
\"
"
,
ndelta
);
return
-
1
;
}
lastslash
++
;
...
...
@@ -214,43 +196,37 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
if
(
!
work
)
{
free
(
osrc
);
free
(
ndelta
);
ERROR
(
"Failed to allocate memory"
);
return
-
1
;
}
strncpy
(
work
,
ndelta
,
lastslashidx
+
1
);
strcpy
(
work
+
lastslashidx
,
"olwork"
);
ret
=
mkdir
(
work
,
0755
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
{
if
((
mkdir
(
work
,
0755
)
<
0
)
&&
errno
!=
EEXIST
)
{
SYSERROR
(
"error: mkdir %s"
,
work
);
free
(
osrc
);
free
(
ndelta
);
free
(
work
);
SYSERROR
(
"Failed to create
\"
%s
\"
"
,
ndelta
);
return
-
1
;
}
if
(
am_unpriv
()
&&
chown_mapped_root
(
work
,
conf
)
<
0
)
WARN
(
"Failed to update ownership of %s"
,
work
);
free
(
work
);
len
=
strlen
(
nsrc
)
+
strlen
(
ndelta
)
+
1
0
;
len
=
strlen
(
nsrc
)
+
strlen
(
ndelta
)
+
1
2
;
new
->
src
=
malloc
(
len
);
if
(
!
new
->
src
)
{
free
(
osrc
);
free
(
ndelta
);
ERROR
(
"Failed to allocate memory"
);
return
-
ENOMEM
;
}
ret
=
snprintf
(
new
->
src
,
len
,
"overlay:%s:%s"
,
nsrc
,
ndelta
);
ret
=
snprintf
(
new
->
src
,
len
,
"overlay
fs
:%s:%s"
,
nsrc
,
ndelta
);
free
(
osrc
);
free
(
ndelta
);
if
(
ret
<
0
||
ret
>=
len
)
{
ERROR
(
"Failed to create string"
);
return
-
1
;
}
if
(
ret
<
0
||
ret
>=
len
)
return
-
ENOMEM
;
return
ovl_do_rsync
(
orig
,
new
,
conf
);
}
else
{
ERROR
(
"overlay clone of %s container is not yet supported"
,
ERROR
(
"overlay
fs
clone of %s container is not yet supported"
,
orig
->
type
);
/*
* Note, supporting this will require ovl_mount supporting
...
...
@@ -263,7 +239,7 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
}
/*
* to say 'lxc-create -t ubuntu -n o1 -B overlay' means you want
* to say 'lxc-create -t ubuntu -n o1 -B overlay
fs
' means you want
* $lxcpath/$lxcname/rootfs to have the created container, while all
* changes after starting the container are written to
* $lxcpath/$lxcname/delta0
...
...
@@ -291,14 +267,14 @@ int ovl_create(struct bdev *bdev, const char *dest, const char *n,
return
-
1
;
}
// overlay:lower:upper
newlen
=
(
2
*
len
)
+
strlen
(
"overlay:"
)
+
2
;
// overlay
fs
:lower:upper
newlen
=
(
2
*
len
)
+
strlen
(
"overlay
fs
:"
)
+
2
;
bdev
->
src
=
malloc
(
newlen
);
if
(
!
bdev
->
src
)
{
ERROR
(
"Out of memory"
);
return
-
1
;
}
ret
=
snprintf
(
bdev
->
src
,
newlen
,
"overlay:%s:%s"
,
dest
,
delta
);
ret
=
snprintf
(
bdev
->
src
,
newlen
,
"overlay
fs
:%s:%s"
,
dest
,
delta
);
if
(
ret
<
0
||
ret
>=
newlen
)
return
-
1
;
...
...
@@ -312,23 +288,14 @@ int ovl_create(struct bdev *bdev, const char *dest, const char *n,
int
ovl_destroy
(
struct
bdev
*
orig
)
{
bool
ovl
;
char
*
upper
=
orig
->
src
;
char
*
upper
;
ovl
=
!
strncmp
(
upper
,
"overlay:"
,
8
);
if
(
!
ovl
&&
strncmp
(
upper
,
"overlayfs:"
,
10
))
if
(
strncmp
(
orig
->
src
,
"overlayfs:"
,
10
)
!=
0
)
return
-
22
;
if
(
ovl
)
upper
+=
8
;
else
upper
+=
10
;
upper
=
strchr
(
upper
,
':'
);
upper
=
strchr
(
orig
->
src
+
10
,
':'
);
if
(
!
upper
)
return
-
22
;
upper
++
;
return
lxc_rmdir_onedev
(
upper
,
NULL
);
}
...
...
@@ -339,6 +306,14 @@ int ovl_detect(const char *path)
return
0
;
}
char
*
ovl_getlower
(
char
*
p
)
{
char
*
p1
=
strchr
(
p
,
':'
);
if
(
p1
)
*
p1
=
'\0'
;
return
p
;
}
int
ovl_mount
(
struct
bdev
*
bdev
)
{
char
*
tmp
,
*
options
,
*
dup
,
*
lower
,
*
upper
;
...
...
@@ -349,9 +324,8 @@ int ovl_mount(struct bdev *bdev)
char
*
mntdata
;
int
ret
,
ret2
;
if
(
strcmp
(
bdev
->
type
,
"overlay
"
)
&&
strcmp
(
bdev
->
type
,
"overlay
fs"
))
if
(
strcmp
(
bdev
->
type
,
"overlayfs"
))
return
-
22
;
if
(
!
bdev
->
src
||
!
bdev
->
dest
)
return
-
22
;
...
...
@@ -445,7 +419,7 @@ int ovl_mount(struct bdev *bdev)
ret
=
ovl_remount_on_enodev
(
lower
,
bdev
->
dest
,
ovl_name
,
MS_MGC_VAL
|
mntflags
,
options_work
);
if
(
ret
<
0
)
{
INFO
(
"Overlay: Error mounting %s onto %s with options %s. "
INFO
(
"Overlay
fs
: Error mounting %s onto %s with options %s. "
"Retrying without workdir: %s."
,
lower
,
bdev
->
dest
,
options_work
,
strerror
(
errno
));
...
...
@@ -453,15 +427,15 @@ int ovl_mount(struct bdev *bdev)
ret
=
ovl_remount_on_enodev
(
lower
,
bdev
->
dest
,
ovl_name
,
MS_MGC_VAL
|
mntflags
,
options
);
if
(
ret
<
0
)
SYSERROR
(
"Overlay: Error mounting %s onto %s with "
SYSERROR
(
"Overlay
fs
: Error mounting %s onto %s with "
"options %s: %s."
,
lower
,
bdev
->
dest
,
options
,
strerror
(
errno
));
else
INFO
(
"Overlay: Mounted %s onto %s with options %s."
,
INFO
(
"Overlay
fs
: Mounted %s onto %s with options %s."
,
lower
,
bdev
->
dest
,
options
);
}
else
{
INFO
(
"Overlay: Mounted %s onto %s with options %s."
,
lower
,
INFO
(
"Overlay
fs
: Mounted %s onto %s with options %s."
,
lower
,
bdev
->
dest
,
options_work
);
}
return
ret
;
...
...
@@ -469,31 +443,13 @@ int ovl_mount(struct bdev *bdev)
int
ovl_umount
(
struct
bdev
*
bdev
)
{
if
(
strcmp
(
bdev
->
type
,
"overlay
"
)
&&
strcmp
(
bdev
->
type
,
"overlay
fs"
))
if
(
strcmp
(
bdev
->
type
,
"overlayfs"
))
return
-
22
;
if
(
!
bdev
->
src
||
!
bdev
->
dest
)
return
-
22
;
return
umount
(
bdev
->
dest
);
}
char
*
ovl_get_lower
(
const
char
*
rootfs_path
)
{
char
*
s1
;
s1
=
strstr
(
rootfs_path
,
":/"
);
if
(
!
s1
)
return
NULL
;
s1
++
;
s1
=
strstr
(
s1
,
":/"
);
if
(
!
s1
)
return
NULL
;
s1
++
;
return
s1
;
}
char
*
ovl_get_rootfs
(
const
char
*
rootfs_path
,
size_t
*
rootfslen
)
{
char
*
rootfsdir
=
NULL
;
...
...
@@ -802,7 +758,7 @@ static int ovl_do_rsync(struct bdev *orig, struct bdev *new, struct lxc_conf *co
else
ret
=
ovl_rsync
(
&
rdata
);
if
(
ret
)
ERROR
(
"copying overlay delta"
);
ERROR
(
"copying overlay
fs
delta"
);
return
ret
;
}
...
...
src/lxc/bdev/lxcoverlay.h
View file @
69dd1636
...
...
@@ -76,7 +76,7 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
* To be called from functions in lxccontainer.c: Get lower directory for
* overlay rootfs.
*/
char
*
ovl_get
_lower
(
const
char
*
rootfs_path
);
char
*
ovl_get
lower
(
char
*
p
);
/*
* Get rootfs path for overlay backed containers. Allocated memory must be freed
...
...
src/lxc/bdev/storage_utils.c
View file @
69dd1636
...
...
@@ -415,7 +415,6 @@ bool unpriv_snap_allowed(struct bdev *b, const char *t, bool snap,
// overlayfs -- which is also allowed)
if
(
strcmp
(
b
->
type
,
"dir"
)
==
0
||
strcmp
(
b
->
type
,
"aufs"
)
==
0
||
strcmp
(
b
->
type
,
"overlay"
)
==
0
||
strcmp
(
b
->
type
,
"overlayfs"
)
==
0
||
strcmp
(
b
->
type
,
"btrfs"
)
==
0
||
strcmp
(
b
->
type
,
"loop"
)
==
0
)
...
...
@@ -428,7 +427,6 @@ bool unpriv_snap_allowed(struct bdev *b, const char *t, bool snap,
// and loop. In particular, not zfs, btrfs, or lvm.
if
(
strcmp
(
t
,
"dir"
)
==
0
||
strcmp
(
t
,
"aufs"
)
==
0
||
strcmp
(
t
,
"overlay"
)
==
0
||
strcmp
(
t
,
"overlayfs"
)
==
0
||
strcmp
(
t
,
"btrfs"
)
==
0
||
strcmp
(
t
,
"loop"
)
==
0
)
...
...
src/lxc/conf.c
View file @
69dd1636
...
...
@@ -3623,6 +3623,7 @@ int chown_mapped_root(char *path, struct lxc_conf *conf)
{
uid_t
rootuid
,
rootgid
;
unsigned
long
val
;
char
*
chownpath
=
path
;
int
hostuid
,
hostgid
,
ret
;
struct
stat
sb
;
char
map1
[
100
],
map2
[
100
],
map3
[
100
],
map4
[
100
],
map5
[
100
];
...
...
@@ -3658,6 +3659,23 @@ int chown_mapped_root(char *path, struct lxc_conf *conf)
}
rootgid
=
(
gid_t
)
val
;
/*
* In case of overlay, we want only the writeable layer to be chowned
*/
if
(
strncmp
(
path
,
"overlayfs:"
,
10
)
==
0
||
strncmp
(
path
,
"aufs:"
,
5
)
==
0
)
{
chownpath
=
strchr
(
path
,
':'
);
if
(
!
chownpath
)
{
ERROR
(
"Bad overlay path: %s"
,
path
);
return
-
1
;
}
chownpath
=
strchr
(
chownpath
+
1
,
':'
);
if
(
!
chownpath
)
{
ERROR
(
"Bad overlay path: %s"
,
path
);
return
-
1
;
}
chownpath
++
;
}
path
=
chownpath
;
if
(
hostuid
==
0
)
{
if
(
chown
(
path
,
rootuid
,
rootgid
)
<
0
)
{
ERROR
(
"Error chowning %s"
,
path
);
...
...
src/lxc/lxccontainer.c
View file @
69dd1636
...
...
@@ -3225,8 +3225,8 @@ static int clone_update_rootfs_wrapper(void *data)
sudo lxc-clone -o o1 -n n1 -s -L|-fssize fssize -v|--vgname vgname \
-p|--lvprefix lvprefix -t|--fstype fstype -B backingstore
-s [ implies overlay]
-s -B overlay
-s [ implies overlay
fs
]
-s -B overlay
fs
-s -B aufs
only rootfs gets converted (copied/snapshotted) on clone.
...
...
@@ -3600,7 +3600,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
if
(
bdev_is_dir
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
))
{
ERROR
(
"Snapshot of directory-backed container requested."
);
ERROR
(
"Making a copy-clone. If you do want snapshots, then"
);
ERROR
(
"please create an aufs or overlay clone first, snapshot that"
);
ERROR
(
"please create an aufs or overlay
fs
clone first, snapshot that"
);
ERROR
(
"and keep the original container pristine."
);
flags
&=
~
LXC_CLONE_SNAPSHOT
|
LXC_CLONE_MAYBE_SNAPSHOT
;
}
...
...
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