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
0e8e6386
Unverified
Commit
0e8e6386
authored
Jul 29, 2017
by
Christian Brauner
Committed by
Stéphane Graber
Aug 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree-wide: struct bdev -> struct lxc_storage
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
d3459849
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
339 additions
and
382 deletions
+339
-382
conf.c
src/lxc/conf.c
+3
-3
confile.c
src/lxc/confile.c
+1
-1
lxccontainer.c
src/lxc/lxccontainer.c
+42
-41
start.c
src/lxc/start.c
+5
-3
aufs.c
src/lxc/storage/aufs.c
+9
-8
aufs.h
src/lxc/storage/aufs.h
+11
-18
btrfs.c
src/lxc/storage/btrfs.c
+10
-11
btrfs.h
src/lxc/storage/btrfs.h
+28
-31
dir.c
src/lxc/storage/dir.c
+12
-12
dir.h
src/lxc/storage/dir.h
+11
-16
loop.c
src/lxc/storage/loop.c
+9
-9
loop.h
src/lxc/storage/loop.h
+11
-16
lvm.c
src/lxc/storage/lvm.c
+10
-9
lvm.h
src/lxc/storage/lvm.h
+19
-20
nbd.c
src/lxc/storage/nbd.c
+10
-9
nbd.h
src/lxc/storage/nbd.h
+15
-21
overlay.c
src/lxc/storage/overlay.c
+10
-9
overlay.h
src/lxc/storage/overlay.h
+23
-32
rbd.c
src/lxc/storage/rbd.c
+7
-7
rbd.h
src/lxc/storage/rbd.h
+11
-16
rsync.c
src/lxc/storage/rsync.c
+2
-4
rsync.h
src/lxc/storage/rsync.h
+2
-2
storage.c
src/lxc/storage/storage.c
+0
-0
storage.h
src/lxc/storage/storage.h
+37
-37
storage_utils.c
src/lxc/storage/storage_utils.c
+9
-9
storage_utils.h
src/lxc/storage/storage_utils.h
+8
-8
zfs.c
src/lxc/storage/zfs.c
+7
-7
zfs.h
src/lxc/storage/zfs.h
+16
-22
lxc_create.c
src/lxc/tools/lxc_create.c
+1
-1
No files found.
src/lxc/conf.c
View file @
0e8e6386
...
@@ -1112,7 +1112,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
...
@@ -1112,7 +1112,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
static
int
lxc_setup_rootfs
(
struct
lxc_conf
*
conf
)
static
int
lxc_setup_rootfs
(
struct
lxc_conf
*
conf
)
{
{
int
ret
;
int
ret
;
struct
bdev
*
bdev
;
struct
lxc_storage
*
bdev
;
const
struct
lxc_rootfs
*
rootfs
;
const
struct
lxc_rootfs
*
rootfs
;
rootfs
=
&
conf
->
rootfs
;
rootfs
=
&
conf
->
rootfs
;
...
@@ -1130,7 +1130,7 @@ static int lxc_setup_rootfs(struct lxc_conf *conf)
...
@@ -1130,7 +1130,7 @@ static int lxc_setup_rootfs(struct lxc_conf *conf)
return
-
1
;
return
-
1
;
}
}
bdev
=
bdev
_init
(
conf
,
rootfs
->
path
,
rootfs
->
mount
,
rootfs
->
options
);
bdev
=
storage
_init
(
conf
,
rootfs
->
path
,
rootfs
->
mount
,
rootfs
->
options
);
if
(
!
bdev
)
{
if
(
!
bdev
)
{
ERROR
(
"Failed to mount rootfs
\"
%s
\"
onto
\"
%s
\"
with options
\"
%s
\"
."
,
ERROR
(
"Failed to mount rootfs
\"
%s
\"
onto
\"
%s
\"
with options
\"
%s
\"
."
,
rootfs
->
path
,
rootfs
->
mount
,
rootfs
->
path
,
rootfs
->
mount
,
...
@@ -1139,7 +1139,7 @@ static int lxc_setup_rootfs(struct lxc_conf *conf)
...
@@ -1139,7 +1139,7 @@ static int lxc_setup_rootfs(struct lxc_conf *conf)
}
}
ret
=
bdev
->
ops
->
mount
(
bdev
);
ret
=
bdev
->
ops
->
mount
(
bdev
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to mount rootfs
\"
%s
\"
onto
\"
%s
\"
with options
\"
%s
\"
."
,
ERROR
(
"Failed to mount rootfs
\"
%s
\"
onto
\"
%s
\"
with options
\"
%s
\"
."
,
rootfs
->
path
,
rootfs
->
mount
,
rootfs
->
path
,
rootfs
->
mount
,
...
...
src/lxc/confile.c
View file @
0e8e6386
...
@@ -2274,7 +2274,7 @@ static int set_config_rootfs_backend(const char *key, const char *value,
...
@@ -2274,7 +2274,7 @@ static int set_config_rootfs_backend(const char *key, const char *value,
return
0
;
return
0
;
}
}
if
(
!
is_valid_
bdev
_type
(
value
))
{
if
(
!
is_valid_
storage
_type
(
value
))
{
ERROR
(
"Bad rootfs.backend: '%s'"
,
value
);
ERROR
(
"Bad rootfs.backend: '%s'"
,
value
);
return
-
1
;
return
-
1
;
}
}
...
...
src/lxc/lxccontainer.c
View file @
0e8e6386
...
@@ -1152,16 +1152,16 @@ static bool create_container_dir(struct lxc_container *c)
...
@@ -1152,16 +1152,16 @@ static bool create_container_dir(struct lxc_container *c)
return
ret
==
0
;
return
ret
==
0
;
}
}
/*
/* do_storage_create: thin wrapper around storage_create(). Like
* do_bdev_create: thin wrapper around bdev_create(). Like bdev_create(),
* storage_create(), it returns a mounted bdev on success, NULL on error.
* it returns a mounted bdev on success, NULL on error.
*/
*/
static
struct
bdev
*
do_bdev_create
(
struct
lxc_container
*
c
,
const
char
*
type
,
static
struct
lxc_storage
*
do_storage_create
(
struct
lxc_container
*
c
,
struct
bdev_specs
*
specs
)
const
char
*
type
,
struct
bdev_specs
*
specs
)
{
{
char
*
dest
;
char
*
dest
;
size_t
len
;
size_t
len
;
struct
bdev
*
bdev
;
struct
lxc_storage
*
bdev
;
int
ret
;
int
ret
;
/* rootfs.path or lxcpath/lxcname/rootfs */
/* rootfs.path or lxcpath/lxcname/rootfs */
...
@@ -1179,7 +1179,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
...
@@ -1179,7 +1179,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
if
(
ret
<
0
||
ret
>=
len
)
if
(
ret
<
0
||
ret
>=
len
)
return
NULL
;
return
NULL
;
bdev
=
bdev
_create
(
dest
,
type
,
c
->
name
,
specs
);
bdev
=
storage
_create
(
dest
,
type
,
c
->
name
,
specs
);
if
(
!
bdev
)
{
if
(
!
bdev
)
{
ERROR
(
"Failed to create backing store type %s"
,
type
);
ERROR
(
"Failed to create backing store type %s"
,
type
);
return
NULL
;
return
NULL
;
...
@@ -1195,7 +1195,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
...
@@ -1195,7 +1195,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
if
(
chown_mapped_root
(
bdev
->
dest
,
c
->
lxc_conf
)
<
0
)
{
if
(
chown_mapped_root
(
bdev
->
dest
,
c
->
lxc_conf
)
<
0
)
{
ERROR
(
"Error chowning %s to container root"
,
bdev
->
dest
);
ERROR
(
"Error chowning %s to container root"
,
bdev
->
dest
);
suggest_default_idmap
();
suggest_default_idmap
();
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
return
NULL
;
return
NULL
;
}
}
}
}
...
@@ -1227,7 +1227,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
...
@@ -1227,7 +1227,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
if
(
pid
==
0
)
{
// child
if
(
pid
==
0
)
{
// child
char
*
patharg
,
*
namearg
,
*
rootfsarg
;
char
*
patharg
,
*
namearg
,
*
rootfsarg
;
struct
bdev
*
bdev
=
NULL
;
struct
lxc_storage
*
bdev
=
NULL
;
int
i
;
int
i
;
int
ret
,
len
,
nargs
=
0
;
int
ret
,
len
,
nargs
=
0
;
char
**
newargv
;
char
**
newargv
;
...
@@ -1237,7 +1237,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
...
@@ -1237,7 +1237,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
exit
(
1
);
exit
(
1
);
}
}
bdev
=
bdev
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
bdev
=
storage
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
if
(
!
bdev
)
{
if
(
!
bdev
)
{
ERROR
(
"Error opening rootfs"
);
ERROR
(
"Error opening rootfs"
);
exit
(
1
);
exit
(
1
);
...
@@ -1653,12 +1653,13 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1653,12 +1653,13 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
}
}
if
(
pid
==
0
)
{
// child
if
(
pid
==
0
)
{
// child
struct
bdev
*
bdev
=
NULL
;
struct
lxc_storage
*
bdev
=
NULL
;
if
(
!
(
bdev
=
do_bdev_create
(
c
,
bdevtype
,
specs
)))
{
bdev
=
do_storage_create
(
c
,
bdevtype
,
specs
);
if
(
!
bdev
)
{
ERROR
(
"Error creating backing store type %s for %s"
,
ERROR
(
"Error creating backing store type %s for %s"
,
bdevtype
?
bdevtype
:
"(none)"
,
c
->
name
);
bdevtype
?
bdevtype
:
"(none)"
,
c
->
name
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
/* save config file again to store the new rootfs location */
/* save config file again to store the new rootfs location */
...
@@ -1667,9 +1668,9 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
...
@@ -1667,9 +1668,9 @@ static bool do_lxcapi_create(struct lxc_container *c, const char *t,
// parent task won't see bdev in config so we delete it
// parent task won't see bdev in config so we delete it
bdev
->
ops
->
umount
(
bdev
);
bdev
->
ops
->
umount
(
bdev
);
bdev
->
ops
->
destroy
(
bdev
);
bdev
->
ops
->
destroy
(
bdev
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
exit
(
0
);
exit
(
EXIT_SUCCESS
);
}
}
if
(
wait_for_pid
(
pid
)
!=
0
)
if
(
wait_for_pid
(
pid
)
!=
0
)
goto
out_unlock
;
goto
out_unlock
;
...
@@ -2508,12 +2509,12 @@ static bool has_snapshots(struct lxc_container *c)
...
@@ -2508,12 +2509,12 @@ static bool has_snapshots(struct lxc_container *c)
static
bool
do_destroy_container
(
struct
lxc_conf
*
conf
)
{
static
bool
do_destroy_container
(
struct
lxc_conf
*
conf
)
{
if
(
am_unpriv
())
{
if
(
am_unpriv
())
{
if
(
userns_exec_1
(
conf
,
bdev
_destroy_wrapper
,
conf
,
if
(
userns_exec_1
(
conf
,
storage
_destroy_wrapper
,
conf
,
"
bdev
_destroy_wrapper"
)
<
0
)
"
storage
_destroy_wrapper"
)
<
0
)
return
false
;
return
false
;
return
true
;
return
true
;
}
}
return
bdev
_destroy
(
conf
);
return
storage
_destroy
(
conf
);
}
}
static
int
lxc_rmdir_onedev_wrapper
(
void
*
data
)
static
int
lxc_rmdir_onedev_wrapper
(
void
*
data
)
...
@@ -3043,14 +3044,14 @@ static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
...
@@ -3043,14 +3044,14 @@ static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
const
char
*
newtype
,
int
flags
,
const
char
*
bdevdata
,
const
char
*
newtype
,
int
flags
,
const
char
*
bdevdata
,
uint64_t
newsize
)
uint64_t
newsize
)
{
{
struct
bdev
*
bdev
;
struct
lxc_storage
*
bdev
;
int
need_rdep
;
int
need_rdep
;
if
(
should_default_to_snapshot
(
c0
,
c
))
if
(
should_default_to_snapshot
(
c0
,
c
))
flags
|=
LXC_CLONE_SNAPSHOT
;
flags
|=
LXC_CLONE_SNAPSHOT
;
bdev
=
bdev_copy
(
c0
,
c
->
name
,
c
->
config_path
,
newtype
,
flags
,
bdevdata
,
bdev
=
storage_copy
(
c0
,
c
->
name
,
c
->
config_path
,
newtype
,
flags
,
newsize
,
&
need_rdep
);
bdevdata
,
newsize
,
&
need_rdep
);
if
(
!
bdev
)
{
if
(
!
bdev
)
{
ERROR
(
"Error copying storage."
);
ERROR
(
"Error copying storage."
);
return
-
1
;
return
-
1
;
...
@@ -3063,7 +3064,7 @@ static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
...
@@ -3063,7 +3064,7 @@ static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
/* Set new bdev type. */
/* Set new bdev type. */
free
(
c
->
lxc_conf
->
rootfs
.
bdev_type
);
free
(
c
->
lxc_conf
->
rootfs
.
bdev_type
);
c
->
lxc_conf
->
rootfs
.
bdev_type
=
strdup
(
bdev
->
type
);
c
->
lxc_conf
->
rootfs
.
bdev_type
=
strdup
(
bdev
->
type
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
if
(
!
c
->
lxc_conf
->
rootfs
.
path
)
{
if
(
!
c
->
lxc_conf
->
rootfs
.
path
)
{
ERROR
(
"Out of memory while setting storage path."
);
ERROR
(
"Out of memory while setting storage path."
);
...
@@ -3118,7 +3119,7 @@ static int clone_update_rootfs(struct clone_update_data *data)
...
@@ -3118,7 +3119,7 @@ static int clone_update_rootfs(struct clone_update_data *data)
char
**
hookargs
=
data
->
hookargs
;
char
**
hookargs
=
data
->
hookargs
;
int
ret
=
-
1
;
int
ret
=
-
1
;
char
path
[
MAXPATHLEN
];
char
path
[
MAXPATHLEN
];
struct
bdev
*
bdev
;
struct
lxc_storage
*
bdev
;
FILE
*
fout
;
FILE
*
fout
;
struct
lxc_conf
*
conf
=
c
->
lxc_conf
;
struct
lxc_conf
*
conf
=
c
->
lxc_conf
;
...
@@ -3138,13 +3139,13 @@ static int clone_update_rootfs(struct clone_update_data *data)
...
@@ -3138,13 +3139,13 @@ static int clone_update_rootfs(struct clone_update_data *data)
if
(
unshare
(
CLONE_NEWNS
)
<
0
)
if
(
unshare
(
CLONE_NEWNS
)
<
0
)
return
-
1
;
return
-
1
;
bdev
=
bdev
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
bdev
=
storage
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
if
(
!
bdev
)
if
(
!
bdev
)
return
-
1
;
return
-
1
;
if
(
strcmp
(
bdev
->
type
,
"dir"
)
!=
0
)
{
if
(
strcmp
(
bdev
->
type
,
"dir"
)
!=
0
)
{
if
(
unshare
(
CLONE_NEWNS
)
<
0
)
{
if
(
unshare
(
CLONE_NEWNS
)
<
0
)
{
ERROR
(
"error unsharing mounts"
);
ERROR
(
"error unsharing mounts"
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
return
-
1
;
return
-
1
;
}
}
if
(
detect_shared_rootfs
())
{
if
(
detect_shared_rootfs
())
{
...
@@ -3154,7 +3155,7 @@ static int clone_update_rootfs(struct clone_update_data *data)
...
@@ -3154,7 +3155,7 @@ static int clone_update_rootfs(struct clone_update_data *data)
}
}
}
}
if
(
bdev
->
ops
->
mount
(
bdev
)
<
0
)
{
if
(
bdev
->
ops
->
mount
(
bdev
)
<
0
)
{
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
return
-
1
;
return
-
1
;
}
}
}
else
{
// TODO come up with a better way
}
else
{
// TODO come up with a better way
...
@@ -3182,14 +3183,14 @@ static int clone_update_rootfs(struct clone_update_data *data)
...
@@ -3182,14 +3183,14 @@ static int clone_update_rootfs(struct clone_update_data *data)
if
(
run_lxc_hooks
(
c
->
name
,
"clone"
,
conf
,
c
->
get_config_path
(
c
),
hookargs
))
{
if
(
run_lxc_hooks
(
c
->
name
,
"clone"
,
conf
,
c
->
get_config_path
(
c
),
hookargs
))
{
ERROR
(
"Error executing clone hook for %s"
,
c
->
name
);
ERROR
(
"Error executing clone hook for %s"
,
c
->
name
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
return
-
1
;
return
-
1
;
}
}
}
}
if
(
!
(
flags
&
LXC_CLONE_KEEPNAME
))
{
if
(
!
(
flags
&
LXC_CLONE_KEEPNAME
))
{
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/etc/hostname"
,
bdev
->
dest
);
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"%s/etc/hostname"
,
bdev
->
dest
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
return
-
1
;
return
-
1
;
...
@@ -3205,9 +3206,9 @@ static int clone_update_rootfs(struct clone_update_data *data)
...
@@ -3205,9 +3206,9 @@ static int clone_update_rootfs(struct clone_update_data *data)
}
}
if
(
fclose
(
fout
)
<
0
)
if
(
fclose
(
fout
)
<
0
)
return
-
1
;
return
-
1
;
}
else
{
storage_put
(
bdev
);
}
}
else
bdev_put
(
bdev
);
return
0
;
return
0
;
}
}
...
@@ -3440,7 +3441,7 @@ static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *n
...
@@ -3440,7 +3441,7 @@ static struct lxc_container *lxcapi_clone(struct lxc_container *c, const char *n
static
bool
do_lxcapi_rename
(
struct
lxc_container
*
c
,
const
char
*
newname
)
static
bool
do_lxcapi_rename
(
struct
lxc_container
*
c
,
const
char
*
newname
)
{
{
struct
bdev
*
bdev
;
struct
lxc_storage
*
bdev
;
struct
lxc_container
*
newc
;
struct
lxc_container
*
newc
;
if
(
!
c
||
!
c
->
name
||
!
c
->
config_path
||
!
c
->
lxc_conf
)
if
(
!
c
||
!
c
->
name
||
!
c
->
config_path
||
!
c
->
lxc_conf
)
...
@@ -3450,14 +3451,14 @@ static bool do_lxcapi_rename(struct lxc_container *c, const char *newname)
...
@@ -3450,14 +3451,14 @@ static bool do_lxcapi_rename(struct lxc_container *c, const char *newname)
ERROR
(
"Renaming a container with snapshots is not supported"
);
ERROR
(
"Renaming a container with snapshots is not supported"
);
return
false
;
return
false
;
}
}
bdev
=
bdev
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
bdev
=
storage
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
if
(
!
bdev
)
{
if
(
!
bdev
)
{
ERROR
(
"Failed to find original backing store type"
);
ERROR
(
"Failed to find original backing store type"
);
return
false
;
return
false
;
}
}
newc
=
lxcapi_clone
(
c
,
newname
,
c
->
config_path
,
LXC_CLONE_KEEPMACADDR
,
NULL
,
bdev
->
type
,
0
,
NULL
);
newc
=
lxcapi_clone
(
c
,
newname
,
c
->
config_path
,
LXC_CLONE_KEEPMACADDR
,
NULL
,
bdev
->
type
,
0
,
NULL
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
if
(
!
newc
)
{
if
(
!
newc
)
{
lxc_container_put
(
newc
);
lxc_container_put
(
newc
);
return
false
;
return
false
;
...
@@ -3569,7 +3570,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
...
@@ -3569,7 +3570,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
if
(
!
c
||
!
lxcapi_is_defined
(
c
))
if
(
!
c
||
!
lxcapi_is_defined
(
c
))
return
-
1
;
return
-
1
;
if
(
!
bdev
_can_backup
(
c
->
lxc_conf
))
{
if
(
!
storage
_can_backup
(
c
->
lxc_conf
))
{
ERROR
(
"%s's backing store cannot be backed up."
,
c
->
name
);
ERROR
(
"%s's backing store cannot be backed up."
,
c
->
name
);
ERROR
(
"Your container must use another backing store type."
);
ERROR
(
"Your container must use another backing store type."
);
return
-
1
;
return
-
1
;
...
@@ -3595,7 +3596,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
...
@@ -3595,7 +3596,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
*/
*/
flags
=
LXC_CLONE_SNAPSHOT
|
LXC_CLONE_KEEPMACADDR
|
LXC_CLONE_KEEPNAME
|
flags
=
LXC_CLONE_SNAPSHOT
|
LXC_CLONE_KEEPMACADDR
|
LXC_CLONE_KEEPNAME
|
LXC_CLONE_KEEPBDEVTYPE
|
LXC_CLONE_MAYBE_SNAPSHOT
;
LXC_CLONE_KEEPBDEVTYPE
|
LXC_CLONE_MAYBE_SNAPSHOT
;
if
(
bdev
_is_dir
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
))
{
if
(
storage
_is_dir
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
))
{
ERROR
(
"Snapshot of directory-backed container requested."
);
ERROR
(
"Snapshot of directory-backed container requested."
);
ERROR
(
"Making a copy-clone. If you do want snapshots, then"
);
ERROR
(
"Making a copy-clone. If you do want snapshots, then"
);
ERROR
(
"please create an aufs or overlayfs clone first, snapshot that"
);
ERROR
(
"please create an aufs or overlayfs clone first, snapshot that"
);
...
@@ -3789,7 +3790,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
...
@@ -3789,7 +3790,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
char
clonelxcpath
[
MAXPATHLEN
];
char
clonelxcpath
[
MAXPATHLEN
];
int
flags
=
0
;
int
flags
=
0
;
struct
lxc_container
*
snap
,
*
rest
;
struct
lxc_container
*
snap
,
*
rest
;
struct
bdev
*
bdev
;
struct
lxc_storage
*
bdev
;
bool
b
=
false
;
bool
b
=
false
;
if
(
!
c
||
!
c
->
name
||
!
c
->
config_path
)
if
(
!
c
||
!
c
->
name
||
!
c
->
config_path
)
...
@@ -3800,7 +3801,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
...
@@ -3800,7 +3801,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
return
false
;
return
false
;
}
}
bdev
=
bdev
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
bdev
=
storage
_init
(
c
->
lxc_conf
,
c
->
lxc_conf
->
rootfs
.
path
,
c
->
lxc_conf
->
rootfs
.
mount
,
NULL
);
if
(
!
bdev
)
{
if
(
!
bdev
)
{
ERROR
(
"Failed to find original backing store type"
);
ERROR
(
"Failed to find original backing store type"
);
return
false
;
return
false
;
...
@@ -3810,7 +3811,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
...
@@ -3810,7 +3811,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
newname
=
c
->
name
;
newname
=
c
->
name
;
if
(
!
get_snappath_dir
(
c
,
clonelxcpath
))
{
if
(
!
get_snappath_dir
(
c
,
clonelxcpath
))
{
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
return
false
;
return
false
;
}
}
// how should we lock this?
// how should we lock this?
...
@@ -3819,7 +3820,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
...
@@ -3819,7 +3820,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
if
(
!
snap
||
!
lxcapi_is_defined
(
snap
))
{
if
(
!
snap
||
!
lxcapi_is_defined
(
snap
))
{
ERROR
(
"Could not open snapshot %s"
,
snapname
);
ERROR
(
"Could not open snapshot %s"
,
snapname
);
if
(
snap
)
lxc_container_put
(
snap
);
if
(
snap
)
lxc_container_put
(
snap
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
return
false
;
return
false
;
}
}
...
@@ -3827,7 +3828,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
...
@@ -3827,7 +3828,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
if
(
!
container_destroy
(
c
))
{
if
(
!
container_destroy
(
c
))
{
ERROR
(
"Could not destroy existing container %s"
,
newname
);
ERROR
(
"Could not destroy existing container %s"
,
newname
);
lxc_container_put
(
snap
);
lxc_container_put
(
snap
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
return
false
;
return
false
;
}
}
}
}
...
@@ -3836,7 +3837,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
...
@@ -3836,7 +3837,7 @@ static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snap
flags
=
LXC_CLONE_SNAPSHOT
|
LXC_CLONE_MAYBE_SNAPSHOT
;
flags
=
LXC_CLONE_SNAPSHOT
|
LXC_CLONE_MAYBE_SNAPSHOT
;
rest
=
lxcapi_clone
(
snap
,
newname
,
c
->
config_path
,
flags
,
rest
=
lxcapi_clone
(
snap
,
newname
,
c
->
config_path
,
flags
,
bdev
->
type
,
NULL
,
0
,
NULL
);
bdev
->
type
,
NULL
,
0
,
NULL
);
bdev
_put
(
bdev
);
storage
_put
(
bdev
);
if
(
rest
&&
lxcapi_is_defined
(
rest
))
if
(
rest
&&
lxcapi_is_defined
(
rest
))
b
=
true
;
b
=
true
;
if
(
rest
)
if
(
rest
)
...
...
src/lxc/start.c
View file @
0e8e6386
...
@@ -1737,10 +1737,12 @@ static int lxc_rmdir_onedev_wrapper(void *data)
...
@@ -1737,10 +1737,12 @@ static int lxc_rmdir_onedev_wrapper(void *data)
static
bool
do_destroy_container
(
struct
lxc_conf
*
conf
)
{
static
bool
do_destroy_container
(
struct
lxc_conf
*
conf
)
{
if
(
am_unpriv
())
{
if
(
am_unpriv
())
{
if
(
userns_exec_1
(
conf
,
bdev
_destroy_wrapper
,
conf
,
if
(
userns_exec_1
(
conf
,
storage
_destroy_wrapper
,
conf
,
"
bdev
_destroy_wrapper"
)
<
0
)
"
storage
_destroy_wrapper"
)
<
0
)
return
false
;
return
false
;
return
true
;
return
true
;
}
}
return
bdev_destroy
(
conf
);
return
storage_destroy
(
conf
);
}
}
src/lxc/storage/aufs.c
View file @
0e8e6386
...
@@ -36,15 +36,16 @@
...
@@ -36,15 +36,16 @@
#include "storage.h"
#include "storage.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc
aufs
,
lxc
);
lxc_log_define
(
aufs
,
lxc
);
/* the bulk of this needs to become a common helper */
/* the bulk of this needs to become a common helper */
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
const
char
*
oldpath
,
const
char
*
lxcpath
);
const
char
*
oldpath
,
const
char
*
lxcpath
);
int
aufs_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
aufs_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
if
(
!
snap
)
{
if
(
!
snap
)
{
ERROR
(
"aufs is only for snapshot clones"
);
ERROR
(
"aufs is only for snapshot clones"
);
...
@@ -174,7 +175,7 @@ int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -174,7 +175,7 @@ int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
* changes after starting the container are written to
* changes after starting the container are written to
* $lxcpath/$lxcname/delta0
* $lxcpath/$lxcname/delta0
*/
*/
int
aufs_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
aufs_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
char
*
delta
;
char
*
delta
;
...
@@ -216,7 +217,7 @@ int aufs_create(struct bdev *bdev, const char *dest, const char *n,
...
@@ -216,7 +217,7 @@ int aufs_create(struct bdev *bdev, const char *dest, const char *n,
return
0
;
return
0
;
}
}
int
aufs_destroy
(
struct
bdev
*
orig
)
int
aufs_destroy
(
struct
lxc_storage
*
orig
)
{
{
char
*
upper
;
char
*
upper
;
...
@@ -236,7 +237,7 @@ int aufs_detect(const char *path)
...
@@ -236,7 +237,7 @@ int aufs_detect(const char *path)
return
0
;
return
0
;
}
}
int
aufs_mount
(
struct
bdev
*
bdev
)
int
aufs_mount
(
struct
lxc_storage
*
bdev
)
{
{
char
*
tmp
,
*
options
,
*
dup
,
*
lower
,
*
upper
;
char
*
tmp
,
*
options
,
*
dup
,
*
lower
,
*
upper
;
int
len
;
int
len
;
...
@@ -308,7 +309,7 @@ int aufs_mount(struct bdev *bdev)
...
@@ -308,7 +309,7 @@ int aufs_mount(struct bdev *bdev)
return
ret
;
return
ret
;
}
}
int
aufs_umount
(
struct
bdev
*
bdev
)
int
aufs_umount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"aufs"
))
if
(
strcmp
(
bdev
->
type
,
"aufs"
))
return
-
22
;
return
-
22
;
...
...
src/lxc/storage/aufs.h
View file @
0e8e6386
...
@@ -33,34 +33,27 @@
...
@@ -33,34 +33,27 @@
#include <mntent.h>
#include <mntent.h>
#endif
#endif
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/* defined in conf.h */
struct
lxc_rootfs
;
struct
lxc_rootfs
;
/*
int
aufs_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* Functions associated with an aufs bdev struct.
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
*/
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
int
aufs_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
aufs_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
int
aufs_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
);
struct
bdev_specs
*
specs
);
int
aufs_destroy
(
struct
bdev
*
orig
);
int
aufs_destroy
(
struct
lxc_storage
*
orig
);
int
aufs_detect
(
const
char
*
path
);
int
aufs_detect
(
const
char
*
path
);
int
aufs_mount
(
struct
bdev
*
bdev
);
int
aufs_mount
(
struct
lxc_storage
*
bdev
);
int
aufs_umount
(
struct
bdev
*
bdev
);
int
aufs_umount
(
struct
lxc_storage
*
bdev
);
/*
/* Get rootfs path for aufs backed containers. Allocated memory must be freed by
* Get rootfs path for aufs backed containers. Allocated memory must be freed
* caller.
* by caller.
*/
*/
char
*
aufs_get_rootfs
(
const
char
*
rootfs_path
,
size_t
*
rootfslen
);
char
*
aufs_get_rootfs
(
const
char
*
rootfs_path
,
size_t
*
rootfslen
);
...
...
src/lxc/storage/btrfs.c
View file @
0e8e6386
...
@@ -41,7 +41,7 @@
...
@@ -41,7 +41,7 @@
#include "storage.h"
#include "storage.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc
btrfs
,
lxc
);
lxc_log_define
(
btrfs
,
lxc
);
/* defined in lxccontainer.c: needs to become common helper */
/* defined in lxccontainer.c: needs to become common helper */
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
...
@@ -188,7 +188,7 @@ int btrfs_detect(const char *path)
...
@@ -188,7 +188,7 @@ int btrfs_detect(const char *path)
return
0
;
return
0
;
}
}
int
btrfs_mount
(
struct
bdev
*
bdev
)
int
btrfs_mount
(
struct
lxc_storage
*
bdev
)
{
{
unsigned
long
mntflags
;
unsigned
long
mntflags
;
char
*
mntdata
;
char
*
mntdata
;
...
@@ -209,7 +209,7 @@ int btrfs_mount(struct bdev *bdev)
...
@@ -209,7 +209,7 @@ int btrfs_mount(struct bdev *bdev)
return
ret
;
return
ret
;
}
}
int
btrfs_umount
(
struct
bdev
*
bdev
)
int
btrfs_umount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"btrfs"
))
if
(
strcmp
(
bdev
->
type
,
"btrfs"
))
return
-
22
;
return
-
22
;
...
@@ -341,7 +341,7 @@ out:
...
@@ -341,7 +341,7 @@ out:
return
ret
;
return
ret
;
}
}
static
int
btrfs_snapshot_wrapper
(
void
*
data
)
int
btrfs_snapshot_wrapper
(
void
*
data
)
{
{
struct
rsync_data_char
*
arg
=
data
;
struct
rsync_data_char
*
arg
=
data
;
if
(
setgid
(
0
)
<
0
)
{
if
(
setgid
(
0
)
<
0
)
{
...
@@ -357,10 +357,10 @@ static int btrfs_snapshot_wrapper(void *data)
...
@@ -357,10 +357,10 @@ static int btrfs_snapshot_wrapper(void *data)
return
btrfs_snapshot
(
arg
->
src
,
arg
->
dest
);
return
btrfs_snapshot
(
arg
->
src
,
arg
->
dest
);
}
}
int
btrfs_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
btrfs_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
struct
lxc_conf
*
conf
)
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
if
(
!
orig
->
dest
||
!
orig
->
src
)
if
(
!
orig
->
dest
||
!
orig
->
src
)
return
-
1
;
return
-
1
;
...
@@ -383,7 +383,6 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -383,7 +383,6 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
// in case rootfs is in custom path, reuse it
// in case rootfs is in custom path, reuse it
if
((
new
->
src
=
dir_new_path
(
orig
->
src
,
oldname
,
cname
,
oldpath
,
lxcpath
))
==
NULL
)
if
((
new
->
src
=
dir_new_path
(
orig
->
src
,
oldname
,
cname
,
oldpath
,
lxcpath
))
==
NULL
)
return
-
1
;
return
-
1
;
}
}
if
((
new
->
dest
=
strdup
(
new
->
src
))
==
NULL
)
if
((
new
->
dest
=
strdup
(
new
->
src
))
==
NULL
)
...
@@ -734,12 +733,12 @@ bool btrfs_try_remove_subvol(const char *path)
...
@@ -734,12 +733,12 @@ bool btrfs_try_remove_subvol(const char *path)
return
btrfs_recursive_destroy
(
path
)
==
0
;
return
btrfs_recursive_destroy
(
path
)
==
0
;
}
}
int
btrfs_destroy
(
struct
bdev
*
orig
)
int
btrfs_destroy
(
struct
lxc_storage
*
orig
)
{
{
return
btrfs_recursive_destroy
(
orig
->
src
);
return
btrfs_recursive_destroy
(
orig
->
src
);
}
}
int
btrfs_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
btrfs_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
bdev
->
src
=
strdup
(
dest
);
bdev
->
src
=
strdup
(
dest
);
...
...
src/lxc/storage/btrfs.h
View file @
0e8e6386
...
@@ -366,13 +366,10 @@ BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequenc
...
@@ -366,13 +366,10 @@ BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequenc
/* defined as btrfs_stack_root_ref_name_len */
/* defined as btrfs_stack_root_ref_name_len */
BTRFS_SETGET_STACK_FUNCS
(
stack_root_ref_name_len
,
struct
btrfs_root_ref
,
name_len
,
16
);
BTRFS_SETGET_STACK_FUNCS
(
stack_root_ref_name_len
,
struct
btrfs_root_ref
,
name_len
,
16
);
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
struct
mytree_node
{
struct
mytree_node
{
...
@@ -387,30 +384,30 @@ struct my_btrfs_tree {
...
@@ -387,30 +384,30 @@ struct my_btrfs_tree {
int
num
;
int
num
;
};
};
/*
extern
int
btrfs_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* Functions associated with a btrfs bdev struct.
const
char
*
oldname
,
const
char
*
cname
,
*/
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
btrfs_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
extern
int
btrfs_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
const
char
*
n
,
struct
bdev_specs
*
specs
);
struct
lxc_conf
*
conf
);
extern
int
btrfs_destroy
(
struct
lxc_storage
*
orig
);
int
btrfs_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
int
btrfs_detect
(
const
char
*
path
);
struct
bdev_specs
*
specs
);
extern
int
btrfs_mount
(
struct
lxc_storage
*
bdev
);
int
btrfs_destroy
(
struct
bdev
*
orig
);
extern
int
btrfs_umount
(
struct
lxc_storage
*
bdev
);
int
btrfs_detect
(
const
char
*
path
);
int
btrfs_mount
(
struct
bdev
*
bdev
);
extern
char
*
get_btrfs_subvol_path
(
int
fd
,
u64
dir_id
,
u64
objid
,
char
*
name
,
int
btrfs_umount
(
struct
bdev
*
bdev
);
int
name_len
);
extern
int
btrfs_list_get_path_rootid
(
int
fd
,
u64
*
treeid
);
/*
extern
bool
is_btrfs_fs
(
const
char
*
path
);
* Helper functions
extern
int
is_btrfs_subvol
(
const
char
*
path
);
*/
extern
bool
btrfs_try_remove_subvol
(
const
char
*
path
);
char
*
get_btrfs_subvol_path
(
int
fd
,
u64
dir_id
,
u64
objid
,
char
*
name
,
extern
int
btrfs_same_fs
(
const
char
*
orig
,
const
char
*
new
);
int
name_len
);
extern
int
btrfs_snapshot
(
const
char
*
orig
,
const
char
*
new
);
int
btrfs_list_get_path_rootid
(
int
fd
,
u64
*
treeid
);
extern
int
btrfs_snapshot_wrapper
(
void
*
data
);
bool
is_btrfs_fs
(
const
char
*
path
);
extern
bool
btrfs_create_clone
(
struct
lxc_conf
*
conf
,
struct
lxc_storage
*
orig
,
int
is_btrfs_subvol
(
const
char
*
path
);
struct
lxc_storage
*
new
,
uint64_t
newsize
);
bool
btrfs_try_remove_subvol
(
const
char
*
path
);
extern
bool
btrfs_create_snapshot
(
struct
lxc_conf
*
conf
,
int
btrfs_same_fs
(
const
char
*
orig
,
const
char
*
new
);
struct
lxc_storage
*
orig
,
int
btrfs_snapshot
(
const
char
*
orig
,
const
char
*
new
);
struct
lxc_storage
*
new
,
uint64_t
newsize
);
#endif /
/ __LXC_BTRFS_H
#endif
/
* __LXC_BTRFS_H */
src/lxc/storage/dir.c
View file @
0e8e6386
...
@@ -29,15 +29,15 @@
...
@@ -29,15 +29,15 @@
#include "storage.h"
#include "storage.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc
dir
,
lxc
);
lxc_log_define
(
dir
,
lxc
);
/*
/* For a simple directory bind mount, we substitute the old container name and
* for a simple directory bind mount, we substitute the old container
* paths for the new.
* name and paths for the new
*/
*/
int
dir_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
dir_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
int
len
,
ret
;
int
len
,
ret
;
...
@@ -62,8 +62,8 @@ int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -62,8 +62,8 @@ int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
return
0
;
return
0
;
}
}
int
dir_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
dir_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
if
(
specs
&&
specs
->
dir
)
if
(
specs
&&
specs
->
dir
)
bdev
->
src
=
strdup
(
specs
->
dir
);
bdev
->
src
=
strdup
(
specs
->
dir
);
...
@@ -87,7 +87,7 @@ int dir_create(struct bdev *bdev, const char *dest, const char *n,
...
@@ -87,7 +87,7 @@ int dir_create(struct bdev *bdev, const char *dest, const char *n,
return
0
;
return
0
;
}
}
int
dir_destroy
(
struct
bdev
*
orig
)
int
dir_destroy
(
struct
lxc_storage
*
orig
)
{
{
if
(
lxc_rmdir_onedev
(
orig
->
src
,
NULL
)
<
0
)
if
(
lxc_rmdir_onedev
(
orig
->
src
,
NULL
)
<
0
)
return
-
1
;
return
-
1
;
...
@@ -103,7 +103,7 @@ int dir_detect(const char *path)
...
@@ -103,7 +103,7 @@ int dir_detect(const char *path)
return
0
;
return
0
;
}
}
int
dir_mount
(
struct
bdev
*
bdev
)
int
dir_mount
(
struct
lxc_storage
*
bdev
)
{
{
unsigned
long
mntflags
;
unsigned
long
mntflags
;
char
*
mntdata
;
char
*
mntdata
;
...
@@ -132,7 +132,7 @@ int dir_mount(struct bdev *bdev)
...
@@ -132,7 +132,7 @@ int dir_mount(struct bdev *bdev)
return
ret
;
return
ret
;
}
}
int
dir_umount
(
struct
bdev
*
bdev
)
int
dir_umount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"dir"
))
if
(
strcmp
(
bdev
->
type
,
"dir"
))
return
-
22
;
return
-
22
;
...
...
src/lxc/storage/dir.h
View file @
0e8e6386
...
@@ -27,26 +27,21 @@
...
@@ -27,26 +27,21 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdint.h>
#include <stdint.h>
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/*
extern
int
dir_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* Functions associated with a dir bdev struct.
const
char
*
oldname
,
const
char
*
cname
,
*/
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
dir_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
extern
int
dir_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
struct
bdev_specs
*
specs
);
int
dir_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
int
dir_destroy
(
struct
lxc_storage
*
orig
);
struct
bdev_specs
*
specs
);
extern
int
dir_detect
(
const
char
*
path
);
int
dir_destroy
(
struct
bdev
*
orig
);
extern
int
dir_mount
(
struct
lxc_storage
*
bdev
);
int
dir_detect
(
const
char
*
path
);
extern
int
dir_umount
(
struct
lxc_storage
*
bdev
);
int
dir_mount
(
struct
bdev
*
bdev
);
int
dir_umount
(
struct
bdev
*
bdev
);
#endif
/* __LXC_DIR_H */
#endif
/* __LXC_DIR_H */
src/lxc/storage/loop.c
View file @
0e8e6386
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
#include "storage_utils.h"
#include "storage_utils.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
l
xcl
oop
,
lxc
);
lxc_log_define
(
loop
,
lxc
);
static
int
do_loop_create
(
const
char
*
path
,
uint64_t
size
,
const
char
*
fstype
);
static
int
do_loop_create
(
const
char
*
path
,
uint64_t
size
,
const
char
*
fstype
);
...
@@ -45,9 +45,10 @@ static int do_loop_create(const char *path, uint64_t size, const char *fstype);
...
@@ -45,9 +45,10 @@ static int do_loop_create(const char *path, uint64_t size, const char *fstype);
* No idea what the original blockdev will be called, but the copy will be
* No idea what the original blockdev will be called, but the copy will be
* called $lxcpath/$lxcname/rootdev
* called $lxcpath/$lxcname/rootdev
*/
*/
int
loop_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
loop_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
char
fstype
[
100
];
char
fstype
[
100
];
uint64_t
size
=
newsize
;
uint64_t
size
=
newsize
;
...
@@ -104,7 +105,7 @@ int loop_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -104,7 +105,7 @@ int loop_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
return
do_loop_create
(
srcdev
,
size
,
fstype
);
return
do_loop_create
(
srcdev
,
size
,
fstype
);
}
}
int
loop_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
loop_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
const
char
*
fstype
;
const
char
*
fstype
;
...
@@ -152,8 +153,7 @@ int loop_create(struct bdev *bdev, const char *dest, const char *n,
...
@@ -152,8 +153,7 @@ int loop_create(struct bdev *bdev, const char *dest, const char *n,
return
do_loop_create
(
srcdev
,
sz
,
fstype
);
return
do_loop_create
(
srcdev
,
sz
,
fstype
);
}
}
int
loop_destroy
(
struct
bdev
*
orig
)
int
loop_destroy
(
struct
lxc_storage
*
orig
)
{
{
return
unlink
(
orig
->
src
+
5
);
return
unlink
(
orig
->
src
+
5
);
}
}
...
@@ -175,7 +175,7 @@ int loop_detect(const char *path)
...
@@ -175,7 +175,7 @@ int loop_detect(const char *path)
return
0
;
return
0
;
}
}
int
loop_mount
(
struct
bdev
*
bdev
)
int
loop_mount
(
struct
lxc_storage
*
bdev
)
{
{
int
ret
,
loopfd
;
int
ret
,
loopfd
;
char
loname
[
MAXPATHLEN
];
char
loname
[
MAXPATHLEN
];
...
@@ -208,7 +208,7 @@ int loop_mount(struct bdev *bdev)
...
@@ -208,7 +208,7 @@ int loop_mount(struct bdev *bdev)
return
ret
;
return
ret
;
}
}
int
loop_umount
(
struct
bdev
*
bdev
)
int
loop_umount
(
struct
lxc_storage
*
bdev
)
{
{
int
ret
;
int
ret
;
...
...
src/lxc/storage/loop.h
View file @
0e8e6386
...
@@ -27,26 +27,21 @@
...
@@ -27,26 +27,21 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdint.h>
#include <stdint.h>
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/*
extern
int
loop_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* functions associated with a loop bdev struct
const
char
*
oldname
,
const
char
*
cname
,
*/
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
loop_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
extern
int
loop_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
n
,
struct
bdev_specs
*
specs
);
int
loop_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
int
loop_destroy
(
struct
lxc_storage
*
orig
);
struct
bdev_specs
*
specs
);
extern
int
loop_detect
(
const
char
*
path
);
int
loop_destroy
(
struct
bdev
*
orig
);
extern
int
loop_mount
(
struct
lxc_storage
*
bdev
);
int
loop_detect
(
const
char
*
path
);
extern
int
loop_umount
(
struct
lxc_storage
*
bdev
);
int
loop_mount
(
struct
bdev
*
bdev
);
int
loop_umount
(
struct
bdev
*
bdev
);
#endif
/* __LXC_LOOP_H */
#endif
/* __LXC_LOOP_H */
src/lxc/storage/lvm.c
View file @
0e8e6386
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
# include <sys/mkdev.h>
# include <sys/mkdev.h>
#endif
#endif
lxc_log_define
(
l
xcl
vm
,
lxc
);
lxc_log_define
(
lvm
,
lxc
);
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
const
char
*
oldpath
,
const
char
*
lxcpath
);
const
char
*
oldpath
,
const
char
*
lxcpath
);
...
@@ -160,7 +160,7 @@ int lvm_detect(const char *path)
...
@@ -160,7 +160,7 @@ int lvm_detect(const char *path)
return
1
;
return
1
;
}
}
int
lvm_mount
(
struct
bdev
*
bdev
)
int
lvm_mount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"lvm"
))
if
(
strcmp
(
bdev
->
type
,
"lvm"
))
return
-
22
;
return
-
22
;
...
@@ -171,7 +171,7 @@ int lvm_mount(struct bdev *bdev)
...
@@ -171,7 +171,7 @@ int lvm_mount(struct bdev *bdev)
return
mount_unknown_fs
(
bdev
->
src
,
bdev
->
dest
,
bdev
->
mntopts
);
return
mount_unknown_fs
(
bdev
->
src
,
bdev
->
dest
,
bdev
->
mntopts
);
}
}
int
lvm_umount
(
struct
bdev
*
bdev
)
int
lvm_umount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"lvm"
))
if
(
strcmp
(
bdev
->
type
,
"lvm"
))
return
-
22
;
return
-
22
;
...
@@ -276,9 +276,10 @@ int lvm_snapshot(const char *orig, const char *path, uint64_t size)
...
@@ -276,9 +276,10 @@ int lvm_snapshot(const char *orig, const char *path, uint64_t size)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
int
lvm_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
lvm_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
char
fstype
[
100
];
char
fstype
[
100
];
uint64_t
size
=
newsize
;
uint64_t
size
=
newsize
;
...
@@ -364,7 +365,7 @@ int lvm_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -364,7 +365,7 @@ int lvm_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
return
0
;
return
0
;
}
}
int
lvm_destroy
(
struct
bdev
*
orig
)
int
lvm_destroy
(
struct
lxc_storage
*
orig
)
{
{
pid_t
pid
;
pid_t
pid
;
...
@@ -378,8 +379,8 @@ int lvm_destroy(struct bdev *orig)
...
@@ -378,8 +379,8 @@ int lvm_destroy(struct bdev *orig)
return
wait_for_pid
(
pid
);
return
wait_for_pid
(
pid
);
}
}
int
lvm_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
lvm_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
const
char
*
vg
,
*
thinpool
,
*
fstype
,
*
lv
=
n
;
const
char
*
vg
,
*
thinpool
,
*
fstype
,
*
lv
=
n
;
uint64_t
sz
;
uint64_t
sz
;
...
...
src/lxc/storage/lvm.h
View file @
0e8e6386
...
@@ -27,30 +27,29 @@
...
@@ -27,30 +27,29 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdint.h>
#include <stdint.h>
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/*
extern
int
lvm_detect
(
const
char
*
path
);
* Functions associated with an lvm bdev struct.
extern
int
lvm_mount
(
struct
lxc_storage
*
bdev
);
*/
extern
int
lvm_umount
(
struct
lxc_storage
*
bdev
);
int
lvm_detect
(
const
char
*
path
);
extern
int
lvm_compare_lv_attr
(
const
char
*
path
,
int
pos
,
const
char
expected
);
int
lvm_mount
(
struct
bdev
*
bdev
);
extern
int
lvm_is_thin_volume
(
const
char
*
path
);
int
lvm_umount
(
struct
bdev
*
bdev
);
extern
int
lvm_is_thin_pool
(
const
char
*
path
);
int
lvm_compare_lv_attr
(
const
char
*
path
,
int
pos
,
const
char
expected
);
extern
int
lvm_snapshot
(
const
char
*
orig
,
const
char
*
path
,
uint64_t
size
);
int
lvm_is_thin_volume
(
const
char
*
path
);
extern
int
lvm_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
int
lvm_is_thin_pool
(
const
char
*
path
);
const
char
*
oldname
,
const
char
*
cname
,
int
lvm_snapshot
(
const
char
*
orig
,
const
char
*
path
,
uint64_t
size
);
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
lvm_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
extern
int
lvm_destroy
(
struct
lxc_storage
*
orig
);
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
extern
int
lvm_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
lvm_destroy
(
struct
bdev
*
orig
);
struct
bdev_specs
*
specs
);
int
lvm_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
bool
lvm_create_clone
(
struct
lxc_conf
*
conf
,
struct
lxc_storage
*
orig
,
struct
bdev_specs
*
specs
);
struct
lxc_storage
*
new
,
uint64_t
newsize
);
extern
bool
lvm_create_snapshot
(
struct
lxc_conf
*
conf
,
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
uint64_t
newsize
);
#endif
/* __LXC_LVM_H */
#endif
/* __LXC_LVM_H */
src/lxc/storage/nbd.c
View file @
0e8e6386
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
#include "storage_utils.h"
#include "storage_utils.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc
nbd
,
lxc
);
lxc_log_define
(
nbd
,
lxc
);
struct
nbd_attach_data
{
struct
nbd_attach_data
{
const
char
*
nbd
;
const
char
*
nbd
;
...
@@ -88,20 +88,21 @@ void detach_nbd_idx(int idx)
...
@@ -88,20 +88,21 @@ void detach_nbd_idx(int idx)
nbd_detach
(
path
);
nbd_detach
(
path
);
}
}
int
nbd_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
nbd_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
return
-
ENOSYS
;
return
-
ENOSYS
;
}
}
int
nbd_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
nbd_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
return
-
ENOSYS
;
return
-
ENOSYS
;
}
}
int
nbd_destroy
(
struct
bdev
*
orig
)
int
nbd_destroy
(
struct
lxc_storage
*
orig
)
{
{
return
-
ENOSYS
;
return
-
ENOSYS
;
}
}
...
@@ -113,7 +114,7 @@ int nbd_detect(const char *path)
...
@@ -113,7 +114,7 @@ int nbd_detect(const char *path)
return
0
;
return
0
;
}
}
int
nbd_mount
(
struct
bdev
*
bdev
)
int
nbd_mount
(
struct
lxc_storage
*
bdev
)
{
{
int
ret
=
-
1
,
partition
;
int
ret
=
-
1
,
partition
;
char
path
[
50
];
char
path
[
50
];
...
@@ -149,7 +150,7 @@ int nbd_mount(struct bdev *bdev)
...
@@ -149,7 +150,7 @@ int nbd_mount(struct bdev *bdev)
return
ret
;
return
ret
;
}
}
int
nbd_umount
(
struct
bdev
*
bdev
)
int
nbd_umount
(
struct
lxc_storage
*
bdev
)
{
{
int
ret
;
int
ret
;
...
...
src/lxc/storage/nbd.h
View file @
0e8e6386
...
@@ -28,31 +28,25 @@
...
@@ -28,31 +28,25 @@
#include <stdbool.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdint.h>
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/*
extern
int
nbd_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* Functions associated with an nbd bdev struct.
const
char
*
oldname
,
const
char
*
cname
,
*/
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
nbd_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
extern
int
nbd_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
struct
bdev_specs
*
specs
);
int
nbd_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
int
nbd_destroy
(
struct
lxc_storage
*
orig
);
struct
bdev_specs
*
specs
);
extern
int
nbd_detect
(
const
char
*
path
);
int
nbd_destroy
(
struct
bdev
*
orig
);
extern
int
nbd_mount
(
struct
lxc_storage
*
bdev
);
int
nbd_detect
(
const
char
*
path
);
extern
int
nbd_umount
(
struct
lxc_storage
*
bdev
);
int
nbd_mount
(
struct
bdev
*
bdev
);
int
nbd_umount
(
struct
bdev
*
bdev
);
extern
bool
attach_nbd
(
char
*
src
,
struct
lxc_conf
*
conf
);
extern
void
detach_nbd_idx
(
int
idx
);
/* helpers */
extern
bool
requires_nbd
(
const
char
*
path
);
bool
attach_nbd
(
char
*
src
,
struct
lxc_conf
*
conf
);
void
detach_nbd_idx
(
int
idx
);
bool
requires_nbd
(
const
char
*
path
);
#endif
/* __LXC_NBD_H */
#endif
/* __LXC_NBD_H */
src/lxc/storage/overlay.c
View file @
0e8e6386
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
#include "storage_utils.h"
#include "storage_utils.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc
overlay
,
lxc
);
lxc_log_define
(
overlay
,
lxc
);
static
char
*
ovl_name
;
static
char
*
ovl_name
;
static
char
*
ovl_version
[]
=
{
"overlay"
,
"overlayfs"
};
static
char
*
ovl_version
[]
=
{
"overlay"
,
"overlayfs"
};
...
@@ -47,7 +47,7 @@ extern char *dir_new_path(char *src, const char *oldname, const char *name,
...
@@ -47,7 +47,7 @@ extern char *dir_new_path(char *src, const char *oldname, const char *name,
const
char
*
oldpath
,
const
char
*
lxcpath
);
const
char
*
oldpath
,
const
char
*
lxcpath
);
static
char
*
ovl_detect_name
(
void
);
static
char
*
ovl_detect_name
(
void
);
static
int
ovl_do_rsync
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
static
int
ovl_do_rsync
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
struct
lxc_conf
*
conf
);
struct
lxc_conf
*
conf
);
static
int
ovl_rsync
(
struct
rsync_data
*
data
);
static
int
ovl_rsync
(
struct
rsync_data
*
data
);
static
int
ovl_rsync_wrapper
(
void
*
data
);
static
int
ovl_rsync_wrapper
(
void
*
data
);
...
@@ -55,7 +55,7 @@ static int ovl_remount_on_enodev(const char *lower, const char *target,
...
@@ -55,7 +55,7 @@ static int ovl_remount_on_enodev(const char *lower, const char *target,
const
char
*
name
,
unsigned
long
mountflags
,
const
char
*
name
,
unsigned
long
mountflags
,
const
void
*
options
);
const
void
*
options
);
int
ovl_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
ovl_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
...
@@ -242,8 +242,8 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -242,8 +242,8 @@ int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
* changes after starting the container are written to
* changes after starting the container are written to
* $lxcpath/$lxcname/delta0
* $lxcpath/$lxcname/delta0
*/
*/
int
ovl_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
ovl_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
char
*
delta
;
char
*
delta
;
int
ret
,
len
=
strlen
(
dest
),
newlen
;
int
ret
,
len
=
strlen
(
dest
),
newlen
;
...
@@ -284,7 +284,7 @@ int ovl_create(struct bdev *bdev, const char *dest, const char *n,
...
@@ -284,7 +284,7 @@ int ovl_create(struct bdev *bdev, const char *dest, const char *n,
return
0
;
return
0
;
}
}
int
ovl_destroy
(
struct
bdev
*
orig
)
int
ovl_destroy
(
struct
lxc_storage
*
orig
)
{
{
char
*
upper
;
char
*
upper
;
...
@@ -312,7 +312,7 @@ char *ovl_getlower(char *p)
...
@@ -312,7 +312,7 @@ char *ovl_getlower(char *p)
return
p
;
return
p
;
}
}
int
ovl_mount
(
struct
bdev
*
bdev
)
int
ovl_mount
(
struct
lxc_storage
*
bdev
)
{
{
char
*
tmp
,
*
options
,
*
dup
,
*
lower
,
*
upper
;
char
*
tmp
,
*
options
,
*
dup
,
*
lower
,
*
upper
;
char
*
options_work
,
*
work
,
*
lastslash
;
char
*
options_work
,
*
work
,
*
lastslash
;
...
@@ -439,7 +439,7 @@ int ovl_mount(struct bdev *bdev)
...
@@ -439,7 +439,7 @@ int ovl_mount(struct bdev *bdev)
return
ret
;
return
ret
;
}
}
int
ovl_umount
(
struct
bdev
*
bdev
)
int
ovl_umount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"overlayfs"
))
if
(
strcmp
(
bdev
->
type
,
"overlayfs"
))
return
-
22
;
return
-
22
;
...
@@ -743,7 +743,8 @@ static char *ovl_detect_name(void)
...
@@ -743,7 +743,8 @@ static char *ovl_detect_name(void)
return
v
;
return
v
;
}
}
static
int
ovl_do_rsync
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
struct
lxc_conf
*
conf
)
static
int
ovl_do_rsync
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
struct
lxc_conf
*
conf
)
{
{
int
ret
=
-
1
;
int
ret
=
-
1
;
struct
rsync_data
rdata
;
struct
rsync_data
rdata
;
...
...
src/lxc/storage/overlay.h
View file @
0e8e6386
...
@@ -35,59 +35,50 @@
...
@@ -35,59 +35,50 @@
#include <mntent.h>
#include <mntent.h>
#endif
#endif
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/* defined in conf.h */
struct
lxc_rootfs
;
struct
lxc_rootfs
;
/*
extern
int
ovl_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* Functions associated with an overlay bdev struct.
const
char
*
oldname
,
const
char
*
cname
,
*/
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
ovl_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
extern
int
ovl_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
struct
bdev_specs
*
specs
);
int
ovl_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
int
ovl_destroy
(
struct
lxc_storage
*
orig
);
struct
bdev_specs
*
specs
);
extern
int
ovl_detect
(
const
char
*
path
);
int
ovl_destroy
(
struct
bdev
*
orig
);
extern
int
ovl_mount
(
struct
lxc_storage
*
bdev
);
int
ovl_detect
(
const
char
*
path
);
extern
int
ovl_umount
(
struct
lxc_storage
*
bdev
);
int
ovl_mount
(
struct
bdev
*
bdev
);
int
ovl_umount
(
struct
bdev
*
bdev
);
/*
/* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
* with overlay lxc.mount.entry entries we need to update absolute paths for
* with overlay lxc.mount.entry entries we need to update absolute paths for
* upper- and workdir. This update is done in two locations:
* upper- and workdir. This update is done in two locations:
* lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
* lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
* independent of each other since lxc_conf->mountlist may container more mount
* independent of each other since lxc_conf->mountlist may container more mount
* entries (e.g. from other included files) than lxc_conf->unexpanded_config .
* entries (e.g. from other included files) than lxc_conf->unexpanded_config .
*/
*/
int
ovl_update_abs_paths
(
struct
lxc_conf
*
lxc_conf
,
const
char
*
lxc_path
,
extern
int
ovl_update_abs_paths
(
struct
lxc_conf
*
lxc_conf
,
const
char
*
lxc_path
,
const
char
*
lxc_name
,
const
char
*
newpath
,
const
char
*
lxc_name
,
const
char
*
newpath
,
const
char
*
newname
);
const
char
*
newname
);
/*
/* To be called from functions in lxccontainer.c: Get lower directory for
* To be called from functions in lxccontainer.c: Get lower directory for
* overlay rootfs.
* overlay rootfs.
*/
*/
char
*
ovl_getlower
(
char
*
p
);
extern
char
*
ovl_get_lower
(
const
char
*
rootfs_path
);
/*
/* Get rootfs path for overlay backed containers. Allocated memory must be freed
* Get rootfs path for overlay backed containers. Allocated memory must be freed
* by caller.
* by caller.
*/
*/
char
*
ovl_get_rootfs
(
const
char
*
rootfs_path
,
size_t
*
rootfslen
);
extern
char
*
ovl_get_rootfs
(
const
char
*
rootfs_path
,
size_t
*
rootfslen
);
/*
/* Create upper- and workdirs for overlay mounts.
* Create upper- and workdirs for overlay mounts.
*/
*/
int
ovl_mkdir
(
const
struct
mntent
*
mntent
,
const
struct
lxc_rootfs
*
rootfs
,
extern
int
ovl_mkdir
(
const
struct
mntent
*
mntent
,
const
char
*
lxc_name
,
const
char
*
lxc_path
);
const
struct
lxc_rootfs
*
rootfs
,
const
char
*
lxc_name
,
const
char
*
lxc_path
);
#endif
/* __LXC_OVERLAY_H */
#endif
/* __LXC_OVERLAY_H */
src/lxc/storage/rbd.c
View file @
0e8e6386
...
@@ -34,9 +34,9 @@
...
@@ -34,9 +34,9 @@
#include "storage_utils.h"
#include "storage_utils.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc
rbd
,
lxc
);
lxc_log_define
(
rbd
,
lxc
);
int
rbd_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
rbd_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
...
@@ -44,8 +44,8 @@ int rbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -44,8 +44,8 @@ int rbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
return
-
1
;
return
-
1
;
}
}
int
rbd_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
rbd_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
const
char
*
rbdpool
,
*
rbdname
=
n
,
*
fstype
;
const
char
*
rbdpool
,
*
rbdname
=
n
,
*
fstype
;
uint64_t
size
;
uint64_t
size
;
...
@@ -125,7 +125,7 @@ int rbd_create(struct bdev *bdev, const char *dest, const char *n,
...
@@ -125,7 +125,7 @@ int rbd_create(struct bdev *bdev, const char *dest, const char *n,
return
0
;
return
0
;
}
}
int
rbd_destroy
(
struct
bdev
*
orig
)
int
rbd_destroy
(
struct
lxc_storage
*
orig
)
{
{
pid_t
pid
;
pid_t
pid
;
char
*
rbdfullname
;
char
*
rbdfullname
;
...
@@ -160,7 +160,7 @@ int rbd_detect(const char *path)
...
@@ -160,7 +160,7 @@ int rbd_detect(const char *path)
return
0
;
return
0
;
}
}
int
rbd_mount
(
struct
bdev
*
bdev
)
int
rbd_mount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"rbd"
))
if
(
strcmp
(
bdev
->
type
,
"rbd"
))
return
-
22
;
return
-
22
;
...
@@ -176,7 +176,7 @@ int rbd_mount(struct bdev *bdev)
...
@@ -176,7 +176,7 @@ int rbd_mount(struct bdev *bdev)
return
mount_unknown_fs
(
bdev
->
src
,
bdev
->
dest
,
bdev
->
mntopts
);
return
mount_unknown_fs
(
bdev
->
src
,
bdev
->
dest
,
bdev
->
mntopts
);
}
}
int
rbd_umount
(
struct
bdev
*
bdev
)
int
rbd_umount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"rbd"
))
if
(
strcmp
(
bdev
->
type
,
"rbd"
))
return
-
22
;
return
-
22
;
...
...
src/lxc/storage/rbd.h
View file @
0e8e6386
...
@@ -27,26 +27,21 @@
...
@@ -27,26 +27,21 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <stdint.h>
#include <stdint.h>
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/*
extern
int
rbd_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* Functions associated with an rdb bdev struct.
const
char
*
oldname
,
const
char
*
cname
,
*/
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
rbd_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
extern
int
rbd_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
struct
bdev_specs
*
specs
);
int
rbd_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
int
rbd_destroy
(
struct
lxc_storage
*
orig
);
struct
bdev_specs
*
specs
);
extern
int
rbd_detect
(
const
char
*
path
);
int
rbd_destroy
(
struct
bdev
*
orig
);
extern
int
rbd_mount
(
struct
lxc_storage
*
bdev
);
int
rbd_detect
(
const
char
*
path
);
extern
int
rbd_umount
(
struct
lxc_storage
*
bdev
);
int
rbd_mount
(
struct
bdev
*
bdev
);
int
rbd_umount
(
struct
bdev
*
bdev
);
#endif
/* __LXC_RDB_H */
#endif
/* __LXC_RDB_H */
src/lxc/storage/rsync.c
View file @
0e8e6386
...
@@ -37,7 +37,7 @@
...
@@ -37,7 +37,7 @@
#include "storage.h"
#include "storage.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc
rsync
,
lxc
);
lxc_log_define
(
rsync
,
lxc
);
/* the bulk of this needs to become a common helper */
/* the bulk of this needs to become a common helper */
int
do_rsync
(
const
char
*
src
,
const
char
*
dest
)
int
do_rsync
(
const
char
*
src
,
const
char
*
dest
)
...
@@ -93,8 +93,7 @@ int rsync_delta_wrapper(void *data)
...
@@ -93,8 +93,7 @@ int rsync_delta_wrapper(void *data)
int
rsync_rootfs
(
struct
rsync_data
*
data
)
int
rsync_rootfs
(
struct
rsync_data
*
data
)
{
{
struct
bdev
*
orig
=
data
->
orig
,
struct
lxc_storage
*
orig
=
data
->
orig
,
*
new
=
data
->
new
;
*
new
=
data
->
new
;
if
(
unshare
(
CLONE_NEWNS
)
<
0
)
{
if
(
unshare
(
CLONE_NEWNS
)
<
0
)
{
SYSERROR
(
"unshare CLONE_NEWNS"
);
SYSERROR
(
"unshare CLONE_NEWNS"
);
...
@@ -139,4 +138,3 @@ int rsync_rootfs_wrapper(void *data)
...
@@ -139,4 +138,3 @@ int rsync_rootfs_wrapper(void *data)
struct
rsync_data
*
arg
=
data
;
struct
rsync_data
*
arg
=
data
;
return
rsync_rootfs
(
arg
);
return
rsync_rootfs
(
arg
);
}
}
src/lxc/storage/rsync.h
View file @
0e8e6386
...
@@ -28,8 +28,8 @@
...
@@ -28,8 +28,8 @@
#include <stdio.h>
#include <stdio.h>
struct
rsync_data
{
struct
rsync_data
{
struct
bdev
*
orig
;
struct
lxc_storage
*
orig
;
struct
bdev
*
new
;
struct
lxc_storage
*
new
;
};
};
struct
rsync_data_char
{
struct
rsync_data_char
{
...
...
src/lxc/storage/storage.c
View file @
0e8e6386
This diff is collapsed.
Click to expand it.
src/lxc/storage/storage.h
View file @
0e8e6386
...
@@ -57,19 +57,19 @@
...
@@ -57,19 +57,19 @@
#define DEFAULT_FS_SIZE 1073741824
#define DEFAULT_FS_SIZE 1073741824
#define DEFAULT_FSTYPE "ext3"
#define DEFAULT_FSTYPE "ext3"
struct
bdev
;
struct
lxc_storage
;
struct
bdev
_ops
{
struct
lxc_storage
_ops
{
/* detect whether path is of this bdev type */
/* detect whether path is of this bdev type */
int
(
*
detect
)(
const
char
*
path
);
int
(
*
detect
)(
const
char
*
path
);
// mount requires src and dest to be set.
// mount requires src and dest to be set.
int
(
*
mount
)(
struct
bdev
*
bdev
);
int
(
*
mount
)(
struct
lxc_storage
*
bdev
);
int
(
*
umount
)(
struct
bdev
*
bdev
);
int
(
*
umount
)(
struct
lxc_storage
*
bdev
);
int
(
*
destroy
)(
struct
bdev
*
bdev
);
int
(
*
destroy
)(
struct
lxc_storage
*
bdev
);
int
(
*
create
)(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
(
*
create
)(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
);
struct
bdev_specs
*
specs
);
/* given original mount, rename the paths for cloned container */
/* given original mount, rename the paths for cloned container */
int
(
*
clone_paths
)(
struct
bdev
*
orig
,
struct
bdev
*
new
,
int
(
*
clone_paths
)(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
...
@@ -77,15 +77,13 @@ struct bdev_ops {
...
@@ -77,15 +77,13 @@ struct bdev_ops {
bool
can_backup
;
bool
can_backup
;
};
};
/*
/* When lxc is mounting a rootfs, then src will be the "lxc.rootfs.path" value,
* When lxc-start is mounting a rootfs, then src will be the "lxc.rootfs" value,
* dest will be the mount dir (i.e. "<libdir>/lxc") When clone or create is
* dest will be mount dir (i.e. $libdir/lxc) When clone or create is doing so,
* doing so, then dest will be "<lxcpath>/<lxcname>/rootfs", since we may need
* then dest will be $lxcpath/$lxcname/rootfs, since we may need to rsync from
* to rsync from one to the other.
* one to the other.
* data is so far unused.
*/
*/
struct
bdev
{
struct
lxc_storage
{
const
struct
bdev
_ops
*
ops
;
const
struct
lxc_storage
_ops
*
ops
;
const
char
*
type
;
const
char
*
type
;
char
*
src
;
char
*
src
;
char
*
dest
;
char
*
dest
;
...
@@ -97,33 +95,35 @@ struct bdev {
...
@@ -97,33 +95,35 @@ struct bdev {
int
nbd_idx
;
int
nbd_idx
;
};
};
bool
bdev
_is_dir
(
struct
lxc_conf
*
conf
,
const
char
*
path
);
extern
bool
storage
_is_dir
(
struct
lxc_conf
*
conf
,
const
char
*
path
);
bool
bdev
_can_backup
(
struct
lxc_conf
*
conf
);
extern
bool
storage
_can_backup
(
struct
lxc_conf
*
conf
);
/*
/* Instantiate a lxc_storage object. The src is used to determine which blockdev
* Instantiate a bdev object. The src is used to determine which blockdev type
* type this should be. The dst and data are optional, and will be used in case
* this should be. The dst and data are optional, and will be used in case of
* of mount/umount.
* mount/umount.
*
*
*
Optionally, src can be 'dir:/var/lib/lxc/c1' or 'lvm:/dev/lxc/c1'. Fo
r
*
The source will be "dir:/var/lib/lxc/c1" or "lvm:/dev/lxc/c1". For othe
r
*
other
backing stores, this will allow additional options. In particular,
* backing stores, this will allow additional options. In particular,
* "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean
* "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean
use
*
use /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta
*
/var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta as the
*
as the
upper, writeable layer.
* upper, writeable layer.
*/
*/
struct
bdev
*
bdev_init
(
struct
lxc_conf
*
conf
,
const
char
*
src
,
const
char
*
dst
,
extern
struct
lxc_storage
*
storage_init
(
struct
lxc_conf
*
conf
,
const
char
*
src
,
const
char
*
data
);
const
char
*
dst
,
const
char
*
data
);
struct
bdev
*
bdev_copy
(
struct
lxc_container
*
c0
,
const
char
*
cname
,
extern
struct
lxc_storage
*
storage_copy
(
struct
lxc_container
*
c0
,
const
char
*
lxcpath
,
const
char
*
bdevtype
,
int
flags
,
const
char
*
cname
,
const
char
*
lxcpath
,
const
char
*
bdevdata
,
uint64_t
newsize
,
int
*
needs_rdep
);
const
char
*
bdevtype
,
int
flags
,
struct
bdev
*
bdev_create
(
const
char
*
dest
,
const
char
*
type
,
const
char
*
cname
,
const
char
*
bdevdata
,
uint64_t
newsize
,
struct
bdev_specs
*
specs
);
int
*
needs_rdep
);
void
bdev_put
(
struct
bdev
*
bdev
);
extern
struct
lxc_storage
*
storage_create
(
const
char
*
dest
,
const
char
*
type
,
bool
bdev_destroy
(
struct
lxc_conf
*
conf
);
const
char
*
cname
,
struct
bdev_specs
*
specs
);
extern
void
storage_put
(
struct
lxc_storage
*
bdev
);
extern
bool
storage_destroy
(
struct
lxc_conf
*
conf
);
/* callback function to be used with userns_exec_1() */
/* callback function to be used with userns_exec_1() */
int
bdev
_destroy_wrapper
(
void
*
data
);
extern
int
storage
_destroy_wrapper
(
void
*
data
);
extern
bool
rootfs_is_blockdev
(
struct
lxc_conf
*
conf
);
extern
bool
rootfs_is_blockdev
(
struct
lxc_conf
*
conf
);
#endif // __LXC_STORAGE_H
#endif // __LXC_STORAGE_H
src/lxc/storage/storage_utils.c
View file @
0e8e6386
...
@@ -126,7 +126,7 @@ bool attach_block_device(struct lxc_conf *conf)
...
@@ -126,7 +126,7 @@ bool attach_block_device(struct lxc_conf *conf)
/*
/*
* return block size of dev->src in units of bytes
* return block size of dev->src in units of bytes
*/
*/
int
blk_getsize
(
struct
bdev
*
bdev
,
uint64_t
*
size
)
int
blk_getsize
(
struct
lxc_storage
*
bdev
,
uint64_t
*
size
)
{
{
int
fd
,
ret
;
int
fd
,
ret
;
char
*
path
=
bdev
->
src
;
char
*
path
=
bdev
->
src
;
...
@@ -150,14 +150,14 @@ void detach_block_device(struct lxc_conf *conf)
...
@@ -150,14 +150,14 @@ void detach_block_device(struct lxc_conf *conf)
}
}
/*
/*
* Given a
bdev
(presumably blockdev-based), detect the fstype
* Given a
lxc_storage
(presumably blockdev-based), detect the fstype
* by trying mounting (in a private mntns) it.
* by trying mounting (in a private mntns) it.
* @
bdev
: bdev to investigate
* @
lxc_storage
: bdev to investigate
* @type: preallocated char* in which to write the fstype
* @type: preallocated char* in which to write the fstype
* @len: length of passed in char*
* @len: length of passed in char*
* Returns length of fstype, of -1 on error
* Returns length of fstype, of -1 on error
*/
*/
int
detect_fs
(
struct
bdev
*
bdev
,
char
*
type
,
int
len
)
int
detect_fs
(
struct
lxc_storage
*
bdev
,
char
*
type
,
int
len
)
{
{
int
p
[
2
],
ret
;
int
p
[
2
],
ret
;
size_t
linelen
;
size_t
linelen
;
...
@@ -285,7 +285,7 @@ int do_mkfs_exec_wrapper(void *args)
...
@@ -285,7 +285,7 @@ int do_mkfs_exec_wrapper(void *args)
* This will return 1 for physical disks, qemu-nbd, loop, etc right now only lvm
* This will return 1 for physical disks, qemu-nbd, loop, etc right now only lvm
* is a block device.
* is a block device.
*/
*/
int
is_blktype
(
struct
bdev
*
b
)
int
is_blktype
(
struct
lxc_storage
*
b
)
{
{
if
(
strcmp
(
b
->
type
,
"lvm"
)
==
0
)
if
(
strcmp
(
b
->
type
,
"lvm"
)
==
0
)
return
1
;
return
1
;
...
@@ -411,7 +411,7 @@ char *linkderef(char *path, char *dest)
...
@@ -411,7 +411,7 @@ char *linkderef(char *path, char *dest)
/*
/*
* is an unprivileged user allowed to make this kind of snapshot
* is an unprivileged user allowed to make this kind of snapshot
*/
*/
bool
unpriv_snap_allowed
(
struct
bdev
*
b
,
const
char
*
t
,
bool
snap
,
bool
unpriv_snap_allowed
(
struct
lxc_storage
*
b
,
const
char
*
t
,
bool
snap
,
bool
maybesnap
)
bool
maybesnap
)
{
{
if
(
!
t
)
{
if
(
!
t
)
{
...
@@ -440,7 +440,7 @@ bool unpriv_snap_allowed(struct bdev *b, const char *t, bool snap,
...
@@ -440,7 +440,7 @@ bool unpriv_snap_allowed(struct bdev *b, const char *t, bool snap,
return
false
;
return
false
;
}
}
bool
is_valid_
bdev
_type
(
const
char
*
type
)
bool
is_valid_
storage
_type
(
const
char
*
type
)
{
{
if
(
strcmp
(
type
,
"dir"
)
==
0
||
if
(
strcmp
(
type
,
"dir"
)
==
0
||
strcmp
(
type
,
"btrfs"
)
==
0
||
strcmp
(
type
,
"btrfs"
)
==
0
||
...
@@ -456,7 +456,7 @@ bool is_valid_bdev_type(const char *type)
...
@@ -456,7 +456,7 @@ bool is_valid_bdev_type(const char *type)
return
false
;
return
false
;
}
}
int
bdev
_destroy_wrapper
(
void
*
data
)
int
storage
_destroy_wrapper
(
void
*
data
)
{
{
struct
lxc_conf
*
conf
=
data
;
struct
lxc_conf
*
conf
=
data
;
...
@@ -473,7 +473,7 @@ int bdev_destroy_wrapper(void *data)
...
@@ -473,7 +473,7 @@ int bdev_destroy_wrapper(void *data)
return
-
1
;
return
-
1
;
}
}
if
(
!
bdev
_destroy
(
conf
))
if
(
!
storage
_destroy
(
conf
))
return
-
1
;
return
-
1
;
return
0
;
return
0
;
...
...
src/lxc/storage/storage_utils.h
View file @
0e8e6386
...
@@ -31,24 +31,24 @@
...
@@ -31,24 +31,24 @@
#include "conf.h"
#include "conf.h"
struct
bdev
;
struct
lxc_storage
;
struct
lxc_conf
;
struct
lxc_conf
;
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
extern
char
*
dir_new_path
(
char
*
src
,
const
char
*
oldname
,
const
char
*
name
,
const
char
*
oldpath
,
const
char
*
lxcpath
);
const
char
*
oldpath
,
const
char
*
lxcpath
);
extern
bool
attach_block_device
(
struct
lxc_conf
*
conf
);
extern
bool
attach_block_device
(
struct
lxc_conf
*
conf
);
extern
void
detach_block_device
(
struct
lxc_conf
*
conf
);
extern
void
detach_block_device
(
struct
lxc_conf
*
conf
);
extern
int
blk_getsize
(
struct
bdev
*
bdev
,
uint64_t
*
size
);
extern
int
blk_getsize
(
struct
lxc_storage
*
bdev
,
uint64_t
*
size
);
extern
int
detect_fs
(
struct
bdev
*
bdev
,
char
*
type
,
int
len
);
extern
int
detect_fs
(
struct
lxc_storage
*
bdev
,
char
*
type
,
int
len
);
extern
int
do_mkfs_exec_wrapper
(
void
*
args
);
extern
int
do_mkfs_exec_wrapper
(
void
*
args
);
extern
int
is_blktype
(
struct
bdev
*
b
);
extern
int
is_blktype
(
struct
lxc_storage
*
b
);
extern
int
mount_unknown_fs
(
const
char
*
rootfs
,
const
char
*
target
,
extern
int
mount_unknown_fs
(
const
char
*
rootfs
,
const
char
*
target
,
const
char
*
options
);
const
char
*
options
);
extern
int
find_fstype_cb
(
char
*
buffer
,
void
*
data
);
extern
int
find_fstype_cb
(
char
*
buffer
,
void
*
data
);
extern
char
*
linkderef
(
char
*
path
,
char
*
dest
);
extern
char
*
linkderef
(
char
*
path
,
char
*
dest
);
extern
bool
unpriv_snap_allowed
(
struct
bdev
*
b
,
const
char
*
t
,
bool
snap
,
extern
bool
unpriv_snap_allowed
(
struct
lxc_storage
*
b
,
const
char
*
t
,
bool
snap
,
bool
maybesnap
);
bool
maybesnap
);
extern
bool
is_valid_
bdev
_type
(
const
char
*
type
);
extern
bool
is_valid_
storage
_type
(
const
char
*
type
);
extern
int
bdev
_destroy_wrapper
(
void
*
data
);
extern
int
storage
_destroy_wrapper
(
void
*
data
);
#endif /
/ __LXC_STORAGE_UTILS_H
#endif
/
* __LXC_STORAGE_UTILS_H */
src/lxc/storage/zfs.c
View file @
0e8e6386
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
#include "utils.h"
#include "utils.h"
#include "zfs.h"
#include "zfs.h"
lxc_log_define
(
lxc
zfs
,
lxc
);
lxc_log_define
(
zfs
,
lxc
);
/*
/*
* zfs ops:
* zfs ops:
...
@@ -83,7 +83,7 @@ int zfs_detect(const char *path)
...
@@ -83,7 +83,7 @@ int zfs_detect(const char *path)
return
found
;
return
found
;
}
}
int
zfs_mount
(
struct
bdev
*
bdev
)
int
zfs_mount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"zfs"
))
if
(
strcmp
(
bdev
->
type
,
"zfs"
))
return
-
22
;
return
-
22
;
...
@@ -104,7 +104,7 @@ int zfs_mount(struct bdev *bdev)
...
@@ -104,7 +104,7 @@ int zfs_mount(struct bdev *bdev)
return
ret
;
return
ret
;
}
}
int
zfs_umount
(
struct
bdev
*
bdev
)
int
zfs_umount
(
struct
lxc_storage
*
bdev
)
{
{
if
(
strcmp
(
bdev
->
type
,
"zfs"
))
if
(
strcmp
(
bdev
->
type
,
"zfs"
))
return
-
22
;
return
-
22
;
...
@@ -201,7 +201,7 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
...
@@ -201,7 +201,7 @@ int zfs_clone(const char *opath, const char *npath, const char *oname,
}
}
}
}
int
zfs_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
int
zfs_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
const
char
*
oldname
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
uint64_t
newsize
,
struct
lxc_conf
*
conf
)
{
{
...
@@ -235,7 +235,7 @@ int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
...
@@ -235,7 +235,7 @@ int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
* snapshot it was based on, so that we don't hold the original
* snapshot it was based on, so that we don't hold the original
* container busy.
* container busy.
*/
*/
int
zfs_destroy
(
struct
bdev
*
orig
)
int
zfs_destroy
(
struct
lxc_storage
*
orig
)
{
{
pid_t
pid
;
pid_t
pid
;
char
output
[
MAXPATHLEN
];
char
output
[
MAXPATHLEN
];
...
@@ -260,8 +260,8 @@ int zfs_destroy(struct bdev *orig)
...
@@ -260,8 +260,8 @@ int zfs_destroy(struct bdev *orig)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
int
zfs_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
zfs_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
struct
bdev_specs
*
specs
)
struct
bdev_specs
*
specs
)
{
{
const
char
*
zfsroot
;
const
char
*
zfsroot
;
char
option
[
MAXPATHLEN
];
char
option
[
MAXPATHLEN
];
...
...
src/lxc/storage/zfs.h
View file @
0e8e6386
...
@@ -28,8 +28,7 @@
...
@@ -28,8 +28,7 @@
#include <stdio.h>
#include <stdio.h>
#include <stdint.h>
#include <stdint.h>
/* defined in bdev.h */
struct
lxc_storage
;
struct
bdev
;
/* defined in lxccontainer.h */
/* defined in lxccontainer.h */
struct
bdev_specs
;
struct
bdev_specs
;
...
@@ -37,25 +36,20 @@ struct bdev_specs;
...
@@ -37,25 +36,20 @@ struct bdev_specs;
/* defined conf.h */
/* defined conf.h */
struct
lxc_conf
;
struct
lxc_conf
;
/*
extern
int
zfs_clonepaths
(
struct
lxc_storage
*
orig
,
struct
lxc_storage
*
new
,
* Functions associated with an zfs bdev struct.
const
char
*
oldname
,
const
char
*
cname
,
*/
const
char
*
oldpath
,
const
char
*
lxcpath
,
int
snap
,
int
zfs_clone
(
const
char
*
opath
,
const
char
*
npath
,
const
char
*
oname
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
const
char
*
nname
,
const
char
*
lxcpath
,
int
snapshot
);
extern
int
zfs_create
(
struct
lxc_storage
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
int
zfs_clonepaths
(
struct
bdev
*
orig
,
struct
bdev
*
new
,
const
char
*
oldname
,
struct
bdev_specs
*
specs
);
const
char
*
cname
,
const
char
*
oldpath
,
const
char
*
lxcpath
,
extern
int
zfs_destroy
(
struct
lxc_storage
*
orig
);
int
snap
,
uint64_t
newsize
,
struct
lxc_conf
*
conf
);
extern
int
zfs_detect
(
const
char
*
path
);
int
zfs_create
(
struct
bdev
*
bdev
,
const
char
*
dest
,
const
char
*
n
,
extern
int
zfs_mount
(
struct
lxc_storage
*
bdev
);
struct
bdev_specs
*
specs
);
extern
int
zfs_umount
(
struct
lxc_storage
*
bdev
);
/*
* TODO: detect whether this was a clone, and if so then also delete the
extern
bool
zfs_copy
(
struct
lxc_conf
*
conf
,
struct
lxc_storage
*
orig
,
* snapshot it was based on, so that we don't hold the original
struct
lxc_storage
*
new
,
uint64_t
newsize
);
* container busy.
extern
bool
zfs_snapshot
(
struct
lxc_conf
*
conf
,
struct
lxc_storage
*
orig
,
*/
struct
lxc_storage
*
new
,
uint64_t
newsize
);
int
zfs_destroy
(
struct
bdev
*
orig
);
int
zfs_detect
(
const
char
*
path
);
int
zfs_list_entry
(
const
char
*
path
,
char
*
output
,
size_t
inlen
);
int
zfs_mount
(
struct
bdev
*
bdev
);
int
zfs_umount
(
struct
bdev
*
bdev
);
#endif
/* __LXC_ZFS_H */
#endif
/* __LXC_ZFS_H */
src/lxc/tools/lxc_create.c
View file @
0e8e6386
...
@@ -251,7 +251,7 @@ int main(int argc, char *argv[])
...
@@ -251,7 +251,7 @@ int main(int argc, char *argv[])
// Final check whether the user gave use a valid bdev type.
// Final check whether the user gave use a valid bdev type.
if
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
&&
if
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
&&
strcmp
(
my_args
.
bdevtype
,
"_unset"
)
&&
strcmp
(
my_args
.
bdevtype
,
"_unset"
)
&&
!
is_valid_
bdev
_type
(
my_args
.
bdevtype
))
{
!
is_valid_
storage
_type
(
my_args
.
bdevtype
))
{
fprintf
(
stderr
,
"%s is not a valid backing storage type.
\n
"
,
my_args
.
bdevtype
);
fprintf
(
stderr
,
"%s is not a valid backing storage type.
\n
"
,
my_args
.
bdevtype
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
...
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