Skip to contentSkip to conversation

blkdeactive: Introduce option "forcevg" to forcibly deactivate VG

PATCH New Leo Yan 3 participants 9 messages Feb 25, 2021 – Mar 3, 2021

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH 1/2 blkdeactive: Introduce option "forcevg" to forcibly deactivate VG

From: Zhang Huan <[email protected]>

This patch introduces new option "forcevg" for LVM, the main purpose is to flush in-flight I/O operations and replace the LV's device mapper table with 'error' target, this is accomplished by using command "dmsetup wipe_table".

To handle the failure as soon as possible, it will not deactivate holders and not try to use command "lvchange", thus can speed up wiping table.

This option is supposed to be used by "lvmlockctl" command to forcibly deactivate volume group, this can avoid watchdog reset when detect drive failures.

[Refactored changes and commit log]
---
 man/blkdeactivate.8_main    | 17 +++++++++++
 scripts/blkdeactivate.sh.in | 71 +++++++++++++++++++++++++++++++++++++++------
 2 files changed, 79 insertions(+), 9 deletions(-)
man/blkdeactivate.8_main +17 -0
index f3c19a8..33f410c 100644
@@ -51,6 +51,17 @@ Retry removal several times in case of failure.
 Deactivate the whole LVM Volume Group when processing a Logical Volume.
 Deactivating the Volume Group as a whole is quicker than deactivating
 each Logical Volume separately.
+.IP \fIforcevg\fP
+Forcibly deactivate the whole LVM Volume Group as soon as possible.
+The primary job of this option is to flush the in-flight I/O operation
+and then replace the LV's device-mapper table with 'error' target.
+This is accomplished by using command "dmsetup wipe_table". After that,
+any applications on the host cannot access the device anymore, so even
+the LV's lock is expired, it's safe for without data corruption and can
+avoid watchdog resetting.
+This option is usually used for sanlock's fence procedure to avoid host
+reset. When this option is used, any other options
+(e.g. "-d retry|force", "-u") will be ignored.
 .RE
 .TP
 .BR -m ", " --mpathoptions \ \fImpath_options\fP
@@ -108,6 +119,12 @@ Volume Group at once when processing an LVM Logical Volume.
 .B blkdeactivate -u -d retry -l wholevg
 .BR
 .P
+Forcibly deactivate the whole vg.
+.BR
+#
+.B blkdeactivate -l forcevg testvg
+.BR
+.P
 Deactivate all supported block devices found in the system. If the deactivation
 of a device-mapper device fails, retry it and force removal.
 .BR
scripts/blkdeactivate.sh.in +62 -9

107 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/2 lvmlockctl: Automatically handle failure

From: Zhang Huan <[email protected]>

When the lock manager detects drive failure, it invokes command "lvmlockctl" to handle the faiulre; in this case, lvmlockctl automatically calls "blkdeactivate -l forcevg" to deactivate VG and calls drop_vg() to cleanup the lockspace.

[Refactored the changes and commit log]
---
 configure                     |  3 +++
 configure.ac                  |  2 ++
 daemons/lvmlockd/lvmlockctl.c | 40 +++++++++++++++++++++++++++-------------
 include/configure.h.in        |  3 +++
 man/lvmlockctl.8_main         | 11 +++++------
 5 files changed, 40 insertions(+), 19 deletions(-)
configure +3 -0
index 7d4f337..a6cd432 100755
@@ -684,6 +684,7 @@ MANGLING
 LVM_RELEASE_DATE
 LVM_RELEASE
 LVM_PATH
+LVM_DIR
 LVM_PATCHLEVEL
 LVM_MINOR
 LVM_MAJOR
@@ -15298,9 +15299,11 @@ SYSCONFDIR="$(eval echo $(eval echo $sysconfdir))"
 
 SBINDIR="$(eval echo $(eval echo $sbindir))"
 LVM_PATH="$SBINDIR/lvm"
+LVM_DIR="$SBINDIR/"
 
 cat >>confdefs.h <<_ACEOF
 #define LVM_PATH "$LVM_PATH"
+#define LVM_DIR "$LVM_DIR"
 _ACEOF
 
 
configure.ac +2 -0
index 99b7c88..11ffdb5 100644
@@ -1820,7 +1820,9 @@ SYSCONFDIR="$(eval echo $(eval echo $sysconfdir))"
 
 SBINDIR="$(eval echo $(eval echo $sbindir))"
 LVM_PATH="$SBINDIR/lvm"
