LVM2: some code cleanups and bugfixs checked by codeDEX tools
cover LVM2: some code cleanups and bugfixs checked by codeDEX tools
When I learn the LVM2 source code and test it, I find some bugs and fix them. At the same time, static scanning tools were used to analyze the code, and several possible problems were found.
repo: https://sourceware.org/git/lvm2.git
repo link: https://sourceware.org/git/lvm2.git
branch: master
wuguanghao (4):
pvmove: check return value of top_level_lv_name() in _set_up_pvmove_lv
lvconvert_poll: check whether lv is a snapshot type in poll_thin_merge_progress
lvconvert: _lvconvert_splitsnapshot check if lv is snapshot type fix core dump when thinpool size more than the remaining space of vg
tools/lvconvert.c | 3 +++ tools/lvconvert_poll.c | 2 +- tools/lvcreate.c | 7 +++++++ tools/pvmove.c | 7 ++++++- 4 files changed, 17 insertions(+), 2 deletions(-)
PATCH 1/4 pvmove: check return value of top_level_lv_name() in _set_up_pvmove_lv
The return value of top_level_lv_name may be NULL, so we should check return value of top_level_lv_name before calling strcmp(lv->name, top_level_lv_name(vg, lv_name)).
--- tools/pvmove.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/pvmove.c +6 -1
@@ -326,6 +326,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,int lv_skipped =0 ;int needs_exclusive = *exclusive;const struct logical_volume *holder; +const char *new_lv_name;/* FIXME Cope with non-contiguous => splitting existing segments */ if (!(lv_mirr = lv_create_empty("pvmove%d", NULL,
@@ -363,7 +364,11 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,if (lv == lv_mirr)continue ; -if (lv_name &&strcmp (lv->name,top_level_lv_name (vg, lv_name))) + new_lv_name =top_level_lv_name (vg, lv_name); +if (!new_lv_name) +return NULL ; + +if (lv_name &&strcmp (lv->name, new_lv_name))continue ;if (!lv_is_on_pvs (lv, source_pvl))
PATCH 2/4 lvconvert_poll: check whether lv is a snapshot type in poll_thin_merge_progress
In reply to Wu Guanghaolv may not be a snapshot type, the return value of find_snapshot(lv) may be NULL. Here, we will call stack if lv is not a snapshot type.
--- tools/lvconvert_poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lvconvert_poll.c +1 -1
@@ -176,7 +176,7 @@ progress_t poll_thin_merge_progress(struct cmd_context *cmd, {uint32_t device_id; -if (!lv_thin_device_id (lv, &device_id)) { +if (!lv_thin_device_id (lv, &device_id) || !lv_is_snapshot (lv)) { stack;return PROGRESS_CHECK_FAILED ; }
PATCH 3/4 lvconvert: _lvconvert_splitsnapshot check if lv is snapshot type
In reply to Wu Guanghaocow may not be a snapshot type, the return value of origin_from_cow(cow) may be NULL
--- tools/lvconvert.c | 3 +++ 1 file changed, 3 insertions(+)
tools/lvconvert.c +3 -0
@@ -1825,6 +1825,9 @@ static int _lvconvert_splitsnapshot(struct cmd_context *cmd, struct logical_volustruct volume_group *vg = cow->vg;const char *cow_name =display_lvname (cow); +if (!lv_is_snapshot (cow)) +return 0 ; +if (lv_is_virtual_origin (origin_from_cow (cow))) {log_error ("Unable to split off snapshot %s with virtual origin." , cow_name);return 0 ;
PATCH 4/4 fix core dump when thinpool size more than the remaining, space of vg
In reply to Wu GuanghaoCreate thinpool through the lvcreate command,
specify the data device size of the thinpool as x,
the metadata device size as y, and the remaining space of the volume group as z. When x + y < z and x + 2y > z, then it must enter the core dump.
Example:
"
sdc 8:32 0 40G 0 disk
# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created.
# vgcreate vg /dev/sdc
Volume group "vg" successfully created
# lvcreate -L 30G --poolmetadatasize 5G -T vg/thinpool
Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
lvcreate: metadata/pv_map.c:198: consume_pv_area: Assertion `to_go <= pva->count' failed. Aborted (core dumped)
"
When the volume group allocates space, it will surround the assertion when it finds that its own space is insufficient, leading to coredump.
So before actually creating the thinpool, we will check if the remaining space of the volume group is sufficient
--- tools/lvcreate.c | 7 +++++++ 1 file changed, 7 insertions(+)
tools/lvcreate.c +7 -0
@@ -1721,6 +1721,13 @@ static int _lvcreate_single(struct cmd_context *cmd, const char *vg_name,if (!handle_pool_metadata_spare (vg, lp->pool_metadata_extents, lp->pvh, lp->pool_metadata_spare)) goto_out; + +if (vg->free_count < (uint64_t )lp->extents + lp->pool_metadata_extents) { +log_error ("%s doesn't have enough space, create thinpool failed. %s" , + vg->name, lp->pool_metadata_spare ? +"metadata back device occupies part of the VG space" :"" ); + goto_out; + }log_verbose ("Making pool %s in VG %s using segtype %s" , lp->pool_name ? :"with generated name" , lp->vg_name, lp->segtype->name);
cover LVM2: some code cleanups and bugfixs checked by codeDEX tools
In reply to Wu GuanghaoDne 11. 09. 20 v 11:38 Wu Guanghao napsal(a):
Quoted 9 lines
When I learn the LVM2 source code and test it, I find some bugs and fix them. At the same time, static scanning tools were used to analyze the code, and several possible problems were found.
repo: https://sourceware.org/git/lvm2.git
repo link: https://sourceware.org/git/lvm2.git
branch: master
Quoted 6 lines
wuguanghao (4):
pvmove: check return value oftop_level_lv_name()in_set_up_pvmove_lv
lvconvert_poll: check whether lv is a snapshot type inpoll_thin_merge_progress
lvconvert:_lvconvert_splitsnapshotcheck if lv is snapshot type fix core dump when thinpool size more than the remaining space of vg
Hi
Great findings - I'll check how they could be applied. In some cases you are rather fixed internal error so it's always great if some test case which show how the error can be hit is provided (like in patch 4)
Regards
Zdenek
cover LVM2: some code cleanups and bugfixs checked by codeDEX tools
Hi
Thanks for your review. If you have a better solution for patch 4, please reply by email.
Regards
Wu Guanghao
? 2020/9/11 19:07, Zdenek Kabelac ??:
Quoted 31 lines
Dne 11. 09. 20 v 11:38 Wu Guanghao napsal(a):
Quoted 9 lines
When I learn the LVM2 source code and test it, I find some bugs and fix them. At the same time, static scanning tools were used to analyze the code, and several possible problems were found.
repo: https://sourceware.org/git/lvm2.git
repo link: https://sourceware.org/git/lvm2.git
branch: masterQuoted 6 lines
wuguanghao (4):
?? pvmove: check return value oftop_level_lv_name()in_set_up_pvmove_lv??lvconvert_poll: check whether lv is a snapshot type inpoll_thin_merge_progress?? lvconvert:_lvconvert_splitsnapshotcheck if lv is snapshot type ?? fix core dump when thinpool size more than the remaining space of vgHi
Great findings - I'll check how they could be applied. In some cases you are rather fixed internal error so it's always great if some test case which show how the error can be hit is provided (like in patch 4)
Regards
Zdenek
.
cover LVM2: some code cleanups and bugfixs checked by codeDEX tools
In reply to Zdenek KabelacDne 11. 09. 20 v 13:07 Zdenek Kabelac napsal(a):
Quoted 19 lines
Dne 11. 09. 20 v 11:38 Wu Guanghao napsal(a):
Quoted 9 lines
When I learn the LVM2 source code and test it, I find some bugs and fix them. At the same time, static scanning tools were used to analyze the code, and several possible problems were found.
repo: https://sourceware.org/git/lvm2.git
repo link: https://sourceware.org/git/lvm2.git
branch: masterQuoted 7 lines
wuguanghao (4):
?? pvmove: check return value oftop_level_lv_name()in_set_up_pvmove_lv??lvconvert_poll: check whether lv is a snapshot type inpoll_thin_merge_progress
?? lvconvert:_lvconvert_splitsnapshotcheck if lv is snapshot type ?? fix core dump when thinpool size more than the remaining space of vg
Quoted 6 lines
Hi
Great findings - I'll check how they could be applied. In some cases you are rather fixed internal error so it's always great if some test case which show how the error can be hit is provided (like in patch 4)
Hi
So the patches are upstream - although they need some extra care:
1 ->
https://www.redhat.com/archives/lvm-devel/2020-September/msg00059.html
Added handling of lv_name
2 ->
https://www.redhat.com/archives/lvm-devel/2020-September/msg00063.html
Switched || to &&
3 ->
https://www.redhat.com/archives/lvm-devel/2020-September/msg00069.html
We are actually splitting 'cow' so lv_is_cow()
4 ->
https://www.redhat.com/archives/lvm-devel/2020-September/msg00062.html
Fixed differently by correcting evaluation of needed extents for allocation.
Once again thanks for reporting mainly the issue from patch 4.
Regards
Zdenek