diff --git a/cmd/mount_zfs/mount_zfs.c b/cmd/mount_zfs/mount_zfs.c index ed9f167ccac8..13935a9cc687 100644 --- a/cmd/mount_zfs/mount_zfs.c +++ b/cmd/mount_zfs/mount_zfs.c @@ -1,409 +1,395 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011 Lawrence Livermore National Security, LLC. */ #include #include #include #include #include #include #include #include #include #include #include #include #define ZS_COMMENT 0x00000000 /* comment */ #define ZS_ZFSUTIL 0x00000001 /* caller is zfs(8) */ libzfs_handle_t *g_zfs; /* * Return the pool/dataset to mount given the name passed to mount. This * is expected to be of the form pool/dataset, however may also refer to * a block device if that device contains a valid zfs label. */ -static char * -parse_dataset(char *dataset) +static void +parse_dataset(const char *target, char **dataset) { - char cwd[PATH_MAX]; - struct stat64 statbuf; - int error; - int len; - /* * We expect a pool/dataset to be provided, however if we're * given a device which is a member of a zpool we attempt to * extract the pool name stored in the label. Given the pool * name we can mount the root dataset. */ - error = stat64(dataset, &statbuf); - if (error == 0) { - nvlist_t *config; - char *name; - int fd; - - fd = open(dataset, O_RDONLY); - if (fd < 0) - goto out; - - error = zpool_read_label(fd, &config, NULL); - (void) close(fd); - if (error) - goto out; - - error = nvlist_lookup_string(config, - ZPOOL_CONFIG_POOL_NAME, &name); - if (error) { - nvlist_free(config); - } else { - dataset = strdup(name); + int fd = open(target, O_RDONLY); + if (fd >= 0) { + nvlist_t *config = NULL; + if (zpool_read_label(fd, &config, NULL) != 0) + config = NULL; + if (close(fd)) + perror("close"); + + if (config) { + char *name = NULL; + if (!nvlist_lookup_string(config, + ZPOOL_CONFIG_POOL_NAME, &name)) + (void) strlcpy(*dataset, name, PATH_MAX); nvlist_free(config); - return (dataset); + if (name) + return; } } -out: + /* * If a file or directory in your current working directory is * named 'dataset' then mount(8) will prepend your current working * directory to the dataset. There is no way to prevent this * behavior so we simply check for it and strip the prepended * patch when it is added. */ - if (getcwd(cwd, PATH_MAX) == NULL) - return (dataset); - - len = strlen(cwd); - - /* Do not add one when cwd already ends in a trailing '/' */ - if (strncmp(cwd, dataset, len) == 0) - return (dataset + len + (cwd[len-1] != '/')); - - return (dataset); + char cwd[PATH_MAX]; + if (getcwd(cwd, PATH_MAX) != NULL) { + int len = strlen(cwd); + /* Do not add one when cwd already ends in a trailing '/' */ + if (strncmp(cwd, target, len) == 0) + target += len + (cwd[len-1] != '/'); + } + strlcpy(*dataset, target, PATH_MAX); } /* * Update the mtab_* code to use the libmount library when it is commonly * available otherwise fallback to legacy mode. The mount(8) utility will * manage the lock file for us to prevent racing updates to /etc/mtab. */ static int mtab_is_writeable(void) { struct stat st; int error, fd; error = lstat("/etc/mtab", &st); if (error || S_ISLNK(st.st_mode)) return (0); fd = open("/etc/mtab", O_RDWR | O_CREAT, 0644); if (fd < 0) return (0); close(fd); return (1); } static int mtab_update(char *dataset, char *mntpoint, char *type, char *mntopts) { struct mntent mnt; FILE *fp; int error; mnt.mnt_fsname = dataset; mnt.mnt_dir = mntpoint; mnt.mnt_type = type; mnt.mnt_opts = mntopts ? mntopts : ""; mnt.mnt_freq = 0; mnt.mnt_passno = 0; fp = setmntent("/etc/mtab", "a+"); if (!fp) { (void) fprintf(stderr, gettext( "filesystem '%s' was mounted, but /etc/mtab " "could not be opened due to error %d\n"), dataset, errno); return (MOUNT_FILEIO); } error = addmntent(fp, &mnt); if (error) { (void) fprintf(stderr, gettext( "filesystem '%s' was mounted, but /etc/mtab " "could not be updated due to error %d\n"), dataset, errno); return (MOUNT_FILEIO); } (void) endmntent(fp); return (MOUNT_SUCCESS); } int main(int argc, char **argv) { zfs_handle_t *zhp; char prop[ZFS_MAXPROPLEN]; uint64_t zfs_version = 0; char mntopts[MNT_LINE_MAX] = { '\0' }; char badopt[MNT_LINE_MAX] = { '\0' }; char mtabopt[MNT_LINE_MAX] = { '\0' }; char mntpoint[PATH_MAX]; - char *dataset; + char dataset[PATH_MAX], *pdataset = dataset; unsigned long mntflags = 0, zfsflags = 0, remount = 0; int sloppy = 0, fake = 0, verbose = 0, nomtab = 0, zfsutil = 0; int error, c; (void) setlocale(LC_ALL, ""); (void) setlocale(LC_NUMERIC, "C"); (void) textdomain(TEXT_DOMAIN); opterr = 0; /* check options */ while ((c = getopt_long(argc, argv, "sfnvo:h?", 0, 0)) != -1) { switch (c) { case 's': sloppy = 1; break; case 'f': fake = 1; break; case 'n': nomtab = 1; break; case 'v': verbose++; break; case 'o': (void) strlcpy(mntopts, optarg, sizeof (mntopts)); break; case 'h': case '?': (void) fprintf(stderr, gettext("Invalid option '%c'\n"), optopt); (void) fprintf(stderr, gettext("Usage: mount.zfs " "[-sfnv] [-o options] \n")); return (MOUNT_USAGE); } } argc -= optind; argv += optind; /* check that we only have two arguments */ if (argc != 2) { if (argc == 0) (void) fprintf(stderr, gettext("missing dataset " "argument\n")); else if (argc == 1) (void) fprintf(stderr, gettext("missing mountpoint argument\n")); else (void) fprintf(stderr, gettext("too many arguments\n")); (void) fprintf(stderr, "usage: mount \n"); return (MOUNT_USAGE); } - dataset = parse_dataset(argv[0]); + parse_dataset(argv[0], &pdataset); /* canonicalize the mount point */ if (realpath(argv[1], mntpoint) == NULL) { (void) fprintf(stderr, gettext("filesystem '%s' cannot be " "mounted at '%s' due to canonicalization error %d.\n"), dataset, argv[1], errno); return (MOUNT_SYSERR); } /* validate mount options and set mntflags */ error = zfs_parse_mount_options(mntopts, &mntflags, &zfsflags, sloppy, badopt, mtabopt); if (error) { switch (error) { case ENOMEM: (void) fprintf(stderr, gettext("filesystem '%s' " "cannot be mounted due to a memory allocation " "failure.\n"), dataset); return (MOUNT_SYSERR); case ENOENT: (void) fprintf(stderr, gettext("filesystem '%s' " "cannot be mounted due to invalid option " "'%s'.\n"), dataset, badopt); (void) fprintf(stderr, gettext("Use the '-s' option " "to ignore the bad mount option.\n")); return (MOUNT_USAGE); default: (void) fprintf(stderr, gettext("filesystem '%s' " "cannot be mounted due to internal error %d.\n"), dataset, error); return (MOUNT_SOFTWARE); } } if (verbose) (void) fprintf(stdout, gettext("mount.zfs:\n" " dataset: \"%s\"\n mountpoint: \"%s\"\n" " mountflags: 0x%lx\n zfsflags: 0x%lx\n" " mountopts: \"%s\"\n mtabopts: \"%s\"\n"), dataset, mntpoint, mntflags, zfsflags, mntopts, mtabopt); if (mntflags & MS_REMOUNT) { nomtab = 1; remount = 1; } if (zfsflags & ZS_ZFSUTIL) zfsutil = 1; if ((g_zfs = libzfs_init()) == NULL) { (void) fprintf(stderr, "%s\n", libzfs_error_init(errno)); return (MOUNT_SYSERR); } /* try to open the dataset to access the mount point */ if ((zhp = zfs_open(g_zfs, dataset, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_SNAPSHOT)) == NULL) { (void) fprintf(stderr, gettext("filesystem '%s' cannot be " "mounted, unable to open the dataset\n"), dataset); libzfs_fini(g_zfs); return (MOUNT_USAGE); } zfs_adjust_mount_options(zhp, mntpoint, mntopts, mtabopt); /* treat all snapshots as legacy mount points */ if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT) (void) strlcpy(prop, ZFS_MOUNTPOINT_LEGACY, ZFS_MAXPROPLEN); else (void) zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, prop, sizeof (prop), NULL, NULL, 0, B_FALSE); /* * Fetch the max supported zfs version in case we get ENOTSUP * back from the mount command, since we need the zfs handle * to do so. */ zfs_version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); if (zfs_version == 0) { fprintf(stderr, gettext("unable to fetch " "ZFS version for filesystem '%s'\n"), dataset); return (MOUNT_SYSERR); } zfs_close(zhp); libzfs_fini(g_zfs); /* * Legacy mount points may only be mounted using 'mount', never using * 'zfs mount'. However, since 'zfs mount' actually invokes 'mount' * we differentiate the two cases using the 'zfsutil' mount option. * This mount option should only be supplied by the 'zfs mount' util. * * The only exception to the above rule is '-o remount' which is * always allowed for non-legacy datasets. This is done because when * using zfs as your root file system both rc.sysinit/umountroot and * systemd depend on 'mount -o remount ' to work. */ if (zfsutil && (strcmp(prop, ZFS_MOUNTPOINT_LEGACY) == 0)) { (void) fprintf(stderr, gettext( "filesystem '%s' cannot be mounted using 'zfs mount'.\n" "Use 'zfs set mountpoint=%s' or 'mount -t zfs %s %s'.\n" "See zfs(8) for more information.\n"), dataset, mntpoint, dataset, mntpoint); return (MOUNT_USAGE); } if (!zfsutil && !(remount || fake) && strcmp(prop, ZFS_MOUNTPOINT_LEGACY)) { (void) fprintf(stderr, gettext( "filesystem '%s' cannot be mounted using 'mount'.\n" "Use 'zfs set mountpoint=%s' or 'zfs mount %s'.\n" "See zfs(8) for more information.\n"), dataset, "legacy", dataset); return (MOUNT_USAGE); } if (!fake) { error = mount(dataset, mntpoint, MNTTYPE_ZFS, mntflags, mntopts); } if (error) { switch (errno) { case ENOENT: (void) fprintf(stderr, gettext("mount point " "'%s' does not exist\n"), mntpoint); return (MOUNT_SYSERR); case EBUSY: (void) fprintf(stderr, gettext("filesystem " "'%s' is already mounted\n"), dataset); return (MOUNT_BUSY); case ENOTSUP: if (zfs_version > ZPL_VERSION) { (void) fprintf(stderr, gettext("filesystem '%s' (v%d) is not " "supported by this implementation of " "ZFS (max v%d).\n"), dataset, (int)zfs_version, (int)ZPL_VERSION); } else { (void) fprintf(stderr, gettext("filesystem '%s' mount " "failed for unknown reason.\n"), dataset); } return (MOUNT_SYSERR); #ifdef MS_MANDLOCK case EPERM: if (mntflags & MS_MANDLOCK) { (void) fprintf(stderr, gettext("filesystem " "'%s' has the 'nbmand=on' property set, " "this mount\noption may be disabled in " "your kernel. Use 'zfs set nbmand=off'\n" "to disable this option and try to " "mount the filesystem again.\n"), dataset); return (MOUNT_SYSERR); } /* fallthru */ #endif default: (void) fprintf(stderr, gettext("filesystem " "'%s' can not be mounted: %s\n"), dataset, strerror(errno)); return (MOUNT_USAGE); } } if (!nomtab && mtab_is_writeable()) { error = mtab_update(dataset, mntpoint, MNTTYPE_ZFS, mtabopt); if (error) return (error); } return (MOUNT_SUCCESS); } diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index ac4d6af1cf42..d8312afd381d 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -1,178 +1,179 @@ # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # [DEFAULT] pre = setup quiet = False pre_user = root user = root timeout = 600 post_user = root post = cleanup failsafe_user = root failsafe = callbacks/zfs_failsafe outputdir = /var/tmp/test_results tags = ['functional'] [tests/functional/acl/posix:Linux] tests = ['posix_001_pos', 'posix_002_pos', 'posix_003_pos', 'posix_004_pos'] tags = ['functional', 'acl', 'posix'] [tests/functional/acl/posix-sa:Linux] tests = ['posix_001_pos', 'posix_002_pos', 'posix_003_pos', 'posix_004_pos'] tags = ['functional', 'acl', 'posix-sa'] [tests/functional/atime:Linux] tests = ['atime_003_pos', 'root_relatime_on'] tags = ['functional', 'atime'] [tests/functional/chattr:Linux] tests = ['chattr_001_pos', 'chattr_002_neg'] tags = ['functional', 'chattr'] [tests/functional/checksum:Linux] tests = ['run_edonr_test'] tags = ['functional', 'checksum'] [tests/functional/cli_root/zfs:Linux] tests = ['zfs_003_neg'] tags = ['functional', 'cli_root', 'zfs'] [tests/functional/cli_root/zfs_mount:Linux] -tests = ['zfs_mount_006_pos', 'zfs_mount_008_pos', 'zfs_multi_mount'] +tests = ['zfs_mount_006_pos', 'zfs_mount_008_pos', 'zfs_mount_013_pos', + 'zfs_mount_014_neg', 'zfs_multi_mount'] tags = ['functional', 'cli_root', 'zfs_mount'] [tests/functional/cli_root/zfs_share:Linux] tests = ['zfs_share_005_pos', 'zfs_share_007_neg', 'zfs_share_009_neg', 'zfs_share_012_pos'] tags = ['functional', 'cli_root', 'zfs_share'] [tests/functional/cli_root/zfs_sysfs:Linux] tests = ['zfeature_set_unsupported', 'zfs_get_unsupported', 'zfs_set_unsupported', 'zfs_sysfs_live', 'zpool_get_unsupported', 'zpool_set_unsupported'] tags = ['functional', 'cli_root', 'zfs_sysfs'] [tests/functional/cli_root/zpool_add:Linux] tests = ['add_nested_replacing_spare'] tags = ['functional', 'cli_root', 'zpool_add'] [tests/functional/cli_root/zpool_expand:Linux] tests = ['zpool_expand_001_pos', 'zpool_expand_002_pos', 'zpool_expand_003_neg', 'zpool_expand_004_pos', 'zpool_expand_005_pos'] tags = ['functional', 'cli_root', 'zpool_expand'] [tests/functional/cli_root/zpool_reopen:Linux] tests = ['zpool_reopen_001_pos', 'zpool_reopen_002_pos', 'zpool_reopen_003_pos', 'zpool_reopen_004_pos', 'zpool_reopen_005_pos', 'zpool_reopen_006_neg', 'zpool_reopen_007_pos'] tags = ['functional', 'cli_root', 'zpool_reopen'] [tests/functional/cli_root/zpool_split:Linux] tests = ['zpool_split_wholedisk'] tags = ['functional', 'cli_root', 'zpool_split'] [tests/functional/compression:Linux] tests = ['compress_004_pos'] tags = ['functional', 'compression'] [tests/functional/deadman:Linux] tests = ['deadman_sync', 'deadman_zio'] pre = post = tags = ['functional', 'deadman'] [tests/functional/devices:Linux] tests = ['devices_001_pos', 'devices_002_neg', 'devices_003_pos'] tags = ['functional', 'devices'] [tests/functional/events:Linux] tests = ['events_001_pos', 'events_002_pos', 'zed_rc_filter'] tags = ['functional', 'events'] [tests/functional/fallocate:Linux] tests = ['fallocate_prealloc', 'fallocate_punch-hole'] tags = ['functional', 'fallocate'] [tests/functional/fault:Linux] tests = ['auto_offline_001_pos', 'auto_online_001_pos', 'auto_replace_001_pos', 'auto_spare_001_pos', 'auto_spare_002_pos', 'auto_spare_multiple', 'auto_spare_ashift', 'auto_spare_shared', 'decrypt_fault', 'decompress_fault', 'scrub_after_resilver', 'zpool_status_-s'] tags = ['functional', 'fault'] [tests/functional/features/large_dnode:Linux] tests = ['large_dnode_002_pos', 'large_dnode_006_pos', 'large_dnode_008_pos'] tags = ['functional', 'features', 'large_dnode'] [tests/functional/io:Linux] tests = ['libaio'] tags = ['functional', 'io'] [tests/functional/mmap:Linux] tests = ['mmap_libaio_001_pos'] tags = ['functional', 'mmap'] [tests/functional/mmp:Linux] tests = ['mmp_on_thread', 'mmp_on_uberblocks', 'mmp_on_off', 'mmp_interval', 'mmp_active_import', 'mmp_inactive_import', 'mmp_exported_import', 'mmp_write_uberblocks', 'mmp_reset_interval', 'multihost_history', 'mmp_on_zdb', 'mmp_write_distribution', 'mmp_hostid'] tags = ['functional', 'mmp'] [tests/functional/mount:Linux] tests = ['umount_unlinked_drain'] tags = ['functional', 'mount'] [tests/functional/pam:Linux] tests = ['pam_basic', 'pam_nounmount'] tags = ['functional', 'pam'] [tests/functional/procfs:Linux] tests = ['procfs_list_basic', 'procfs_list_concurrent_readers', 'procfs_list_stale_read', 'pool_state'] tags = ['functional', 'procfs'] [tests/functional/projectquota:Linux] tests = ['projectid_001_pos', 'projectid_002_pos', 'projectid_003_pos', 'projectquota_001_pos', 'projectquota_002_pos', 'projectquota_003_pos', 'projectquota_004_neg', 'projectquota_005_pos', 'projectquota_006_pos', 'projectquota_007_pos', 'projectquota_008_pos', 'projectquota_009_pos', 'projectspace_001_pos', 'projectspace_002_pos', 'projectspace_003_pos', 'projectspace_004_pos', 'projecttree_001_pos', 'projecttree_002_pos', 'projecttree_003_neg'] tags = ['functional', 'projectquota'] [tests/functional/rsend:Linux] tests = ['send_realloc_dnode_size', 'send_encrypted_files'] tags = ['functional', 'rsend'] [tests/functional/snapshot:Linux] tests = ['snapshot_015_pos', 'snapshot_016_pos'] tags = ['functional', 'snapshot'] [tests/functional/tmpfile:Linux] tests = ['tmpfile_001_pos', 'tmpfile_002_pos', 'tmpfile_003_pos', 'tmpfile_stat_mode'] tags = ['functional', 'tmpfile'] [tests/functional/upgrade:Linux] tests = ['upgrade_projectquota_001_pos'] tags = ['functional', 'upgrade'] [tests/functional/user_namespace:Linux] tests = ['user_namespace_001'] tags = ['functional', 'user_namespace'] [tests/functional/userquota:Linux] tests = ['groupspace_001_pos', 'groupspace_002_pos', 'groupspace_003_pos', 'userquota_013_pos', 'userspace_003_pos'] tags = ['functional', 'userquota'] diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index 21d1950e74f1..2b81e1c196f8 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -1,221 +1,222 @@ # # Copyright (c) 2016, 2019 by Delphix. All rights reserved. # These variables are used by zfs-tests.sh to constrain which utilities # may be used by the suite. The suite will create a directory which is # the only element of $PATH and create symlinks from that dir to the # binaries listed below. # # Please keep the contents of each variable sorted for ease of reading # and maintenance. # export SYSTEM_FILES_COMMON='arp awk base64 basename bc bunzip2 bzcat cat chgrp chmod chown cksum cmp cp cpio cut date dd df diff dirname dmesg du echo egrep expr false file find fio getconf getent getfacl grep gunzip gzip head hostname id iostat kill ksh ln logname ls mkdir mknod mktemp mount mv net od openssl pamtester pax pgrep ping pkill printenv printf ps pwd python python2 python3 quotaon readlink rm rmdir scp script sed seq setfacl sh sleep sort ssh stat strings su sudo sum swapoff swapon sync tail tar tee timeout touch tr true truncate umask umount uname uniq uuidgen vmstat wait wc which xargs' export SYSTEM_FILES_FREEBSD='chflags compress diskinfo dumpon env fsck getextattr gpart jail jexec jls lsextattr md5 mdconfig mkfifo newfs pw rmextattr setextattr sha256 showmount swapctl sysctl uncompress' export SYSTEM_FILES_LINUX='attr bash blkid blockdev chattr dmidecode exportfs fallocate fdisk free getfattr groupadd groupdel groupmod hostid losetup lsattr lsblk lscpu lsmod lsscsi md5sum mkswap modprobe mpstat nproc parted perf setenforce setfattr sha256sum udevadm useradd userdel usermod' export ZFS_FILES='zdb zfs zhack zinject zpool ztest raidz_test arc_summary arcstat dbufstat + mount.zfs zed zgenhostid zstream zstreamdump zfs_ids_to_path zpool_influxdb' export ZFSTEST_FILES='badsend btree_test chg_usr_exec devname2devid dir_rd_update file_check file_trunc file_write get_diff largest_file libzfs_input_check mkbusy mkfile mkfiles mktree mmap_exec mmap_libaio mmapwrite nvlist_to_lua randfree_file randwritecomp readmmap rename_dir rm_lnkcnt_zero_file threadsappend user_ns_exec xattrtest stride_dd' diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am index 37c0942381cc..8c90b2e75e5a 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/Makefile.am @@ -1,27 +1,29 @@ pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_mount dist_pkgdata_SCRIPTS = \ setup.ksh \ cleanup.ksh \ zfs_mount_001_pos.ksh \ zfs_mount_002_pos.ksh \ zfs_mount_003_pos.ksh \ zfs_mount_004_pos.ksh \ zfs_mount_005_pos.ksh \ zfs_mount_006_pos.ksh \ zfs_mount_007_pos.ksh \ zfs_mount_008_pos.ksh \ zfs_mount_009_neg.ksh \ zfs_mount_010_neg.ksh \ zfs_mount_011_neg.ksh \ zfs_mount_012_pos.ksh \ + zfs_mount_013_pos.ksh \ + zfs_mount_014_neg.ksh \ zfs_mount_all_001_pos.ksh \ zfs_mount_all_fail.ksh \ zfs_mount_all_mountpoints.ksh \ zfs_mount_encrypted.ksh \ zfs_mount_remount.ksh \ zfs_mount_test_race.ksh \ zfs_multi_mount.ksh dist_pkgdata_DATA = \ zfs_mount.cfg \ zfs_mount.kshlib 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 new file mode 100755 index 000000000000..9a62ffb02104 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_013_pos.ksh @@ -0,0 +1,76 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# +# CDDL HEADER END +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib + +# +# DESCRIPTION: +# Verify zfs mount helper functions for both devices and pools. +# + +verify_runnable "both" + +set -A vdevs $(get_disklist_fullpath $TESTPOOL) +vdev=${vdevs[0]} +mntpoint=$TESTDIR/$TESTPOOL +helper="mount.zfs -o zfsutil" +fs=$TESTPOOL/$TESTFS + +function cleanup +{ + log_must force_unmount $vdev + [[ -d $mntpoint ]] && log_must rm -rf $mntpoint + return 0 +} +log_onexit cleanup + +log_note "Verify zfs mount helper functions for both devices and pools" + +# Ensure that the ZFS filesystem is unmounted +force_unmount $fs +log_must mkdir -p $mntpoint + +log_note "Verify ' '" +log_must $helper $fs $mntpoint +log_must ismounted $fs +force_unmount $fs + +log_note "Verify '\$PWD/ ' prefix workaround" +log_must $helper $PWD/$fs $mntpoint +log_must ismounted $fs +force_unmount $fs + +log_note "Verify '-f ' fakemount" +log_must $helper -f $fs $mntpoint +log_mustnot ismounted $fs + +log_note "Verify '-o ro -v ' verbose RO" +log_must ${helper},ro -v $fs $mntpoint +log_must ismounted $fs +force_unmount $fs + +log_note "Verify ' '" +log_must $helper $vdev $mntpoint +log_must ismounted $mntpoint +log_must umount $TESTPOOL + +log_note "Verify '-o abc -s ' sloppy option" +log_must ${helper},abc -s $vdev $mntpoint +log_must ismounted $mntpoint +log_must umount $TESTPOOL + +log_pass "zfs mount helper correctly handles both device and pool strings" \ No newline at end of file diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_014_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_014_neg.ksh new file mode 100755 index 000000000000..5cf0bc7b3a05 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_014_neg.ksh @@ -0,0 +1,68 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# +# CDDL HEADER END +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib + +# +# DESCRIPTION: +# Verify zfs mount helper failure on known bad parameters +# + +verify_runnable "both" + +set -A vdevs $(get_disklist_fullpath $TESTPOOL) +vdev=${vdevs[0]} + +mntpoint="$(get_prop mountpoint $TESTPOOL)" +helper="mount.zfs -o zfsutil" +fs=$TESTPOOL/$TESTFS + +function cleanup +{ + log_must force_unmount $vdev + return 0 +} +log_onexit cleanup + +log_note "Verify zfs mount helper failure on known bad parameters" + +# Ensure that the ZFS filesystem is unmounted. +force_unmount $fs + +log_note "Verify failure without '-o zfsutil'" +log_mustnot mount.zfs $fs $mntpoint + +log_note "Verify '-o abc ' bad option fails" +log_mustnot ${helper},abc $vdev $mntpoint + +log_note "Verify '\$NONEXISTFSNAME ' fails" +log_mustnot $helper $NONEXISTFSNAME $mntpoint + +log_note "Verify ' (\$NONEXISTFSNAME|/dev/null)' fails" +log_mustnot $helper $fs $NONEXISTFSNAME +log_mustnot $helper $fs /dev/null + +log_note "Verify '/dev/null ' fails" +log_mustnot $helper /dev/null $mntpoint + +log_note "Verify '[device|pool]' fails" +log_mustnot mount.zfs +log_mustnot $helper +log_mustnot $helper $vdev +log_mustnot $helper $TESTPOOL + +log_pass "zfs mount helper fails when expected" \ No newline at end of file