stable-2.02 - lvresize: deny operation on swap dev without force option
PATCH 1/1 stable-2.02 - lvresize: deny operation on swap dev without force option
When lvmetad is active on system and some memory pages of lvmetad swapout, user may issue lvextend/lvresize on swap LV. The resize operation will suspend & resume swap device (by reload dm table). After suspended swap device, lvmetad will be in UN status for waiting swapin pages from suspended swap dev. lvmetad will hung, then lvresize will fail to conection to lvmetad. then the resize operation will fail, lvresize leaves suspended swap, the logic dead lock is happending.
This commit add "--force" checking for lvresize on swap device. The "--force" and related error info make user to understand swap device should be deactive when resizing.
--- lib/device/dev-swap.c | 19 +++++++++++++++++++ lib/device/dev-type.h | 1 + lib/metadata/lv_manip.c | 9 +++++++++ 3 files changed, 29 insertions(+)
lib/device/dev-swap.c +19 -0
@@ -14,6 +14,7 @@#include "lib.h" #include "dev-type.h" +#include "dev-cache.h" #ifdef __linux__
@@ -73,4 +74,22 @@ int dev_is_swap(struct device *dev, uint64_t *offset_found, int full) return ret; } +/* User may set up swap LV with complex underlying devs. */ +int lv_is_swap (struct logical_volume *lv,int *is_swap) +{ +struct device *dev; +struct dev_iter *iter; + +if (!(iter =dev_iter_create (NULL ,1 ))) + return_0; + + *is_swap =0 ; +while ((dev =dev_iter_get (iter))) { + *is_swap |=dev_is_swap (dev,NULL ,1 ); + } +dev_iter_destroy (iter); + +return 1 ; +} +#endif
lib/device/dev-type.h +1 -0
@@ -63,6 +63,7 @@ int dev_is_luks(struct device *dev, uint64_t *signature, int full);int dasd_is_cdl_formatted (struct device *dev);int udev_dev_is_mpath_component (struct device *dev);int udev_dev_is_md_component (struct device *dev); +int lv_is_swap (struct logical_volume *lv,int *is_swap);int dev_is_lvm1 (struct device *dev,char *buf,int buflen);int dev_is_pool (struct device *dev,char *buf,int buflen);
lib/metadata/lv_manip.c +9 -0
@@ -4830,6 +4830,7 @@ static int _lvresize_check(struct logical_volume *lv, {struct volume_group *vg = lv->vg;struct lv_segment *seg =first_seg (lv); +int is_swap;if (lv_is_external_origin (lv)) {/*
@@ -4927,6 +4928,14 @@ static int _lvresize_check(struct logical_volume *lv,return 0 ; } +if (lv_is_swap (lv, &is_swap)) { +if (is_swap && !lp->force) { +log_error ("LV is a swap device, and command without --force option." ); +log_error ("Please make sure swap is DEACTIVE and re-run with --force option." ); +return 0 ; + } + } +return 1 ; }
Signature · 7 lines
2.26.2 _______________________________________________ linux-lvm mailing list [email protected] https://listman.redhat.com/mailman/listinfo/linux-lvm read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/
----- Original Message -----
From: "Zhao Heming" <[email protected]>
To: [email protected], [email protected], [email protected]
Cc: "Zhao Heming" <[email protected]>
Sent: Wednesday, March 24, 2021 6:09:09 AM
Subject: [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option
When lvmetad is active on system and some memory pages of lvmetad swapout, user may issue lvextend/lvresize on swap LV. The resize operation will suspend & resume swap device (by reload dm table). After suspended swap device, lvmetad will be in UN status for waiting swapin pages from suspended swap dev. lvmetad will hung, then lvresize will fail to conection to lvmetad. then the resize operation will fail, lvresize leaves suspended swap, the logic dead lock is happending.
Hi
It seems there is something wrong elsewhere.
There should be no contact to lvmetad while ANY devices are in suspend state. Maybe something got reshuffled into wrong place.
Can you please provide 'lvextend -vvvvv' when it hangs ?
Regards
Zdenek
_______________________________________________
linux-lvm mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/
Quoted 19 lines · Zdenek Kabelac
----- Original Message -----
From: "Zhao Heming" <[email protected]>
To: [email protected], [email protected], [email protected]
Cc: "Zhao Heming" <[email protected]>
Sent: Wednesday, March 24, 2021 6:09:09 AM
Subject: [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force optionWhen lvmetad is active on system and some memory pages of lvmetad swapout, user may issue lvextend/lvresize on swap LV. The resize operation will suspend & resume swap device (by reload dm table). After suspended swap device, lvmetad will be in UN status for waiting swapin pages from suspended swap dev. lvmetad will hung, then lvresize will fail to conection to lvmetad. then the resize operation will fail, lvresize leaves suspended swap, the logic dead lock is happending.
Quoted 8 lines
Hi
It seems there is something wrong elsewhere.
There should be no contact to lvmetad while ANY devices are in suspend state. Maybe something got reshuffled into wrong place.Can you please provide 'lvextend -vvvvv' when it hangs ?
I can't show your "-vvvvv", the issue was reported from one suse customer.
the syslog shows machine was running lvextend at the start time of lvmetad UN.
the machine running lvm2 version is 2.02.120. some code may different with latest stable-2.02 branch. the machine became no response and triggered coredump later.
Quoted 1 line
There should be no contact to lvmetad while ANY devices are in suspend state.
lvextend promise itself doesn't need to contact lvmetad. and if my understanding is correct, critical_section_inc() is only process internal protection. if another lvm2 cmd calling lvmetad when lvextend executing, the story will happen on my way.
(in my opinion) the flow:
1. lvmetad some page swapped out
2. lvextend was running, swap device was suspended successfully. (enter critical section)
3. lvmetad kept running (by whatever calling)
4. lvmetad need to swap in some pages but swap device suspended. lvmetad status become UN.
5. the lvextend resumed suspended swap device but failed.
I guess lvmetad UN may trigger/block kernel dm layer failed to resume. I can't find log/info to show the reason of resume failed. From the coredump, lvmetad stacks show lvmetad in UN state, and swap status is suspended (dm dev with flags: DMF_BLOCK_IO_FOR_SUSPEND, DMF_SUSPENDED).
Thanks,
heming
_______________________________________________
linux-lvm mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/