Skip to contentSkip to conversation

Enable In-Drive-Mutex Locking scheme

RFC New Leo Yan 2 participants 8 messages May 7, 2021 – Jun 8, 2021

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v2 cover Enable In-Drive-Mutex Locking scheme

This patch set enables the In-Drive-Mutex (IDM) locking scheme. The previous patch series [1] have given a briefly introduction for IDM and it's associated locking manager and lib.

This series follows up Dave's comments and refines the patches.

And this patch series has been tested with IDM/sanlock/DLM locking schemes for VG and LV creating, removing, activating and deactivating, these operations can work as expected for all of these three locking schemes.

[1] https://listman.redhat.com/archives/lvm-devel/2021-April/msg00111.html

Changes from RFCv1:
* Updated commit log for LVB (Dave);
* Refined the change to only pass PV list for IDM lock type (Dave);
* Refined retriving PV list with function lv_is_on_pv() (Dave);
* Added condition checking for passing PV list in lvmlockd after found a regression on sanlock locking scheme.

Leo Yan (5):
lvmlockd: idm: Introduce new locking scheme
lvmlockd: idm: Hook Seagate IDM wrapper APIs
lib: locking: Add new type "idm"
lib: locking: Parse PV list for IDM locking
tools: Add support for "idm" lock type

 configure                            | 173 ++++++
 configure.ac                         |  20 +
 daemons/lvmlockd/Makefile.in         |   5 +
 daemons/lvmlockd/lvmlockd-core.c     | 281 ++++++++-
 daemons/lvmlockd/lvmlockd-idm.c      | 837 +++++++++++++++++++++++++++
 daemons/lvmlockd/lvmlockd-internal.h | 110 ++++
 lib/display/display.c                |   4 +
 lib/locking/lvmlockd.c               | 330 ++++++++++-
 lib/metadata/metadata-exported.h     |   1 +
 lib/metadata/metadata.c              |  12 +-
 tools/lvconvert.c                    |   2 +
 tools/toollib.c                      |  11 +-
 12 files changed, 1726 insertions(+), 60 deletions(-)
 create mode 100644 daemons/lvmlockd/lvmlockd-idm.c
Signature · 1 line
2.25.1
author
#1 lore raw

RFC v2 1/5 lvmlockd: idm: Introduce new locking scheme

Alongside the existed locking schemes of DLM and sanlock, this patch is to introduce new locking scheme: In-Drive-Mutex (IDM).

With the IDM support in the drive, the locks are resident in the drive, thus, the locking lease is maintained in a central place: the drive firmware. We can consider this is a typical client-server model, every host (or node) in the server cluster launches the request for leasing mutex to a drive firmware, the drive firmware works as an arbitrator to grant the mutex to a requester and it can reject other applicants if the mutex has been acquired. To satisfy the LVM activation for different modes, IDM supports two locking modes:
exclusive and shareable.

Every IDM is identified with two IDs, one is the host ID and another is the resource ID. The resource ID is a unique identifier for what the resource it's protected, in the integration with lvmlockd, the resource ID is combined with VG's UUID and LV's UUID; for the global locking, the bytes in resource ID are all zeros, and for the VG locking, the
LV's UUID is set as zero. Every host can generate a random UUID and
use it as the host ID for the SCSI command, this ID is used to clarify the ownership for mutex.

For easily invoking the IDM commands to drive, like other locking scheme (e.g. sanlock), a daemon program named IDM lock manager is created, so the detailed IDM SCSI commands are encapsulated in the daemon, and lvmlockd uses the wrapper APIs to communicate with the daemon program.

This patch introduces the IDM locking wrapper layer, it forwards the locking requests from lvmlockd to the IDM lock manager, and returns the result from drives' responding.

One thing should be mentioned is the IDM's LVB. IDM supports LVB to max 7 bytes when stores into the drive, the most significant byte of 8 bytes is reserved for control bits. For this reason, the patch maps the timestamp in macrosecond unit with its cached LVB, essentially, if any timestamp was updated by other nodes, that means the local LVB is invalidate. When the timestamp is stored into drive's LVB, it's possbile to cause time-going-backwards issue, which is introduced by the time precision or missing synchronization acrossing over multiple nodes. So the IDM wrapper fixes up the timestamp by increment 1 to the latest value and write back into drive.

Currently LVB is used to track VG changes and its purpose is to notify lvmetad cache invalidation when detects any metadata has been altered; but lvmetad is not used anymore for caching metadata, LVB doesn't really work. It's possible that the LVB functionality could be useful again in the future, so let's enable it for IDM in the first place.

---
 configure                            | 173 ++++++
 configure.ac                         |  20 +
 daemons/lvmlockd/Makefile.in         |   5 +
 daemons/lvmlockd/lvmlockd-idm.c      | 837 +++++++++++++++++++++++++++
 daemons/lvmlockd/lvmlockd-internal.h | 108 ++++
 5 files changed, 1143 insertions(+)
 create mode 100644 daemons/lvmlockd/lvmlockd-idm.c
configure +173 -0
index 4c38cbebb..df9aa2af6 100755
@@ -745,6 +745,7 @@ BUILD_DMFILEMAPD
 BUILD_LOCKDDLM_CONTROL
 BUILD_LOCKDDLM
 BUILD_LOCKDSANLOCK
+BUILD_LOCKDIDM
 BUILD_LVMLOCKD
 BUILD_LVMPOLLD
 BUILD_LVMDBUSD
@@ -780,6 +781,8 @@ LOCKD_DLM_LIBS
 LOCKD_DLM_CFLAGS
 LOCKD_SANLOCK_LIBS
 LOCKD_SANLOCK_CFLAGS
+LOCKD_IDM_LIBS
+LOCKD_IDM_CFLAGS
 VALGRIND_LIBS
 VALGRIND_CFLAGS
 GENPNG
@@ -940,6 +943,7 @@ enable_lvmpolld
 enable_lvmlockd_sanlock
 enable_lvmlockd_dlm
 enable_lvmlockd_dlmcontrol
+enable_lvmlockd_idm
 enable_use_lvmlockd
 with_lvmlockd_pidfile
 enable_use_lvmpolld
@@ -1011,6 +1015,8 @@ LOCKD_DLM_CFLAGS
 LOCKD_DLM_LIBS
 LOCKD_DLM_CONTROL_CFLAGS
 LOCKD_DLM_CONTROL_LIBS
+LOCKD_IDM_CFLAGS
+LOCKD_IDM_LIBS
 NOTIFY_DBUS_CFLAGS
 NOTIFY_DBUS_LIBS
 BLKID_CFLAGS
@@ -1659,6 +1665,7 @@ Optional Features:
   --enable-lvmlockd-dlm   enable the LVM lock daemon using dlm
   --enable-lvmlockd-dlmcontrol
                           enable lvmlockd remote refresh using libdlmcontrol
+  --enable-lvmlockd-idm   enable the LVM lock daemon using idm
   --disable-use-lvmlockd  disable usage of LVM lock daemon
   --disable-use-lvmpolld  disable usage of LVM Poll Daemon
   --enable-dmfilemapd     enable the dmstats filemap daemon
@@ -1810,6 +1817,10 @@ Some influential environment variables:
               C compiler flags for LOCKD_DLM_CONTROL, overriding pkg-config
   LOCKD_DLM_CONTROL_LIBS
               linker flags for LOCKD_DLM_CONTROL, overriding pkg-config
+  LOCKD_IDM_CFLAGS
+              C compiler flags for LOCKD_IDM, overriding pkg-config
+  LOCKD_IDM_LIBS
+              linker flags for LOCKD_IDM, overriding pkg-config
   NOTIFY_DBUS_CFLAGS
               C compiler flags for NOTIFY_DBUS, overriding pkg-config
   NOTIFY_DBUS_LIBS
@@ -3104,6 +3115,7 @@ case "$host_os" in
 		LOCKDSANLOCK=no
 		LOCKDDLM=no
 		LOCKDDLM_CONTROL=no
+		LOCKDIDM=no
 		ODIRECT=yes
 		DM_IOCTLS=yes
 		SELINUX=yes
@@ -11121,6 +11133,167 @@ $as_echo "#define LOCKDDLM_CONTROL_SUPPORT 1" >>confdefs.h
 	BUILD_LVMLOCKD=yes
 fi
 
