zfs_fs: Fix errors when not changing mountpoint

Running `zfs set mountpoint=/mnt/my-ds tank/my-ds`, ZFS may try to
unmount the dataset even if the mountpoint didn't change.
To avoid the confusing error message, this command is now only run when
the mountpoint actually changes.
This commit is contained in:
Felix Uhl 2024-08-22 17:51:15 +02:00 committed by mergify[bot]
parent 4b866c9942
commit f6b2e0052d

View file

@ -73,7 +73,7 @@
"pbkdf2salt" "pbkdf2salt"
"keyformat" "keyformat"
]; ];
updateOptions = builtins.removeAttrs config.options onetimeProperties; updateOptions = builtins.removeAttrs config.options (onetimeProperties ++ [ "mountpoint" ]);
mountpoint = config.options.mountpoint or config.mountpoint; mountpoint = config.options.mountpoint or config.mountpoint;
in in
'' ''
@ -84,12 +84,15 @@
else else
zfs set ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name} zfs set ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name}
${lib.optionalString (mountpoint != null) '' ${lib.optionalString (mountpoint != null) ''
# zfs will try unmount the dataset to change the mountpoint if [[ "$(zfs get -H -o value mountpoint ${config._name})" != "${mountpoint}" ]]; then
# but this might fail if the dataset is in use echo "Changing mountpoint to '${mountpoint}' for ${config._name}..."
if ! zfs set mountpoint=${mountpoint} ${config._name}; then # zfs will try unmount the dataset to change the mountpoint
echo "Failed to set mountpoint to '${mountpoint}' for ${config._name}." >&2 # but this might fail if the dataset is in use
echo "You may need to run when the pool is not mounted i.e. in a recovery system:" >&2 if ! zfs set mountpoint=${mountpoint} ${config._name}; then
echo " zfs set mountpoint=${mountpoint} ${config._name}" >&2 echo "Failed to set mountpoint to '${mountpoint}' for ${config._name}." >&2
echo "You may need to run when the pool is not mounted i.e. in a recovery system:" >&2
echo " zfs set mountpoint=${mountpoint} ${config._name}" >&2
fi
fi fi
''} ''}
''} ''}