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
9c382925
Commit
9c382925
authored
Jun 29, 2018
by
2xsec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-create: share internal API symbols
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
ce9ed7c0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
37 deletions
+55
-37
Makefile.am
src/lxc/Makefile.am
+1
-1
lxc_create.c
src/lxc/tools/lxc_create.c
+54
-36
No files found.
src/lxc/Makefile.am
View file @
9c382925
...
@@ -284,7 +284,7 @@ lxc_top_SOURCES = tools/lxc_top.c tools/arguments.c
...
@@ -284,7 +284,7 @@ lxc_top_SOURCES = tools/lxc_top.c tools/arguments.c
lxc_unfreeze_SOURCES
=
tools/lxc_unfreeze.c tools/arguments.c
lxc_unfreeze_SOURCES
=
tools/lxc_unfreeze.c tools/arguments.c
lxc_unshare_SOURCES
=
tools/lxc_unshare.c tools/arguments.c
lxc_unshare_SOURCES
=
tools/lxc_unshare.c tools/arguments.c
lxc_wait_SOURCES
=
tools/lxc_wait.c tools/arguments.c
lxc_wait_SOURCES
=
tools/lxc_wait.c tools/arguments.c
lxc_create_SOURCES
=
tools/lxc_create.c tools/arguments.c
tools/tool_utils.c
lxc_create_SOURCES
=
tools/lxc_create.c tools/arguments.c
lxc_snapshot_SOURCES
=
tools/lxc_snapshot.c tools/arguments.c
lxc_snapshot_SOURCES
=
tools/lxc_snapshot.c tools/arguments.c
lxc_checkpoint_SOURCES
=
tools/lxc_checkpoint.c tools/arguments.c
lxc_checkpoint_SOURCES
=
tools/lxc_checkpoint.c tools/arguments.c
endif
endif
...
...
src/lxc/tools/lxc_create.c
View file @
9c382925
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
*/
#define _GNU_SOURCE
#include <ctype.h>
#include <ctype.h>
#include <fcntl.h>
#include <fcntl.h>
#include <libgen.h>
#include <libgen.h>
...
@@ -29,7 +30,10 @@
...
@@ -29,7 +30,10 @@
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "arguments.h"
#include "tool_utils.h"
#include "log.h"
#include "utils.h"
lxc_log_define
(
lxc_create
,
lxc
);
static
uint64_t
get_fssize
(
char
*
s
)
static
uint64_t
get_fssize
(
char
*
s
)
{
{
...
@@ -39,11 +43,13 @@ static uint64_t get_fssize(char *s)
...
@@ -39,11 +43,13 @@ static uint64_t get_fssize(char *s)
ret
=
strtoull
(
s
,
&
end
,
0
);
ret
=
strtoull
(
s
,
&
end
,
0
);
if
(
end
==
s
)
if
(
end
==
s
)
{
{
fprintf
(
stderr
,
"Invalid blockdev size '%s', using default size
\n
"
,
s
);
ERROR
(
"Invalid blockdev size '%s', using default size
"
,
s
);
return
0
;
return
0
;
}
}
while
(
isblank
(
*
end
))
while
(
isblank
(
*
end
))
end
++
;
end
++
;
if
(
*
end
==
'\0'
)
if
(
*
end
==
'\0'
)
ret
*=
1024ULL
*
1024ULL
;
/* MB by default */
ret
*=
1024ULL
*
1024ULL
;
/* MB by default */
else
if
(
*
end
==
'b'
||
*
end
==
'B'
)
else
if
(
*
end
==
'b'
||
*
end
==
'B'
)
...
@@ -56,15 +62,15 @@ static uint64_t get_fssize(char *s)
...
@@ -56,15 +62,15 @@ static uint64_t get_fssize(char *s)
ret
*=
1024ULL
*
1024ULL
*
1024ULL
;
ret
*=
1024ULL
*
1024ULL
*
1024ULL
;
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
else
else
{
{
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
;
}
}
return
ret
;
return
ret
;
}
}
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
{
switch
(
c
)
{
switch
(
c
)
{
case
'B'
:
args
->
bdevtype
=
arg
;
break
;
case
'B'
:
args
->
bdevtype
=
arg
;
break
;
...
@@ -120,8 +126,8 @@ static void create_helpfn(const struct lxc_arguments *args)
...
@@ -120,8 +126,8 @@ static void create_helpfn(const struct lxc_arguments *args)
argv
[
2
]
=
NULL
;
argv
[
2
]
=
NULL
;
execv
(
path
,
argv
);
execv
(
path
,
argv
);
fprintf
(
stderr
,
"Error executing %s -h
\n
"
,
path
);
ERROR
(
"Error executing %s -h
"
,
path
);
exit
(
EXIT_FAILURE
);
_
exit
(
EXIT_FAILURE
);
}
}
static
struct
lxc_arguments
my_args
=
{
static
struct
lxc_arguments
my_args
=
{
...
@@ -170,34 +176,38 @@ Options :\n\
...
@@ -170,34 +176,38 @@ Options :\n\
static
bool
validate_bdev_args
(
struct
lxc_arguments
*
a
)
static
bool
validate_bdev_args
(
struct
lxc_arguments
*
a
)
{
{
if
(
str
cmp
(
a
->
bdevtype
,
"best"
)
!=
0
)
{
if
(
str
ncmp
(
a
->
bdevtype
,
"best"
,
strlen
(
a
->
bdevtype
))
)
{
if
(
a
->
fstype
||
a
->
fssize
)
{
if
(
a
->
fstype
||
a
->
fssize
)
{
if
(
str
cmp
(
a
->
bdevtype
,
"lvm"
)
!=
0
&&
if
(
str
ncmp
(
a
->
bdevtype
,
"lvm"
,
strlen
(
a
->
bdevtype
))
&&
str
cmp
(
a
->
bdevtype
,
"loop"
)
!=
0
&&
str
ncmp
(
a
->
bdevtype
,
"loop"
,
strlen
(
a
->
bdevtype
))
&&
str
cmp
(
a
->
bdevtype
,
"rbd"
)
!=
0
)
{
str
ncmp
(
a
->
bdevtype
,
"rbd"
,
strlen
(
a
->
bdevtype
))
)
{
fprintf
(
stderr
,
"filesystem type and size are only valid with block devices
\n
"
);
ERROR
(
"Filesystem type and size are only valid with block devices
"
);
return
false
;
return
false
;
}
}
}
}
if
(
strcmp
(
a
->
bdevtype
,
"lvm"
)
!=
0
)
{
if
(
strncmp
(
a
->
bdevtype
,
"lvm"
,
strlen
(
a
->
bdevtype
)))
{
if
(
a
->
lvname
||
a
->
vgname
||
a
->
thinpool
)
{
if
(
a
->
lvname
||
a
->
vgname
||
a
->
thinpool
)
{
fprintf
(
stderr
,
"--lvname, --vgname and --thinpool are only valid with -B lvm
\n
"
);
ERROR
(
"--lvname, --vgname and --thinpool are only valid with -B lvm
"
);
return
false
;
return
false
;
}
}
}
}
if
(
strcmp
(
a
->
bdevtype
,
"rbd"
)
!=
0
)
{
if
(
strncmp
(
a
->
bdevtype
,
"rbd"
,
strlen
(
a
->
bdevtype
)))
{
if
(
a
->
rbdname
||
a
->
rbdpool
)
{
if
(
a
->
rbdname
||
a
->
rbdpool
)
{
fprintf
(
stderr
,
"--rbdname and --rbdpool are only valid with -B rbd
\n
"
);
ERROR
(
"--rbdname and --rbdpool are only valid with -B rbd
"
);
return
false
;
return
false
;
}
}
}
}
if
(
strcmp
(
a
->
bdevtype
,
"zfs"
)
!=
0
)
{
if
(
strncmp
(
a
->
bdevtype
,
"zfs"
,
strlen
(
a
->
bdevtype
)))
{
if
(
a
->
zfsroot
)
{
if
(
a
->
zfsroot
)
{
fprintf
(
stderr
,
"zfsroot is only valid with -B zfs
\n
"
);
ERROR
(
"zfsroot is only valid with -B zfs
"
);
return
false
;
return
false
;
}
}
}
}
}
}
return
true
;
return
true
;
}
}
...
@@ -244,33 +254,31 @@ int main(int argc, char *argv[])
...
@@ -244,33 +254,31 @@ int main(int argc, char *argv[])
}
}
if
(
!
my_args
.
template
)
{
if
(
!
my_args
.
template
)
{
fprintf
(
stderr
,
"A template must be specified.
\n
"
);
ERROR
(
"A template must be specified.
"
);
fprintf
(
stderr
,
"Use
\"
none
\"
if you really want a container without a rootfs.
\n
"
);
ERROR
(
"Use
\"
none
\"
if you really want a container without a rootfs.
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
strcmp
(
my_args
.
template
,
"none"
)
==
0
)
if
(
!
strncmp
(
my_args
.
template
,
"none"
,
strlen
(
my_args
.
template
))
)
my_args
.
template
=
NULL
;
my_args
.
template
=
NULL
;
memset
(
&
spec
,
0
,
sizeof
(
spec
));
if
(
!
my_args
.
bdevtype
)
if
(
!
my_args
.
bdevtype
)
my_args
.
bdevtype
=
"_unset"
;
my_args
.
bdevtype
=
"_unset"
;
if
(
!
validate_bdev_args
(
&
my_args
))
if
(
!
validate_bdev_args
(
&
my_args
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
strcmp
(
my_args
.
bdevtype
,
"none"
)
==
0
)
if
(
!
strncmp
(
my_args
.
bdevtype
,
"none"
,
strlen
(
my_args
.
bdevtype
))
)
my_args
.
bdevtype
=
"dir"
;
my_args
.
bdevtype
=
"dir"
;
/* Final check whether the user gave use a valid bdev type. */
/* Final check whether the user gave use a valid bdev type. */
if
(
str
cmp
(
my_args
.
bdevtype
,
"best"
)
&&
if
(
str
ncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
)
)
&&
str
cmp
(
my_args
.
bdevtype
,
"_unset"
)
&&
str
ncmp
(
my_args
.
bdevtype
,
"_unset"
,
strlen
(
my_args
.
bdevtype
)
)
&&
!
is_valid_storage_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
);
ERROR
(
"%s is not a valid backing storage type.
"
,
my_args
.
bdevtype
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
!
my_args
.
lxcpath
[
0
])
if
(
!
my_args
.
lxcpath
[
0
])
my_args
.
lxcpath
[
0
]
=
lxc_get_global_config_item
(
"lxc.lxcpath"
);
my_args
.
lxcpath
[
0
]
=
lxc_get_global_config_item
(
"lxc.lxcpath"
);
...
@@ -279,48 +287,58 @@ int main(int argc, char *argv[])
...
@@ -279,48 +287,58 @@ 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
)
{
fprintf
(
stderr
,
"You lack access to %s
\n
"
,
ERROR
(
"You lack access to %s"
,
my_args
.
lxcpath
[
0
]);
my_args
.
lxcpath
[
0
]);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"Failed to create lxc container.
\n
"
);
ERROR
(
"Failed to create lxc container.
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
c
->
is_defined
(
c
))
{
if
(
c
->
is_defined
(
c
))
{
lxc_container_put
(
c
);
lxc_container_put
(
c
);
fprintf
(
stderr
,
"Container already exists
\n
"
);
ERROR
(
"Container already exists
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
my_args
.
configfile
)
if
(
my_args
.
configfile
)
c
->
load_config
(
c
,
my_args
.
configfile
);
c
->
load_config
(
c
,
my_args
.
configfile
);
else
else
c
->
load_config
(
c
,
lxc_get_global_config_item
(
"lxc.default_config"
));
c
->
load_config
(
c
,
lxc_get_global_config_item
(
"lxc.default_config"
));
memset
(
&
spec
,
0
,
sizeof
(
spec
));
if
(
my_args
.
fstype
)
if
(
my_args
.
fstype
)
spec
.
fstype
=
my_args
.
fstype
;
spec
.
fstype
=
my_args
.
fstype
;
if
(
my_args
.
fssize
)
if
(
my_args
.
fssize
)
spec
.
fssize
=
my_args
.
fssize
;
spec
.
fssize
=
my_args
.
fssize
;
if
((
strcmp
(
my_args
.
bdevtype
,
"zfs"
)
==
0
)
||
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
==
0
))
{
if
((
!
strncmp
(
my_args
.
bdevtype
,
"zfs"
,
strlen
(
my_args
.
bdevtype
)))
||
(
!
strncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
))))
{
if
(
my_args
.
zfsroot
)
if
(
my_args
.
zfsroot
)
spec
.
zfs
.
zfsroot
=
my_args
.
zfsroot
;
spec
.
zfs
.
zfsroot
=
my_args
.
zfsroot
;
}
}
if
((
strcmp
(
my_args
.
bdevtype
,
"lvm"
)
==
0
)
||
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
==
0
))
{
if
((
!
strncmp
(
my_args
.
bdevtype
,
"lvm"
,
strlen
(
my_args
.
bdevtype
)))
||
(
!
strncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
))))
{
if
(
my_args
.
lvname
)
if
(
my_args
.
lvname
)
spec
.
lvm
.
lv
=
my_args
.
lvname
;
spec
.
lvm
.
lv
=
my_args
.
lvname
;
if
(
my_args
.
vgname
)
if
(
my_args
.
vgname
)
spec
.
lvm
.
vg
=
my_args
.
vgname
;
spec
.
lvm
.
vg
=
my_args
.
vgname
;
if
(
my_args
.
thinpool
)
if
(
my_args
.
thinpool
)
spec
.
lvm
.
thinpool
=
my_args
.
thinpool
;
spec
.
lvm
.
thinpool
=
my_args
.
thinpool
;
}
}
if
((
strcmp
(
my_args
.
bdevtype
,
"rbd"
)
==
0
)
||
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
==
0
))
{
if
((
!
strncmp
(
my_args
.
bdevtype
,
"rbd"
,
strlen
(
my_args
.
bdevtype
)))
||
(
!
strncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
))))
{
if
(
my_args
.
rbdname
)
if
(
my_args
.
rbdname
)
spec
.
rbd
.
rbdname
=
my_args
.
rbdname
;
spec
.
rbd
.
rbdname
=
my_args
.
rbdname
;
if
(
my_args
.
rbdpool
)
if
(
my_args
.
rbdpool
)
spec
.
rbd
.
rbdpool
=
my_args
.
rbdpool
;
spec
.
rbd
.
rbdpool
=
my_args
.
rbdpool
;
}
}
...
@@ -328,7 +346,7 @@ int main(int argc, char *argv[])
...
@@ -328,7 +346,7 @@ int main(int argc, char *argv[])
if
(
my_args
.
dir
)
if
(
my_args
.
dir
)
spec
.
dir
=
my_args
.
dir
;
spec
.
dir
=
my_args
.
dir
;
if
(
strcmp
(
my_args
.
bdevtype
,
"_unset"
)
==
0
)
if
(
!
strncmp
(
my_args
.
bdevtype
,
"_unset"
,
strlen
(
my_args
.
bdevtype
))
)
my_args
.
bdevtype
=
NULL
;
my_args
.
bdevtype
=
NULL
;
if
(
my_args
.
quiet
)
if
(
my_args
.
quiet
)
...
...
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