zfs: fix test and add documentation

This commit is contained in:
dylan madisetti 2024-08-26 13:03:25 -04:00
parent cc2e247193
commit ea3ce722ea
No known key found for this signature in database
GPG key ID: 9080F46A6E933A9D
3 changed files with 28 additions and 12 deletions

View file

@ -80,6 +80,7 @@
type = "zpool"; type = "zpool";
mode = { mode = {
topology = { topology = {
type = "topology";
vdev = [ vdev = [
{ {
mode = "mirror"; mode = "mirror";

View file

@ -53,3 +53,4 @@
}; };
}; };
} }

View file

@ -1,9 +1,11 @@
{ config, options, lib, diskoLib, rootMountPoint, ... }: { config, options, lib, diskoLib, rootMountPoint, ... }:
let let
# TODO: Consider expanding to handle `disk` `file` and `draid` mode options.
modeOptions = [ modeOptions = [
"" ""
"mirror" "mirror"
"raidz" "raidz"
"raidz1"
"raidz2" "raidz2"
"raidz3" "raidz3"
]; ];
@ -32,7 +34,7 @@ in
mode = lib.mkOption { mode = lib.mkOption {
type = lib.types.enum modeOptions; type = lib.types.enum modeOptions;
default = ""; default = "";
description = "mode of the zfs vdev"; description = "Mode of the zfs vdev";
}; };
members = lib.mkOption { members = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
@ -51,27 +53,39 @@ in
internal = true; internal = true;
description = "Type"; description = "Type";
}; };
# zfs disk types # zfs device types
vdev = lib.mkOption { vdev = lib.mkOption {
type = lib.types.listOf vdev; type = lib.types.listOf vdev;
default = [ ]; default = [ ];
description = "A list of storage vdevs"; description = ''
A list of storage vdevs. See
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Virtual_Devices_(vdevs)
for details.
'';
example = [{ example = [{
mode = "mirror"; mode = "mirror";
members = [ "x" "y" ]; members = [ "x" "y" "/dev/sda1" ];
}]; }];
}; };
special = lib.mkOption { special = lib.mkOption {
type = lib.types.nullOr vdev; type = lib.types.nullOr vdev;
default = null; default = null;
description = "A list of devices for the special vdev"; description = ''
A vdev definition for a special device. See
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#special
for details.
'';
}; };
cache = lib.mkOption { cache = lib.mkOption {
type = lib.types.nullOr lib.types.str; type = lib.types.listOf lib.types.str;
default = null; default = null;
description = "The cache device"; description = ''
A dedicated zfs cache device (L2ARC). See
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Cache_Devices
for details.
'';
}; };
# TODO: Consider # TODO: Consider supporting log, spare, and dedup options.
}; };
}); });
}; };
@ -125,8 +139,8 @@ in
}") }")
''); '');
formatVdev = (vdev: formatOutput vdev.mode vdev.members); formatVdev = (vdev: formatOutput vdev.mode vdev.members);
hasTopology = builtins.isString config.mode; hasTopology = !(builtins.isString config.mode);
mode = if hasTopology then config.mode else "prescribed"; mode = if !hasTopology then config.mode else "prescribed";
topology = if hasTopology then config.mode.topology else { }; topology = if hasTopology then config.mode.topology else { };
in in
'' ''
@ -164,8 +178,8 @@ in
(lib.concatMapStrings formatVdev topology.vdev)} (lib.concatMapStrings formatVdev topology.vdev)}
${lib.optionalString (hasTopology && topology.special != null) ${lib.optionalString (hasTopology && topology.special != null)
(formatOutput "special ${topology.special.mode}" topology.special.members)} (formatOutput "special ${topology.special.mode}" topology.special.members)}
${lib.optionalString (hasTopology && topology.cache != null) ${lib.optionalString (hasTopology && topology.cache != [])
(formatOutput "cache" [topology.cache])} (formatOutput "cache" topology.cache)}
all_devices=() all_devices=()
for line in "''${entries[@]}"; do for line in "''${entries[@]}"; do
# lineformat is mode=device1 device2 device3 # lineformat is mode=device1 device2 device3