File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
etc/systemd/system/open-iscsi.service.d Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ #
2
+ # Customize the open-iscsi service to be zfs aware. When attempting a service
3
+ # stop, check if there are any zpools still actively using iSCSI devices.
4
+ #
5
+ [Service]
6
+ ExecStop=
7
+ ExecStop=/lib/open-iscsi/zpool_on_iscsi.sh
8
+ ExecStop=/lib/open-iscsi/umountiscsi.sh
9
+ ExecStop=/bin/sync
10
+ ExecStop=/lib/open-iscsi/logout-all.sh
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ #
3
+ # Copyright (c) 2021 by Delphix. All rights reserved.
4
+ #
5
+
6
+ #
7
+ # This script checks if any iSCSI devices are in use by an active zfs pool.
8
+ #
9
+
10
+ PATH=/sbin:/bin
11
+
12
+ ZFS_FS_TYPE=" zfs_member"
13
+
14
+ function usage() {
15
+ echo " Usage: $0 [--verbose]" >&2
16
+ exit 2
17
+ }
18
+
19
+ if [[ $# -gt 1 ]]; then
20
+ usage
21
+ fi
22
+
23
+ VERBOSE=0
24
+ if [[ $# -eq 1 ]]; then
25
+ if [[ " $1 " != " --verbose" ]]; then
26
+ usage
27
+ fi
28
+ VERBOSE=1
29
+ fi
30
+
31
+ shopt -s nullglob
32
+
33
+ # locate iscsi devices that belong to a zfs pool
34
+ while read -r type transport device; do
35
+ # first locate iscsi devices
36
+ [[ " $type " == " disk" && " $transport " == " iscsi" ]] || continue
37
+ [[ $VERBOSE -eq 0 ]] || echo " ${device} uses iSCSI"
38
+
39
+ # locate any partitions for this device
40
+ for partition in /dev/" ${device} " ?* ; do
41
+ # check if partition type is zfs and grab the pool name
42
+ read -r fstype pool <<< " $(lsblk -n -o FSTYPE,LABEL " ${partition} " )"
43
+ [[ " $fstype " == " $ZFS_FS_TYPE " && -n " $pool " ]] || continue
44
+ [[ $VERBOSE -eq 0 ]] || echo " ${partition} is a member of pool ${pool} "
45
+
46
+ # check if pool is active (imported)
47
+ health=$( zpool list -H -o name,health " ${pool} " 2>&1 )
48
+ status=$?
49
+ [[ $VERBOSE -eq 0 ]] || echo " ${health} ($status )"
50
+ if [[ $status -eq 0 ]]; then
51
+ echo " device '${partition} ' in use by zfs pool '${pool} '" >&2
52
+ exit 1
53
+ fi
54
+ done
55
+ done < <( lsblk --scsi -n -o TYPE,TRAN,NAME)
56
+
57
+ exit 0
You can’t perform that action at this time.
0 commit comments