mirror_zfs/module/os/linux/zfs
Umer Saleem 27e8f56102
Fix inconsistent mount options for ZFS root
While mounting ZFS root during boot on Linux distributions from initrd,
mount from busybox is effectively used which executes mount system call
directly. This skips the ZFS helper mount.zfs, which checks and enables
the mount options as specified in dataset properties. As a result,
datasets mounted during boot from initrd do not have correct mount
options as specified in ZFS dataset properties.

There has been an attempt to use mount.zfs in zfs initrd script,
responsible for mounting the ZFS root filesystem (PR#13305). This was
later reverted (PR#14908) after discovering that using mount.zfs breaks
mounting of snapshots on root (/) and other child datasets of root have
the same issue (Issue#9461).

This happens because switching from busybox mount to mount.zfs correctly
parses the mount options but also adds 'mntpoint=/root' to the mount
options, which is then prepended to the snapshot mountpoint in
'.zfs/snapshot'. '/root' is the directory on Debian with initramfs-tools
where root filesystem is mounted before pivot_root. When Linux runtime
is reached, trying to access the snapshots on root results in
automounting the snapshot on '/root/.zfs/*', which fails.

This commit attempts to fix the automounting of snapshots on root, while
using mount.zfs in initrd script. Since the mountpoint of dataset is
stored in vfs_mntpoint field, we can check if current mountpoint of
dataset and vfs_mntpoint are same or not. If they are not same, reset
the vfs_mntpoint field with current mountpoint. This fixes the
mountpoints of root dataset and children in respective vfs_mntpoint
fields when we try to access the snapshots of root dataset or its
children. With correct mountpoint for root dataset and children stored
in vfs_mntpoint, all snapshots of root dataset are mounted correctly
and become accessible.

This fix will come into play only if current process, that is trying to
access the snapshots is not in chroot context. The Linux kernel API
that is used to convert struct path into char format (d_path), returns
the complete path for given struct path. It works in chroot environment
as well and returns the correct path from original filesystem root.

However d_path fails to return the complete path if any directory from
original root filesystem is mounted using --bind flag or --rbind flag
in chroot environment. In this case, if we try to access the snapshot
from outside the chroot environment, d_path returns the path correctly,
i.e. it returns the correct path to the directory that is mounted with
--bind flag. However inside the chroot environment, it only returns the
path inside chroot.

For now, there is not a better way in my understanding that gives the
complete path in char format and handles the case where directories from
root filesystem are mounted with --bind or --rbind on another path which
user will later chroot into. So this fix gets enabled if current
process trying to access the snapshot is not in chroot context.

With the snapshots issue fixed for root filesystem, using mount.zfs in
ZFS initrd script, mounts the datasets with correct mount options.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Ameer Hamza <ahamza@ixsystems.com>
Signed-off-by: Umer Saleem <usaleem@ixsystems.com>
Closes #16646
2024-10-17 09:09:39 -04:00
..
abd_os.c Always validate checksums for Direct I/O reads 2024-10-09 12:28:08 -07:00
arc_os.c arc_os: split userspace and Linux kernel code 2024-09-19 15:48:54 -07:00
mmp_os.c Cleanup: 64-bit kernel module parameters should use fixed width types 2022-10-13 10:03:29 -07:00
policy.c config: remove HAVE_HAS_CAPABILITY 2024-09-18 11:23:51 -07:00
qat_compress.c Intel QAT 1.7 compatibility 2023-09-07 14:38:17 -07:00
qat_crypt.c Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
qat.c Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
spa_misc_os.c Selectable block allocators 2023-09-01 18:00:30 -07:00
trace.c Replace dead opensolaris.org license link 2022-07-11 14:16:13 -07:00
vdev_disk.c config: remove HAVE_BIO_SET_DEV 2024-09-18 11:23:51 -07:00
vdev_file.c zfs_file: rename zfs_file_fallocate to zfs_file_deallocate 2024-09-18 11:35:04 -07:00
vdev_label_os.c RAID-Z expansion feature 2023-11-08 10:19:41 -08:00
zfs_acl.c Fix an uninitialized data access (#16511) 2024-09-10 09:08:45 -07:00
zfs_ctldir.c Fix inconsistent mount options for ZFS root 2024-10-17 09:09:39 -04:00
zfs_debug.c zfs_debug: specific variant for userspace 2024-09-19 15:49:50 -07:00
zfs_dir.c snapdir: add 'disabled' value to make .zfs inaccessible 2024-10-02 09:12:02 -07:00
zfs_file_os.c zfs_file: rename zfs_file_fallocate to zfs_file_deallocate 2024-09-18 11:35:04 -07:00
zfs_ioctl_os.c linux: log a scary warning when used with an experimental kernel 2024-09-23 10:44:54 -07:00
zfs_racct.c Adding Direct IO Support 2024-09-14 13:47:59 -07:00
zfs_sysfs.c Introduce kmem_scnprintf() 2022-10-29 13:05:11 -07:00
zfs_uio.c config: remove HAVE_GET_USER_PAGES_* 2024-09-18 11:23:51 -07:00
zfs_vfsops.c Fix inconsistent mount options for ZFS root 2024-10-17 09:09:39 -04:00
zfs_vnops_os.c Support for longnames for files/directories (Linux part) 2024-10-01 13:40:27 -07:00
zfs_znode_os.c Linux 6.12: PG_error flag was removed 2024-10-01 13:54:05 -07:00
zio_crypt.c ZIL: Assert record sizes in different places 2023-11-28 13:35:14 -08:00
zpl_ctldir.c snapdir: add 'disabled' value to make .zfs inaccessible 2024-10-02 09:12:02 -07:00
zpl_export.c Support for longnames for files/directories (Linux part) 2024-10-01 13:40:27 -07:00
zpl_file_range.c config: remove HAVE_VFS_COPY_FILE_RANGE 2024-09-18 11:23:50 -07:00
zpl_file.c Avoid BUG in migrate_folio_extra 2024-09-26 08:57:09 -07:00
zpl_inode.c Support for longnames for files/directories (Linux part) 2024-10-01 13:40:27 -07:00
zpl_super.c config: remove HAVE_INODE_SET_IVERSION 2024-09-18 11:23:50 -07:00
zpl_xattr.c Allocate zap_attribute_t from kmem instead of stack 2024-10-01 13:39:08 -07:00
zvol_os.c cityhash: replace invocations with specialized versions when possible 2024-09-19 15:19:17 -07:00