zfs(4): remove "experimental" from zfs_bclone_enabled
[zfs.git] / contrib / dracut / 02zfsexpandknowledge / module-setup.sh.in
blobb1f2d8f4c7b32c0b808a852b106ac85d34644f11
1 #!/usr/bin/env bash
3 get_devtype() {
4 local typ
5 typ=$(udevadm info --query=property --name="$1" | sed -n 's|^ID_FS_TYPE=||p')
6 if [[ -z "$typ" ]] ; then
7 typ=$(blkid -c /dev/null "$1" -o value -s TYPE)
8 fi
9 echo "$typ"
12 get_pool_devices() {
13 # also present in 99zfssystemd
14 local poolconfigtemp
15 local poolconfigoutput
16 local pooldev
17 local resolved
18 poolconfigtemp="$(mktemp)"
19 if ! @sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1 ; then
20 poolconfigoutput="$(cat "$poolconfigtemp")"
21 dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput"
22 else
23 awk -F '\t' '/\t\/dev/ { print $2 }' "$poolconfigtemp" | \
24 while read -r pooldev ; do
25 if [[ -e "$pooldev" ]] ; then
26 resolved="$(readlink -f "$pooldev")"
27 dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
28 echo "$resolved"
30 done
32 rm -f "$poolconfigtemp"
35 find_zfs_block_devices() {
36 local dev
37 local mp
38 local fstype
39 local _
40 numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
41 if [[ "$numfields" = "10" ]] ; then
42 fields="_ _ _ _ mp _ _ fstype dev _"
43 else
44 fields="_ _ _ _ mp _ _ _ fstype dev _"
46 # shellcheck disable=SC2086
47 while read -r ${fields?} ; do
48 [[ "$fstype" = "zfs" ]] || continue
49 [[ "$mp" = "$1" ]] && get_pool_devices "${dev%%/*}"
50 done < /proc/self/mountinfo
53 array_contains () {
54 local e
55 for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
56 return 1
59 check() {
60 # https://github.com/dracutdevs/dracut/pull/1711 provides a zfs_devs
61 # function to detect the physical devices backing zfs pools. If this
62 # function exists in the version of dracut this module is being called
63 # from, then it does not need to run.
64 type zfs_devs >/dev/null 2>&1 && return 1
66 local mp
67 local dev
68 local blockdevs
69 local fstype
70 local majmin
71 local _depdev
72 local _depdevname
73 local _depdevtype
75 # shellcheck disable=SC2154
76 if [[ -n "$hostonly" ]]; then
78 for mp in \
79 "/" \
80 "/etc" \
81 "/bin" \
82 "/sbin" \
83 "/lib" \
84 "/lib64" \
85 "/usr" \
86 "/usr/bin" \
87 "/usr/sbin" \
88 "/usr/lib" \
89 "/usr/lib64" \
90 "/boot";
92 mp=$(readlink -f "$mp")
93 mountpoint "$mp" >/dev/null 2>&1 || continue
94 blockdevs=$(find_zfs_block_devices "$mp")
95 if [[ -z "$blockdevs" ]] ; then continue ; fi
96 dinfo "zfsexpandknowledge: block devices backing ZFS dataset $mp: ${blockdevs//$'\n'/ }"
97 for dev in $blockdevs
99 array_contains "$dev" "${host_devs[@]}" || host_devs+=("$dev")
100 fstype=$(get_devtype "$dev")
101 host_fs_types["$dev"]="$fstype"
102 majmin=$(get_maj_min "$dev")
103 if [[ -d "/sys/dev/block/$majmin/slaves" ]] ; then
104 for _depdev in "/sys/dev/block/$majmin/slaves"/*; do
105 [[ -f "$_depdev/dev" ]] || continue
106 _depdev="/dev/${_depdev##*/}"
107 _depdevname=$(udevadm info --query=property --name="$_depdev" | sed -n 's|^DEVNAME=||p')
108 _depdevtype=$(get_devtype "$_depdevname")
109 dinfo "zfsexpandknowledge: underlying block device backing ZFS dataset $mp: ${_depdevname//$'\n'/ }"
110 array_contains "$_depdevname" "${host_devs[@]}" || host_devs+=("$_depdevname")
111 host_fs_types["$_depdevname"]="$_depdevtype"
112 done
114 done
115 done
116 for a in "${host_devs[@]}"
118 dinfo "zfsexpandknowledge: host device $a"
119 done
120 for a in "${!host_fs_types[@]}"
122 dinfo "zfsexpandknowledge: device $a of type ${host_fs_types[$a]}"
123 done
127 return 1