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
87a70c57
Unverified
Commit
87a70c57
authored
Aug 20, 2018
by
Christian Brauner
Committed by
GitHub
Aug 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2550 from 2xsec/bugfix
storage: exit() => _exit()
parents
de206187
75457df5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
41 deletions
+66
-41
nbd.c
src/lxc/storage/nbd.c
+24
-5
lxc_wait.c
src/lxc/tools/lxc_wait.c
+42
-36
No files found.
src/lxc/storage/nbd.c
View file @
87a70c57
...
@@ -48,8 +48,8 @@ struct nbd_attach_data {
...
@@ -48,8 +48,8 @@ struct nbd_attach_data {
const
char
*
path
;
const
char
*
path
;
};
};
static
bool
clone_attach_nbd
(
const
char
*
nbd
,
const
char
*
path
);
static
int
do_attach_nbd
(
void
*
d
);
static
int
do_attach_nbd
(
void
*
d
);
static
bool
clone_attach_nbd
(
const
char
*
nbd
,
const
char
*
path
);
static
bool
nbd_busy
(
int
idx
);
static
bool
nbd_busy
(
int
idx
);
static
void
nbd_detach
(
const
char
*
path
);
static
void
nbd_detach
(
const
char
*
path
);
static
int
nbd_get_partition
(
const
char
*
src
);
static
int
nbd_get_partition
(
const
char
*
src
);
...
@@ -69,16 +69,21 @@ bool attach_nbd(char *src, struct lxc_conf *conf)
...
@@ -69,16 +69,21 @@ bool attach_nbd(char *src, struct lxc_conf *conf)
p
=
strchr
(
orig
,
':'
);
p
=
strchr
(
orig
,
':'
);
if
(
p
)
if
(
p
)
*
p
=
'\0'
;
*
p
=
'\0'
;
while
(
1
)
{
while
(
1
)
{
sprintf
(
path
,
"/dev/nbd%d"
,
i
);
sprintf
(
path
,
"/dev/nbd%d"
,
i
);
if
(
!
file_exists
(
path
))
if
(
!
file_exists
(
path
))
return
false
;
return
false
;
if
(
nbd_busy
(
i
))
{
if
(
nbd_busy
(
i
))
{
i
++
;
i
++
;
continue
;
continue
;
}
}
if
(
!
clone_attach_nbd
(
path
,
orig
))
if
(
!
clone_attach_nbd
(
path
,
orig
))
return
false
;
return
false
;
conf
->
nbd_idx
=
i
;
conf
->
nbd_idx
=
i
;
return
true
;
return
true
;
}
}
...
@@ -152,10 +157,10 @@ int nbd_mount(struct lxc_storage *bdev)
...
@@ -152,10 +157,10 @@ int nbd_mount(struct lxc_storage *bdev)
}
}
/* It might take awhile for the partition files to show up */
/* It might take awhile for the partition files to show up */
if
(
partition
)
{
if
(
partition
)
if
(
!
wait_for_partition
(
path
))
if
(
!
wait_for_partition
(
path
))
return
-
2
;
return
-
2
;
}
ret
=
mount_unknown_fs
(
path
,
bdev
->
dest
,
bdev
->
mntopts
);
ret
=
mount_unknown_fs
(
path
,
bdev
->
dest
,
bdev
->
mntopts
);
if
(
ret
<
0
)
if
(
ret
<
0
)
ERROR
(
"Error mounting %s"
,
bdev
->
src
);
ERROR
(
"Error mounting %s"
,
bdev
->
src
);
...
@@ -178,6 +183,7 @@ bool requires_nbd(const char *path)
...
@@ -178,6 +183,7 @@ bool requires_nbd(const char *path)
{
{
if
(
strncmp
(
path
,
"nbd:"
,
4
)
==
0
)
if
(
strncmp
(
path
,
"nbd:"
,
4
)
==
0
)
return
true
;
return
true
;
return
false
;
return
false
;
}
}
...
@@ -226,6 +232,7 @@ static int do_attach_nbd(void *d)
...
@@ -226,6 +232,7 @@ static int do_attach_nbd(void *d)
exit
(
0
);
exit
(
0
);
}
else
if
(
fdsi
.
ssi_signo
==
SIGCHLD
)
{
}
else
if
(
fdsi
.
ssi_signo
==
SIGCHLD
)
{
int
status
;
int
status
;
/* If qemu-nbd fails, or is killed by a signal,
/* If qemu-nbd fails, or is killed by a signal,
* then exit */
* then exit */
while
(
waitpid
(
-
1
,
&
status
,
WNOHANG
)
>
0
)
{
while
(
waitpid
(
-
1
,
&
status
,
WNOHANG
)
>
0
)
{
...
@@ -240,12 +247,13 @@ static int do_attach_nbd(void *d)
...
@@ -240,12 +247,13 @@ static int do_attach_nbd(void *d)
}
}
close
(
sfd
);
close
(
sfd
);
if
(
sigprocmask
(
SIG_UNBLOCK
,
&
mask
,
NULL
)
==
-
1
)
if
(
sigprocmask
(
SIG_UNBLOCK
,
&
mask
,
NULL
)
==
-
1
)
WARN
(
"Warning: unblocking signals for nbd watcher"
);
WARN
(
"Warning: unblocking signals for nbd watcher"
);
execlp
(
"qemu-nbd"
,
"qemu-nbd"
,
"-c"
,
nbd
,
path
,
(
char
*
)
NULL
);
execlp
(
"qemu-nbd"
,
"qemu-nbd"
,
"-c"
,
nbd
,
path
,
(
char
*
)
NULL
);
SYSERROR
(
"Error executing qemu-nbd"
);
SYSERROR
(
"Error executing qemu-nbd"
);
exit
(
1
);
_
exit
(
1
);
}
}
static
bool
clone_attach_nbd
(
const
char
*
nbd
,
const
char
*
path
)
static
bool
clone_attach_nbd
(
const
char
*
nbd
,
const
char
*
path
)
...
@@ -259,6 +267,7 @@ static bool clone_attach_nbd(const char *nbd, const char *path)
...
@@ -259,6 +267,7 @@ static bool clone_attach_nbd(const char *nbd, const char *path)
pid
=
lxc_clone
(
do_attach_nbd
,
&
data
,
CLONE_NEWPID
);
pid
=
lxc_clone
(
do_attach_nbd
,
&
data
,
CLONE_NEWPID
);
if
(
pid
<
0
)
if
(
pid
<
0
)
return
false
;
return
false
;
return
true
;
return
true
;
}
}
...
@@ -270,6 +279,7 @@ static bool nbd_busy(int idx)
...
@@ -270,6 +279,7 @@ static bool nbd_busy(int idx)
ret
=
snprintf
(
path
,
100
,
"/sys/block/nbd%d/pid"
,
idx
);
ret
=
snprintf
(
path
,
100
,
"/sys/block/nbd%d/pid"
,
idx
);
if
(
ret
<
0
||
ret
>=
100
)
if
(
ret
<
0
||
ret
>=
100
)
return
true
;
return
true
;
return
file_exists
(
path
);
return
file_exists
(
path
);
}
}
...
@@ -282,15 +292,17 @@ static void nbd_detach(const char *path)
...
@@ -282,15 +292,17 @@ static void nbd_detach(const char *path)
SYSERROR
(
"Error forking to detach nbd"
);
SYSERROR
(
"Error forking to detach nbd"
);
return
;
return
;
}
}
if
(
pid
)
{
if
(
pid
)
{
ret
=
wait_for_pid
(
pid
);
ret
=
wait_for_pid
(
pid
);
if
(
ret
<
0
)
if
(
ret
<
0
)
ERROR
(
"nbd disconnect returned an error"
);
ERROR
(
"nbd disconnect returned an error"
);
return
;
return
;
}
}
execlp
(
"qemu-nbd"
,
"qemu-nbd"
,
"-d"
,
path
,
(
char
*
)
NULL
);
execlp
(
"qemu-nbd"
,
"qemu-nbd"
,
"-d"
,
path
,
(
char
*
)
NULL
);
SYSERROR
(
"Error executing qemu-nbd"
);
SYSERROR
(
"Error executing qemu-nbd"
);
exit
(
1
);
_
exit
(
1
);
}
}
/*
/*
...
@@ -303,24 +315,31 @@ static int nbd_get_partition(const char *src)
...
@@ -303,24 +315,31 @@ static int nbd_get_partition(const char *src)
char
*
p
=
strchr
(
src
,
':'
);
char
*
p
=
strchr
(
src
,
':'
);
if
(
!
p
)
if
(
!
p
)
return
0
;
return
0
;
p
=
strchr
(
p
+
1
,
':'
);
p
=
strchr
(
p
+
1
,
':'
);
if
(
!
p
)
if
(
!
p
)
return
0
;
return
0
;
p
++
;
p
++
;
if
(
*
p
<
'1'
||
*
p
>
'9'
)
if
(
*
p
<
'1'
||
*
p
>
'9'
)
return
0
;
return
0
;
return
*
p
-
'0'
;
return
*
p
-
'0'
;
}
}
static
bool
wait_for_partition
(
const
char
*
path
)
static
bool
wait_for_partition
(
const
char
*
path
)
{
{
int
count
=
0
;
int
count
=
0
;
while
(
count
<
5
)
{
while
(
count
<
5
)
{
if
(
file_exists
(
path
))
if
(
file_exists
(
path
))
return
true
;
return
true
;
sleep
(
1
);
sleep
(
1
);
count
++
;
count
++
;
}
}
ERROR
(
"Device %s did not show up after 5 seconds"
,
path
);
ERROR
(
"Device %s did not show up after 5 seconds"
,
path
);
return
false
;
return
false
;
}
}
src/lxc/tools/lxc_wait.c
View file @
87a70c57
...
@@ -37,25 +37,8 @@
...
@@ -37,25 +37,8 @@
lxc_log_define
(
lxc_wait
,
lxc
);
lxc_log_define
(
lxc_wait
,
lxc
);
static
int
my_checker
(
const
struct
lxc_arguments
*
args
)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
{
static
int
my_checker
(
const
struct
lxc_arguments
*
args
);
if
(
!
args
->
states
)
{
ERROR
(
"Missing state option to wait for"
);
return
-
1
;
}
return
0
;
}
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
case
's'
:
args
->
states
=
optarg
;
break
;
case
't'
:
args
->
timeout
=
atol
(
optarg
);
break
;
}
return
0
;
}
static
const
struct
option
my_longopts
[]
=
{
static
const
struct
option
my_longopts
[]
=
{
{
"state"
,
required_argument
,
0
,
's'
},
{
"state"
,
required_argument
,
0
,
's'
},
...
@@ -64,8 +47,8 @@ static const struct option my_longopts[] = {
...
@@ -64,8 +47,8 @@ static const struct option my_longopts[] = {
};
};
static
struct
lxc_arguments
my_args
=
{
static
struct
lxc_arguments
my_args
=
{
.
progname
=
"lxc-wait"
,
.
progname
=
"lxc-wait"
,
.
help
=
"\
.
help
=
"\
--name=NAME --state=STATE
\n
\
--name=NAME --state=STATE
\n
\
\n
\
\n
\
lxc-wait waits for NAME container state to reach STATE
\n
\
lxc-wait waits for NAME container state to reach STATE
\n
\
...
@@ -77,12 +60,38 @@ Options :\n\
...
@@ -77,12 +60,38 @@ Options :\n\
ABORTING, FREEZING, FROZEN, THAWED
\n
\
ABORTING, FREEZING, FROZEN, THAWED
\n
\
-t, --timeout=TMO Seconds to wait for state changes
\n
\
-t, --timeout=TMO Seconds to wait for state changes
\n
\
--rcfile=FILE Load configuration file FILE
\n
"
,
--rcfile=FILE Load configuration file FILE
\n
"
,
.
options
=
my_longopts
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
.
parser
=
my_parser
,
.
checker
=
my_checker
,
.
checker
=
my_checker
,
.
timeout
=
-
1
,
.
log_priority
=
"ERROR"
,
.
log_file
=
"none"
,
.
timeout
=
-
1
,
};
};
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
case
's'
:
args
->
states
=
optarg
;
break
;
case
't'
:
args
->
timeout
=
atol
(
optarg
);
break
;
}
return
0
;
}
static
int
my_checker
(
const
struct
lxc_arguments
*
args
)
{
if
(
!
args
->
states
)
{
ERROR
(
"Missing state option to wait for"
);
return
-
1
;
}
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
struct
lxc_container
*
c
;
struct
lxc_container
*
c
;
...
@@ -91,18 +100,15 @@ int main(int argc, char *argv[])
...
@@ -91,18 +100,15 @@ 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 */
log
.
name
=
my_args
.
name
;
if
(
my_args
.
log_file
||
my_args
.
log_priority
)
{
log
.
file
=
my_args
.
log_file
;
log
.
name
=
my_args
.
name
;
log
.
level
=
my_args
.
log_priority
;
log
.
file
=
my_args
.
log_file
;
log
.
prefix
=
my_args
.
progname
;
log
.
level
=
my_args
.
log_priority
;
log
.
quiet
=
my_args
.
quiet
;
log
.
prefix
=
my_args
.
progname
;
log
.
lxcpath
=
my_args
.
lxcpath
[
0
];
log
.
quiet
=
my_args
.
quiet
;
log
.
lxcpath
=
my_args
.
lxcpath
[
0
];
if
(
lxc_log_init
(
&
log
))
if
(
lxc_log_init
(
&
log
))
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
)
...
...
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