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
e3df7a88
Commit
e3df7a88
authored
Apr 06, 2016
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #948 from brauner/bugfix_branch
lxc-create: bugfixes and small improvements
parents
66c26578
a7c36c83
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
28 deletions
+43
-28
lxc_create.c
src/lxc/lxc_create.c
+43
-28
No files found.
src/lxc/lxc_create.c
View file @
e3df7a88
...
@@ -17,21 +17,20 @@
...
@@ -17,21 +17,20 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
*/
#include <lxc/lxccontainer.h>
#include <stdio.h>
#include <libgen.h>
#include <unistd.h>
#include <ctype.h>
#include <ctype.h>
#include <fcntl.h>
#include <fcntl.h>
#include <
sys/types
.h>
#include <
libgen
.h>
#include <stdint.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <lxc/lxccontainer.h>
#include <sys/types.h>
#include "lxc.h"
#include "log.h"
#include "bdev/bdev.h"
#include "arguments.h"
#include "arguments.h"
#include "log.h"
#include "lxc.h"
#include "utils.h"
#include "utils.h"
#include "bdev/bdev.h"
lxc_log_define
(
lxc_create_ui
,
lxc
);
lxc_log_define
(
lxc_create_ui
,
lxc
);
...
@@ -103,7 +102,8 @@ static const struct option my_longopts[] = {
...
@@ -103,7 +102,8 @@ static const struct option my_longopts[] = {
LXC_COMMON_OPTIONS
LXC_COMMON_OPTIONS
};
};
static
void
create_helpfn
(
const
struct
lxc_arguments
*
args
)
{
static
void
create_helpfn
(
const
struct
lxc_arguments
*
args
)
{
char
*
argv
[
3
],
*
path
;
char
*
argv
[
3
],
*
path
;
pid_t
pid
;
pid_t
pid
;
...
@@ -121,9 +121,10 @@ static void create_helpfn(const struct lxc_arguments *args) {
...
@@ -121,9 +121,10 @@ static void create_helpfn(const struct lxc_arguments *args) {
argv
[
0
]
=
path
;
argv
[
0
]
=
path
;
argv
[
1
]
=
"-h"
;
argv
[
1
]
=
"-h"
;
argv
[
2
]
=
NULL
;
argv
[
2
]
=
NULL
;
execv
(
path
,
argv
);
execv
(
path
,
argv
);
ERROR
(
"Error executing %s -h"
,
path
);
ERROR
(
"Error executing %s -h"
,
path
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
static
struct
lxc_arguments
my_args
=
{
static
struct
lxc_arguments
my_args
=
{
...
@@ -210,20 +211,20 @@ int main(int argc, char *argv[])
...
@@ -210,20 +211,20 @@ int main(int argc, char *argv[])
int
flags
=
0
;
int
flags
=
0
;
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
1
);
exit
(
EXIT_FAILURE
);
if
(
!
my_args
.
log_file
)
if
(
!
my_args
.
log_file
)
my_args
.
log_file
=
"none"
;
my_args
.
log_file
=
"none"
;
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
if
(
lxc_log_init
(
my_args
.
name
,
my_args
.
log_file
,
my_args
.
log_priority
,
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
my_args
.
progname
,
my_args
.
quiet
,
my_args
.
lxcpath
[
0
]))
exit
(
1
);
exit
(
EXIT_FAILURE
);
lxc_log_options_no_override
();
lxc_log_options_no_override
();
if
(
!
my_args
.
template
)
{
if
(
!
my_args
.
template
)
{
fprintf
(
stderr
,
"A template must be specified.
\n
"
);
fprintf
(
stderr
,
"A template must be specified.
\n
"
);
fprintf
(
stderr
,
"Use
\"
none
\"
if you really want a container without a rootfs.
\n
"
);
fprintf
(
stderr
,
"Use
\"
none
\"
if you really want a container without a rootfs.
\n
"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
strcmp
(
my_args
.
template
,
"none"
)
==
0
)
if
(
strcmp
(
my_args
.
template
,
"none"
)
==
0
)
...
@@ -232,36 +233,44 @@ int main(int argc, char *argv[])
...
@@ -232,36 +233,44 @@ int main(int argc, char *argv[])
memset
(
&
spec
,
0
,
sizeof
(
spec
));
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
(
1
);
exit
(
EXIT_FAILURE
);
if
(
strcmp
(
my_args
.
bdevtype
,
"none"
)
==
0
)
if
(
strcmp
(
my_args
.
bdevtype
,
"none"
)
==
0
)
my_args
.
bdevtype
=
"dir"
;
my_args
.
bdevtype
=
"dir"
;
// Final check whether the user gave use a valid bdev type.
if
(
!
is_valid_bdev_type
(
my_args
.
bdevtype
)
&&
strcmp
(
my_args
.
bdevtype
,
"_unset"
))
{
fprintf
(
stderr
,
"%s is not a valid backing storage type.
\n
"
,
my_args
.
bdevtype
);
exit
(
EXIT_FAILURE
);
}
if
(
geteuid
())
{
if
(
geteuid
())
{
if
(
mkdir_p
(
my_args
.
lxcpath
[
0
],
0755
))
{
if
(
mkdir_p
(
my_args
.
lxcpath
[
0
],
0755
))
{
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
access
(
my_args
.
lxcpath
[
0
],
O_RDWR
)
<
0
)
{
if
(
access
(
my_args
.
lxcpath
[
0
],
O_RDWR
)
<
0
)
{
fprintf
(
stderr
,
"You lack access to %s
\n
"
,
my_args
.
lxcpath
[
0
]);
fprintf
(
stderr
,
"You lack access to %s
\n
"
,
my_args
.
lxcpath
[
0
]);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
strcmp
(
my_args
.
bdevtype
,
"dir"
)
&&
strcmp
(
my_args
.
bdevtype
,
"_unset"
)
&&
if
(
strcmp
(
my_args
.
bdevtype
,
"dir"
)
&&
strcmp
(
my_args
.
bdevtype
,
"_unset"
)
&&
strcmp
(
my_args
.
bdevtype
,
"btrfs"
))
{
strcmp
(
my_args
.
bdevtype
,
"btrfs"
))
{
fprintf
(
stderr
,
"Unprivileged users cannot create %s containers"
,
my_args
.
bdevtype
);
fprintf
(
stderr
,
"Unprivileged users cannot create %s containers"
,
my_args
.
bdevtype
);
exit
(
1
);
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
,
"
System error loading container
\n
"
);
fprintf
(
stderr
,
"
Failed to create lxc container.
\n
"
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
if
(
c
->
is_defined
(
c
))
{
if
(
c
->
is_defined
(
c
))
{
lxc_container_put
(
c
);
fprintf
(
stderr
,
"Container already exists
\n
"
);
fprintf
(
stderr
,
"Container already exists
\n
"
);
exit
(
1
);
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
);
...
@@ -273,11 +282,12 @@ int main(int argc, char *argv[])
...
@@ -273,11 +282,12 @@ int main(int argc, char *argv[])
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
(
(
strcmp
(
my_args
.
bdevtype
,
"zfs"
)
==
0
)
||
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
==
0
)
)
{
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
((
strcmp
(
my_args
.
bdevtype
,
"lvm"
)
==
0
)
||
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
==
0
))
{
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
)
...
@@ -285,25 +295,30 @@ int main(int argc, char *argv[])
...
@@ -285,25 +295,30 @@ int main(int argc, char *argv[])
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
((
strcmp
(
my_args
.
bdevtype
,
"rbd"
)
==
0
)
||
(
strcmp
(
my_args
.
bdevtype
,
"best"
)
==
0
))
{
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
;
}
}
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
(
strcmp
(
my_args
.
bdevtype
,
"_unset"
)
==
0
)
my_args
.
bdevtype
=
NULL
;
my_args
.
bdevtype
=
NULL
;
if
(
my_args
.
quiet
)
if
(
my_args
.
quiet
)
flags
=
LXC_CREATE_QUIET
;
flags
=
LXC_CREATE_QUIET
;
if
(
!
c
->
create
(
c
,
my_args
.
template
,
my_args
.
bdevtype
,
&
spec
,
flags
,
&
argv
[
optind
]))
{
if
(
!
c
->
create
(
c
,
my_args
.
template
,
my_args
.
bdevtype
,
&
spec
,
flags
,
&
argv
[
optind
]))
{
ERROR
(
"Error creating container %s"
,
c
->
name
);
ERROR
(
"Error creating container %s"
,
c
->
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
exit
(
1
);
exit
(
EXIT_FAILURE
);
}
}
lxc_container_put
(
c
);
INFO
(
"container %s created"
,
c
->
name
);
INFO
(
"container %s created"
,
c
->
name
);
exit
(
0
);
exit
(
EXIT_SUCCESS
);
}
}
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