Fix zpool create with > 1 log/dedup/special vdev

The type keyword was included before every vdev:

```shell
zpool create -f <name> /dev/sda log mirror /dev/sdb /dev/sdc log mirror /dev/sdd /dev/sde
```

but this is incorrect and should instead be:

```shell
zpool create -f <name> /dev/sda log mirror /dev/sdb /dev/sdc mirror /dev/sdd /dev/sde
```
This commit is contained in:
Michon van Dooren committed 2024-11-17 22:19:33 +01:00
1 parent 9b56c1afdb
commit 6a472cc248
1 file changed
+20 -15
+20 -15
View File
@@ -160,13 +160,14 @@ in
inherit config options; inherit config options;
default = default =
let let
formatOutput = mode: members: '' formatOutput = type: mode: members: ''
entries+=("${mode}=${ entries+=("${type} ${mode}=${
lib.concatMapStringsSep " " lib.concatMapStringsSep " "
(d: if lib.strings.hasPrefix "/" d then d else "/dev/disk/by-partlabel/disk-${d}-zfs") members (d: if lib.strings.hasPrefix "/" d then d else "/dev/disk/by-partlabel/disk-${d}-zfs") members
}") }")
''; '';
formatVdev = vdev: formatOutput vdev.mode vdev.members; formatVdev = type: vdev: formatOutput type vdev.mode vdev.members;
formatVdevList = type: vdevs: lib.concatMapStrings (formatVdev type) vdevs;
hasTopology = !(builtins.isString config.mode); hasTopology = !(builtins.isString config.mode);
mode = if hasTopology then "prescribed" else config.mode; mode = if hasTopology then "prescribed" else config.mode;
topology = lib.optionalAttrs hasTopology config.mode.topology; topology = lib.optionalAttrs hasTopology config.mode.topology;
@@ -207,27 +208,31 @@ in
else else
entries=() entries=()
${lib.optionalString (hasTopology && topology.vdev != null) ${lib.optionalString (hasTopology && topology.vdev != null)
(lib.concatMapStrings formatVdev topology.vdev)} (formatVdevList "" topology.vdev)}
${lib.optionalString (hasTopology && topology.spare != []) ${lib.optionalString (hasTopology && topology.spare != [])
(formatOutput "spare" topology.spare)} (formatOutput "spare" "" topology.spare)}
${lib.optionalString (hasTopology && topology.log != []) ${lib.optionalString (hasTopology && topology.log != [])
(lib.concatMapStrings (vdev: formatOutput "log ${vdev.mode}" vdev.members) topology.log)} (formatVdevList "log" topology.log)}
${lib.optionalString (hasTopology && topology.dedup != []) ${lib.optionalString (hasTopology && topology.dedup != [])
(lib.concatMapStrings (vdev: formatOutput "dedup ${vdev.mode}" vdev.members) topology.dedup)} (formatVdevList "dedup" topology.dedup)}
${lib.optionalString (hasTopology && topology.special != null && topology.special != []) ${lib.optionalString (hasTopology && topology.special != null && topology.special != [])
(lib.concatMapStrings (formatVdevList "special" (lib.lists.toList topology.special))}
(vdev: formatOutput "special ${vdev.mode}" vdev.members)
(lib.lists.toList topology.special)
)}
${lib.optionalString (hasTopology && topology.cache != []) ${lib.optionalString (hasTopology && topology.cache != [])
(formatOutput "cache" topology.cache)} (formatOutput "cache" "" topology.cache)}
all_devices=() all_devices=()
last_type=
for line in "''${entries[@]}"; do for line in "''${entries[@]}"; do
# lineformat is mode=device1 device2 device3 # lineformat is type mode=device1 device2 device3
mode=''${line%%=*} mode="''${line%%=*}"
devs=''${line#*=} type="''${mode%% *}"
mode="''${mode#"$type "}"
devs="''${line#*=}"
IFS=' ' read -r -a devices <<< "$devs" IFS=' ' read -r -a devices <<< "$devs"
all_devices+=("''${devices[@]}") all_devices+=("''${devices[@]}")
if ! [ "$type" = "$last_type" ]; then
topology+=" $type"
last_type="$type"
fi
topology+=" ''${mode} ''${devices[*]}" topology+=" ''${mode} ''${devices[*]}"
done done
# all_devices sorted should equal zfs_devices sorted # all_devices sorted should equal zfs_devices sorted