zfs: support for root dataset mountpoint and mountpoint=none

This commit is contained in:
Jörg Thalheim 2022-08-26 10:28:07 +02:00
parent 57b7c5506a
commit 722dde361c
3 changed files with 36 additions and 10 deletions

View file

@ -256,29 +256,48 @@ let
mount.zfs = mount.noop;
mount.zpool = q: x: (
mount.zpool = q: x:
let
datasets = [{
inherit (q) name;
type = "zfs_filesystem";
dataset = q.name;
mountpoint = x.mountpoint or "/${q.name}";
options = q.rootFsOptions or { };
}] ++ x.datasets;
in
recursiveUpdate
(foldl' recursiveUpdate { } (map (mount-f (q // { pool = q.name; })) x.datasets))
(foldl' recursiveUpdate { }
(
(map
(x: mount-f
({
dataset = x.dataset or "${q.name}/${x.name}";
mountpoint = x.mountpoint or "/${q.name}/${x.name}";
} // q)
x)
datasets)
)
)
{
zpool.${q.device} = ''
zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}'
'';
}
);
};
mount.zfs_filesystem = q: x: {
zfs.${x.mountpoint} = ''
if ! findmnt '${q.pool}/${x.name}' /mnt${x.mountpoint} > /dev/null 2>&1; then
zfs.${q.mountpoint} = lib.optionalString ((x.options.mountpoint or "") != "none") ''
if ! findmnt '${q.dataset}' /mnt${q.mountpoint} > /dev/null 2>&1; then
mount \
${lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil"} \
-t zfs ${q.pool}/${x.name} /mnt${x.mountpoint} \
-t zfs ${q.dataset} /mnt${q.mountpoint} \
-o X-mount.mkdir
fi
'';
};
mount.zfs_volume = q: x:
mount-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content;
mount-f { device = "/dev/zvol/${q.dataset}"; } x.content;
in
{

View file

@ -16,6 +16,8 @@
compression = "lz4";
"com.sun:auto-snapshot" = "false";
};
mountpoint = "/";
datasets = [
{
type = "zfs_filesystem";
@ -23,6 +25,11 @@
mountpoint = "/zfs_fs";
options."com.sun:auto-snapshot" = "true";
}
{
type = "zfs_filesystem";
name = "zfs_unmounted_fs";
options.mountpoint = "none";
}
{
type = "zfs_filesystem";
name = "zfs_legacy_fs";

View file

@ -17,9 +17,9 @@ makeDiskoTest {
assert_property("zroot", "com.sun:auto-snapshot", "false")
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
assert_property("zroot/zfs_testvolume", "volsize", "10M")
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")
# FIXME: we cannot mount rootfs yet
#machine.succeed("mountpoint /mnt");
machine.succeed("mountpoint /mnt");
machine.succeed("mountpoint /mnt/zfs_fs");
machine.succeed("mountpoint /mnt/zfs_legacy_fs");
machine.succeed("mountpoint /mnt/ext4onzfs");