mirror of
https://github.com/nix-community/disko.git
synced 2026-12-02 14:03:28 +01:00
Fix zpool create for disk vdev after mirror vdev
A config like
```nix
{
vdev = [
{
mode = "mirror";
members = [ "data1" "data2" ];
}
{
members = [ "data3" ];
}
];
}
```
would result in the following command:
```shell
zpool create -f <name> mirror /dev/data1 /dev/data2 /dev/data3
```
which would result in a single vdev with a 3-way mirror, rather than a
vdev with a 2-way mirror and a second vdev with a single disk. By
reordering the vdevs to handle those with an empty mode first we
transform this into:
```shell
zpool create -f <name> /dev/data3 mirror /dev/data1 /dev/data2
```
which does have the desired outcome.
This commit is contained in:
4 files changed
+196
-19
No files matched your search
+140
-16
@@ -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,7 +43,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
spare = {
|
data3 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdc";
|
device = "/dev/vdc";
|
||||||
content = {
|
content = {
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
log = {
|
spare = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdd";
|
device = "/dev/vdd";
|
||||||
content = {
|
content = {
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
dedup = {
|
log1 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vde";
|
device = "/dev/vde";
|
||||||
content = {
|
content = {
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
special = {
|
log2 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdf";
|
device = "/dev/vdf";
|
||||||
content = {
|
content = {
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
cache = {
|
log3 = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "/dev/vdg";
|
device = "/dev/vdg";
|
||||||
content = {
|
content = {
|
||||||
@@ -123,6 +123,118 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
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 = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
cache = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/vdn";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "zroot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
zpool = {
|
zpool = {
|
||||||
zroot = {
|
zroot = {
|
||||||
@@ -133,26 +245,38 @@
|
|||||||
vdev = [
|
vdev = [
|
||||||
{
|
{
|
||||||
mode = "mirror";
|
mode = "mirror";
|
||||||
members = [
|
members = [ "data1" "data2" ];
|
||||||
"x"
|
}
|
||||||
"y"
|
{
|
||||||
];
|
members = [ "data3" ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
spare = [ "spare" ];
|
spare = [ "spare" ];
|
||||||
log = [
|
log = [
|
||||||
{
|
{
|
||||||
members = [ "log" ];
|
mode = "mirror";
|
||||||
|
members = [ "log1" "log2" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "log3" ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
dedup = [
|
dedup = [
|
||||||
{
|
{
|
||||||
members = [ "dedup" ];
|
mode = "mirror";
|
||||||
|
members = [ "dedup1" "dedup2" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "dedup3" ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
special = [
|
special = [
|
||||||
{
|
{
|
||||||
members = [ "special" ];
|
mode = "mirror";
|
||||||
|
members = [ "special1" "special2" ];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
members = [ "special3" ];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
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" "/dev/vdg" "/dev/vdh" ];
|
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 =
|
||||||
|
|||||||
+4
-2
@@ -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"
|
||||||
@@ -167,7 +167,9 @@ in
|
|||||||
}")
|
}")
|
||||||
'';
|
'';
|
||||||
formatVdev = type: vdev: formatOutput type vdev.mode vdev.members;
|
formatVdev = type: vdev: formatOutput type vdev.mode vdev.members;
|
||||||
formatVdevList = type: vdevs: lib.concatMapStrings (formatVdev type) vdevs;
|
formatVdevList = type: vdevs: lib.concatMapStrings
|
||||||
|
(formatVdev type)
|
||||||
|
(builtins.sort (a: b: a.mode < b.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;
|
||||||
|
|||||||
@@ -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