linux-lvm.redhat.com archive mirror
 help / color / mirror / Atom feed
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>
Subject: [linux-lvm] [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option
Date: Wed, 24 Mar 2021 13:09:09 +0800	[thread overview]
Message-ID: <1616562549-25903-1-git-send-email-heming.zhao@suse.com> (raw)

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/


             reply	other threads:[~2021-03-24  5:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24  5:09 Zhao Heming [this message]
2021-03-24  9:07 ` [linux-lvm] [PATCH] [PATCH] stable-2.02 - lvresize: deny operation on swap dev without force option Zdenek Kabelac
2021-03-24 11:02   ` heming.zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1616562549-25903-1-git-send-email-heming.zhao@suse.com \
    --to=heming.zhao@suse.com \
    --cc=linux-lvm@redhat.com \
    --cc=teigland@redhat.com \
    --cc=zkabelac@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).