mirror of
https://github.com/nix-community/disko.git
synced 2026-12-01 21:43:29 +01:00
Merge pull request #883 from MaienM/feature/zfs-vdev-types
ZFS: Add log, spare & dedup vdev types, support multiple special vdevs, fix bug with mixed vdev types
This commit is contained in:
4 files changed
+346
-34
No files matched your search
+199
-14
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
x = {
|
data1 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/sdx";
|
device = "/dev/vda";
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
y = {
|
data2 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/sdy";
|
device = "/dev/vdb";
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
@@ -43,9 +43,169 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
z = {
|
data3 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/sdz";
|
device = "/dev/vdc";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
spare = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdd";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
log1 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vde";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
log2 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdf";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
log3 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdg";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
dedup1 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdh";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
dedup2 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdi";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
dedup3 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdj";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
special1 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdk";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
special2 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdl";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
special3 = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdm";
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
@@ -61,7 +221,7 @@
|
|||||||
};
|
};
|
||||||
cache = {
|
cache = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdc";
|
device = "/dev/vdn";
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
@@ -85,15 +245,40 @@
|
|||||||
vdev = [
|
vdev = [
|
||||||
{
|
{
|
||||||
mode = "mirror";
|
mode = "mirror";
|
||||||
members = [
|
members = [ "data1" "data2" ];
|
||||||
"x"
|
}
|
||||||
"y"
|
{
|
||||||
];
|
members = [ "data3" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
spare = [ "spare" ];
|
||||||
|
log = [
|
||||||
|
{
|
||||||
|
mode = "mirror";
|
||||||
|
members = [ "log1" "log2" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "log3" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
dedup = [
|
||||||
|
{
|
||||||
|
mode = "mirror";
|
||||||
|
members = [ "dedup1" "dedup2" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "dedup3" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
special = [
|
||||||
|
{
|
||||||
|
mode = "mirror";
|
||||||
|
members = [ "special1" "special2" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "special3" ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
special = {
|
|
||||||
members = [ "z" ];
|
|
||||||
};
|
|
||||||
cache = [ "cache" ];
|
cache = [ "cache" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
+17
-1
@@ -38,7 +38,23 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
# list of devices generated inside qemu
|
# list of devices generated inside qemu
|
||||||
devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ];
|
devices = [
|
||||||
|
"/dev/vda"
|
||||||
|
"/dev/vdb"
|
||||||
|
"/dev/vdc"
|
||||||
|
"/dev/vdd"
|
||||||
|
"/dev/vde"
|
||||||
|
"/dev/vdf"
|
||||||
|
"/dev/vdg"
|
||||||
|
"/dev/vdh"
|
||||||
|
"/dev/vdi"
|
||||||
|
"/dev/vdj"
|
||||||
|
"/dev/vdk"
|
||||||
|
"/dev/vdl"
|
||||||
|
"/dev/vdm"
|
||||||
|
"/dev/vdn"
|
||||||
|
"/dev/vdo"
|
||||||
|
];
|
||||||
|
|
||||||
# This is the test generator for a disko test
|
# This is the test generator for a disko test
|
||||||
makeDiskoTest =
|
makeDiskoTest =
|
||||||
|
|||||||
+95
-19
@@ -1,6 +1,6 @@
|
|||||||
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
||||||
let
|
let
|
||||||
# TODO: Consider expanding to handle `disk` `file` and `draid` mode options.
|
# TODO: Consider expanding to handle `file` and `draid` mode options.
|
||||||
modeOptions = [
|
modeOptions = [
|
||||||
""
|
""
|
||||||
"mirror"
|
"mirror"
|
||||||
@@ -63,19 +63,79 @@ in
|
|||||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Virtual_Devices_(vdevs)
|
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Virtual_Devices_(vdevs)
|
||||||
for details.
|
for details.
|
||||||
'';
|
'';
|
||||||
example = [{
|
example = [
|
||||||
mode = "mirror";
|
{
|
||||||
members = [ "x" "y" "/dev/sda1" ];
|
mode = "mirror";
|
||||||
}];
|
members = [ "x" "y" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "z" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
spare = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
A list of devices to use as hot spares. See
|
||||||
|
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Hot_Spares
|
||||||
|
for details.
|
||||||
|
'';
|
||||||
|
example = [ "x" "y" ];
|
||||||
|
};
|
||||||
|
log = lib.mkOption {
|
||||||
|
type = lib.types.listOf vdev;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
A list of vdevs used for the zfs intent log (ZIL). See
|
||||||
|
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Intent_Log
|
||||||
|
for details.
|
||||||
|
'';
|
||||||
|
example = [
|
||||||
|
{
|
||||||
|
mode = "mirror";
|
||||||
|
members = [ "x" "y" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "z" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
dedup = lib.mkOption {
|
||||||
|
type = lib.types.listOf vdev;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
A list of vdevs used for the deduplication table. See
|
||||||
|
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#dedup
|
||||||
|
for details.
|
||||||
|
'';
|
||||||
|
example = [
|
||||||
|
{
|
||||||
|
mode = "mirror";
|
||||||
|
members = [ "x" "y" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "z" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
special = lib.mkOption {
|
special = lib.mkOption {
|
||||||
type = lib.types.nullOr vdev;
|
type = lib.types.either (lib.types.listOf vdev) (lib.types.nullOr vdev);
|
||||||
default = null;
|
default = [ ];
|
||||||
description = ''
|
description = ''
|
||||||
A vdev definition for a special device. See
|
A list of vdevs used as special devices. See
|
||||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#special
|
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#special
|
||||||
for details.
|
for details.
|
||||||
'';
|
'';
|
||||||
|
example = [
|
||||||
|
{
|
||||||
|
mode = "mirror";
|
||||||
|
members = [ "x" "y" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "z" ];
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
cache = lib.mkOption {
|
cache = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
@@ -85,8 +145,8 @@ in
|
|||||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Cache_Devices
|
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Cache_Devices
|
||||||
for details.
|
for details.
|
||||||
'';
|
'';
|
||||||
|
example = [ "x" "y" ];
|
||||||
};
|
};
|
||||||
# TODO: Consider supporting log, spare, and dedup options.
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -134,13 +194,16 @@ 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)
|
||||||
|
(builtins.sort (a: _: a.mode == "") 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;
|
||||||
@@ -181,18 +244,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.special != null)
|
${lib.optionalString (hasTopology && topology.spare != [])
|
||||||
(formatOutput "special ${topology.special.mode}" topology.special.members)}
|
(formatOutput "spare" "" topology.spare)}
|
||||||
|
${lib.optionalString (hasTopology && topology.log != [])
|
||||||
|
(formatVdevList "log" topology.log)}
|
||||||
|
${lib.optionalString (hasTopology && topology.dedup != [])
|
||||||
|
(formatVdevList "dedup" topology.dedup)}
|
||||||
|
${lib.optionalString (hasTopology && topology.special != null && topology.special != [])
|
||||||
|
(formatVdevList "special" (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
|
||||||
|
|||||||
@@ -38,5 +38,40 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
||||||
assert_property("zroot/zfs_fs", "compression", "zstd")
|
assert_property("zroot/zfs_fs", "compression", "zstd")
|
||||||
machine.succeed("mountpoint /zfs_fs");
|
machine.succeed("mountpoint /zfs_fs");
|
||||||
|
|
||||||
|
# Take the status output and flatten it so that each device is on a single line prefixed with with the group (either
|
||||||
|
# the pool name or a designation like log/cache/spare/dedup/special) and first portion of the vdev name (empty for a
|
||||||
|
# disk from a single vdev, mirror for devices in a mirror. This makes it easy to verify that the layout is as
|
||||||
|
# expected.
|
||||||
|
group = ""
|
||||||
|
vdev = ""
|
||||||
|
actual = []
|
||||||
|
for line in machine.succeed("zpool status -P zroot").split("\n"):
|
||||||
|
first_word = line.strip().split(" ", 1)[0]
|
||||||
|
if line.startswith("\t ") and first_word.startswith("/"):
|
||||||
|
actual.append(f"{group}{vdev}{first_word}")
|
||||||
|
elif line.startswith("\t "):
|
||||||
|
vdev = f"{first_word.split('-', 1)[0]} "
|
||||||
|
elif line.startswith("\t"):
|
||||||
|
group = f"{first_word} "
|
||||||
|
vdev = ""
|
||||||
|
actual.sort()
|
||||||
|
expected=sorted([
|
||||||
|
'zroot /dev/disk/by-partlabel/disk-data3-zfs',
|
||||||
|
'zroot mirror /dev/disk/by-partlabel/disk-data1-zfs',
|
||||||
|
'zroot mirror /dev/disk/by-partlabel/disk-data2-zfs',
|
||||||
|
'dedup /dev/disk/by-partlabel/disk-dedup3-zfs',
|
||||||
|
'dedup mirror /dev/disk/by-partlabel/disk-dedup1-zfs',
|
||||||
|
'dedup mirror /dev/disk/by-partlabel/disk-dedup2-zfs',
|
||||||
|
'special /dev/disk/by-partlabel/disk-special3-zfs',
|
||||||
|
'special mirror /dev/disk/by-partlabel/disk-special1-zfs',
|
||||||
|
'special mirror /dev/disk/by-partlabel/disk-special2-zfs',
|
||||||
|
'logs /dev/disk/by-partlabel/disk-log3-zfs',
|
||||||
|
'logs mirror /dev/disk/by-partlabel/disk-log1-zfs',
|
||||||
|
'logs mirror /dev/disk/by-partlabel/disk-log2-zfs',
|
||||||
|
'cache /dev/disk/by-partlabel/disk-cache-zfs',
|
||||||
|
'spares /dev/disk/by-partlabel/disk-spare-zfs',
|
||||||
|
])
|
||||||
|
assert actual == expected, f"Incorrect pool layout. Expected:\n\t{'\n\t'.join(expected)}\nActual:\n\t{'\n\t'.join(actual)}"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user