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
e9b0c679
Commit
e9b0c679
authored
Jun 29, 2018
by
2xsec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-copy: share internal API symbols
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
d899f11b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
40 deletions
+54
-40
Makefile.am
src/lxc/Makefile.am
+1
-1
lxc_copy.c
src/lxc/tools/lxc_copy.c
+53
-39
No files found.
src/lxc/Makefile.am
View file @
e9b0c679
...
@@ -277,7 +277,7 @@ lxc_freeze_SOURCES = tools/lxc_freeze.c tools/arguments.c
...
@@ -277,7 +277,7 @@ lxc_freeze_SOURCES = tools/lxc_freeze.c tools/arguments.c
lxc_info_SOURCES
=
tools/lxc_info.c tools/arguments.c
lxc_info_SOURCES
=
tools/lxc_info.c tools/arguments.c
lxc_monitor_SOURCES
=
tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
lxc_monitor_SOURCES
=
tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
lxc_ls_SOURCES
=
tools/lxc_ls.c tools/arguments.c
lxc_ls_SOURCES
=
tools/lxc_ls.c tools/arguments.c
lxc_copy_SOURCES
=
tools/lxc_copy.c tools/arguments.c
tools/tool_utils.c
lxc_copy_SOURCES
=
tools/lxc_copy.c tools/arguments.c
lxc_start_SOURCES
=
tools/lxc_start.c tools/arguments.c
lxc_start_SOURCES
=
tools/lxc_start.c tools/arguments.c
lxc_stop_SOURCES
=
tools/lxc_stop.c tools/arguments.c
lxc_stop_SOURCES
=
tools/lxc_stop.c tools/arguments.c
lxc_top_SOURCES
=
tools/lxc_top.c tools/arguments.c tools/tool_utils.c
lxc_top_SOURCES
=
tools/lxc_top.c tools/arguments.c tools/tool_utils.c
...
...
src/lxc/tools/lxc_copy.c
View file @
e9b0c679
...
@@ -36,12 +36,15 @@
...
@@ -36,12 +36,15 @@
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "arguments.h"
#include "tool_utils.h"
#include "log.h"
#include "utils.h"
#ifndef HAVE_GETSUBOPT
#ifndef HAVE_GETSUBOPT
#include "include/getsubopt.h"
#include "include/getsubopt.h"
#endif
#endif
lxc_log_define
(
lxc_copy
,
lxc
);
enum
mnttype
{
enum
mnttype
{
LXC_MNT_BIND
,
LXC_MNT_BIND
,
LXC_MNT_OVL
,
LXC_MNT_OVL
,
...
@@ -178,22 +181,22 @@ int main(int argc, char *argv[])
...
@@ -178,22 +181,22 @@ int main(int argc, char *argv[])
if
(
geteuid
())
{
if
(
geteuid
())
{
if
(
access
(
my_args
.
lxcpath
[
0
],
O_RDONLY
)
<
0
)
{
if
(
access
(
my_args
.
lxcpath
[
0
],
O_RDONLY
)
<
0
)
{
if
(
!
my_args
.
quiet
)
ERROR
(
"You lack access to %s"
,
my_args
.
lxcpath
[
0
]);
fprintf
(
stderr
,
"You lack access to %s
\n
"
,
my_args
.
lxcpath
[
0
]);
exit
(
ret
);
exit
(
ret
);
}
}
}
}
if
(
!
my_args
.
newname
&&
!
(
my_args
.
task
==
DESTROY
))
{
if
(
!
my_args
.
newname
&&
!
(
my_args
.
task
==
DESTROY
))
{
if
(
!
my_args
.
quiet
)
ERROR
(
"You must provide a NEWNAME for the clone."
);
printf
(
"Error: You must provide a NEWNAME for the clone.
\n
"
);
exit
(
ret
);
exit
(
ret
);
}
}
if
(
my_args
.
task
==
SNAP
||
my_args
.
task
==
DESTROY
)
if
(
my_args
.
task
==
SNAP
||
my_args
.
task
==
DESTROY
)
flags
|=
LXC_CLONE_SNAPSHOT
;
flags
|=
LXC_CLONE_SNAPSHOT
;
if
(
my_args
.
keepname
)
if
(
my_args
.
keepname
)
flags
|=
LXC_CLONE_KEEPNAME
;
flags
|=
LXC_CLONE_KEEPNAME
;
if
(
my_args
.
keepmac
)
if
(
my_args
.
keepmac
)
flags
|=
LXC_CLONE_KEEPMACADDR
;
flags
|=
LXC_CLONE_KEEPMACADDR
;
...
@@ -206,26 +209,26 @@ int main(int argc, char *argv[])
...
@@ -206,26 +209,26 @@ int main(int argc, char *argv[])
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
ERROR
(
"Failed to load rcfile
"
);
goto
out
;
goto
out
;
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
ERROR
(
"Out of memory setting new config filename
"
);
goto
out
;
goto
out
;
}
}
}
}
if
(
!
c
->
may_control
(
c
))
{
if
(
!
c
->
may_control
(
c
))
{
if
(
!
my_args
.
quiet
)
ERROR
(
"Insufficent privileges to control %s"
,
c
->
name
);
fprintf
(
stderr
,
"Insufficent privileges to control %s
\n
"
,
c
->
name
);
goto
out
;
goto
out
;
}
}
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
c
->
is_defined
(
c
))
{
if
(
!
my_args
.
quiet
)
ERROR
(
"Container %s is not defined"
,
c
->
name
);
fprintf
(
stderr
,
"Error: container %s is not defined
\n
"
,
c
->
name
);
goto
out
;
goto
out
;
}
}
...
@@ -258,32 +261,36 @@ static struct mnts *add_mnt(struct mnts **mnts, unsigned int *num, enum mnttype
...
@@ -258,32 +261,36 @@ static struct mnts *add_mnt(struct mnts **mnts, unsigned int *num, enum mnttype
static
int
mk_rand_ovl_dirs
(
struct
mnts
*
mnts
,
unsigned
int
num
,
struct
lxc_arguments
*
arg
)
static
int
mk_rand_ovl_dirs
(
struct
mnts
*
mnts
,
unsigned
int
num
,
struct
lxc_arguments
*
arg
)
{
{
char
upperdir
[
TOOL_
MAXPATHLEN
];
char
upperdir
[
MAXPATHLEN
];
char
workdir
[
TOOL_
MAXPATHLEN
];
char
workdir
[
MAXPATHLEN
];
unsigned
int
i
;
unsigned
int
i
;
int
ret
;
int
ret
;
struct
mnts
*
m
=
NULL
;
struct
mnts
*
m
=
NULL
;
for
(
i
=
0
,
m
=
mnts
;
i
<
num
;
i
++
,
m
++
)
{
for
(
i
=
0
,
m
=
mnts
;
i
<
num
;
i
++
,
m
++
)
{
if
(
m
->
mnt_type
==
LXC_MNT_OVL
)
{
if
(
m
->
mnt_type
==
LXC_MNT_OVL
)
{
ret
=
snprintf
(
upperdir
,
TOOL_
MAXPATHLEN
,
"%s/%s/delta#XXXXXX"
,
ret
=
snprintf
(
upperdir
,
MAXPATHLEN
,
"%s/%s/delta#XXXXXX"
,
arg
->
newpath
,
arg
->
newname
);
arg
->
newpath
,
arg
->
newname
);
if
(
ret
<
0
||
ret
>=
TOOL_
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
return
-
1
;
return
-
1
;
if
(
!
mkdtemp
(
upperdir
))
if
(
!
mkdtemp
(
upperdir
))
return
-
1
;
return
-
1
;
m
->
upper
=
strdup
(
upperdir
);
m
->
upper
=
strdup
(
upperdir
);
if
(
!
m
->
upper
)
if
(
!
m
->
upper
)
return
-
1
;
return
-
1
;
}
}
if
(
m
->
mnt_type
==
LXC_MNT_OVL
)
{
if
(
m
->
mnt_type
==
LXC_MNT_OVL
)
{
ret
=
snprintf
(
workdir
,
TOOL_
MAXPATHLEN
,
"%s/%s/work#XXXXXX"
,
ret
=
snprintf
(
workdir
,
MAXPATHLEN
,
"%s/%s/work#XXXXXX"
,
arg
->
newpath
,
arg
->
newname
);
arg
->
newpath
,
arg
->
newname
);
if
(
ret
<
0
||
ret
>=
TOOL_
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
return
-
1
;
return
-
1
;
if
(
!
mkdtemp
(
workdir
))
if
(
!
mkdtemp
(
workdir
))
return
-
1
;
return
-
1
;
m
->
workdir
=
strdup
(
workdir
);
m
->
workdir
=
strdup
(
workdir
);
if
(
!
m
->
workdir
)
if
(
!
m
->
workdir
)
return
-
1
;
return
-
1
;
...
@@ -359,8 +366,7 @@ static int do_clone(struct lxc_container *c, char *newname, char *newpath,
...
@@ -359,8 +366,7 @@ static int do_clone(struct lxc_container *c, char *newname, char *newpath,
clone
=
c
->
clone
(
c
,
newname
,
newpath
,
flags
,
bdevtype
,
NULL
,
fssize
,
clone
=
c
->
clone
(
c
,
newname
,
newpath
,
flags
,
bdevtype
,
NULL
,
fssize
,
args
);
args
);
if
(
!
clone
)
{
if
(
!
clone
)
{
if
(
!
my_args
.
quiet
)
ERROR
(
"Failed to clone"
);
fprintf
(
stderr
,
"clone failed
\n
"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -373,7 +379,7 @@ static int do_clone_ephemeral(struct lxc_container *c,
...
@@ -373,7 +379,7 @@ static int do_clone_ephemeral(struct lxc_container *c,
struct
lxc_arguments
*
arg
,
char
**
args
,
int
flags
)
struct
lxc_arguments
*
arg
,
char
**
args
,
int
flags
)
{
{
char
*
premount
;
char
*
premount
;
char
randname
[
TOOL_
MAXPATHLEN
];
char
randname
[
MAXPATHLEN
];
unsigned
int
i
;
unsigned
int
i
;
int
ret
=
0
;
int
ret
=
0
;
bool
bret
=
true
,
started
=
false
;
bool
bret
=
true
,
started
=
false
;
...
@@ -383,15 +389,18 @@ static int do_clone_ephemeral(struct lxc_container *c,
...
@@ -383,15 +389,18 @@ static int do_clone_ephemeral(struct lxc_container *c,
attach_options
.
env_policy
=
LXC_ATTACH_CLEAR_ENV
;
attach_options
.
env_policy
=
LXC_ATTACH_CLEAR_ENV
;
if
(
!
arg
->
newname
)
{
if
(
!
arg
->
newname
)
{
ret
=
snprintf
(
randname
,
TOOL_
MAXPATHLEN
,
"%s/%s_XXXXXX"
,
arg
->
newpath
,
arg
->
name
);
ret
=
snprintf
(
randname
,
MAXPATHLEN
,
"%s/%s_XXXXXX"
,
arg
->
newpath
,
arg
->
name
);
if
(
ret
<
0
||
ret
>=
TOOL_
MAXPATHLEN
)
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
return
-
1
;
return
-
1
;
if
(
!
mkdtemp
(
randname
))
if
(
!
mkdtemp
(
randname
))
return
-
1
;
return
-
1
;
if
(
chmod
(
randname
,
0770
)
<
0
)
{
if
(
chmod
(
randname
,
0770
)
<
0
)
{
(
void
)
remove
(
randname
);
(
void
)
remove
(
randname
);
return
-
1
;
return
-
1
;
}
}
arg
->
newname
=
randname
+
strlen
(
arg
->
newpath
)
+
1
;
arg
->
newname
=
randname
+
strlen
(
arg
->
newpath
)
+
1
;
}
}
...
@@ -423,9 +432,11 @@ static int do_clone_ephemeral(struct lxc_container *c,
...
@@ -423,9 +432,11 @@ static int do_clone_ephemeral(struct lxc_container *c,
struct
mnts
*
n
=
NULL
;
struct
mnts
*
n
=
NULL
;
for
(
i
=
0
,
n
=
mnt_table
;
i
<
mnt_table_size
;
i
++
,
n
++
)
{
for
(
i
=
0
,
n
=
mnt_table
;
i
<
mnt_table_size
;
i
++
,
n
++
)
{
char
*
mntentry
=
NULL
;
char
*
mntentry
=
NULL
;
mntentry
=
set_mnt_entry
(
n
);
mntentry
=
set_mnt_entry
(
n
);
if
(
!
mntentry
)
if
(
!
mntentry
)
goto
destroy_and_put
;
goto
destroy_and_put
;
bret
=
clone
->
set_config_item
(
clone
,
"lxc.mount.entry"
,
mntentry
);
bret
=
clone
->
set_config_item
(
clone
,
"lxc.mount.entry"
,
mntentry
);
free
(
mntentry
);
free
(
mntentry
);
if
(
!
bret
)
if
(
!
bret
)
...
@@ -467,9 +478,11 @@ static int do_clone_ephemeral(struct lxc_container *c,
...
@@ -467,9 +478,11 @@ static int do_clone_ephemeral(struct lxc_container *c,
destroy_and_put:
destroy_and_put:
if
(
started
)
if
(
started
)
clone
->
shutdown
(
clone
,
-
1
);
clone
->
shutdown
(
clone
,
-
1
);
ret
=
clone
->
get_config_item
(
clone
,
"lxc.ephemeral"
,
tmp_buf
,
TOOL_MAXPATHLEN
);
ret
=
clone
->
get_config_item
(
clone
,
"lxc.ephemeral"
,
tmp_buf
,
MAXPATHLEN
);
if
(
ret
>
0
&&
strcmp
(
tmp_buf
,
"0"
))
if
(
ret
>
0
&&
strcmp
(
tmp_buf
,
"0"
))
clone
->
destroy
(
clone
);
clone
->
destroy
(
clone
);
free_mnts
();
free_mnts
();
lxc_container_put
(
clone
);
lxc_container_put
(
clone
);
return
-
1
;
return
-
1
;
...
@@ -478,7 +491,7 @@ destroy_and_put:
...
@@ -478,7 +491,7 @@ destroy_and_put:
static
int
do_clone_rename
(
struct
lxc_container
*
c
,
char
*
newname
)
static
int
do_clone_rename
(
struct
lxc_container
*
c
,
char
*
newname
)
{
{
if
(
!
c
->
rename
(
c
,
newname
))
{
if
(
!
c
->
rename
(
c
,
newname
))
{
fprintf
(
stderr
,
"Error: Renaming container %s to %s failed
\n
"
,
c
->
name
,
newname
);
ERROR
(
"Renaming container %s to %s failed
"
,
c
->
name
,
newname
);
return
-
1
;
return
-
1
;
}
}
...
@@ -519,6 +532,7 @@ static void free_mnts()
...
@@ -519,6 +532,7 @@ static void free_mnts()
free
(
n
->
upper
);
free
(
n
->
upper
);
free
(
n
->
workdir
);
free
(
n
->
workdir
);
}
}
free
(
mnt_table
);
free
(
mnt_table
);
mnt_table
=
NULL
;
mnt_table
=
NULL
;
mnt_table_size
=
0
;
mnt_table_size
=
0
;
...
@@ -532,8 +546,7 @@ static uint64_t get_fssize(char *s)
...
@@ -532,8 +546,7 @@ static uint64_t get_fssize(char *s)
ret
=
strtoull
(
s
,
&
end
,
0
);
ret
=
strtoull
(
s
,
&
end
,
0
);
if
(
end
==
s
)
{
if
(
end
==
s
)
{
if
(
!
my_args
.
quiet
)
ERROR
(
"Invalid blockdev size '%s', using default size"
,
s
);
fprintf
(
stderr
,
"Invalid blockdev size '%s', using default size
\n
"
,
s
);
return
0
;
return
0
;
}
}
while
(
isblank
(
*
end
))
while
(
isblank
(
*
end
))
...
@@ -551,8 +564,7 @@ static uint64_t get_fssize(char *s)
...
@@ -551,8 +564,7 @@ static uint64_t get_fssize(char *s)
}
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
{
}
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
{
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
}
else
{
}
else
{
if
(
!
my_args
.
quiet
)
ERROR
(
"Invalid blockdev unit size '%c' in '%s', "
"using default size"
,
*
end
,
s
);
fprintf
(
stderr
,
"Invalid blockdev unit size '%c' in '%s', "
"using default size
\n
"
,
*
end
,
s
);
return
0
;
return
0
;
}
}
...
@@ -591,7 +603,7 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
...
@@ -591,7 +603,7 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
return
-
1
;
return
-
1
;
break
;
break
;
case
'B'
:
case
'B'
:
if
(
strcmp
(
arg
,
"overlay"
)
==
0
)
if
(
!
strncmp
(
arg
,
"overlay"
,
strlen
(
arg
))
)
arg
=
"overlayfs"
;
arg
=
"overlayfs"
;
args
->
bdevtype
=
arg
;
args
->
bdevtype
=
arg
;
break
;
break
;
...
@@ -637,10 +649,10 @@ static int parse_bind_mnt(char *mntstring, enum mnttype type)
...
@@ -637,10 +649,10 @@ static int parse_bind_mnt(char *mntstring, enum mnttype type)
if
(
len
==
1
)
{
/* bind=src */
if
(
len
==
1
)
{
/* bind=src */
m
->
dest
=
construct_path
(
mntarray
[
0
],
false
);
m
->
dest
=
construct_path
(
mntarray
[
0
],
false
);
}
else
if
(
len
==
2
)
{
/* bind=src:option or bind=src:dest */
}
else
if
(
len
==
2
)
{
/* bind=src:option or bind=src:dest */
if
(
strncmp
(
mntarray
[
1
],
"rw"
,
strlen
(
mntarray
[
1
]))
==
0
)
if
(
!
strncmp
(
mntarray
[
1
],
"rw"
,
strlen
(
mntarray
[
1
]))
)
m
->
options
=
strdup
(
"rw"
);
m
->
options
=
strdup
(
"rw"
);
if
(
strncmp
(
mntarray
[
1
],
"ro"
,
strlen
(
mntarray
[
1
]))
==
0
)
if
(
!
strncmp
(
mntarray
[
1
],
"ro"
,
strlen
(
mntarray
[
1
]))
)
m
->
options
=
strdup
(
"ro"
);
m
->
options
=
strdup
(
"ro"
);
if
(
m
->
options
)
if
(
m
->
options
)
...
@@ -689,6 +701,7 @@ static int parse_mntsubopts(char *subopts, char *const *keys, char *mntparameter
...
@@ -689,6 +701,7 @@ static int parse_mntsubopts(char *subopts, char *const *keys, char *mntparameter
break
;
break
;
}
}
}
}
return
0
;
return
0
;
}
}
...
@@ -749,19 +762,19 @@ static char *mount_tmpfs(const char *oldname, const char *newname,
...
@@ -749,19 +762,19 @@ static char *mount_tmpfs(const char *oldname, const char *newname,
FILE
*
fp
=
NULL
;
FILE
*
fp
=
NULL
;
if
(
arg
->
tmpfs
&&
arg
->
keepdata
)
{
if
(
arg
->
tmpfs
&&
arg
->
keepdata
)
{
fprintf
(
stderr
,
"%s
\n
"
,
ERROR
(
"%s
"
,
"A container can only be placed on a tmpfs when the "
"A container can only be placed on a tmpfs when the "
"overlay storage driver is used"
);
"overlay storage driver is used"
);
goto
err_free
;
goto
err_free
;
}
}
if
(
arg
->
tmpfs
&&
!
arg
->
bdevtype
)
{
if
(
arg
->
tmpfs
&&
!
arg
->
bdevtype
)
{
arg
->
bdevtype
=
"overlayfs"
;
arg
->
bdevtype
=
"overlayfs"
;
}
else
if
(
arg
->
tmpfs
&&
arg
->
bdevtype
&&
}
else
if
(
arg
->
tmpfs
&&
arg
->
bdevtype
&&
str
cmp
(
arg
->
bdevtype
,
"overlayfs"
)
!=
0
)
{
str
ncmp
(
arg
->
bdevtype
,
"overlayfs"
,
strlen
(
arg
->
bdevtype
))
)
{
fprintf
(
stderr
,
"%s
\n
"
,
ERROR
(
"%s
"
,
"A container can only be placed on a tmpfs when the "
"A container can only be placed on a tmpfs when the "
"overlay storage driver is used"
);
"overlay storage driver is used"
);
goto
err_free
;
goto
err_free
;
}
}
...
@@ -781,7 +794,7 @@ static char *mount_tmpfs(const char *oldname, const char *newname,
...
@@ -781,7 +794,7 @@ static char *mount_tmpfs(const char *oldname, const char *newname,
goto
err_free
;
goto
err_free
;
if
(
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
))
{
if
(
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
))
{
fprintf
(
stderr
,
"Failed to set close-on-exec on file descriptor.
\n
"
);
ERROR
(
"Failed to set close-on-exec on file descriptor.
"
);
goto
err_close
;
goto
err_close
;
}
}
...
@@ -815,6 +828,7 @@ err_close:
...
@@ -815,6 +828,7 @@ err_close:
close
(
fd
);
close
(
fd
);
else
if
(
fp
)
else
if
(
fp
)
fclose
(
fp
);
fclose
(
fp
);
err_free:
err_free:
free
(
premount
);
free
(
premount
);
return
NULL
;
return
NULL
;
...
...
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