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
c141d481
Unverified
Commit
c141d481
authored
Aug 18, 2018
by
2xsec
Committed by
Christian Brauner
Aug 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-create: add default log priority & cleanups
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
d0e1b257
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
120 deletions
+123
-120
lxc_create.c
src/lxc/tools/lxc_create.c
+123
-120
No files found.
src/lxc/tools/lxc_create.c
View file @
c141d481
...
@@ -31,64 +31,15 @@
...
@@ -31,64 +31,15 @@
#include "arguments.h"
#include "arguments.h"
#include "log.h"
#include "log.h"
#include "storage_utils.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc_create
,
lxc
);
lxc_log_define
(
lxc_create
,
lxc
);
static
uint64_t
get_fssize
(
char
*
s
)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
{
static
uint64_t
get_fssize
(
char
*
s
);
uint64_t
ret
;
static
void
create_helpfn
(
const
struct
lxc_arguments
*
args
);
char
*
end
;
static
bool
validate_bdev_args
(
struct
lxc_arguments
*
args
);
ret
=
strtoull
(
s
,
&
end
,
0
);
if
(
end
==
s
)
{
ERROR
(
"Invalid blockdev size '%s', using default size"
,
s
);
return
0
;
}
while
(
isblank
(
*
end
))
end
++
;
if
(
*
end
==
'\0'
)
ret
*=
1024ULL
*
1024ULL
;
/* MB by default */
else
if
(
*
end
==
'b'
||
*
end
==
'B'
)
ret
*=
1ULL
;
else
if
(
*
end
==
'k'
||
*
end
==
'K'
)
ret
*=
1024ULL
;
else
if
(
*
end
==
'm'
||
*
end
==
'M'
)
ret
*=
1024ULL
*
1024ULL
;
else
if
(
*
end
==
'g'
||
*
end
==
'G'
)
ret
*=
1024ULL
*
1024ULL
*
1024ULL
;
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
else
{
ERROR
(
"Invalid blockdev unit size '%c' in '%s', using default size"
,
*
end
,
s
);
return
0
;
}
return
ret
;
}
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
case
'B'
:
args
->
bdevtype
=
arg
;
break
;
case
'f'
:
args
->
configfile
=
arg
;
break
;
case
't'
:
args
->
template
=
arg
;
break
;
case
'0'
:
args
->
lvname
=
arg
;
break
;
case
'1'
:
args
->
vgname
=
arg
;
break
;
case
'2'
:
args
->
thinpool
=
arg
;
break
;
case
'3'
:
args
->
fstype
=
arg
;
break
;
case
'4'
:
args
->
fssize
=
get_fssize
(
arg
);
break
;
case
'5'
:
args
->
zfsroot
=
arg
;
break
;
case
'6'
:
args
->
dir
=
arg
;
break
;
case
'7'
:
args
->
rbdname
=
arg
;
break
;
case
'8'
:
args
->
rbdpool
=
arg
;
break
;
}
return
0
;
}
static
const
struct
option
my_longopts
[]
=
{
static
const
struct
option
my_longopts
[]
=
{
{
"bdev"
,
required_argument
,
0
,
'B'
},
{
"bdev"
,
required_argument
,
0
,
'B'
},
...
@@ -106,31 +57,6 @@ static const struct option my_longopts[] = {
...
@@ -106,31 +57,6 @@ static const struct option my_longopts[] = {
LXC_COMMON_OPTIONS
LXC_COMMON_OPTIONS
};
};
static
void
create_helpfn
(
const
struct
lxc_arguments
*
args
)
{
char
*
argv
[
3
],
*
path
;
pid_t
pid
;
if
(
!
args
->
template
)
return
;
pid
=
fork
();
if
(
pid
)
{
(
void
)
wait_for_pid
(
pid
);
return
;
}
path
=
get_template_path
(
args
->
template
);
argv
[
0
]
=
path
;
argv
[
1
]
=
"-h"
;
argv
[
2
]
=
NULL
;
execv
(
path
,
argv
);
ERROR
(
"Error executing %s -h"
,
path
);
_exit
(
EXIT_FAILURE
);
}
static
struct
lxc_arguments
my_args
=
{
static
struct
lxc_arguments
my_args
=
{
.
progname
=
"lxc-create"
,
.
progname
=
"lxc-create"
,
.
helpfn
=
create_helpfn
,
.
helpfn
=
create_helpfn
,
...
@@ -173,59 +99,143 @@ Options :\n\
...
@@ -173,59 +99,143 @@ Options :\n\
.
options
=
my_longopts
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
parser
=
my_parser
,
.
checker
=
NULL
,
.
checker
=
NULL
,
.
log_priority
=
"ERROR"
,
.
log_file
=
"none"
,
};
};
static
bool
validate_bdev_args
(
struct
lxc_arguments
*
a
)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
case
'B'
:
args
->
bdevtype
=
arg
;
break
;
case
'f'
:
args
->
configfile
=
arg
;
break
;
case
't'
:
args
->
template
=
arg
;
break
;
case
'0'
:
args
->
lvname
=
arg
;
break
;
case
'1'
:
args
->
vgname
=
arg
;
break
;
case
'2'
:
args
->
thinpool
=
arg
;
break
;
case
'3'
:
args
->
fstype
=
arg
;
break
;
case
'4'
:
args
->
fssize
=
get_fssize
(
arg
);
break
;
case
'5'
:
args
->
zfsroot
=
arg
;
break
;
case
'6'
:
args
->
dir
=
arg
;
break
;
case
'7'
:
args
->
rbdname
=
arg
;
break
;
case
'8'
:
args
->
rbdpool
=
arg
;
break
;
}
return
0
;
}
static
uint64_t
get_fssize
(
char
*
s
)
{
{
if
(
strncmp
(
a
->
bdevtype
,
"best"
,
strlen
(
a
->
bdevtype
))
!=
0
)
{
uint64_t
ret
;
if
(
a
->
fstype
||
a
->
fssize
)
{
char
*
end
;
if
(
strncmp
(
a
->
bdevtype
,
"lvm"
,
strlen
(
a
->
bdevtype
))
!=
0
&&
strncmp
(
a
->
bdevtype
,
"loop"
,
strlen
(
a
->
bdevtype
))
!=
0
&&
ret
=
strtoull
(
s
,
&
end
,
0
);
strncmp
(
a
->
bdevtype
,
"rbd"
,
strlen
(
a
->
bdevtype
))
!=
0
)
{
if
(
end
==
s
)
{
ERROR
(
"Invalid blockdev size '%s', using default size"
,
s
);
return
0
;
}
while
(
isblank
(
*
end
))
end
++
;
if
(
*
end
==
'\0'
)
{
ret
*=
1024ULL
*
1024ULL
;
/* MB by default */
}
else
if
(
*
end
==
'b'
||
*
end
==
'B'
)
{
ret
*=
1ULL
;
}
else
if
(
*
end
==
'k'
||
*
end
==
'K'
)
{
ret
*=
1024ULL
;
}
else
if
(
*
end
==
'm'
||
*
end
==
'M'
)
{
ret
*=
1024ULL
*
1024ULL
;
}
else
if
(
*
end
==
'g'
||
*
end
==
'G'
)
{
ret
*=
1024ULL
*
1024ULL
*
1024ULL
;
}
else
if
(
*
end
==
't'
||
*
end
==
'T'
)
{
ret
*=
1024ULL
*
1024ULL
*
1024ULL
*
1024ULL
;
}
else
{
ERROR
(
"Invalid blockdev unit size '%c' in '%s', using default size"
,
*
end
,
s
);
return
0
;
}
return
ret
;
}
static
void
create_helpfn
(
const
struct
lxc_arguments
*
args
)
{
char
*
argv
[
3
],
*
path
;
pid_t
pid
;
if
(
!
args
->
template
)
return
;
pid
=
fork
();
if
(
pid
)
{
(
void
)
wait_for_pid
(
pid
);
return
;
}
path
=
get_template_path
(
args
->
template
);
argv
[
0
]
=
path
;
argv
[
1
]
=
"-h"
;
argv
[
2
]
=
NULL
;
execv
(
path
,
argv
);
ERROR
(
"Error executing %s -h"
,
path
);
_exit
(
EXIT_FAILURE
);
}
static
bool
validate_bdev_args
(
struct
lxc_arguments
*
args
)
{
if
(
strncmp
(
args
->
bdevtype
,
"best"
,
strlen
(
args
->
bdevtype
))
!=
0
)
{
if
(
args
->
fstype
||
args
->
fssize
)
if
(
strncmp
(
args
->
bdevtype
,
"lvm"
,
strlen
(
args
->
bdevtype
))
!=
0
&&
strncmp
(
args
->
bdevtype
,
"loop"
,
strlen
(
args
->
bdevtype
))
!=
0
&&
strncmp
(
args
->
bdevtype
,
"rbd"
,
strlen
(
args
->
bdevtype
))
!=
0
)
{
ERROR
(
"Filesystem type and size are only valid with block devices"
);
ERROR
(
"Filesystem type and size are only valid with block devices"
);
return
false
;
return
false
;
}
}
}
if
(
strncmp
(
a
->
bdevtype
,
"lvm"
,
strlen
(
a
->
bdevtype
))
!=
0
)
{
if
(
strncmp
(
a
rgs
->
bdevtype
,
"lvm"
,
strlen
(
args
->
bdevtype
))
!=
0
)
if
(
a
->
lvname
||
a
->
vgname
||
a
->
thinpool
)
{
if
(
a
rgs
->
lvname
||
args
->
vgname
||
args
->
thinpool
)
{
ERROR
(
"--lvname, --vgname and --thinpool are only valid with -B lvm"
);
ERROR
(
"--lvname, --vgname and --thinpool are only valid with -B lvm"
);
return
false
;
return
false
;
}
}
}
if
(
strncmp
(
a
->
bdevtype
,
"rbd"
,
strlen
(
a
->
bdevtype
))
!=
0
)
{
if
(
strncmp
(
a
rgs
->
bdevtype
,
"rbd"
,
strlen
(
args
->
bdevtype
))
!=
0
)
if
(
a
->
rbdname
||
a
->
rbdpool
)
{
if
(
a
rgs
->
rbdname
||
args
->
rbdpool
)
{
ERROR
(
"--rbdname and --rbdpool are only valid with -B rbd"
);
ERROR
(
"--rbdname and --rbdpool are only valid with -B rbd"
);
return
false
;
return
false
;
}
}
}
if
(
strncmp
(
a
->
bdevtype
,
"zfs"
,
strlen
(
a
->
bdevtype
))
!=
0
)
{
if
(
strncmp
(
a
rgs
->
bdevtype
,
"zfs"
,
strlen
(
args
->
bdevtype
))
!=
0
)
if
(
a
->
zfsroot
)
{
if
(
a
rgs
->
zfsroot
)
{
ERROR
(
"zfsroot is only valid with -B zfs"
);
ERROR
(
"zfsroot is only valid with -B zfs"
);
return
false
;
return
false
;
}
}
}
}
}
return
true
;
}
static
bool
is_valid_storage_type
(
const
char
*
type
)
{
if
(
strcmp
(
type
,
"dir"
)
==
0
||
strcmp
(
type
,
"btrfs"
)
==
0
||
strcmp
(
type
,
"loop"
)
==
0
||
strcmp
(
type
,
"lvm"
)
==
0
||
strcmp
(
type
,
"nbd"
)
==
0
||
strcmp
(
type
,
"overlay"
)
==
0
||
strcmp
(
type
,
"overlayfs"
)
==
0
||
strcmp
(
type
,
"rbd"
)
==
0
||
strcmp
(
type
,
"zfs"
)
==
0
)
return
true
;
return
true
;
return
false
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
...
@@ -238,12 +248,7 @@ int main(int argc, char *argv[])
...
@@ -238,12 +248,7 @@ int main(int argc, char *argv[])
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
if
(
lxc_arguments_parse
(
&
my_args
,
argc
,
argv
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
/* Only create log if explicitly instructed */
if
(
my_args
.
log_file
||
my_args
.
log_priority
)
{
log
.
name
=
my_args
.
name
;
log
.
name
=
my_args
.
name
;
if
(
!
my_args
.
log_file
)
log
.
file
=
"none"
;
else
log
.
file
=
my_args
.
log_file
;
log
.
file
=
my_args
.
log_file
;
log
.
level
=
my_args
.
log_priority
;
log
.
level
=
my_args
.
log_priority
;
log
.
prefix
=
my_args
.
progname
;
log
.
prefix
=
my_args
.
progname
;
...
@@ -252,7 +257,6 @@ int main(int argc, char *argv[])
...
@@ -252,7 +257,6 @@ int main(int argc, char *argv[])
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
if
(
!
my_args
.
template
)
{
if
(
!
my_args
.
template
)
{
ERROR
(
"A template must be specified"
);
ERROR
(
"A template must be specified"
);
...
@@ -318,10 +322,9 @@ int main(int argc, char *argv[])
...
@@ -318,10 +322,9 @@ int main(int argc, char *argv[])
spec
.
fssize
=
my_args
.
fssize
;
spec
.
fssize
=
my_args
.
fssize
;
if
((
strncmp
(
my_args
.
bdevtype
,
"zfs"
,
strlen
(
my_args
.
bdevtype
))
==
0
)
||
if
((
strncmp
(
my_args
.
bdevtype
,
"zfs"
,
strlen
(
my_args
.
bdevtype
))
==
0
)
||
(
strncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
))
==
0
))
{
(
strncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
))
==
0
))
if
(
my_args
.
zfsroot
)
if
(
my_args
.
zfsroot
)
spec
.
zfs
.
zfsroot
=
my_args
.
zfsroot
;
spec
.
zfs
.
zfsroot
=
my_args
.
zfsroot
;
}
if
((
strncmp
(
my_args
.
bdevtype
,
"lvm"
,
strlen
(
my_args
.
bdevtype
))
==
0
)
||
if
((
strncmp
(
my_args
.
bdevtype
,
"lvm"
,
strlen
(
my_args
.
bdevtype
))
==
0
)
||
(
strncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
))
==
0
))
{
(
strncmp
(
my_args
.
bdevtype
,
"best"
,
strlen
(
my_args
.
bdevtype
))
==
0
))
{
...
@@ -354,7 +357,7 @@ int main(int argc, char *argv[])
...
@@ -354,7 +357,7 @@ int main(int argc, char *argv[])
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
]))
{
fprintf
(
stderr
,
"Error creating container %s
\n
"
,
c
->
name
);
ERROR
(
"Failed to create container %s
"
,
c
->
name
);
lxc_container_put
(
c
);
lxc_container_put
(
c
);
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