linux-lvm.redhat.com archive mirror
 help / color / mirror / Atom feed
* [linux-lvm] [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option
@ 2021-03-24  5:09 Zhao Heming
  2021-03-24  9:07 ` Zdenek Kabelac
  0 siblings, 1 reply; 3+ messages in thread
From: Zhao Heming @ 2021-03-24  5:09 UTC (permalink / raw)
  To: linux-lvm, zkabelac, teigland; +Cc: Zhao Heming

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.

Signed-off-by: Zhao Heming <heming.zhao@suse.com>
---
 lib/device/dev-swap.c   | 19 +++++++++++++++++++
 lib/device/dev-type.h   |  1 +
 lib/metadata/lv_manip.c |  9 +++++++++
 3 files changed, 29 insertions(+)

diff --git a/lib/device/dev-swap.c b/lib/device/dev-swap.c
index 3bfb72b38ce6..a65e75b06157 100644
--- a/lib/device/dev-swap.c
+++ b/lib/device/dev-swap.c
@@ -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
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
index bd989f8c8a2a..bbf6c0f1efad 100644
--- a/lib/device/dev-type.h
+++ b/lib/device/dev-type.h
@@ -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);
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 0918780f143c..c099db8419b0 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -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;
 }
 
-- 
2.26.2

_______________________________________________
linux-lvm mailing list
linux-lvm@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [linux-lvm] [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option
  2021-03-24  5:09 [linux-lvm] [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option Zhao Heming
@ 2021-03-24  9:07 ` Zdenek Kabelac
  2021-03-24 11:02   ` heming.zhao
  0 siblings, 1 reply; 3+ messages in thread
From: Zdenek Kabelac @ 2021-03-24  9:07 UTC (permalink / raw)
  To: Zhao Heming; +Cc: teigland, linux-lvm



----- Original Message -----
From: "Zhao Heming" <heming.zhao@suse.com>
To: linux-lvm@redhat.com, zkabelac@redhat.com, teigland@redhat.com
Cc: "Zhao Heming" <heming.zhao@suse.com>
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
linux-lvm@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [linux-lvm] [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option
  2021-03-24  9:07 ` Zdenek Kabelac
@ 2021-03-24 11:02   ` heming.zhao
  0 siblings, 0 replies; 3+ messages in thread
From: heming.zhao @ 2021-03-24 11:02 UTC (permalink / raw)
  To: Zdenek Kabelac; +Cc: teigland, linux-lvm

On 3/24/21 5:07 PM, Zdenek Kabelac wrote:
> 
> 
> ----- Original Message -----
> From: "Zhao Heming" <heming.zhao@suse.com>
> To: linux-lvm@redhat.com, zkabelac@redhat.com, teigland@redhat.com
> Cc: "Zhao Heming" <heming.zhao@suse.com>
> 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 ?
> 

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.

> 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
linux-lvm@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-24 11:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24  5:09 [linux-lvm] [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option Zhao Heming
2021-03-24  9:07 ` Zdenek Kabelac
2021-03-24 11:02   ` heming.zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).