+################################################################################
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build lvmlockdidm" >&5
+$as_echo_n "checking whether to build lvmlockdidm... " >&6; }
+# Check whether --enable-lvmlockd-idm was given.
+if test "${enable_lvmlockd_idm+set}" = set; then :
+  enableval=$enable_lvmlockd_idm; LOCKDIDM=$enableval
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LOCKDIDM" >&5
+$as_echo "$LOCKDIDM" >&6; }
+
+BUILD_LOCKDIDM=$LOCKDIDM
+
+if test "$BUILD_LOCKDIDM" = yes; then
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for LOCKD_IDM" >&5
+$as_echo_n "checking for LOCKD_IDM... " >&6; }
+
+if test -n "$LOCKD_IDM_CFLAGS"; then
+    pkg_cv_LOCKD_IDM_CFLAGS="$LOCKD_IDM_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libseagate_ilm >= 0.1.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libseagate_ilm >= 0.1.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LOCKD_IDM_CFLAGS=`$PKG_CONFIG --cflags "libseagate_ilm >= 0.1.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$LOCKD_IDM_LIBS"; then
+    pkg_cv_LOCKD_IDM_LIBS="$LOCKD_IDM_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libseagate_ilm >= 0.1.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libseagate_ilm >= 0.1.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LOCKD_IDM_LIBS=`$PKG_CONFIG --libs "libseagate_ilm >= 0.1.0" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        LOCKD_IDM_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libseagate_ilm >= 0.1.0" 2>&1`
+        else
+	        LOCKD_IDM_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libseagate_ilm >= 0.1.0" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$LOCKD_IDM_PKG_ERRORS" >&5
+
+	$bailout
+elif test $pkg_failed = untried; then
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	$bailout
+else
+	LOCKD_IDM_CFLAGS=$pkg_cv_LOCKD_IDM_CFLAGS
+	LOCKD_IDM_LIBS=$pkg_cv_LOCKD_IDM_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+fi
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BLKID" >&5
+$as_echo_n "checking for BLKID... " >&6; }
+
+if test -n "$BLKID_CFLAGS"; then
+    pkg_cv_BLKID_CFLAGS="$BLKID_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.24\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "blkid >= 2.24") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_BLKID_CFLAGS=`$PKG_CONFIG --cflags "blkid >= 2.24" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$BLKID_LIBS"; then
+    pkg_cv_BLKID_LIBS="$BLKID_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.24\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "blkid >= 2.24") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_BLKID_LIBS=`$PKG_CONFIG --libs "blkid >= 2.24" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+	        BLKID_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "blkid >= 2.24" 2>&1`
+        else
+	        BLKID_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "blkid >= 2.24" 2>&1`
+        fi
+	# Put the nasty error message in config.log where it belongs
+	echo "$BLKID_PKG_ERRORS" >&5
+
+	$bailout
+elif test $pkg_failed = untried; then
+     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+	$bailout
+else
+	BLKID_CFLAGS=$pkg_cv_BLKID_CFLAGS
+	BLKID_LIBS=$pkg_cv_BLKID_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+	HAVE_LOCKD_IDM=yes
+fi
+
+$as_echo "#define LOCKDIDM_SUPPORT 1" >>confdefs.h
+
+	BUILD_LVMLOCKD=yes
+fi
+
 ################################################################################
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build lvmlockd" >&5
 $as_echo_n "checking whether to build lvmlockd... " >&6; }
configure.ac +20 -0
index ee21b879d..8a2ccf912 100644
@@ -43,6 +43,7 @@ case "$host_os" in
 		LOCKDSANLOCK=no
 		LOCKDDLM=no
 		LOCKDDLM_CONTROL=no
+		LOCKDIDM=no
 		ODIRECT=yes
 		DM_IOCTLS=yes
 		SELINUX=yes
@@ -960,6 +961,25 @@ if test "$BUILD_LOCKDDLM_CONTROL" = yes; then
 	BUILD_LVMLOCKD=yes
 fi
 
+################################################################################
+dnl -- Build lvmlockdidm
+AC_MSG_CHECKING(whether to build lvmlockdidm)
+AC_ARG_ENABLE(lvmlockd-idm,
+	      AC_HELP_STRING([--enable-lvmlockd-idm],
+			     [enable the LVM lock daemon using idm]),
+	      LOCKDIDM=$enableval)
+AC_MSG_RESULT($LOCKDIDM)
+
+BUILD_LOCKDIDM=$LOCKDIDM
+
+dnl -- Look for Seagate IDM libraries
+if test "$BUILD_LOCKDIDM" = yes; then
+	PKG_CHECK_MODULES(LOCKD_IDM, libseagate_ilm >= 0.1.0, [HAVE_LOCKD_IDM=yes], $bailout)
+	PKG_CHECK_MODULES(BLKID, blkid >= 2.24, [HAVE_LOCKD_IDM=yes], $bailout)
+	AC_DEFINE([LOCKDIDM_SUPPORT], 1, [Define to 1 to include code that uses lvmlockd IDM option.])
+	BUILD_LVMLOCKD=yes
+fi
+
 ################################################################################
 dnl -- Build lvmlockd
 AC_MSG_CHECKING(whether to build lvmlockd)
daemons/lvmlockd/Makefile.in +5 -0
index bd577d1e6..578292166 100644
@@ -30,6 +30,11 @@ ifeq ("@BUILD_LOCKDDLM@", "yes")
   LOCK_LIBS += -ldlmcontrol
 endif
 
+ifeq ("@BUILD_LOCKDIDM@", "yes")
+  SOURCES += lvmlockd-idm.c
+  LOCK_LIBS += -lseagate_ilm -lblkid
+endif
+
 SOURCES2 = lvmlockctl.c
 
 TARGETS = lvmlockd lvmlockctl
daemons/lvmlockd/lvmlockd-idm.c new file +837 -0

837 lines not on this page · raw message

daemons/lvmlockd/lvmlockd-internal.h +108 -0

148 lines not on this page · raw message

Signature · 1 line
2.25.1
author
#2 lore raw

RFC v2 2/5 lvmlockd: idm: Hook Seagate IDM wrapper APIs

In reply to Leo Yan

To allow the IDM locking scheme be used by users, this patch hooks the IDM wrapper; it also introducs a new locking type "idm" and we can use it for global lock with option '-g idm'.

To support IDM locking type, the main change in the data structure is to add pvs path arrary. The pvs list is transferred from the lvm commands, when lvmlockd core layer receives message, it extracts the message with the keyword "path[idx]". Finally, the pv list will pass to IDM lock manager as the target drives for sending IDM SCSI commands.

---
 daemons/lvmlockd/lvmlockd-core.c     | 281 ++++++++++++++++++++++++---
 daemons/lvmlockd/lvmlockd-internal.h |   4 +-
 2 files changed, 257 insertions(+), 28 deletions(-)
daemons/lvmlockd/lvmlockd-core.c +254 -27
index 094491029..dc213fd93 100644
@@ -421,6 +421,63 @@ struct lockspace *alloc_lockspace(void)
 	return ls;
 }
 
+static char **alloc_pvs_path(struct pvs *pvs, int num)
+{
+	if (!num)
+		return NULL;
+
+	pvs->path = malloc(sizeof(char *) * num);
+	if (!pvs->path)
+		return NULL;
+
+	memset(pvs->path, 0x0, sizeof(char *) * num);
+	return pvs->path;
+}
+
+static void free_pvs_path(struct pvs *pvs)
+{
+	int i;
+
+	for (i = 0; i < pvs->num; i++) {
+		if (!pvs->path[i])
+			continue;
+
+		free((char *)pvs->path[i]);
+		pvs->path[i] = NULL;
+	}
+
+	if (!pvs->path) {
+		free(pvs->path);
+		pvs->path = NULL;
+	}
+}
+
+static char **alloc_and_copy_pvs_path(struct pvs *dst, struct pvs *src)
+{
+	int i;
+
+	if (!alloc_pvs_path(dst, src->num))
+		return NULL;
+
+	dst->num = 0;
+	for (i = 0; i < src->num; i++) {
+		if (!src->path[i] || !strcmp(src->path[i], "none"))
+			continue;
+
+		dst->path[dst->num] = strdup(src->path[i]);
+		if (!dst->path[dst->num]) {
+			log_error("out of memory for copying pvs path");
+			goto failed;
+		}
+		dst->num++;
+	}
+	return dst->path;
+
+failed:
+	free_pvs_path(dst);
+	return NULL;
+}
+
 static struct action *alloc_action(void)
 {
 	struct action *act;
@@ -510,6 +567,9 @@ static void free_action(struct action *act)
 		free(act->path);
 		act->path = NULL;
 	}
+
+	free_pvs_path(&act->pvs);
+
 	pthread_mutex_lock(&unused_struct_mutex);
 	if (unused_action_count >= MAX_UNUSED_ACTION) {
 		free(act);
@@ -564,9 +624,12 @@ static int setup_structs(void)
 	struct lock *lk;
 	int data_san = lm_data_size_sanlock();
 	int data_dlm = lm_data_size_dlm();
+	int data_idm = lm_data_size_idm();
 	int i;
 
 	resource_lm_data_size = data_san > data_dlm ? data_san : data_dlm;
+	resource_lm_data_size = resource_lm_data_size > data_idm ?
+					resource_lm_data_size : data_idm;
 
 	pthread_mutex_init(&unused_struct_mutex, NULL);
 	INIT_LIST_HEAD(&unused_action);
@@ -683,6 +746,8 @@ static const char *lm_str(int x)
 		return "dlm";
 	case LD_LM_SANLOCK:
 		return "sanlock";
+	case LD_LM_IDM:
+		return "idm";
 	default:
 		return "lm_unknown";
 	}
@@ -968,6 +1033,8 @@ static int lm_prepare_lockspace(struct lockspace *ls, struct action *act)
 		rv = lm_prepare_lockspace_dlm(ls);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		rv = lm_prepare_lockspace_sanlock(ls);
+	else if (ls->lm_type == LD_LM_IDM)
+		rv = lm_prepare_lockspace_idm(ls);
 	else
 		return -1;
 
@@ -984,6 +1051,8 @@ static int lm_add_lockspace(struct lockspace *ls, struct action *act, int adopt)
 		rv = lm_add_lockspace_dlm(ls, adopt);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		rv = lm_add_lockspace_sanlock(ls, adopt);
+	else if (ls->lm_type == LD_LM_IDM)
+		rv = lm_add_lockspace_idm(ls, adopt);
 	else
 		return -1;
 
@@ -1000,6 +1069,8 @@ static int lm_rem_lockspace(struct lockspace *ls, struct action *act, int free_v
 		rv = lm_rem_lockspace_dlm(ls, free_vg);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		rv = lm_rem_lockspace_sanlock(ls, free_vg);
+	else if (ls->lm_type == LD_LM_IDM)
+		rv = lm_rem_lockspace_idm(ls, free_vg);
 	else
 		return -1;
 
@@ -1017,6 +1088,9 @@ static int lm_lock(struct lockspace *ls, struct resource *r, int mode, struct ac
 		rv = lm_lock_dlm(ls, r, mode, vb_out, adopt);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		rv = lm_lock_sanlock(ls, r, mode, vb_out, retry, adopt);
+	else if (ls->lm_type == LD_LM_IDM)
+		rv = lm_lock_idm(ls, r, mode, vb_out, act->lv_uuid,
+				 &act->pvs, adopt);
 	else
 		return -1;
 
@@ -1034,6 +1108,8 @@ static int lm_convert(struct lockspace *ls, struct resource *r,
 		rv = lm_convert_dlm(ls, r, mode, r_version);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		rv = lm_convert_sanlock(ls, r, mode, r_version);
+	else if (ls->lm_type == LD_LM_IDM)
+		rv = lm_convert_idm(ls, r, mode, r_version);
 	else
 		return -1;
 
@@ -1051,6 +1127,8 @@ static int lm_unlock(struct lockspace *ls, struct resource *r, struct action *ac
 		rv = lm_unlock_dlm(ls, r, r_version, lmu_flags);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		rv = lm_unlock_sanlock(ls, r, r_version, lmu_flags);
+	else if (ls->lm_type == LD_LM_IDM)
+		rv = lm_unlock_idm(ls, r, r_version, lmu_flags);
 	else
 		return -1;
 
@@ -1065,6 +1143,8 @@ static int lm_hosts(struct lockspace *ls, int notify)
 		return lm_hosts_dlm(ls, notify);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		return lm_hosts_sanlock(ls, notify);
+	else if (ls->lm_type == LD_LM_IDM)
+		return lm_hosts_idm(ls, notify);
 	return -1;
 }
 
@@ -1074,6 +1154,8 @@ static void lm_rem_resource(struct lockspace *ls, struct resource *r)
 		lm_rem_resource_dlm(ls, r);
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		lm_rem_resource_sanlock(ls, r);
+	else if (ls->lm_type == LD_LM_IDM)
+		lm_rem_resource_idm(ls, r);
 }
 
 static int lm_find_free_lock(struct lockspace *ls, uint64_t *free_offset, int *sector_size, int *align_size)
@@ -1082,6 +1164,8 @@ static int lm_find_free_lock(struct lockspace *ls, uint64_t *free_offset, int *s
 		return 0;
 	else if (ls->lm_type == LD_LM_SANLOCK)
 		return lm_find_free_lock_sanlock(ls, free_offset, sector_size, align_size);
+	else if (ls->lm_type == LD_LM_IDM)
+		return 0;
 	return -1;
 }
 
@@ -1690,8 +1774,8 @@ static int res_update(struct lockspace *ls, struct resource *r,
 }
 
 /*
- * There is nothing to deallocate when freeing a dlm LV, the LV
- * will simply be unlocked by rem_resource.
+ * For DLM and IDM locking scheme, there is nothing to deallocate when freeing a
+ * LV, the LV will simply be unlocked by rem_resource.
  */
 
 static int free_lv(struct lockspace *ls, struct resource *r)
@@ -1700,6 +1784,8 @@ static int free_lv(struct lockspace *ls, struct resource *r)
 		return lm_free_lv_sanlock(ls, r);
 	else if (ls->lm_type == LD_LM_DLM)
 		return 0;
+	else if (ls->lm_type == LD_LM_IDM)
+		return 0;
 	else
 		return -EINVAL;
 }
@@ -2760,6 +2846,8 @@ out_act:
 	ls->drop_vg = drop_vg;
 	if (ls->lm_type == LD_LM_DLM && !strcmp(ls->name, gl_lsname_dlm))
 		global_dlm_lockspace_exists = 0;
+	if (ls->lm_type == LD_LM_IDM && !strcmp(ls->name, gl_lsname_idm))
+		global_idm_lockspace_exists = 0;
 
 	/*
 	 * Avoid a name collision of the same lockspace is added again before
@@ -2851,6 +2939,8 @@ static void gl_ls_name(char *ls_name)
 		memcpy(ls_name, gl_lsname_dlm, MAX_NAME);
 	else if (gl_use_sanlock)
 		memcpy(ls_name, gl_lsname_sanlock, MAX_NAME);
+	else if (gl_use_idm)
+		memcpy(ls_name, gl_lsname_idm, MAX_NAME);
 	else
 		memset(ls_name, 0, MAX_NAME);
 }
@@ -2879,9 +2969,20 @@ static int add_lockspace_thread(const char *ls_name,
 	strncpy(ls->name, ls_name, MAX_NAME);
 	ls->lm_type = lm_type;
 
-	if (act)
+	if (act) {
 		ls->start_client_id = act->client_id;
 
+		/*
+		 * Copy PV list to lockspact structure, so this is
+		 * used for VG locking for idm scheme.
+		 */
+		if (lm_type == LD_LM_IDM &&
+				!alloc_and_copy_pvs_path(&ls->pvs, &act->pvs)) {
+			free(ls);
+			return -ENOMEM;
+		}
+	}
+
 	if (vg_uuid)
 		strncpy(ls->vg_uuid, vg_uuid, 64);
 
@@ -2908,6 +3009,18 @@ static int add_lockspace_thread(const char *ls_name,
 	pthread_mutex_lock(&lockspaces_mutex);
 	ls2 = find_lockspace_name(ls->name);
 	if (ls2) {
+		/*
+		 * If find an existed lockspace, we need to update the PV list
+		 * based on the latest information, and release for the old
+		 * PV list in case it keeps stale information.
+		 */
+		free_pvs_path(&ls2->pvs);
+		if (lm_type == LD_LM_IDM &&
+				!alloc_and_copy_pvs_path(&ls2->pvs, &ls->pvs)) {
+			log_debug("add_lockspace_thread %s fails to allocate pvs", ls->name);
+			rv = -ENOMEM;
+		}
+
 		if (ls2->thread_stop) {
 			log_debug("add_lockspace_thread %s exists and stopping", ls->name);
 			rv = -EAGAIN;
@@ -2920,6 +3033,7 @@ static int add_lockspace_thread(const char *ls_name,
 		}
 		pthread_mutex_unlock(&lockspaces_mutex);
 		free_resource(r);
+		free_pvs_path(&ls->pvs);
 		free(ls);
 		return rv;
 	}
@@ -2933,6 +3047,8 @@ static int add_lockspace_thread(const char *ls_name,
 
 	if (ls->lm_type == LD_LM_DLM && !strcmp(ls->name, gl_lsname_dlm))
 		global_dlm_lockspace_exists = 1;
+	if (ls->lm_type == LD_LM_IDM && !strcmp(ls->name, gl_lsname_idm))
+		global_idm_lockspace_exists = 1;
 	list_add_tail(&ls->list, &lockspaces);
 	pthread_mutex_unlock(&lockspaces_mutex);
 
@@ -2943,6 +3059,7 @@ static int add_lockspace_thread(const char *ls_name,
 		list_del(&ls->list);
 		pthread_mutex_unlock(&lockspaces_mutex);
 		free_resource(r);
+		free_pvs_path(&ls->pvs);
 		free(ls);
 		return rv;
 	}
@@ -2951,16 +3068,15 @@ static int add_lockspace_thread(const char *ls_name,
 }
 
 /*
- * There is no add_sanlock_global_lockspace or
- * rem_sanlock_global_lockspace because with sanlock,
- * the global lockspace is one of the vg lockspaces.
+ * There is no variant for sanlock because, with sanlock, the global
+ * lockspace is one of the vg lockspaces.
  */
-
-static int add_dlm_global_lockspace(struct action *act)
+static int add_global_lockspace(char *ls_name, int lm_type,
+				struct action *act)
 {
 	int rv;
 
-	if (global_dlm_lockspace_exists)
+	if (global_dlm_lockspace_exists || global_idm_lockspace_exists)
 		return 0;
 
 	/*
@@ -2968,9 +3084,9 @@ static int add_dlm_global_lockspace(struct action *act)
 	 * lock request, insert an internal gl sh lock request?
 	 */
 
-	rv = add_lockspace_thread(gl_lsname_dlm, NULL, NULL, LD_LM_DLM, NULL, act);
+	rv = add_lockspace_thread(ls_name, NULL, NULL, lm_type, NULL, act);
 	if (rv < 0)
-		log_debug("add_dlm_global_lockspace add_lockspace_thread %d", rv);
+		log_debug("add_global_lockspace add_lockspace_thread %d", rv);
 
 	/*
 	 * EAGAIN may be returned for a short period because
@@ -2983,12 +3099,12 @@ static int add_dlm_global_lockspace(struct action *act)
 }
 
 /*
- * If dlm gl lockspace is the only one left, then stop it.
- * This is not used for an explicit rem_lockspace action from
- * the client, only for auto remove.
+ * When DLM or IDM locking scheme is used for global lock, if the global
+ * lockspace is the only one left, then stop it.  This is not used for
+ * an explicit rem_lockspace action from the client, only for auto
+ * remove.
  */
-
-static int rem_dlm_global_lockspace(void)
+static int rem_global_lockspace(char *ls_name)
 {
 	struct lockspace *ls, *ls_gl = NULL;
 	int others = 0;
@@ -2996,7 +3112,7 @@ static int rem_dlm_global_lockspace(void)
 
 	pthread_mutex_lock(&lockspaces_mutex);
 	list_for_each_entry(ls, &lockspaces, list) {
-		if (!strcmp(ls->name, gl_lsname_dlm)) {
+		if (!strcmp(ls->name, ls_name)) {
 			ls_gl = ls;
 			continue;
 		}
@@ -3028,6 +3144,26 @@ out:
 	return rv;
 }
 
+static int add_dlm_global_lockspace(struct action *act)
+{
+	return add_global_lockspace(gl_lsname_dlm, LD_LM_DLM, act);
+}
+
+static int rem_dlm_global_lockspace(void)
+{
+	return rem_global_lockspace(gl_lsname_dlm);
+}
+
+static int add_idm_global_lockspace(struct action *act)
+{
+	return add_global_lockspace(gl_lsname_idm, LD_LM_IDM, act);
+}
+
+static int rem_idm_global_lockspace(void)
+{
+	return rem_global_lockspace(gl_lsname_idm);
+}
+
 /*
  * When the first dlm lockspace is added for a vg, automatically add a separate
  * dlm lockspace for the global lock.
@@ -3053,6 +3189,9 @@ static int add_lockspace(struct action *act)
 		if (gl_use_dlm) {
 			rv = add_dlm_global_lockspace(act);
 			return rv;
+		} else if (gl_use_idm) {
+			rv = add_idm_global_lockspace(act);
+			return rv;
 		} else {
 			return -EINVAL;
 		}
@@ -3061,6 +3200,8 @@ static int add_lockspace(struct action *act)
 	if (act->rt == LD_RT_VG) {
 		if (gl_use_dlm)
 			add_dlm_global_lockspace(NULL);
+		else if (gl_use_idm)
+			add_idm_global_lockspace(NULL);
 
 		vg_ls_name(act->vg_name, ls_name);
 
@@ -3128,14 +3269,15 @@ static int rem_lockspace(struct action *act)
 	pthread_mutex_unlock(&lockspaces_mutex);
 
 	/*
-	 * The dlm global lockspace was automatically added when
-	 * the first dlm vg lockspace was added, now reverse that
-	 * by automatically removing the dlm global lockspace when
-	 * the last dlm vg lockspace is removed.
+	 * For DLM and IDM locking scheme, the global lockspace was
+	 * automatically added when the first vg lockspace was added,
+	 * now reverse that by automatically removing the dlm global
+	 * lockspace when the last vg lockspace is removed.
 	 */
-
 	if (rt == LD_RT_VG && gl_use_dlm)
 		rem_dlm_global_lockspace();
+	else if (rt == LD_RT_VG && gl_use_idm)
+		rem_idm_global_lockspace();
 
 	return 0;
 }
@@ -3259,6 +3401,7 @@ static int for_each_lockspace(int do_stop, int do_free, int do_force)
 				if (ls->free_vg) {
 					/* In future we may need to free ls->actions here */
 					free_ls_resources(ls);
+					free_pvs_path(&ls->pvs);
 					free(ls);
 					free_count++;
 				}
@@ -3272,6 +3415,7 @@ static int for_each_lockspace(int do_stop, int do_free, int do_force)
 		if (!gl_type_static) {
 			gl_use_dlm = 0;
 			gl_use_sanlock = 0;
+			gl_use_idm = 0;
 		}
 	}
 	pthread_mutex_unlock(&lockspaces_mutex);
@@ -3347,6 +3491,9 @@ static int work_init_vg(struct action *act)
 		rv = lm_init_vg_sanlock(ls_name, act->vg_name, act->flags, act->vg_args);
 	else if (act->lm_type == LD_LM_DLM)
 		rv = lm_init_vg_dlm(ls_name, act->vg_name, act->flags, act->vg_args);
+	else if (act->lm_type == LD_LM_IDM)
+		/* Non't do anything for IDM when initialize VG */
+		rv = 0;
 	else
 		rv = -EINVAL;
 
@@ -3450,6 +3597,8 @@ static int work_init_lv(struct action *act)
 
 	} else if (act->lm_type == LD_LM_DLM) {
 		return 0;
+	} else if (act->lm_type == LD_LM_IDM) {
+		return 0;
 	} else {
 		log_error("init_lv ls_name %s bad lm_type %d", ls_name, act->lm_type);
 		return -EINVAL;
@@ -3513,20 +3662,29 @@ static void *worker_thread_main(void *arg_in)
 		if (act->op == LD_OP_RUNNING_LM) {
 			int run_sanlock = lm_is_running_sanlock();
 			int run_dlm = lm_is_running_dlm();
+			int run_idm = lm_is_running_idm();
 
 			if (daemon_test) {
 				run_sanlock = gl_use_sanlock;
 				run_dlm = gl_use_dlm;
+				run_idm = gl_use_idm;
 			}
 
-			if (run_sanlock && run_dlm)
+			/*
+			 * It's not possible to enable multiple locking schemes
+			 * for global lock, otherwise, it must be conflict and
+			 * reports it!
+			 */
+			if ((run_sanlock + run_dlm + run_idm) >= 2)
 				act->result = -EXFULL;
-			else if (!run_sanlock && !run_dlm)
+			else if (!run_sanlock && !run_dlm && !run_idm)
 				act->result = -ENOLCK;
 			else if (run_sanlock)
 				act->result = LD_LM_SANLOCK;
 			else if (run_dlm)
 				act->result = LD_LM_DLM;
+			else if (run_idm)
+				act->result = LD_LM_IDM;
 			add_client_result(act);
 
 		} else if ((act->op == LD_OP_LOCK) && (act->flags & LD_AF_SEARCH_LS)) {
@@ -3814,6 +3972,9 @@ static int client_send_result(struct client *cl, struct action *act)
 		} else if (gl_use_dlm) {
 			if (!gl_lsname_dlm[0])
 				strcat(result_flags, "NO_GL_LS,");
+		} else if (gl_use_idm) {
+			if (!gl_lsname_idm[0])
+				strcat(result_flags, "NO_GL_LS,");
 		} else {
 			int found_lm = 0;
 
@@ -3821,6 +3982,8 @@ static int client_send_result(struct client *cl, struct action *act)
 				found_lm++;
 			if (lm_support_sanlock() && lm_is_running_sanlock())
 				found_lm++;
+			if (lm_support_idm() && lm_is_running_idm())
+				found_lm++;
 
 			if (!found_lm)
 				strcat(result_flags, "NO_GL_LS,NO_LM");
@@ -3996,11 +4159,13 @@ static int add_lock_action(struct action *act)
 		if (gl_use_sanlock && (act->op == LD_OP_ENABLE || act->op == LD_OP_DISABLE)) {
 			vg_ls_name(act->vg_name, ls_name);
 		} else {
-			if (!gl_use_dlm && !gl_use_sanlock) {
+			if (!gl_use_dlm && !gl_use_sanlock && !gl_use_idm) {
 				if (lm_is_running_dlm())
 					gl_use_dlm = 1;
 				else if (lm_is_running_sanlock())
 					gl_use_sanlock = 1;
+				else if (lm_is_running_idm())
+					gl_use_idm = 1;
 			}
 			gl_ls_name(ls_name);
 		}
@@ -4048,6 +4213,17 @@ static int add_lock_action(struct action *act)
 			add_dlm_global_lockspace(NULL);
 			goto retry;
 
+		} else if (act->op == LD_OP_LOCK && act->rt == LD_RT_GL && act->mode != LD_LK_UN && gl_use_idm) {
+			/*
+			 * Automatically start the idm global lockspace when
+			 * a command tries to acquire the global lock.
+			 */
+			log_debug("lockspace \"%s\" not found for idm gl, adding...", ls_name);
+			act->flags |= LD_AF_SEARCH_LS;
+			act->flags |= LD_AF_WAIT_STARTING;
+			add_idm_global_lockspace(NULL);
+			goto retry;
+
 		} else if (act->op == LD_OP_LOCK && act->mode == LD_LK_UN) {
 			log_debug("lockspace \"%s\" not found for unlock ignored", ls_name);
 			return -ENOLS;
@@ -4268,6 +4444,8 @@ static int str_to_lm(const char *str)
 		return LD_LM_SANLOCK;
 	if (!strcmp(str, "dlm"))
 		return LD_LM_DLM;
+	if (!strcmp(str, "idm"))
+		return LD_LM_IDM;
 	return -2; 
 }
 
@@ -4603,12 +4781,14 @@ static void client_recv_action(struct client *cl)
 	const char *vg_sysid;
 	const char *path;
 	const char *str;
+	struct pvs pvs;
+	char buf[11];	/* p a t h [ x x x x ] \0 */
 	int64_t val;
 	uint32_t opts = 0;
 	int result = 0;
 	int cl_pid;
 	int op, rt, lm, mode;
-	int rv;
+	int rv, i;
 
 	buffer_init(&req.buffer);
 
@@ -4697,11 +4877,13 @@ static void client_recv_action(struct client *cl)
 	if (!cl->name[0] && cl_name)
 		strncpy(cl->name, cl_name, MAX_NAME);
 
-	if (!gl_use_dlm && !gl_use_sanlock && (lm > 0)) {
+	if (!gl_use_dlm && !gl_use_sanlock && !gl_use_idm && (lm > 0)) {
 		if (lm == LD_LM_DLM && lm_support_dlm())
 			gl_use_dlm = 1;
 		else if (lm == LD_LM_SANLOCK && lm_support_sanlock())
 			gl_use_sanlock = 1;
+		else if (lm == LD_LM_IDM && lm_support_idm())
+			gl_use_idm = 1;
 
 		log_debug("set gl_use_%s", lm_str(lm));
 	}
@@ -4758,6 +4940,40 @@ static void client_recv_action(struct client *cl)
 	if (val)
 		act->host_id = val;
 
+	/* Create PV list for idm */
+	if (lm == LD_LM_IDM) {
+		memset(&pvs, 0x0, sizeof(pvs));
+
+		pvs.num = daemon_request_int(req, "path_num", 0);
+		log_error("pvs_num = %d", pvs.num);
+
+		if (!pvs.num)
+			goto skip_pvs_path;
+
+		/* Receive the pv list which is transferred from LVM command */
+		if (!alloc_pvs_path(&pvs, pvs.num)) {
+			log_error("fail to allocate pvs path");
+			rv = -ENOMEM;
+			goto out;
+		}
+
+		for (i = 0; i < pvs.num; i++) {
+			snprintf(buf, sizeof(buf), "path[%d]", i);
+			pvs.path[i] = (char *)daemon_request_str(req, buf, NULL);
+		}
+
+		if (!alloc_and_copy_pvs_path(&act->pvs, &pvs)) {
+			log_error("fail to allocate pvs path");
+			rv = -ENOMEM;
+			goto out;
+		}
+
+		if (pvs.path)
+			free(pvs.path);
+		pvs.path = NULL;
+	}
+
+skip_pvs_path:
 	act->max_retries = daemon_request_int(req, "max_retries", DEFAULT_MAX_RETRIES);
 
 	dm_config_destroy(req.cft);
@@ -4779,6 +4995,12 @@ static void client_recv_action(struct client *cl)
 		goto out;
 	}
 
+	if (lm == LD_LM_IDM && !lm_support_idm()) {
+		log_debug("idm not supported");
+		rv = -EPROTONOSUPPORT;
+		goto out;
+	}
+
 	if (act->op == LD_OP_LOCK && act->mode != LD_LK_UN)
 		cl->lock_ops = 1;
 
@@ -5377,6 +5599,7 @@ static void adopt_locks(void)
 		}
 		
 		list_del(&ls->list);
+		free_pvs_path(&ls->pvs);
 		free(ls);
 	}
 
@@ -5417,6 +5640,7 @@ static void adopt_locks(void)
 		if (rv < 0) {
 			log_error("Failed to create lockspace thread for VG %s", ls->vg_name);
 			list_del(&ls->list);
+			free_pvs_path(&ls->pvs);
 			free(ls);
 			free_action(act);
 			count_start_fail++;
@@ -5859,6 +6083,7 @@ static int main_loop(daemon_state *ds_arg)
 	}
 
 	strcpy(gl_lsname_dlm, S_NAME_GL_DLM);
+	strcpy(gl_lsname_idm, S_NAME_GL_IDM);
 
 	INIT_LIST_HEAD(&lockspaces);
 	pthread_mutex_init(&lockspaces_mutex, NULL);
@@ -6112,6 +6337,8 @@ int main(int argc, char *argv[])
 				gl_use_dlm = 1;
 			else if (lm == LD_LM_SANLOCK && lm_support_sanlock())
 				gl_use_sanlock = 1;
+			else if (lm == LD_LM_IDM && lm_support_idm())
+				gl_use_idm = 1;
 			else {
 				fprintf(stderr, "invalid gl-type option\n");
 				exit(EXIT_FAILURE);
daemons/lvmlockd/lvmlockd-internal.h +3 -1
index 983d66589..06a50ad85 100644
@@ -121,7 +121,7 @@ struct client {
 #define DEFAULT_MAX_RETRIES 4
 
 struct pvs {
-	const char **path;
+	char **path;
 	int num;
 };
 
@@ -338,7 +338,9 @@ EXTERN int gl_use_idm;
 EXTERN int gl_vg_removed;
 EXTERN char gl_lsname_dlm[MAX_NAME+1];
 EXTERN char gl_lsname_sanlock[MAX_NAME+1];
+EXTERN char gl_lsname_idm[MAX_NAME+1];
 EXTERN int global_dlm_lockspace_exists;
+EXTERN int global_idm_lockspace_exists;
 
 EXTERN int daemon_test; /* run as much as possible without a live lock manager */
 EXTERN int daemon_debug;
Signature · 1 line
2.25.1
#3 lore raw

RFC v2 2/5 lvmlockd: idm: Hook Seagate IDM wrapper APIs

Quoted 25 lines · Leo Yan

To allow the IDM locking scheme be used by users, this patch hooks the IDM wrapper; it also introducs a new locking type "idm" and we can use it for global lock with option '-g idm'.

To support IDM locking type, the main change in the data structure is to add pvs path arrary. The pvs list is transferred from the lvm commands, when lvmlockd core layer receives message, it extracts the message with the keyword "path[idx]". Finally, the pv list will pass to IDM lock manager as the target drives for sending IDM SCSI commands.

---
  daemons/lvmlockd/lvmlockd-core.c     | 281 ++++++++++++++++++++++++---
  daemons/lvmlockd/lvmlockd-internal.h |   4 +-
  2 files changed, 257 insertions(+), 28 deletions(-)
daemons/lvmlockd/lvmlockd-core.c +0 -0
index 094491029..dc213fd93 100644
@@ -421,6 +421,63 @@ struct lockspace *alloc_lockspace(void)
  	return ls;
... ...

daemons/lvmlockd/lvmlockd-core.c static void client_recv_action(struct client *cl) · line 4788

Quoted 8 lines
daemons/lvmlockd/lvmlockd-core.c +2 -0
@@ -4603,12 +4781,14 @@ static void client_recv_action(struct client *cl)
  	const char *vg_sysid;
  	const char *path;
  	const char *str;
+	struct pvs pvs;
+	char buf[11];	/* p a t h [ x x x x ] \0 */
  	int64_t val;
  	uint32_t opts = 0;
  	int result = 0;

Hello

SUSE build tools detected a minor compiling warning/error on the array buf[]:

[CC] lvmlockd-core.c
gcc -MT lvmlockd-core.o -MMD -MP -MF lvmlockd-core.d -c -I. -I../.. -I../../include -include configure.h -I../../libdaemon/server -I/usr/include/valgrind -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -Wall -Wcast-align -Wfloat-equal -Wformat-security -Winline -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpointer-arith -Wredundant-decls -Wshadow -Wundef -Wwrite-strings -Wclobbered -Wempty-body -Wignored-qualifiers -Wlogical-op -Wtype-limits -Wsync-nand -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wstrict-prototypes -Wuninitialized -Wjump-misses-init -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -fPIC -fPIE -DUSE_SD_NOTIFY lvmlockd-core.c -o lvmlockd-core.o lvmlockd-core.c: In function 'client_thread_main':
lvmlockd-core.c:4959:37: warning: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Wformat-truncation=]

     snprintf(buf, sizeof(buf), "path[%d]", i);
                                      ^~
lvmlockd-core.c:4959:31: note: directive argument in the range [0, 2147483647]
     snprintf(buf, sizeof(buf), "path[%d]", i);
                                ^~~~~~~~~~
In file included from /usr/include/stdio.h:862:0,
                  from ../../device_mapper/all.h:36,
                  from ../../tools/tool.h:22,
                  from lvmlockd-core.c:11:
/usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 8 and 17 bytes into a destination of size 11
    return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         __bos (__s), __fmt, __va_arg_pack ());
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

make[2]: Leaving directory '/usr/src/packages/BUILD/LVM2.2.03.12/daemons/lvmlockd' make[1]: *** [../make.tmpl:353: lvmlockd] Error 2
make: *** [make.tmpl:353: daemons] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.y3SyO6 (%build)

Regards
heming

author
#4 lore raw

RFC v2 2/5 lvmlockd: idm: Hook Seagate IDM wrapper APIs

On Tue, Jun 08, 2021 at 12:58:58PM +0800, heming.zhao at suse.com wrote:

[...]

Quoted 32 lines

daemons/lvmlockd/lvmlockd-core.c static void client_recv_action(struct client *cl) · line 4788

Quoted 9 lines
daemons/lvmlockd/lvmlockd-core.c +2 -0
@@ -4603,12 +4781,14 @@ static void client_recv_action(struct client *cl)
  	const char *vg_sysid;
  	const char *path;
  	const char *str;
+	struct pvs pvs;
+	char buf[11];	/* p a t h [ x x x x ] \0 */
  	int64_t val;
  	uint32_t opts = 0;
  	int result = 0;

Hello

SUSE build tools detected a minor compiling warning/error on the array buf[]:

[CC] lvmlockd-core.c
gcc -MT lvmlockd-core.o -MMD -MP -MF lvmlockd-core.d -c -I. -I../.. -I../../include -include configure.h -I../../libdaemon/server -I/usr/include/valgrind -DHAVE_CONFIG_H -D_FILE_OFFSET_BITS=64 -Wall -Wcast-align -Wfloat-equal -Wformat-security -Winline -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpointer-arith -Wredundant-decls -Wshadow -Wundef -Wwrite-strings -Wclobbered -Wempty-body -Wignored-qualifiers -Wlogical-op -Wtype-limits -Wsync-nand -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wstrict-prototypes -Wuninitialized -Wjump-misses-init -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -fPIC -fPIE -DUSE_SD_NOTIFY lvmlockd-core.c -o lvmlockd-core.o lvmlockd-core.c: In function 'client_thread_main':
lvmlockd-core.c:4959:37: warning: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Wformat-truncation=]

    snprintf(buf, sizeof(buf), "path[%d]", i);
                                     ^~
lvmlockd-core.c:4959:31: note: directive argument in the range [0, 2147483647]
    snprintf(buf, sizeof(buf), "path[%d]", i);
                               ^~~~~~~~~~
In file included from /usr/include/stdio.h:862:0,
                 from ../../device_mapper/all.h:36,
                 from ../../tools/tool.h:22,
                 from lvmlockd-core.c:11:
/usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 8 and 17 bytes into a destination of size 11
   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 4 lines

make[2]: Leaving directory '/usr/src/packages/BUILD/LVM2.2.03.12/daemons/lvmlockd' make[1]: *** [../make.tmpl:353: lvmlockd] Error 2
make: *** [make.tmpl:353: daemons] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.y3SyO6 (%build)

Thanks for reporting the issue, Heming.

Please see the patch for fixing the compilation warning:
https://listman.redhat.com/archives/lvm-devel/2021-June/msg00046.html

Thanks,
Leo

author
#5 lore raw

RFC v2 3/5 lib: locking: Add new type "idm"

In reply to Leo Yan

We can consider the drive firmware a server to handle the locking request from nodes, this essentially is a client-server model. DLM uses the kernel as a central place to manage locks, so it also complies with client-server model for locking operations. This is why IDM and DLM are similar with each other for their wrappers.

This patch largely works by generalizing the DLM code paths and then providing degeneralized functions as wrappers for both IDM and DLM.

---
 lib/display/display.c            |  4 ++
 lib/locking/lvmlockd.c           | 72 +++++++++++++++++++++++++++-----
 lib/metadata/metadata-exported.h |  1 +
 lib/metadata/metadata.c          | 12 +++++-
 4 files changed, 78 insertions(+), 11 deletions(-)
lib/display/display.c +4 -0
index f0f03c0a5..f9c9ef836 100644
@@ -95,6 +95,8 @@ const char *get_lock_type_string(lock_type_t lock_type)
 		return "dlm";
 	case LOCK_TYPE_SANLOCK:
 		return "sanlock";
+	case LOCK_TYPE_IDM:
+		return "idm";
 	}
 	return "invalid";
 }
@@ -111,6 +113,8 @@ lock_type_t get_lock_type_from_string(const char *str)
 		return LOCK_TYPE_DLM;
 	if (!strcmp(str, "sanlock"))
 		return LOCK_TYPE_SANLOCK;
+	if (!strcmp(str, "idm"))
+		return LOCK_TYPE_IDM;
 	return LOCK_TYPE_INVALID;
 }
 
lib/locking/lvmlockd.c +62 -10

184 lines not on this page · raw message

lib/metadata/metadata-exported.h +1 -0
index 874088993..80755c2a3 100644
@@ -353,6 +353,7 @@ typedef enum {
 	LOCK_TYPE_CLVM = 1,
 	LOCK_TYPE_DLM = 2,
 	LOCK_TYPE_SANLOCK = 3,
+	LOCK_TYPE_IDM = 4,
 } lock_type_t;
 
 struct cmd_context;
lib/metadata/metadata.c +11 -1
index ed1c05f75..b815eda87 100644
@@ -2235,6 +2235,13 @@ static int _validate_lv_lock_args(struct logical_volume *lv)
 				   lv->vg->name, display_lvname(lv), lv->lock_args);
 			r = 0;
 		}
+
+	} else if (!strcmp(lv->vg->lock_type, "idm")) {
+		if (strcmp(lv->lock_args, "idm")) {
+			log_error(INTERNAL_ERROR "LV %s/%s has invalid lock_args \"%s\"",
+				   lv->vg->name, display_lvname(lv), lv->lock_args);
+			r = 0;
+		}
 	}
 
 	return r;
@@ -2582,7 +2589,8 @@ int vg_validate(struct volume_group *vg)
 			r = 0;
 		}
 
-		if (strcmp(vg->lock_type, "sanlock") && strcmp(vg->lock_type, "dlm")) {
+		if (strcmp(vg->lock_type, "sanlock") && strcmp(vg->lock_type, "dlm") &&
+		    strcmp(vg->lock_type, "idm")) {
 			log_error(INTERNAL_ERROR "VG %s has unknown lock_type %s",
 				  vg->name, vg->lock_type);
 			r = 0;
@@ -4368,6 +4376,8 @@ int is_lockd_type(const char *lock_type)
 		return 1;
 	if (!strcmp(lock_type, "sanlock"))
 		return 1;
+	if (!strcmp(lock_type, "idm"))
+		return 1;
 	return 0;
 }
 
Signature · 1 line
2.25.1
author
#6 lore raw

RFC v2 4/5 lib: locking: Parse PV list for IDM locking

In reply to Leo Yan

For shared VG or LV locking, IDM locking scheme needs to use the PV list assocated with VG or LV for sending SCSI commands, thus it requires to use some places to generate PV list.

In reviewing the flow for LVM commands, the best place to generate PV list is in the locking lib. So this is why this patch parses PV list as shown. It iterates over all the PV nodes one by one, and compare with the VG name or LV prefix string. If any PV matches, then the PV is added into the PV list. Finally the PV list is sent to lvmlockd daemon.

Here as mentioned, it compares LV prefix string with the format "lv_name_", the reason is it needs to find out all relevant PVs, e.g. for the thin pool, it has LVs for metadata, pool, error, and raw LV, so we can use the prefix string to find out all PVs belonging to the thin pool.

For the global lock, it's not covered in this patch. To avoid the egg and chicken issue, we need to prepare the global lock ahead before any locking can be used. So the global lock's PV list is established in lvmlockd daemon by iterating all drives with partition labeled with "propeller".

---
 lib/locking/lvmlockd.c | 258 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 241 insertions(+), 17 deletions(-)
lib/locking/lvmlockd.c +241 -17
index 268f9fc2f..0ad29c25c 100644
@@ -25,6 +25,11 @@ static int _use_lvmlockd = 0;         /* is 1 if command is configured to use lv
 static int _lvmlockd_connected = 0;   /* is 1 if command is connected to lvmlockd */
 static int _lvmlockd_init_failed = 0; /* used to suppress further warnings */
 
+struct lvmlockd_pvs {
+	char **path;
+	int num;
+};
+
 void lvmlockd_set_socket(const char *sock)
 {
 	_lvmlockd_socket = sock;
@@ -178,18 +183,34 @@ static int _lockd_result(daemon_reply reply, int *result, uint32_t *lockd_flags)
 	return 1;
 }
 
-static daemon_reply _lockd_send(const char *req_name, ...)
+static daemon_reply _lockd_send_with_pvs(const char *req_name,
+				const struct lvmlockd_pvs *lock_pvs, ...)
 {
-	va_list ap;
 	daemon_reply repl;
 	daemon_request req;
+	int i;
+	char key[32];
+	const char *val;
+	va_list ap;
 
 	req = daemon_request_make(req_name);
 
-	va_start(ap, req_name);
+	va_start(ap, lock_pvs);
 	daemon_request_extend_v(req, ap);
 	va_end(ap);
 
+	/* Pass PV list */
+	if (lock_pvs && lock_pvs->num) {
+		daemon_request_extend(req, "path_num = " FMTd64,
+				      (int64_t)(lock_pvs)->num, NULL);
+
+		for (i = 0; i < lock_pvs->num; i++) {
+			snprintf(key, sizeof(key), "path[%d] = %%s", i);
+			val = lock_pvs->path[i] ? lock_pvs->path[i] : "none";
+			daemon_request_extend(req, key, val, NULL);
+		}
+	}
+
 	repl = daemon_send(_lvmlockd, req);
 
 	daemon_request_destroy(req);
@@ -197,6 +218,166 @@ static daemon_reply _lockd_send(const char *req_name, ...)
 	return repl;
 }
 
+#define _lockd_send(req_name, args...)	\
+	_lockd_send_with_pvs(req_name, NULL, ##args)
+
+static int _lockd_retrive_vg_pv_num(struct volume_group *vg)
+{
+	struct pv_list *pvl;
+	int num = 0;
+
+	dm_list_iterate_items(pvl, &vg->pvs)
+		num++;
+
+	return num;
+}
+
+static void _lockd_retrive_vg_pv_list(struct volume_group *vg,
+				      struct lvmlockd_pvs *lock_pvs)
+{
+	struct pv_list *pvl;
+	int pv_num, i;
+
+	memset(lock_pvs, 0x0, sizeof(*lock_pvs));
+
+	pv_num = _lockd_retrive_vg_pv_num(vg);
+	if (!pv_num) {
+		log_error("Fail to any PVs for VG %s", vg->name);
+		return;
+	}
+
+	/* Allocate buffer for PV list */
+	lock_pvs->path = zalloc(sizeof(*lock_pvs->path) * pv_num);
+	if (!lock_pvs->path) {
+		log_error("Fail to allocate PV list for VG %s", vg->name);
+		return;
+	}
+
+	i = 0;
+	dm_list_iterate_items(pvl, &vg->pvs) {
+		lock_pvs->path[i] = strdup(pv_dev_name(pvl->pv));
+		if (!lock_pvs->path[i]) {
+			log_error("Fail to allocate PV path for VG %s", vg->name);
+			goto fail;
+		}
+
+		log_debug("VG %s find PV device %s", vg->name, lock_pvs->path[i]);
+		i++;
+	}
+
+	lock_pvs->num = pv_num;
+	return;
+
+fail:
+	for (i = 0; i < pv_num; i++) {
+		if (!lock_pvs->path[i])
+			continue;
+		free(lock_pvs->path[i]);
+	}
+	free(lock_pvs->path);
+	return;
+}
+
+static int _lockd_retrive_lv_pv_num(struct volume_group *vg,
+				    const char *lv_name)
+{
+	struct logical_volume *lv = find_lv(vg, lv_name);
+	struct pv_list *pvl;
+	int num;
+
+	if (!lv)
+		return 0;
+
+	num = 0;
+	dm_list_iterate_items(pvl, &vg->pvs) {
+		if (lv_is_on_pv(lv, pvl->pv))
+			num++;
+	}
+
+	return num;
+}
+
+static void _lockd_retrive_lv_pv_list(struct volume_group *vg,
+				      const char *lv_name,
+				      struct lvmlockd_pvs *lock_pvs)
+{
+	struct logical_volume *lv = find_lv(vg, lv_name);
+	struct pv_list *pvl;
+	int pv_num, i = 0;
+
+	memset(lock_pvs, 0x0, sizeof(*lock_pvs));
+
+	/* Cannot find any existed LV? */
+	if (!lv)
+		return;
+
+	pv_num = _lockd_retrive_lv_pv_num(vg, lv_name);
+	if (!pv_num) {
+		/*
+		 * Fixup for 'lvcreate --type error -L1 -n $lv1 $vg', in this
+		 * case, the drive path list is empty since it doesn't establish
+		 * the structure 'pvseg->lvseg->lv->name'.
+		 *
+		 * So create drive path list with all drives in the VG.
+		 */
+		log_error("Fail to find any PVs for %s/%s, try to find PVs from VG instead",
+			  vg->name, lv_name);
+		_lockd_retrive_vg_pv_list(vg, lock_pvs);
+		return;
+	}
+
+	/* Allocate buffer for PV list */
+	lock_pvs->path = malloc(sizeof(*lock_pvs->path) * pv_num);
+	if (!lock_pvs->path) {
+		log_error("Fail to allocate PV list for %s/%s", vg->name, lv_name);
+		return;
+	}
+
+	dm_list_iterate_items(pvl, &vg->pvs) {
+		if (lv_is_on_pv(lv, pvl->pv)) {
+			lock_pvs->path[i] = strdup(pv_dev_name(pvl->pv));
+			if (!lock_pvs->path[i]) {
+				log_error("Fail to allocate PV path for LV %s/%s",
+					  vg->name, lv_name);
+				goto fail;
+			}
+
+			log_debug("Find PV device %s for LV %s/%s",
+				  lock_pvs->path[i], vg->name, lv_name);
+			i++;
+		}
+	}
+
+	lock_pvs->num = pv_num;
+	return;
+
+fail:
+	for (i = 0; i < pv_num; i++) {
+		if (!lock_pvs->path[i])
+			continue;
+		free(lock_pvs->path[i]);
+		lock_pvs->path[i] = NULL;
+	}
+	free(lock_pvs->path);
+	lock_pvs->path = NULL;
+	lock_pvs->num = 0;
+	return;
+}
+
+static void _lockd_free_pv_list(struct lvmlockd_pvs *lock_pvs)
+{
+	int i;
+
+	for (i = 0; i < lock_pvs->num; i++) {
+		free(lock_pvs->path[i]);
+		lock_pvs->path[i] = NULL;
+	}
+
+	free(lock_pvs->path);
+	lock_pvs->path = NULL;
+	lock_pvs->num = 0;
+}
+
 /*
  * result/lockd_flags are values returned from lvmlockd.
  *
@@ -227,6 +408,7 @@ static int _lockd_request(struct cmd_context *cmd,
 		          const char *lv_lock_args,
 		          const char *mode,
 		          const char *opts,
+			  const struct lvmlockd_pvs *lock_pvs,
 		          int *result,
 		          uint32_t *lockd_flags)
 {
@@ -251,7 +433,8 @@ static int _lockd_request(struct cmd_context *cmd,
 		cmd_name = "none";
 
 	if (vg_name && lv_name) {
-		reply = _lockd_send(req_name,
+		reply = _lockd_send_with_pvs(req_name,
+					lock_pvs,
 					"cmd = %s", cmd_name,
 					"pid = " FMTd64, (int64_t) pid,
 					"mode = %s", mode,
@@ -271,7 +454,8 @@ static int _lockd_request(struct cmd_context *cmd,
 			  req_name, mode, vg_name, lv_name, *result, *lockd_flags);
 
 	} else if (vg_name) {
-		reply = _lockd_send(req_name,
+		reply = _lockd_send_with_pvs(req_name,
+					lock_pvs,
 					"cmd = %s", cmd_name,
 					"pid = " FMTd64, (int64_t) pid,
 					"mode = %s", mode,
@@ -288,7 +472,8 @@ static int _lockd_request(struct cmd_context *cmd,
 			  req_name, mode, vg_name, *result, *lockd_flags);
 
 	} else {
-		reply = _lockd_send(req_name,
+		reply = _lockd_send_with_pvs(req_name,
+					lock_pvs,
 					"cmd = %s", cmd_name,
 					"pid = " FMTd64, (int64_t) pid,
 					"mode = %s", mode,
@@ -1134,6 +1319,7 @@ int lockd_start_vg(struct cmd_context *cmd, struct volume_group *vg, int start_i
 	int host_id = 0;
 	int result;
 	int ret;
+	struct lvmlockd_pvs lock_pvs;
 
 	memset(uuid, 0, sizeof(uuid));
 
@@ -1169,7 +1355,28 @@ int lockd_start_vg(struct cmd_context *cmd, struct volume_group *vg, int start_i
 		host_id = find_config_tree_int(cmd, local_host_id_CFG, NULL);
 	}
 
-	reply = _lockd_send("start_vg",
+	/*
+	 * Create the VG's PV list when start the VG, the PV list
+	 * is passed to lvmlockd, and the the PVs path will be used
+	 * to send SCSI commands for idm locking scheme.
+	 */
+	if (!strcmp(vg->lock_type, "idm")) {
+		_lockd_retrive_vg_pv_list(vg, &lock_pvs);
+		reply = _lockd_send_with_pvs("start_vg",
+				&lock_pvs,
+				"pid = " FMTd64, (int64_t) getpid(),
+				"vg_name = %s", vg->name,
+				"vg_lock_type = %s", vg->lock_type,
+				"vg_lock_args = %s", vg->lock_args ?: "none",
+				"vg_uuid = %s", uuid[0] ? uuid : "none",
+				"version = " FMTd64, (int64_t) vg->seqno,
+				"host_id = " FMTd64, (int64_t) host_id,
+				"opts = %s", start_init ? "start_init" : "none",
+				NULL);
+		_lockd_free_pv_list(&lock_pvs);
+	} else {
+		reply = _lockd_send_with_pvs("start_vg",
+				NULL,
 				"pid = " FMTd64, (int64_t) getpid(),
 				"vg_name = %s", vg->name,
 				"vg_lock_type = %s", vg->lock_type,
@@ -1179,6 +1386,7 @@ int lockd_start_vg(struct cmd_context *cmd, struct volume_group *vg, int start_i
 				"host_id = " FMTd64, (int64_t) host_id,
 				"opts = %s", start_init ? "start_init" : "none",
 				NULL);
+	}
 
 	if (!_lockd_result(reply, &result, &lockd_flags)) {
 		ret = 0;
@@ -1406,7 +1614,7 @@ int lockd_global_create(struct cmd_context *cmd, const char *def_mode, const cha
  req:
 	if (!_lockd_request(cmd, "lock_gl",
 			      NULL, vg_lock_type, NULL, NULL, NULL, NULL, mode, NULL,
-			      &result, &lockd_flags)) {
+			      NULL, &result, &lockd_flags)) {
 		/* No result from lvmlockd, it is probably not running. */
 		log_error("Global lock failed: check that lvmlockd is running.");
 		return 0;
@@ -1642,7 +1850,7 @@ int lockd_global(struct cmd_context *cmd, const char *def_mode)
 
 	if (!_lockd_request(cmd, "lock_gl",
 			    NULL, NULL, NULL, NULL, NULL, NULL, mode, opts,
-			    &result, &lockd_flags)) {
+			    NULL, &result, &lockd_flags)) {
 		/* No result from lvmlockd, it is probably not running. */
 
 		/* We don't care if an unlock fails. */
@@ -1910,7 +2118,7 @@ int lockd_vg(struct cmd_context *cmd, const char *vg_name, const char *def_mode,
 
 	if (!_lockd_request(cmd, "lock_vg",
 			      vg_name, NULL, NULL, NULL, NULL, NULL, mode, NULL,
-			      &result, &lockd_flags)) {
+			      NULL, &result, &lockd_flags)) {
 		/*
 		 * No result from lvmlockd, it is probably not running.
 		 * Decide if it is ok to continue without a lock in
@@ -2170,6 +2378,7 @@ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg,
 	uint32_t lockd_flags;
 	int refreshed = 0;
 	int result;
+	struct lvmlockd_pvs lock_pvs;
 
 	/*
 	 * Verify that when --readonly is used, no LVs should be activated or used.
@@ -2235,13 +2444,28 @@ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg,
  retry:
 	log_debug("lockd LV %s/%s mode %s uuid %s", vg->name, lv_name, mode, lv_uuid);
 
-	if (!_lockd_request(cmd, "lock_lv",
-			       vg->name, vg->lock_type, vg->lock_args,
-			       lv_name, lv_uuid, lock_args, mode, opts,
-			       &result, &lockd_flags)) {
-		/* No result from lvmlockd, it is probably not running. */
-		log_error("Locking failed for LV %s/%s", vg->name, lv_name);
-		return 0;
+	/* Pass PV list for IDM lock type */
+	if (!strcmp(vg->lock_type, "idm")) {
+		_lockd_retrive_lv_pv_list(vg, lv_name, &lock_pvs);
+		if (!_lockd_request(cmd, "lock_lv",
+				       vg->name, vg->lock_type, vg->lock_args,
+				       lv_name, lv_uuid, lock_args, mode, opts,
+				       &lock_pvs, &result, &lockd_flags)) {
+			_lockd_free_pv_list(&lock_pvs);
+			/* No result from lvmlockd, it is probably not running. */
+			log_error("Locking failed for LV %s/%s", vg->name, lv_name);
+			return 0;
+		}
+		_lockd_free_pv_list(&lock_pvs);
+	} else {
+		if (!_lockd_request(cmd, "lock_lv",
+				       vg->name, vg->lock_type, vg->lock_args,
+				       lv_name, lv_uuid, lock_args, mode, opts,
+				       NULL, &result, &lockd_flags)) {
+			/* No result from lvmlockd, it is probably not running. */
+			log_error("Locking failed for LV %s/%s", vg->name, lv_name);
+			return 0;
+		}
 	}
 
 	/* The lv was not active/locked. */
Signature · 1 line
2.25.1
author
#7 lore raw

RFC v2 5/5 tools: Add support for "idm" lock type

In reply to Leo Yan

This patch is to update the comment and code to support "idm" lock type which is used for LVM toolkit.

---
 tools/lvconvert.c |  2 ++
 tools/toollib.c   | 11 ++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)
tools/lvconvert.c +2 -0
index 4c159b01e..1f2178ce5 100644
@@ -3415,6 +3415,8 @@ static int _lvconvert_to_pool(struct cmd_context *cmd,
 				pool_lv->lock_args = "pending";
 			else if (!strcmp(vg->lock_type, "dlm"))
 				pool_lv->lock_args = "dlm";
+			else if (!strcmp(vg->lock_type, "idm"))
+				pool_lv->lock_args = "idm";
 			/* The lock_args will be set in vg_write(). */
 		}
 	}
tools/toollib.c +6 -5
index 67fbbdaa0..cda6d74f3 100644
@@ -591,15 +591,15 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
 	 * new VG, and is it compatible with current lvm.conf settings.
 	 *
 	 * The end result is to set vp_new->lock_type to:
-	 * none | clvm | dlm | sanlock.
+	 * none | clvm | dlm | sanlock | idm.
 	 *
 	 * If 'vgcreate --lock-type <arg>' is set, the answer is given
-	 * directly by <arg> which is one of none|clvm|dlm|sanlock.
+	 * directly by <arg> which is one of none|clvm|dlm|sanlock|idm.
 	 *
 	 * 'vgcreate --clustered y' is the way to create clvm VGs.
 	 *
 	 * 'vgcreate --shared' is the way to create lockd VGs.
-	 * lock_type of sanlock or dlm is selected based on
+	 * lock_type of sanlock, dlm or idm is selected based on
 	 * which lock manager is running.
 	 *
 	 *
@@ -646,7 +646,7 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
 	 * - lvmlockd is used
 	 * - VGs with CLUSTERED set are ignored (requires clvmd)
 	 * - VGs with lockd type can be used
-	 * - vgcreate can create new VGs with lock_type sanlock or dlm
+	 * - vgcreate can create new VGs with lock_type sanlock, dlm or idm
 	 * - 'vgcreate --clustered y' fails
 	 * - 'vgcreate --shared' works
 	 * - 'vgcreate' (neither option) creates a local VG
@@ -658,7 +658,7 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
 		lock_type = arg_str_value(cmd, locktype_ARG, "");
 
 		if (arg_is_set(cmd, shared_ARG) && !is_lockd_type(lock_type)) {
-			log_error("The --shared option requires lock type sanlock or dlm.");
+			log_error("The --shared option requires lock type sanlock, dlm or idm.");
 			return 0;
 		}
 
@@ -697,6 +697,7 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
 
 	case LOCK_TYPE_SANLOCK:
 	case LOCK_TYPE_DLM:
+	case LOCK_TYPE_IDM:
 		if (!use_lvmlockd) {
 			log_error("Using a shared lock type requires lvmlockd.");
 			return 0;
Signature · 1 line
2.25.1