+LVM_DIR="$SBINDIR/"
 AC_DEFINE_UNQUOTED(LVM_PATH, ["$LVM_PATH"], [Path to lvm binary.])
+AC_DEFINE_UNQUOTED(LVM_DIR, ["$LVM_DIR"], [Path to lvm binary dir.])
 
 USRSBINDIR="$(eval echo $(eval echo $usrsbindir))"
 CLVMD_PATH="$USRSBINDIR/clvmd"
daemons/lvmlockd/lvmlockctl.c +27 -13
index 436221d..35b409d 100644
@@ -17,6 +17,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #include <syslog.h>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -32,6 +33,7 @@ static int gl_enable = 0;
 static int gl_disable = 0;
 static int stop_lockspaces = 0;
 static char *arg_vg_name = NULL;
+static int do_drop(void);
 
 #define DUMP_SOCKET_NAME "lvmlockd-dump.sock"
 #define DUMP_BUF_SIZE (1024 * 1024)
@@ -53,6 +55,11 @@ do { \
 #define MAX_NAME 64
 #define MAX_ARGS 64
 
+#define BLKDEACTIVATE_CMD "blkdeactivate -l forcevg "
+/* The max string length for blkdeactivate command */
+#define MAX_BLKDEACTIVATE_CMD	(sizeof(LVM_DIR) + sizeof(BLKDEACTIVATE_CMD) + \
+				 MAX_NAME + 1)
+
 /*
  * lvmlockd dumps the client info before the lockspaces,
  * so we can look up client info when printing lockspace info.
@@ -506,11 +513,9 @@ static int do_kill(void)
 	daemon_reply reply;
 	int result;
 	int rv;
+	char deactivate_cmd[MAX_BLKDEACTIVATE_CMD+1] = { 0 };
 
 	syslog(LOG_EMERG, "Lost access to sanlock lease storage in VG %s.", arg_vg_name);
-	/* These two lines explain the manual alternative to the FIXME below. */
-	syslog(LOG_EMERG, "Immediately deactivate LVs in VG %s.", arg_vg_name);
-	syslog(LOG_EMERG, "Once VG is unused, run lvmlockctl --drop %s.", arg_vg_name);
 
 	/*
 	 * It may not be strictly necessary to notify lvmlockd of the kill, but
@@ -534,16 +539,25 @@ static int do_kill(void)
 
 	daemon_reply_destroy(reply);
 
-	/*
-	 * FIXME: here is where we should implement a strong form of
-	 * blkdeactivate, and if it completes successfully, automatically call
-	 * do_drop() afterward.  (The drop step may not always be necessary
-	 * if the lvm commands run while shutting things down release all the
-	 * leases.)
-	 *
-	 * run_strong_blkdeactivate();
-	 * do_drop();
-	 */
+	snprintf(deactivate_cmd, MAX_BLKDEACTIVATE_CMD, "%s%s%s",
+		 LVM_DIR, BLKDEACTIVATE_CMD, arg_vg_name);
+
+	syslog(LOG_EMERG, "Immediately deactivate LVs in VG %s.", arg_vg_name);
+	rv = system(deactivate_cmd);
+	if (rv) {
+		syslog(LOG_EMERG, "Deactivated LVs in VG %s failed.",
+		       arg_vg_name);
+		return rv;
+	} else {
+		syslog(LOG_EMERG, "Deactivated LVs in VG %s successfully.",
+		       arg_vg_name);
+	}
+
+	rv = do_drop();
+	if (rv)
+		syslog(LOG_EMERG, "lvmlockctl --drop %s failed.", arg_vg_name);
+	else
+		syslog(LOG_EMERG, "lvmlockctl --drop %s success.", arg_vg_name);
 
 	return rv;
 }
include/configure.h.in +3 -0
index 812cacc..9e7b127 100644
@@ -643,6 +643,9 @@
 /* Path to lvm binary. */
 #undef LVM_PATH
 
+/* Path to lvm binary dir. */
+#undef LVM_DIR
+
 /* Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.
    */
 #undef MAJOR_IN_MKDEV
man/lvmlockctl.8_main +5 -6
index b7ac0ec..99698bc 100644
@@ -65,17 +65,16 @@ and prints it.
 .SS kill
 
 This is run by sanlock when it loses access to the storage holding leases
