Skip to content

Commit a9eeea3

Browse files
Enzimemergify[bot]
authored andcommitted
zfs_fs: support updating mountpoint properly
Use `zfs set -u` to update the `mountpoint` flag without mounting or unmounting the filesystem. This flag was added in OpenZFS 2.2.0, which was released October 2023. The previous logic would not update `mountpoint` if `config.options` was empty or only contained `mountpoint`.
1 parent 88b015b commit a9eeea3

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

lib/types/zfs_fs.nix

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,15 @@
7373
"pbkdf2salt"
7474
"keyformat"
7575
];
76-
updateOptions = builtins.removeAttrs config.options (onetimeProperties ++ [ "mountpoint" ]);
77-
mountpoint = config.options.mountpoint or config.mountpoint;
76+
updateOptions = builtins.removeAttrs createOptions onetimeProperties;
7877
in
7978
''
8079
if ! zfs get type ${config._name} >/dev/null 2>&1; then
8180
zfs create -up ${config._name} \
8281
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") (createOptions))}
8382
${lib.optionalString (updateOptions != {}) ''
8483
else
85-
zfs set ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name}
86-
${lib.optionalString (mountpoint != null) ''
87-
if [[ "$(zfs get -H -o value mountpoint ${config._name})" != "${mountpoint}" ]]; then
88-
echo "Changing mountpoint to '${mountpoint}' for ${config._name}..."
89-
# zfs will try unmount the dataset to change the mountpoint
90-
# but this might fail if the dataset is in use
91-
if ! zfs set mountpoint=${mountpoint} ${config._name}; then
92-
echo "Failed to set mountpoint to '${mountpoint}' for ${config._name}." >&2
93-
echo "You may need to run when the pool is not mounted i.e. in a recovery system:" >&2
94-
echo " zfs set mountpoint=${mountpoint} ${config._name}" >&2
95-
fi
96-
fi
97-
''}
84+
zfs set -u ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name}
9885
''}
9986
fi
10087
'';

0 commit comments

Comments
 (0)