diff --git a/cmd/mount_zfs/mount_zfs.c b/cmd/mount_zfs/mount_zfs.c index ca39d22847..5196c3e5cb 100644 --- a/cmd/mount_zfs/mount_zfs.c +++ b/cmd/mount_zfs/mount_zfs.c @@ -50,6 +50,21 @@ libzfs_handle_t *g_zfs; static void parse_dataset(const char *target, char **dataset) { + /* + * Prior to util-linux 2.36.2, if a file or directory in the + * current working directory was named 'dataset' then mount(8) + * would prepend the current working directory to the dataset. + * Check for it and strip the prepended path when it is added. + */ + char cwd[PATH_MAX]; + if (getcwd(cwd, PATH_MAX) == NULL) { + perror("getcwd"); + return; + } + int len = strlen(cwd); + if (strncmp(cwd, target, len) == 0) + target += len; + /* Assume pool/dataset is more likely */ strlcpy(*dataset, target, PATH_MAX); diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh index 810a69470d..e6a4be1577 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh @@ -32,7 +32,9 @@ typeset -r fs=$TESTPOOL/$TESTFS function cleanup { cd $STF_SUITE - [[ -d $TESTDIR/$$ ]] && (rm -rf $TESTDIR/$$ || log_fail) + if [[ -d $TESTDIR/$$ ]]; then + log_must rm -rf $TESTDIR/$$ + fi mounted && zfs $mountcmd $TESTPOOL return 0 } @@ -50,13 +52,25 @@ force_unmount $fs log_note "Verify mount(8) does not canonicalize before calling helper" # Canonicalization is confused by files in PWD matching [device|mountpoint] -mkdir -p $TESTDIR/$$/$TESTPOOL && cd $TESTDIR/$$ || log_fail +log_must mkdir -p $TESTDIR/$$/$TESTPOOL +log_must cd $TESTDIR/$$ # The env flag directs zfs to exec /bin/mount, which then calls helper log_must eval ZFS_MOUNT_HELPER=1 zfs $mountcmd -v $TESTPOOL # mount (2.35.2) still suffers from a cosmetic PWD prefix bug log_must mounted $TESTPOOL force_unmount $TESTPOOL +log_note "Verify CWD prefix filter " +log_must cd / +log_must zfs set mountpoint=legacy $TESTPOOL +log_must mkdir -p $mntpoint +log_must mount -t zfs $TESTPOOL $mntpoint +log_must ismounted $TESTPOOL +log_must umount $mntpoint +log_must zfs set mountpoint=$mntpoint $TESTPOOL +log_must cd - +force_unmount $TESTPOOL + log_note "Verify '-f ' fakemount" log_must $helper -f $fs $mntpoint log_mustnot ismounted $fs @@ -75,4 +89,4 @@ log_note "Verify ' '" log_must $helper ${vdevs[0]} $mntpoint log_must mounted $mntpoint -log_pass "zfs mount helper correctly handles both device and pool strings" \ No newline at end of file +log_pass "zfs mount helper correctly handles both device and pool strings"