-for a VG.  It currently emits a syslog message stating that the VG must
-be immediately deactivated.  In the future it may automatically attempt to
-forcibly deactivate the VG.  For more, see
-.BR lvmlockd (8).
+for a VG.  It will call 'deactivate -l forcevg <vgname>' to forcibly
+deactivate the whole VG.  After successful deactivate, do 'drop vg' to
+clear the stale lockspace.  For more, see
+.BR lvmlockd (8), blkdeactivate (8).
 
 .SS drop
 
 This should only be run after a VG has been successfully deactivated
 following an lvmlockctl --kill command.  It clears the stale lockspace
-from lvmlockd.  In the future, this may become automatic along with an
-automatic handling of --kill.  For more, see
+from lvmlockd.  For more, see
 .BR lvmlockd (8).
 
 .SS gl-enable
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 lvmlockctl: Automatically handle failure

Quoted 6 lines · Leo Yan

From: Zhang Huan <[email protected]>

When the lock manager detects drive failure, it invokes command "lvmlockctl" to handle the faiulre; in this case, lvmlockctl automatically calls "blkdeactivate -l forcevg" to deactivate VG and calls drop_vg() to cleanup the lockspace.

Hi, I have a couple commits to replace this one, which make it configurable. There are a couple small things left to look at. See this branch:

https://sourceware.org/git/?p=lvm2.git;a=shortlog;h=refs/heads/dev-dct-lvmlockctl-kill-1

I've been testing this by just setting lvm.conf
lvmlockctl_kill_command="vgchange -an"
and running lvmlockctl --kill <vgname>

We'll likely leave lvmlockctl_kill_command empty (disabled) by default for now, with a suggestion to consider the blkdeactivate command.

Dave

author
#4 lore raw

PATCH 2/2 lvmlockctl: Automatically handle failure

Hi David,

Quoted 6 lines · David Teigland

After some more changes this seems to be about done, please let me know if this works for you. I'm thinking about holding off on the blkdeactivate change for a while to see if we can get a better alternative in the near term (to avoid carrying the temporary forcevg option.)

https://sourceware.org/git/?p=lvm2.git;a=shortlog;h=refs/heads/dev-dct-lvmlockctl-kill-2

I verified the patches on the branch "dev-dct-lvmlockctl-kill-2", below is the testing result.

With setting the lvm.conf with config:

lvmlockctl_kill_command = "blkdeactivate -l forcevg"

After the failure happened, the device-mapper will be set to "error" target and the lockspace for the failed VG will be removed. So I can confirm the failure handling is expected.

But I found the building failure which is caused by the patch "lvmlockctl: use lvm.conf lvmlockctl_kill_command", you should include below change:

include/configure.h.in +3 -0
index 812cacc..9e7b127 100644
@@ -643,6 +643,9 @@
 /* Path to lvm binary. */
 #undef LVM_PATH
 
+/* Path to lvm binary dir. */
+#undef LVM_DIR
+
 /* Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>.
    */
 #undef MAJOR_IN_MKDEV

Thank you a lot!

Leo

#5 lore raw

PATCH 1/2 blkdeactive: Introduce option "forcevg" to forcibly deactivate VG

In reply to Leo Yan

Dne 25. 02. 21 v 12:04 Leo Yan napsal(a):

Quoted 6 lines

From: Zhang Huan <[email protected]>

This patch introduces new option "forcevg" for LVM, the main purpose is to flush in-flight I/O operations and replace the LV's device mapper table with 'error' target, this is accomplished by using command "dmsetup wipe_table".

Hi

For this moment - I'd prefer different solution in upstream.

We should first see what are the chance to support forcible deactivation within lvm2 code directly.

This 'out-of-control' external logic may cause significant data loss breakages
- as the external tools have not so good idea about connections between targets.

There need to be something like: vgchange -an --force --yes

tried first when the lvm2 'metadata' are present
and eventually support work with targets withot 'metadata' but with LVM- uuid devices in the DM table.

Giving this to the hands of fairly naive script like blkdeactive isn't the right choice here.

Zdenek

author
#6 lore raw

PATCH 1/2 blkdeactive: Introduce option "forcevg" to forcibly deactivate VG

Hi Zdenek,

Quoted 12 lines · Zdenek Kabelac

Dne 25. 02. 21 v 12:04 Leo Yan napsal(a):

Quoted 6 lines

From: Zhang Huan <[email protected]>

This patch introduces new option "forcevg" for LVM, the main purpose is to flush in-flight I/O operations and replace the LV's device mapper table with 'error' target, this is accomplished by using command "dmsetup wipe_table".

Hi

