Whamcloud - gitweb
LU-4277 scripts: ofd status integrated with zpool status 07/30907/7
authorNathaniel Clark <nathaniel.l.clark@intel.com>
Wed, 24 Jan 2018 13:35:05 +0000 (08:35 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 6 Feb 2018 04:28:41 +0000 (04:28 +0000)
Add zedlet to ZFS ZED that markes OFD as degraded/undegraded,
when a zpool is degraded or online, respectivly.

Test-Parameters: trivial
Signed-off-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Change-Id: Ia8ec3cf3a31ce24d8598d690bcb0356245712858
Reviewed-on: https://review.whamcloud.com/30907
Tested-by: Jenkins
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre.spec.in
lustre/scripts/Makefile.am
lustre/scripts/statechange-lustre.sh [new file with mode: 0755]

index d548c06..f228a4e 100644 (file)
@@ -490,6 +490,7 @@ echo '%{_sbindir}/wiretest' >>lustre-tests.files
 %files osd-zfs-mount
 %defattr(-,root,root)
 %{_libdir}/@PACKAGE@/mount_osd_zfs.so
+%{_sysconfdir}/zfs/zed.d/*
 %endif
 %endif
 %endif
index a4ed9f7..8b52188 100644 (file)
@@ -63,6 +63,11 @@ bin_SCRIPTS  += lustre_req_history
 hadir = $(sysconfdir)/ha.d/resource.d
 ha_SCRIPTS = Lustre.ha_v2
 
+if ZFS_ENABLED
+zedletdir = $(sysconfdir)/zfs/zed.d/
+zedlet_SCRIPTS = statechange-lustre.sh
+endif
+
 scriptlibdir = @libexecdir@/@PACKAGE@
 scriptlib_SCRIPTS = haconfig
 scriptlib_DATA = lc_common
@@ -78,7 +83,7 @@ EXTRA_DIST = license-status lustre_rmmod ldev lc_mon lhbadm \
             lc_servip lustre_routes_config lustre_routes_conversion \
             $(addsuffix .in,$(genscripts)) lfs_migrate lustre_req_history \
             lustre lsvcgss lc_common haconfig Lustre.ha_v2 dkms.mkconf \
-            zfsobj2fid ko2iblnd-probe
+            zfsobj2fid ko2iblnd-probe statechange-lustre.sh
 
 CLEANFILES = $(genscripts)
 
diff --git a/lustre/scripts/statechange-lustre.sh b/lustre/scripts/statechange-lustre.sh
new file mode 100755 (executable)
index 0000000..c3225b2
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License Version 1.0 (CDDL-1.0).
+# You can obtain a copy of the license from the top-level file
+# "OPENSOLARIS.LICENSE" or at <http://opensource.org/licenses/CDDL-1.0>.
+# You may not use this file except in compliance with the license.
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2018, Intel Corporation.
+#
+
+#
+# Adjust lustre service degrade state in response to a statechange
+#
+# ZEVENT_SUBCLASS: 'statechange'
+# POOL HEALTH: status from "zpool list health" (either ONLINE or DEGRADED)
+#
+# depends on lctl(1)
+#
+# Exit codes:
+#   0: normal exit
+#   1: lctl missing
+#   2: zpool missing
+#   3: zfs missing
+#   4: Pool status neither "ONLINE" nor "DEGRADED
+
+[ -f "${ZED_ZEDLET_DIR}/zed.rc" ] && . "${ZED_ZEDLET_DIR}/zed.rc"
+. "${ZED_ZEDLET_DIR}/zed-functions.sh"
+
+LCTL=${LCTL:-/usr/sbin/lctl}
+ZPOOL=${ZPOOL:-/usr/sbin/zpool}
+ZFS=${ZFS:-/usr/sbin/zfs}
+
+zed_check_cmd "$LCTL" || exit 1
+zed_check_cmd "$ZPOOL" || exit 2
+zed_check_cmd "$ZFS" || exit 3
+
+#
+# sync_degrade_state (dataset, state)
+#
+sync_degrade_state()
+{
+    local dataset="$1"
+    local state="$2"
+    local service=$($ZFS list -H -o lustre:svname ${dataset})
+
+    zed_log_msg "Lustre:sync_degrade_state pool:${dataset} degraded:${state}"
+
+    if [ -n "${service}" ] && [ "${service}"  != "-" ] ; then
+       local current=$($LCTL get_param -n obdfilter.${service}.degraded)
+
+       if [ "${current}" != "${state}" ] ; then
+           $LCTL set_param obdfilter.${service}.degraded=${state}
+       fi
+    fi
+}
+
+
+#
+# use pool state as deciding factor
+#
+POOL_STATE=$($ZPOOL list -H -o health ${ZEVENT_POOL})
+
+if [ "${POOL_STATE}" == "ONLINE" ] ; then
+    MODE="0"
+elif [ "${POOL_STATE}" == "DEGRADED" ] ; then
+    MODE="1"
+else
+    exit 4
+fi
+
+#
+# visit target pool's datasets and adjust lustre service degrade mode
+#
+read -r -a DATASETS <<< \
+    $($ZFS get -rH -s local -t filesystem -o name lustre:svname ${ZEVENT_POOL})
+
+for dataset in "${DATASETS[@]}" ; do
+    sync_degrade_state "${dataset}" "${MODE}"
+done
+
+exit 0