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
6c5ee20c
Unverified
Commit
6c5ee20c
authored
Dec 09, 2020
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage/lvm: cleanup do_lvm_create()
Fixes: Coverity 1461741 Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
f4d45f9a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
42 deletions
+21
-42
lvm.c
src/lxc/storage/lvm.c
+21
-42
No files found.
src/lxc/storage/lvm.c
View file @
6c5ee20c
...
@@ -97,41 +97,32 @@ static int lvm_snapshot_exec_wrapper(void *data)
...
@@ -97,41 +97,32 @@ static int lvm_snapshot_exec_wrapper(void *data)
*/
*/
static
int
do_lvm_create
(
const
char
*
path
,
uint64_t
size
,
const
char
*
thinpool
)
static
int
do_lvm_create
(
const
char
*
path
,
uint64_t
size
,
const
char
*
thinpool
)
{
{
__do_free
char
*
pathdup
=
NULL
;
int
len
,
ret
;
int
len
,
ret
;
char
*
pathdup
,
*
vg
,
*
lv
;
char
*
vg
,
*
lv
;
char
cmd_output
[
PATH_MAX
];
char
cmd_output
[
PATH_MAX
];
char
sz
[
24
];
char
sz
[
24
];
__do_free
char
*
tp
=
NULL
;
__do_free
char
*
tp
=
NULL
;
struct
lvcreate_args
cmd_args
=
{
0
};
struct
lvcreate_args
cmd_args
=
{
0
};
ret
=
snprintf
(
sz
,
24
,
"%"
PRIu64
"b"
,
size
);
ret
=
snprintf
(
sz
,
24
,
"%"
PRIu64
"b"
,
size
);
if
(
ret
<
0
||
ret
>=
24
)
{
if
(
ret
<
0
||
ret
>=
24
)
ERROR
(
"Failed to create string: %d"
,
ret
);
return
log_error
(
-
EIO
,
"Failed to create string: %d"
,
ret
);
return
-
1
;
}
pathdup
=
strdup
(
path
);
pathdup
=
strdup
(
path
);
if
(
!
pathdup
)
{
if
(
!
pathdup
)
ERROR
(
"Failed to duplicate string
\"
%s
\"
"
,
path
);
return
log_error
(
-
ENOMEM
,
"Failed to duplicate string
\"
%s
\"
"
,
path
);
return
-
1
;
}
lv
=
strrchr
(
pathdup
,
'/'
);
lv
=
strrchr
(
pathdup
,
'/'
);
if
(
!
lv
)
{
if
(
!
lv
)
ERROR
(
"Failed to detect
\"
/
\"
in string
\"
%s
\"
"
,
pathdup
);
return
log_error
(
-
EINVAL
,
"Failed to detect
\"
/
\"
in string
\"
%s
\"
"
,
pathdup
);
free
(
pathdup
);
return
-
1
;
}
*
lv
=
'\0'
;
*
lv
=
'\0'
;
lv
++
;
lv
++
;
TRACE
(
"Parsed logical volume
\"
%s
\"
"
,
lv
);
TRACE
(
"Parsed logical volume
\"
%s
\"
"
,
lv
);
vg
=
strrchr
(
pathdup
,
'/'
);
vg
=
strrchr
(
pathdup
,
'/'
);
if
(
!
vg
)
{
if
(
!
vg
)
ERROR
(
"Failed to detect
\"
/
\"
in string
\"
%s
\"
"
,
pathdup
);
return
log_error
(
-
EINVAL
,
"Failed to detect
\"
/
\"
in string
\"
%s
\"
"
,
pathdup
);
free
(
pathdup
);
return
-
1
;
}
vg
++
;
vg
++
;
TRACE
(
"Parsed volume group
\"
%s
\"
"
,
vg
);
TRACE
(
"Parsed volume group
\"
%s
\"
"
,
vg
);
...
@@ -140,18 +131,13 @@ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool)
...
@@ -140,18 +131,13 @@ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool)
tp
=
must_realloc
(
NULL
,
len
);
tp
=
must_realloc
(
NULL
,
len
);
ret
=
snprintf
(
tp
,
len
,
"%s/%s"
,
pathdup
,
thinpool
);
ret
=
snprintf
(
tp
,
len
,
"%s/%s"
,
pathdup
,
thinpool
);
if
(
ret
<
0
||
ret
>=
len
)
{
if
(
ret
<
0
||
ret
>=
len
)
ERROR
(
"Failed to create string: %d"
,
ret
);
return
log_error
(
-
EIO
,
"Failed to create string: %d"
,
ret
);
free
(
pathdup
);
return
-
1
;
}
ret
=
lvm_is_thin_pool
(
tp
);
ret
=
lvm_is_thin_pool
(
tp
);
TRACE
(
"got %d for thin pool at path: %s"
,
ret
,
tp
);
TRACE
(
"got %d for thin pool at path: %s"
,
ret
,
tp
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to detect whether
\"
%s
\"
is a thinpool"
,
tp
);
return
log_error
(
-
EINVAL
,
"Failed to detect whether
\"
%s
\"
is a thinpool"
,
tp
);
free
(
pathdup
);
return
-
1
;
}
else
if
(
!
ret
)
{
}
else
if
(
!
ret
)
{
TRACE
(
"Detected that
\"
%s
\"
is not a thinpool"
,
tp
);
TRACE
(
"Detected that
\"
%s
\"
is not a thinpool"
,
tp
);
tp
=
NULL
;
tp
=
NULL
;
...
@@ -165,30 +151,23 @@ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool)
...
@@ -165,30 +151,23 @@ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool)
cmd_args
.
lv
=
lv
;
cmd_args
.
lv
=
lv
;
cmd_args
.
size
=
sz
;
cmd_args
.
size
=
sz
;
cmd_args
.
sigwipe
=
true
;
cmd_args
.
sigwipe
=
true
;
TRACE
(
"Creating new lvm storage volume
\"
%s
\"
on volume group
\"
%s
\"
"
TRACE
(
"Creating new lvm storage volume
\"
%s
\"
on volume group
\"
%s
\"
of size
\"
%s
\"
"
,
lv
,
vg
,
sz
);
"of size
\"
%s
\"
"
,
lv
,
vg
,
sz
);
ret
=
run_command_status
(
cmd_output
,
sizeof
(
cmd_output
),
lvm_create_exec_wrapper
,
ret
=
run_command_status
(
cmd_output
,
sizeof
(
cmd_output
),
(
void
*
)
&
cmd_args
);
lvm_create_exec_wrapper
,
(
void
*
)
&
cmd_args
);
/* If lvcreate is old and doesn't support signature wiping, try again without it.
/* If lvcreate is old and doesn't support signature wiping, try again without it.
* Test for exit code EINVALID_CMD_LINE(3) of lvcreate command.
* Test for exit code EINVALID_CMD_LINE(3) of lvcreate command.
*/
*/
if
(
WIFEXITED
(
ret
)
&&
WEXITSTATUS
(
ret
)
==
3
)
{
if
(
WIFEXITED
(
ret
)
&&
WEXITSTATUS
(
ret
)
==
3
)
{
cmd_args
.
sigwipe
=
false
;
cmd_args
.
sigwipe
=
false
;
ret
=
run_command
(
cmd_output
,
sizeof
(
cmd_output
),
ret
=
run_command
(
cmd_output
,
sizeof
(
cmd_output
),
lvm_create_exec_wrapper
,
lvm_create_exec_wrapper
,
(
void
*
)
&
cmd_args
);
(
void
*
)
&
cmd_args
);
}
}
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
ERROR
(
"Failed to create logical volume
\"
%s
\"
: %s"
,
lv
,
return
log_error
(
-
1
,
"Failed to create logical volume
\"
%s
\"
: %s"
,
lv
,
cmd_output
);
cmd_output
);
TRACE
(
"Created new lvm storage volume
\"
%s
\"
on volume group
\"
%s
\"
of size
\"
%s
\"
"
,
lv
,
vg
,
sz
);
free
(
pathdup
);
return
-
1
;
}
TRACE
(
"Created new lvm storage volume
\"
%s
\"
on volume group
\"
%s
\"
"
"of size
\"
%s
\"
"
,
lv
,
vg
,
sz
);
free
(
pathdup
);
return
ret
;
return
ret
;
}
}
...
...
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