For this moment - I'd prefer different solution in upstream.

Quoted 8 lines

We should first see what are the chance to support forcible deactivation within lvm2 code directly.

This 'out-of-control' external logic may cause significant data loss breakages - as the external tools have not so good idea about connections between targets.

There need to be something like: vgchange -an --force --yes

I have to admit that I am not familiar with the LVM internal, so it's quite possible that my understanding is not mature, but let me bring up the question.

If we use "vgchange -an --force --yes" or "lvchange" commands to disable VG or LV, seems to me this is likely to cause the egg and chicken problem, and at the end it easily leads to "deadlock" result.

The reason is when the lock manager invokes "lvmlockctl --kill" to kill VG, usually this means the lock manager has detected the drive failures (e.g. the sanlock lock manager finds it cannot renew lease due to the I/O failures), for this case, it's likely the node has no chance to access metadata anymore. So if we use "vgchange" command to disable VG, it's possible to stuck for long time.

And before we use "vgchange" to deactivate the VG, here I have another concern is if the LV is mounted (so the device-mapper is in used), then there have dependency to need firstly umount LV, otherwise also might cause problem for using "vgchange" command.

How about think for this?

Thanks for suggestions,
Leo

Quoted 9 lines

tried first when the lvm2 'metadata' are present
and eventually support work with targets withot 'metadata' but with LVM- uuid devices in the DM table.

Giving this to the hands of fairly naive script like blkdeactive isn't the right choice here.

Zdenek

#7 lore raw

PATCH 1/2 blkdeactive: Introduce option "forcevg" to forcibly deactivate VG

Dne 25. 02. 21 v 13:39 Leo Yan napsal(a):

Quoted 24 lines

Hi Zdenek,

Quoted 12 lines · Zdenek Kabelac

Dne 25. 02. 21 v 12:04 Leo Yan napsal(a):

Quoted 6 lines

From: Zhang Huan <[email protected]>

This patch introduces new option "forcevg" for LVM, the main purpose is to flush in-flight I/O operations and replace the LV's device mapper table with 'error' target, this is accomplished by using command "dmsetup wipe_table".

Hi

For this moment - I'd prefer different solution in upstream.

Quoted 8 lines

We should first see what are the chance to support forcible deactivation within lvm2 code directly.

This 'out-of-control' external logic may cause significant data loss breakages - as the external tools have not so good idea about connections between targets.

There need to be something like: vgchange -an --force --yes

Quoted 7 lines

I have to admit that I am not familiar with the LVM internal, so it's quite possible that my understanding is not mature, but let me bring up the question.

If we use "vgchange -an --force --yes" or "lvchange" commands to disable VG or LV, seems to me this is likely to cause the egg and chicken problem, and at the end it easily leads to "deadlock" result.

lvm supports options --nolocking --noudevsync
so there should be a mechanism to bypass many problem when necessary -

it's just we shouldn't use the biggest hammer as the first thing in the row.

the option --force should be able to 'gradualy' raise 'actions'.

Depending on what kind of trouble is user expecting.

But under-cutting device with error target should be definitely the last.

Quoted 6 lines

The reason is when the lock manager invokes "lvmlockctl --kill" to kill VG, usually this means the lock manager has detected the drive failures (e.g. the sanlock lock manager finds it cannot renew lease due to the I/O failures), for this case, it's likely the node has no chance to access metadata anymore. So if we use "vgchange" command to disable VG, it's possible to stuck for long time.

Yep - there likely need to be also improved mechanism to recognize locking manager is in some limbo state.

Zdenek

#8 lore raw

PATCH 1/2 blkdeactive: Introduce option "forcevg" to forcibly deactivate VG

Quoted 10 lines · Zdenek Kabelac

lvm supports options --nolocking --noudevsync
so there should be a mechanism to bypass many problem when necessary -

it's just we shouldn't use the biggest hammer as the first thing in the row.

the option --force should be able to 'gradualy' raise 'actions'.

Depending on what kind of trouble is user expecting.

But under-cutting device with error target should be definitely the last.

I think we need a solution like you're talking about, specifically a way to deactivate a VG without metadata, based only on info from dm devices. It's needed for a couple of other cases I know of also.

If we had a command like that, we could also add an option for it to go directly to wipe_table. (In this specific sanlock scenario we know that the devices are not responsive, so we know that intermediate steps would just get stuck.)

Until we have that command, blkdeactivate seems to be a workable option, and it's simple to change it later with a config setting.