diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 2b266601fdf..37af92ad561 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -428,6 +428,252 @@ .. aio .. + cddl + zfs + bin + .. + include + .. + tests + acl + cifs + .. + nontrivial + .. + trivial + .. + .. + atime + .. + bootfs + .. + cache + .. + cachefile + .. + clean_mirror + .. + cli_root + zfs_upgrade + .. + zfs_promote + .. + zfs_clone + .. + zfs_property + .. + zfs_destroy + .. + zpool_create + .. + zpool_history + .. + zpool_expand + .. + zpool_remove + .. + zfs_mount + .. + zfs_unshare + .. + zdb + .. + zpool_online + .. + zpool_get + .. + zpool_export + .. + zfs_copies + .. + zfs_get + .. + zfs + .. + zpool_clear + .. + zpool_import + blockfiles + .. + .. + zpool + .. + zpool_offline + .. + zpool_replace + .. + zfs_rollback + .. + zpool_set + .. + zfs_send + .. + zfs_set + .. + zpool_detach + .. + zfs_diff + .. + zpool_scrub + .. + zfs_inherit + .. + zfs_snapshot + .. + zfs_share + .. + zpool_destroy + .. + zpool_status + .. + zfs_unmount + .. + zfs_receive + .. + zfs_create + .. + zpool_upgrade + blockfiles + .. + .. + zpool_add + .. + zfs_rename + .. + zpool_attach + .. + zfs_reservation + .. + .. + cli_user + misc + .. + zfs_list + .. + zpool_iostat + .. + zpool_list + .. + .. + compression + .. + ctime + .. + delegate + .. + devices + .. + exec + .. + grow_pool + .. + grow_replicas + .. + history + .. + hotplug + .. + hotspare + .. + inheritance + .. + interop + .. + inuse + .. + iscsi + .. + large_files + .. + largest_pool + .. + link_count + .. + migration + .. + mmap + .. + mount + .. + mv_files + .. + nestedfs + .. + no_space + .. + online_offline + .. + pool_names + .. + poolversion + .. + quota + .. + redundancy + .. + refquota + .. + refreserv + .. + rename_dirs + .. + replacement + .. + reservation + .. + rootpool + .. + rsend + .. + scrub_mirror + .. + slog + .. + snapshot + .. + snapused + .. + sparse + .. + threadsappend + .. + truncate + .. + txg_integrity + .. + userquota + .. + utils_test + .. + write_dirs + .. + xattr + .. + zfsd + .. + zil + .. + zinject + .. + zones + .. + zvol + zvol_ENOSPC + .. + zvol_cli + .. + zvol_misc + .. + zvol_swap + .. + .. + zvol_thrash + .. + .. + .. + .. + dtrace + .. fifo .. file diff --git a/share/mk/atf.test.mk b/share/mk/atf.test.mk index babecd9f6a8..dd9a462ade1 100644 --- a/share/mk/atf.test.mk +++ b/share/mk/atf.test.mk @@ -21,6 +21,7 @@ ATF_TESTS_C?= ATF_TESTS_CXX?= ATF_TESTS_SH?= +ATF_TESTS_KSH93?= .if !empty(ATF_TESTS_C) PROGS+= ${ATF_TESTS_C} @@ -80,3 +81,28 @@ ${_T}: ${ATF_TESTS_SH_SRC_${_T}} mv ${.TARGET}.tmp ${.TARGET} .endfor .endif + +.if !empty(ATF_TESTS_KSH93) +SCRIPTS+= ${ATF_TESTS_KSH93} +_TESTS+= ${ATF_TESTS_KSH93} +.for _T in ${ATF_TESTS_KSH93} +SCRIPTSDIR_${_T}= ${TESTSDIR} +TEST_INTERFACE.${_T}= atf +CLEANFILES+= ${_T} ${_T}.tmp +# TODO(jmmv): It seems to me that this SED and SRC functionality should +# exist in bsd.prog.mk along the support for SCRIPTS. Move it there if +# this proves to be useful within the tests. +ATF_TESTS_KSH93_SED_${_T}?= # empty +ATF_TESTS_KSH93_SRC_${_T}?= ${_T}.sh +${_T}: ${ATF_TESTS_KSH93_SRC_${_T}} + echo '#! /usr/libexec/atf-sh -s/usr/local/bin/ksh93' > ${.TARGET}.tmp +.if empty(ATF_TESTS_KSH93_SED_${_T}) + cat ${.ALLSRC:N*Makefile*} >>${.TARGET}.tmp +.else + cat ${.ALLSRC:N*Makefile*} \ + | sed ${ATF_TESTS_KSH93_SED_${_T}} >>${.TARGET}.tmp +.endif + chmod +x ${.TARGET}.tmp + mv ${.TARGET}.tmp ${.TARGET} +.endfor +.endif diff --git a/tests/sys/Makefile b/tests/sys/Makefile index 1ff81373435..49b43c6f7c6 100644 --- a/tests/sys/Makefile +++ b/tests/sys/Makefile @@ -1,9 +1,12 @@ # $FreeBSD$ +.include + TESTSDIR= ${TESTSBASE}/sys TESTS_SUBDIRS+= acl TESTS_SUBDIRS+= aio +TESTS_SUBDIRS+= ${_cddl} TESTS_SUBDIRS+= fifo TESTS_SUBDIRS+= file TESTS_SUBDIRS+= fs @@ -21,6 +24,10 @@ TESTS_SUBDIRS+= sys TESTS_SUBDIRS+= vfs TESTS_SUBDIRS+= vm +.if ${MK_CDDL} != "no" +_cddl= cddl +.endif + # Items not integrated into kyua runs by default SUBDIR+= pjdfstest diff --git a/tests/sys/cddl/Makefile b/tests/sys/cddl/Makefile new file mode 100644 index 00000000000..f326602b77c --- /dev/null +++ b/tests/sys/cddl/Makefile @@ -0,0 +1,13 @@ +# $FreeBSD$ + +.include + +TESTSDIR= ${TESTSBASE}/sys/cddl + +TESTS_SUBDIRS+= ${_zfs} + +.if ${MK_ZFS} != "no" +_zfs= zfs +.endif + +.include diff --git a/tests/sys/cddl/zfs/Makefile b/tests/sys/cddl/zfs/Makefile new file mode 100644 index 00000000000..0b2e334d1a3 --- /dev/null +++ b/tests/sys/cddl/zfs/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD$ + +.include + +TESTSDIR= ${TESTSBASE}/sys/cddl/zfs + +TESTS_SUBDIRS+= tests include + +SUBDIR+= bin + +.include diff --git a/tests/sys/cddl/zfs/bin/Makefile b/tests/sys/cddl/zfs/bin/Makefile new file mode 100644 index 00000000000..21fff8e2ea5 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/Makefile @@ -0,0 +1,61 @@ +# $FreeBSD$ + +.include + +PACKAGE= tests +MAN= +BINDIR= ${TESTSBASE}/sys/cddl/zfs/bin +SCRIPTSDIR= ${TESTSBASE}/sys/cddl/zfs/bin + +SCRIPTS+= bsddisks.ksh +SCRIPTS+= dircmp.ksh +SCRIPTS+= dumpadm.ksh +SCRIPTS+= ff.ksh +SCRIPTS+= fmadm.ksh +SCRIPTS+= fmdump.ksh +SCRIPTS+= format.ksh +SCRIPTS+= groupadd.ksh +SCRIPTS+= groupdel.ksh +SCRIPTS+= groupmod.ksh +SCRIPTS+= groupshow.ksh +SCRIPTS+= svcs.ksh +SCRIPTS+= swap.ksh +SCRIPTS+= testenv.ksh +SCRIPTS+= useradd.ksh +SCRIPTS+= userdel.ksh +SCRIPTS+= usermod.ksh +SCRIPTS+= zfs.ksh +SCRIPTS+= zfs_crypto.ksh +SCRIPTS+= zfs_version.ksh +SCRIPTS+= zlogin.ksh +SCRIPTS+= zoneadm.ksh +SCRIPTS+= zonecfg.ksh +SCRIPTS+= zpool.ksh +SCRIPTS+= zpool_bsd.ksh +SCRIPTS+= zpool_smi.ksh +SCRIPTS+= zpool_version.ksh + +PROGS+= chg_usr_exec +# Not ported to FreeBSD +# PROGRS+= devname2devid +PROGS+= dir_rd_update +PROGS+= file_check +PROGS+= file_trunc +PROGS+= file_write +PROGS+= largest_file +PROGS+= mkfile +PROGS+= mktree +PROGS+= mmapwrite +PROGS+= randfree_file +PROGS+= readmmap +PROGS+= rename_dir +PROGS+= rm_lnkcnt_zero_file + +.for p in ${PROGS} +SRCS.$p= $p.c +.endfor + +LIBADD.mmapwrite+= pthread +LIBADD.rm_lnkcnt_zero_file+= pthread + +.include diff --git a/tests/sys/cddl/zfs/bin/bsddisks.ksh b/tests/sys/cddl/zfs/bin/bsddisks.ksh new file mode 100644 index 00000000000..e544fb078bb --- /dev/null +++ b/tests/sys/cddl/zfs/bin/bsddisks.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +BSDDEVS="ad|da|mlxd|myld|aacd|ided|twed" +ls /dev|egrep "^($BSDDEVS)[0-9]+\$" |sed 's/^/\/dev\//' diff --git a/tests/sys/cddl/zfs/bin/chg_usr_exec.c b/tests/sys/cddl/zfs/bin/chg_usr_exec.c new file mode 100644 index 00000000000..c1de099aa1b --- /dev/null +++ b/tests/sys/cddl/zfs/bin/chg_usr_exec.c @@ -0,0 +1,78 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)chg_usr_exec.c 1.3 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + char *plogin = NULL; + char cmds[BUFSIZ] = { 0 }; + char sep[] = " "; + struct passwd *ppw = NULL; + int i, len; + + if (argc < 3 || strlen(argv[1]) == 0) { + (void) printf("\tUsage: %s ...\n", argv[0]); + return (1); + } + + plogin = argv[1]; + len = 0; + for (i = 2; i < argc; i++) { + (void) snprintf(cmds+len, sizeof (cmds)-len, + "%s%s", argv[i], sep); + len += strlen(argv[i]) + strlen(sep); + } + + if ((ppw = getpwnam(plogin)) == NULL) { + perror("getpwnam"); + return (errno); + } + if (setgid(ppw->pw_gid) != 0) { + perror("setgid"); + return (errno); + } + if (setuid(ppw->pw_uid) != 0) { + perror("setuid"); + return (errno); + } + + if (execl("/bin/sh", "sh", "-c", cmds, (char *)0) != 0) { + perror("execl"); + return (errno); + } + + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/devname2devid.c b/tests/sys/cddl/zfs/bin/devname2devid.c new file mode 100644 index 00000000000..b9f3eec6326 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/devname2devid.c @@ -0,0 +1,123 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)devname2devid.c 1.3 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include +#include + +/* + * Usage: devname2devid + * + * Examples: + * # ./devname2devid /dev/dsk/c1t4d0s0 + * devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/a + * # ./devname2devid /dev/dsk/c1t4d0 + * devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/wd + * # ./devname2devid /dev/dsk/c1t4d0s1 + * devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/b + * # + * + * This program accepts a disk or disk slice path and prints a + * device id. + * + * Exit values: + * 0 - means success + * 1 - means failure + * + */ +int +main(int argc, char *argv[]) +{ + int fd; + ddi_devid_t devid; + char *minor_name, *devidstr, *device; +#ifdef DEBUG + devid_nmlist_t *list = NULL; + char *search_path; + int i; +#endif + + if (argc == 1) { + (void) printf("%s [search path]\n", + argv[0]); + exit(1); + } + device = argv[1]; + + if ((fd = open(device, O_RDONLY|O_NDELAY)) < 0) { + perror(device); + exit(1); + } + if (devid_get(fd, &devid) != 0) { + perror("devid_get"); + exit(1); + } + if (devid_get_minor_name(fd, &minor_name) != 0) { + perror("devid_get_minor_name"); + exit(1); + } + if ((devidstr = devid_str_encode(devid, minor_name)) == 0) { + perror("devid_str_encode"); + exit(1); + } + + (void) printf("devid %s\n", devidstr); + + devid_str_free(devidstr); + +#ifdef DEBUG + if (argc == 3) { + search_path = argv[2]; + } else { + search_path = "/dev/rdsk"; + } + + if (devid_deviceid_to_nmlist(search_path, devid, DEVID_MINOR_NAME_ALL, + &list)) { + perror("devid_deviceid_to_nmlist"); + exit(1); + } + + /* loop through list and process device names and numbers */ + for (i = 0; list[i].devname != NULL; i++) { + (void) printf("devname: %s %p\n", list[i].devname, list[i].dev); + } + devid_free_nmlist(list); + +#endif /* DEBUG */ + + devid_str_free(minor_name); + devid_free(devid); + + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/dir_rd_update.c b/tests/sys/cddl/zfs/bin/dir_rd_update.c new file mode 100644 index 00000000000..6e7fd93e10a --- /dev/null +++ b/tests/sys/cddl/zfs/bin/dir_rd_update.c @@ -0,0 +1,122 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)dir_rd_update.c 1.2 07/01/09 SMI" + +/* + * Assertion: + * + * A read operation and directory update operation performed + * concurrently on the same directory can lead to deadlock + * on a UFS logging file system, but not on a ZFS file system. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#define TMP_DIR /tmp + +static char dirpath[256]; + +int +main(int argc, char **argv) +{ + char *cp1 = ""; + int i = 0; + int ret = 0; + int testdd = 0; + pid_t pid; + static const int op_num = 5; + + if (argc == 1) { + (void) printf("Usage: %s \n", argv[0]); + exit(-1); + } + for (i = 0; i < 256; i++) { + dirpath[i] = 0; + } + + cp1 = argv[1]; + (void) strcpy(&dirpath[0], (const char *)cp1); + (void) strcat(&dirpath[strlen(dirpath)], "TMP_DIR"); + + ret = mkdir(dirpath, 0777); + if (ret != 0) { + if (errno != EEXIST) { + (void) printf( + "%s: mkdir(<%s>, 0777) failed: errno (decimal)=%d\n", + argv[0], dirpath, errno); + exit(-1); + } + } + testdd = open(dirpath, O_RDONLY|O_SYNC); + if (testdd < 0) { + (void) printf( +"%s: open(<%s>, O_RDONLY|O_SYNC) failed: errno (decimal)=%d\n", + argv[0], dirpath, errno); + exit(-1); + } else { + (void) close(testdd); + } + pid = fork(); + if (pid > 0) { + int fd = open(dirpath, O_RDONLY|O_SYNC); + char buf[16]; + int rdret; + int j = 0; + + while (j < op_num) { + (void) sleep(1); + rdret = read(fd, buf, 16); + if (rdret == -1) { + (void) printf("readdir failed"); + } + j++; + } + } else if (pid == 0) { + int fd = open(dirpath, O_RDONLY); + int chownret; + int k = 0; + + while (k < op_num) { + (void) sleep(1); + chownret = fchown(fd, 0, 0); + if (chownret == -1) { + (void) printf("chown failed"); + } + + k++; + } + } + + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/dircmp.ksh b/tests/sys/cddl/zfs/bin/dircmp.ksh new file mode 100644 index 00000000000..251c4a869c0 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/dircmp.ksh @@ -0,0 +1,5 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +diff -qr $* diff --git a/tests/sys/cddl/zfs/bin/dumpadm.ksh b/tests/sys/cddl/zfs/bin/dumpadm.ksh new file mode 100644 index 00000000000..a96a71d7931 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/dumpadm.ksh @@ -0,0 +1,10 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +if [ $# != 0 ] +then + echo "ERROR option not supported" + return 1 +fi +grep dumpdev /etc/rc.conf diff --git a/tests/sys/cddl/zfs/bin/ff.ksh b/tests/sys/cddl/zfs/bin/ff.ksh new file mode 100644 index 00000000000..5e596ddcfd7 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/ff.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo dummy +exit 0 diff --git a/tests/sys/cddl/zfs/bin/file_check.c b/tests/sys/cddl/zfs/bin/file_check.c new file mode 100644 index 00000000000..dc2f348a724 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/file_check.c @@ -0,0 +1,89 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)file_check.c 1.3 07/05/25 SMI" + +#include "file_common.h" + +static unsigned char bigbuffer[BIGBUFFERSIZE]; + +/* + * Given a filename, check that the file consists entirely + * of a particular pattern. If the pattern is not specified a + * default will be used. For default values see file_common.h + */ +int +main(int argc, char **argv) +{ + int bigfd; + long i, n; + uint8_t fillchar = DATA; + int bigbuffersize = BIGBUFFERSIZE; + int64_t read_count = 0; + + /* + * Validate arguments + */ + if (argc < 2) { + (void) printf("Usage: %s filename [pattern]\n", + argv[0]); + exit(1); + } + + if (argv[2]) { + fillchar = atoi(argv[2]); + } + + /* + * Read the file contents and check every character + * against the supplied pattern. Abort if the + * pattern check fails. + */ + if ((bigfd = open(argv[1], O_RDONLY)) == -1) { + (void) printf("open %s failed %d\n", argv[1], errno); + exit(1); + } + + do { + if ((n = read(bigfd, &bigbuffer, bigbuffersize)) == -1) { + (void) printf("read failed (%ld), %d\n", n, errno); + exit(errno); + } + + for (i = 0; i < n; i++) { + if (bigbuffer[i] != fillchar) { + (void) printf("error %s: 0x%x != 0x%x)\n", + argv[1], bigbuffer[i], fillchar); + exit(1); + } + } + + read_count += n; + } while (n == bigbuffersize); + + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/file_common.h b/tests/sys/cddl/zfs/bin/file_common.h new file mode 100644 index 00000000000..3ae1b07cd22 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/file_common.h @@ -0,0 +1,65 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef FILE_COMMON_H +#define FILE_COMMON_H + +#pragma ident "@(#)file_common.h 1.3 07/05/25 SMI" + +/* + * header file for file_* utilities. These utilities + * are used by the test cases to perform various file + * operations (append writes, for example). + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#define BLOCKSZ 8192 +#define DATA 0xa5 +#define DATA_RANGE 120 +#define BIGBUFFERSIZE 0x800000 +#define BIGFILESIZE 20 + +extern char *optarg; +extern int optind, opterr, optopt; + +#ifdef __cplusplus +} +#endif + +#endif /* FILE_COMMON_H */ diff --git a/tests/sys/cddl/zfs/bin/file_trunc.c b/tests/sys/cddl/zfs/bin/file_trunc.c new file mode 100644 index 00000000000..5fe3ad61a32 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/file_trunc.c @@ -0,0 +1,240 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +#pragma ident "@(#)file_trunc.c 1.2 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FSIZE 256*1024*1024 +#define BSIZE 512 + +/* Initialize Globals */ +static long fsize = FSIZE; +static size_t bsize = BSIZE; +static int count = 0; +static int rflag = 0; +static int seed = 0; +static int vflag = 0; +static int errflag = 0; +static off_t offset = 0; +static char *filename = NULL; + +static void usage(char *execname); +static void parse_options(int argc, char *argv[]); +static void do_write(int fd); +static void do_trunc(int fd); + +static void +usage(char *execname) +{ + (void) fprintf(stderr, + "usage: %s [-b blocksize] [-c count] [-f filesize]" + " [-o offset] [-s seed] [-r] [-v] filename\n", execname); + (void) exit(1); +} + +int +main(int argc, char *argv[]) +{ + int i = 0; + int fd = -1; + + parse_options(argc, argv); + + fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); + if (fd < 0) { + perror("open"); + exit(3); + } + + while (i < count) { + (void) do_write(fd); + (void) do_trunc(fd); + + i++; + } + + (void) close(fd); + return (0); +} + +static void +parse_options(int argc, char *argv[]) +{ + int c; + + extern char *optarg; + extern int optind, optopt; + + count = fsize / bsize; + seed = time(NULL); + while ((c = getopt(argc, argv, "b:c:f:o:rs:v")) != -1) { + switch (c) { + case 'b': + bsize = atoi(optarg); + break; + + case 'c': + count = atoi(optarg); + break; + + case 'f': + fsize = atoi(optarg); + break; + + case 'o': + offset = atoi(optarg); + break; + + case 'r': + rflag++; + break; + + case 's': + seed = atoi(optarg); + break; + + case 'v': + vflag++; + break; + + case ':': + (void) fprintf(stderr, + "Option -%c requires an operand\n", optopt); + errflag++; + break; + + case '?': + (void) fprintf(stderr, + "Unrecognized option: -%c\n", optopt); + errflag++; + break; + } + + if (errflag) { + (void) usage(argv[0]); + } + } + if (argc <= optind) { + (void) fprintf(stderr, + "No filename specified\n"); + usage(argv[0]); + } + filename = argv[optind]; + + if (vflag) { + (void) fprintf(stderr, "Seed = %d\n", seed); + } + srandom(seed); +} + +static void +do_write(int fd) +{ + off_t roffset = 0; + char *buf = NULL; + char *rbuf = NULL; + + buf = (char *)calloc(1, bsize); + rbuf = (char *)calloc(1, bsize); + if (buf == NULL || rbuf == NULL) { + perror("malloc"); + exit(4); + } + + roffset = random() % fsize; + if (lseek(fd, (offset + roffset), SEEK_SET) < 0) { + perror("lseek"); + exit(5); + } + + strcpy(buf, "ZFS Test Suite Truncation Test"); + if (write(fd, buf, bsize) < bsize) { + perror("write"); + exit(6); + } + + if (rflag) { + if (lseek(fd, (offset + roffset), SEEK_SET) < 0) { + perror("lseek"); + exit(7); + } + + if (read(fd, rbuf, bsize) < bsize) { + perror("read"); + exit(8); + } + + if (memcmp(buf, rbuf, bsize) != 0) { + perror("memcmp"); + exit(9); + } + } + if (vflag) { + (void) fprintf(stderr, + "Wrote to offset %ld\n", (offset + roffset)); + if (rflag) { + (void) fprintf(stderr, + "Read back from offset %ld\n", (offset + roffset)); + } + } + + (void) free(buf); + (void) free(rbuf); +} + +static void +do_trunc(int fd) +{ + off_t roffset = 0; + + roffset = random() % fsize; + if (ftruncate(fd, (offset + roffset)) < 0) { + perror("truncate"); + exit(7); + } + + if (vflag) { + (void) fprintf(stderr, + "Truncated at offset %ld\n", + (offset + roffset)); + } +} diff --git a/tests/sys/cddl/zfs/bin/file_write.c b/tests/sys/cddl/zfs/bin/file_write.c new file mode 100644 index 00000000000..1c276589ec3 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/file_write.c @@ -0,0 +1,239 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)file_write.c 1.4 07/10/09 SMI" + +#include "file_common.h" +#include + +static unsigned char bigbuffer[BIGBUFFERSIZE]; + +/* + * Writes (or appends) a given value to a file repeatedly. + * See header file for defaults. + */ + +static void usage(void); +static char *execname; + +int +main(int argc, char **argv) +{ + int bigfd; + int c; + int oflag = 0; + int err = 0; + int k; + long i; + int64_t good_writes = 0; + uint8_t nxtfillchar; + /* + * Default Parameters + */ + int write_count = BIGFILESIZE; + uint8_t fillchar = DATA; + int block_size = BLOCKSZ; + char *filename = NULL; + char *operation = NULL; + off_t noffset, offset = 0; + int verbose = 0; + int rsync = 0; + int wsync = 0; + + execname = argv[0]; + + /* + * Process Arguments + */ + while ((c = getopt(argc, argv, "b:c:d:s:f:o:vwr")) != -1) { + switch (c) { + case 'b': + block_size = atoi(optarg); + break; + case 'c': + write_count = atoi(optarg); + break; + case 'd': + fillchar = atoi(optarg); + break; + case 's': + offset = atoll(optarg); + break; + case 'f': + filename = optarg; + break; + case 'o': + operation = optarg; + break; + case 'v': + verbose = 1; + break; + case 'w': + wsync = 1; + break; + case 'r': + rsync = 1; + break; + case '?': + (void) printf("unknown arg %c\n", optopt); + usage(); + break; + } + } + + /* + * Validate Parameters + */ + if (!filename) { + (void) printf("Filename not specified (-f )\n"); + err++; + } + + if (!operation) { + (void) printf("Operation not specified (-o ).\n"); + err++; + } + + if (block_size > BIGBUFFERSIZE) { + (void) printf("block_size is too large max==%d.\n", + BIGBUFFERSIZE); + err++; + } + + if (err) usage(); + + /* + * Prepare the buffer and determine the requested operation + */ + nxtfillchar = fillchar; + k = 0; + + for (i = 0; i < block_size; i++) { + bigbuffer[i] = nxtfillchar; + + if (fillchar == 0) { + if ((k % DATA_RANGE) == 0) { + k = 0; + } + nxtfillchar = k++; + } + } + + /* + * using the strncmp of operation will make the operation match the + * first shortest match - as the operations are unique from the first + * character this means that we match single character operations + */ + if ((strncmp(operation, "create", strlen(operation) + 1)) == 0 || + (strncmp(operation, "overwrite", strlen(operation) + 1)) == 0) { + oflag = (O_RDWR|O_CREAT); + } else if ((strncmp(operation, "append", strlen(operation) + 1)) == 0) { + oflag = (O_RDWR|O_APPEND); + } else { + (void) printf("valid operations are not '%s'\n", + operation); + usage(); + } + +#ifdef UNSUPPORTED + if (rsync) { + oflag = oflag | O_RSYNC; + } +#endif + + if (wsync) { + oflag = oflag | O_SYNC; + } + + /* + * Given an operation (create/overwrite/append), open the file + * accordingly and perform a write of the appropriate type. + */ + if ((bigfd = open(filename, oflag, 0666)) == -1) { + (void) printf("open %s: failed [%s]%d. Aborting!\n", filename, + strerror(errno), errno); + exit(errno); + } + noffset = lseek(bigfd, offset, SEEK_SET); + if (noffset != offset) { + (void) printf("lseek %s (%lld/%lld) failed [%s]%d.Aborting!\n", + filename, offset, noffset, strerror(errno), errno); + exit(errno); + } + + if (verbose) { + (void) printf("%s: block_size = %d, write_count = %d, " + "offset = %lld, data = %s%d\n", filename, block_size, + write_count, offset, + (fillchar == 0) ? "0->" : "", + (fillchar == 0) ? DATA_RANGE : fillchar); + } + + for (i = 0; i < write_count; i++) { + ssize_t n; + + if ((n = write(bigfd, &bigbuffer, block_size)) == -1) { + (void) printf("write failed (%ld), good_writes = %lld, " + "error: %s[%d]\n", (long)n, good_writes, + strerror(errno), + errno); + exit(errno); + } + good_writes++; + } + + if (verbose) { + (void) printf("Success: good_writes = %lld (%lld)\n", + good_writes, (good_writes * block_size)); + } + + return (0); +} + +static void +usage(void) +{ + char *base = (char *)"file_write"; + char *exec = (char *)execname; + + if (exec != NULL) + exec = strdup(exec); + if (exec != NULL) + base = basename(exec); + + (void) printf("Usage: %s [-v] -o {create,overwrite,append} -f file_name" + " [-b block_size]\n" + "\t[-s offset] [-c write_count] [-d data]\n" + "\twhere [data] equal to zero causes chars " + "0->%d to be repeated throughout\n", base, DATA_RANGE); + + if (exec) { + free(exec); + } + + exit(1); +} diff --git a/tests/sys/cddl/zfs/bin/fmadm.ksh b/tests/sys/cddl/zfs/bin/fmadm.ksh new file mode 100644 index 00000000000..5e596ddcfd7 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/fmadm.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo dummy +exit 0 diff --git a/tests/sys/cddl/zfs/bin/fmdump.ksh b/tests/sys/cddl/zfs/bin/fmdump.ksh new file mode 100644 index 00000000000..5e596ddcfd7 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/fmdump.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo dummy +exit 0 diff --git a/tests/sys/cddl/zfs/bin/format.ksh b/tests/sys/cddl/zfs/bin/format.ksh new file mode 100644 index 00000000000..5e596ddcfd7 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/format.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo dummy +exit 0 diff --git a/tests/sys/cddl/zfs/bin/groupadd.ksh b/tests/sys/cddl/zfs/bin/groupadd.ksh new file mode 100644 index 00000000000..a4e13a19444 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupadd.ksh @@ -0,0 +1,13 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +a= +g= +for i in $* +do + a="$a $g" + g=$i +done + +/usr/sbin/pw groupadd $g $a diff --git a/tests/sys/cddl/zfs/bin/groupdel.ksh b/tests/sys/cddl/zfs/bin/groupdel.ksh new file mode 100644 index 00000000000..16f01f48bd8 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupdel.ksh @@ -0,0 +1,13 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +a= +g= +for i in $* +do + a="$a $g" + g=$i +done + +/usr/sbin/pw groupdel $a $g diff --git a/tests/sys/cddl/zfs/bin/groupmod.ksh b/tests/sys/cddl/zfs/bin/groupmod.ksh new file mode 100644 index 00000000000..9c1ea72647b --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupmod.ksh @@ -0,0 +1,13 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +a= +g= +for i in $* +do + a="$a $g" + g=$i +done + +/usr/sbin/pw groupmod $g $a diff --git a/tests/sys/cddl/zfs/bin/groupshow.ksh b/tests/sys/cddl/zfs/bin/groupshow.ksh new file mode 100644 index 00000000000..f6469aa0721 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupshow.ksh @@ -0,0 +1,5 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +/usr/sbin/pw groupshow $* diff --git a/tests/sys/cddl/zfs/bin/largest_file.c b/tests/sys/cddl/zfs/bin/largest_file.c new file mode 100644 index 00000000000..67b7b95dbbe --- /dev/null +++ b/tests/sys/cddl/zfs/bin/largest_file.c @@ -0,0 +1,132 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)largest_file.c 1.3 07/05/25 SMI" + +#include "file_common.h" +#include +#include +#include + +/* + * -------------------------------------------------------------- + * + * Assertion: + * The last byte of the largest file size can be + * accessed without any errors. Also, the writing + * beyond the last byte of the largest file size + * will produce an errno of EFBIG. + * + * -------------------------------------------------------------- + * If the write() system call below returns a "1", + * then the last byte can be accessed. + * -------------------------------------------------------------- + */ +static void sigxfsz(int); +static void usage(char *); + +int +main(int argc, char **argv) +{ + int fd = 0; + off_t offset = (OFF_MAX - 1); + off_t lseek_ret = 0; + int write_ret = 0; + int err = 0; + char mybuf[5]; + char *testfile; + + if (argc != 2) { + usage(argv[0]); + } + + (void) sigset(SIGXFSZ, sigxfsz); + + testfile = strdup(argv[1]); + + fd = open(testfile, O_CREAT | O_RDWR); + if (fd < 0) { + perror("Failed to create testfile"); + err = errno; + goto out; + } + + lseek_ret = lseek(fd, offset, SEEK_SET); + if (lseek_ret < 0) { + perror("Failed to seek to end of testfile"); + err = errno; + goto out; + } + + write_ret = write(fd, mybuf, 1); + if (write_ret < 0) { + perror("Failed to write to end of file"); + err = errno; + goto out; + } + + offset = 0; + lseek_ret = lseek(fd, offset, SEEK_CUR); + if (lseek_ret < 0) { + perror("Failed to seek to end of file"); + err = errno; + goto out; + } + + write_ret = write(fd, mybuf, 1); + if (write_ret < 0) { + if (errno == EFBIG) { + (void) printf("write errno=EFBIG: success\n"); + err = 0; + } else { + perror("Did not receive EFBIG"); + err = errno; + } + } else { + (void) printf("write completed successfully, test failed\n"); + err = 1; + } + +out: + (void) unlink(testfile); + free(testfile); + return (err); +} + +static void +usage(char *name) +{ + (void) printf("%s \n", name); + exit(1); +} + +/* ARGSUSED */ +static void +sigxfsz(int signo) +{ + (void) printf("\nlargest_file: sigxfsz() caught SIGXFSZ\n"); +} diff --git a/tests/sys/cddl/zfs/bin/mkfile.c b/tests/sys/cddl/zfs/bin/mkfile.c new file mode 100644 index 00000000000..cb74471a4c6 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/mkfile.c @@ -0,0 +1,214 @@ +/*- + * Copyright (c) 2001-2013 + * HATANO Tomomi. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef lint +static char rcsid[] = "$Id: mkfile.c,v 1.5 2013-10-26 10:11:34+09 hatanou Exp $"; +#endif /* !lint */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MKFILE_WBUF ((size_t)(1048576)) /* Is 1M a reasonable value? */ + +/* SunOS's mkfile(8) sets "sticky bit." */ +#define MKFILE_FLAG (O_WRONLY | O_CREAT | O_TRUNC) +#define MKFILE_MODE (S_IRUSR | S_IWUSR | S_ISVTX) + +static char buf[MKFILE_WBUF]; +static int nofill = 0; +static int verbose = 0; + +static void +usage() +{ + fprintf(stderr, + "Usage: mkfile [-nv] [e|p|t|g|m|k|b] ...\n"); +} + +static unsigned long long +getsize(char *s) +{ + int sh; + unsigned long long length; + char *suffix; + + /* + * NOTE: We don't handle 'Z' (zetta) or 'Y' (yotta) suffixes yet. + * These are too large to store in unsigned long long (64bits). + * In the future, we'll have to use larger type, + * something like uint128_t. + */ + length = strtoull(s, &suffix, 10); + sh = 0; + switch (tolower(*suffix)) { + case 'e': /* Exabytes. */ + sh = 60; + break; + case 'p': /* Petabytes. */ + sh = 50; + break; + case 't': /* Terabytes. */ + sh = 40; + break; + case 'g': /* Gigabytes. */ + sh = 30; + break; + case 'm': /* Megabytes. */ + sh = 20; + break; + case 'k': /* Kilobytes. */ + sh = 10; + break; + case 'b': /* Blocks. */ + sh = 9; + break; + case '\0': /* Bytes. */ + break; + default: /* Unknown... */ + errno = EINVAL; + return 0; + } + if (sh) { + unsigned long long l; + + l = length; + length <<= sh; + /* Check overflow. */ + if ((length >> sh) != l) { + errno = ERANGE; + return 0; + } + } + + return length; +} + +static int +create_file(char *f, unsigned long long s) +{ + int fd; + size_t w; + ssize_t ws; + + if (verbose) { + fprintf(stdout, "%s %llu bytes\n", f, s); + fflush(stdout); + } + + /* Open file to create. */ + if ((fd = open(f, MKFILE_FLAG, MKFILE_MODE)) < 0) { + return -1; + } + + /* Seek to the end and write 1 byte. */ + if ((lseek(fd, (off_t)(s - 1LL), SEEK_SET) == (off_t)-1) || + (write(fd, buf, (size_t)1) == (ssize_t)-1)) { + /* + * We don't close(fd) here to avoid overwriting errno. + * This is fd-leak, but is not harmful + * because returning error causes mkfile(8) to exit. + */ + return -1; + } + + /* Fill. */ + if (!nofill) { + if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) { + /* Same as above. */ + return -1; + } + while (s) { + w = (s > MKFILE_WBUF) ? MKFILE_WBUF : s; + if ((ws = write(fd, buf, w)) == (ssize_t)-1) { + /* Same as above. */ + return -1; + } + s -= ws; + } + } + close(fd); + + return 0; +} + +int +main(int argc, char *argv[]) +{ + unsigned long long fsize; + char ch; + + /* We have at least 2 arguments. */ + if (argc < 3) { + usage(); + return EXIT_FAILURE; + } + + /* Options. */ + while ((ch = getopt(argc, argv, "nv")) != -1) { + switch (ch) { + case 'n': + nofill = 1; + break; + case 'v': + verbose = 1; + break; + default: + usage(); + return EXIT_FAILURE; + } + } + argc -= optind; + argv += optind; + + /* File size to create. */ + if ((fsize = getsize(*argv)) == 0) { + perror(*argv); + return EXIT_FAILURE; + } + + /* Filenames to create. */ + bzero(buf, MKFILE_WBUF); + while (++argv, --argc) { + if (create_file(*argv, fsize) == -1) { + perror(*argv); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/tests/sys/cddl/zfs/bin/mktree.c b/tests/sys/cddl/zfs/bin/mktree.c new file mode 100644 index 00000000000..03aa2d67609 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/mktree.c @@ -0,0 +1,196 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)mktree.c 1.3 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TYPE_D 'D' +#define TYPE_F 'F' + +extern int errno; + +static char fdname[MAXPATHLEN] = {0}; +static char *pbasedir = NULL; +static int nlevel = 2; +static int ndir = 2; +static int nfile = 2; + +static void usage(char *this); +static void crtfile(char *pname); +static char *getfdname(char *pdir, char type, int level, int dir, int file); +static int mktree(char *pbasedir, int level); + +int +main(int argc, char *argv[]) +{ + int c, ret; + + while ((c = getopt(argc, argv, "b:l:d:f:")) != -1) { + switch (c) { + case 'b': + pbasedir = optarg; + break; + case 'l': + nlevel = atoi(optarg); + break; + case 'd': + ndir = atoi(optarg); + break; + case 'f': + nfile = atoi(optarg); + break; + case '?': + usage(argv[0]); + } + } + if (nlevel < 0 || ndir < 0 || nfile < 0 || pbasedir == NULL) { + usage(argv[0]); + } + + ret = mktree(pbasedir, 1); + + return (ret); +} + +static void +usage(char *this) +{ + (void) fprintf(stderr, + "\tUsage: %s -b -l [nlevel] -d [ndir] -f [nfile]\n", + this); + exit(1); +} + +static int +mktree(char *pdir, int level) +{ + int d, f; + char dname[MAXPATHLEN] = {0}; + char fname[MAXPATHLEN] = {0}; + + if (level > nlevel) { + return (1); + } + + for (d = 0; d < ndir; d++) { + (void) memset(dname, '\0', sizeof (dname)); + (void) strcpy(dname, getfdname(pdir, TYPE_D, level, d, 0)); + + if (mkdir(dname, 0777) != 0) { + (void) fprintf(stderr, "mkdir(%s) failed." + "\n[%d]: %s.\n", + dname, errno, strerror(errno)); + exit(errno); + } + + /* + * No sub-directory need be created, only create files in it. + */ + if (mktree(dname, level+1) != 0) { + for (f = 0; f < nfile; f++) { + (void) memset(fname, '\0', sizeof (fname)); + (void) strcpy(fname, + getfdname(dname, TYPE_F, level+1, d, f)); + crtfile(fname); + } + } + } + + for (f = 0; f < nfile; f++) { + (void) memset(fname, '\0', sizeof (fname)); + (void) strcpy(fname, getfdname(pdir, TYPE_F, level, d, f)); + crtfile(fname); + } + + return (0); +} + +static char * +getfdname(char *pdir, char type, int level, int dir, int file) +{ + (void) snprintf(fdname, sizeof (fdname), + "%s/%c-l%dd%df%d", pdir, type, level, dir, file); + return (fdname); +} + +static void +crtfile(char *pname) +{ + int fd = -1; + int afd = -1; + int i, size; + char *context = "0123456789ABCDF"; + char *pbuf; + + if (pname == NULL) { + exit(1); + } + + size = sizeof (char) * 1024; + pbuf = (char *)valloc(size); + for (i = 0; i < size / strlen(context); i++) { + int offset = i * strlen(context); + (void) snprintf(pbuf+offset, size-offset, "%s", context); + } + + if ((fd = open(pname, O_CREAT|O_RDWR, 0777)) < 0) { + (void) fprintf(stderr, "open(%s, O_CREAT|O_RDWR, 0777) failed." + "\n[%d]: %s.\n", pname, errno, strerror(errno)); + exit(errno); + } + if (write(fd, pbuf, 1024) < 1024) { + (void) fprintf(stderr, "write(fd, pbuf, 1024) failed." + "\n[%d]: %s.\n", errno, strerror(errno)); + exit(errno); + } + +#if UNSUPPORTED + if ((afd = openat(fd, "xattr", O_CREAT | O_RDWR | O_XATTR, 0777)) < 0) { + (void) fprintf(stderr, "openat failed.\n[%d]: %s.\n", + errno, strerror(errno)); + exit(errno); + } + if (write(afd, pbuf, 1024) < 1024) { + (void) fprintf(stderr, "write(afd, pbuf, 1024) failed." + "\n[%d]: %s.\n", errno, strerror(errno)); + exit(errno); + } + + (void) close(afd); +#endif + (void) close(fd); + free(pbuf); +} diff --git a/tests/sys/cddl/zfs/bin/mmapwrite.c b/tests/sys/cddl/zfs/bin/mmapwrite.c new file mode 100644 index 00000000000..756b33b5cb9 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/mmapwrite.c @@ -0,0 +1,99 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)mmapwrite.c 1.4 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include + +/* + * -------------------------------------------------------------------- + * Bug Id: 5032643 + * + * Simply writing to a file and mmaping that file at the same time can + * result in deadlock. Nothing perverse like writing from the file's + * own mapping is required. + * -------------------------------------------------------------------- + */ + +static void * +mapper(void *fdp) +{ + void *addr; + int fd = *(int *)fdp; + + if ((addr = + mmap(0, 8192, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { + perror("mmap"); + exit(1); + } + for (;;) { + if (mmap(addr, 8192, PROT_READ, + MAP_SHARED|MAP_FIXED, fd, 0) == MAP_FAILED) { + perror("mmap"); + exit(1); + } + } + /* NOTREACHED */ + return ((void *)1); +} + +int +main(int argc, char **argv) +{ + int fd; + char buf[BUFSIZ]; + pthread_t pt; + + if (argc != 2) { + (void) printf("usage: %s \n", argv[0]); + exit(1); + } + + if ((fd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666)) == -1) { + perror("open"); + exit(1); + } + + if (pthread_create(&pt, NULL, mapper, &fd) != 0) { + perror("pthread_create"); + exit(1); + } + for (;;) { + if (write(fd, buf, sizeof (buf)) == -1) { + perror("write"); + exit(1); + } + } + + /* NOTREACHED */ + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/randfree_file.c b/tests/sys/cddl/zfs/bin/randfree_file.c new file mode 100644 index 00000000000..3c43abcf6c2 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/randfree_file.c @@ -0,0 +1,104 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)randfree_file.c 1.3 07/05/25 SMI" + +#include "file_common.h" + +/* + * Create a file with assigned size and then free the specified + * section of the file + */ + +static void usage(char *progname); + +static void +usage(char *progname) +{ + (void) fprintf(stderr, + "usage: %s [-l filesize] [-s start-offset]" + "[-n section-len] filename\n", progname); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + char *filename, *buf; + size_t filesize; + off_t start_off, off_len; + int fd, ch; + struct flock fl; + + while ((ch = getopt(argc, argv, "l:s:n:")) != EOF) { + switch (ch) { + case 'l': + filesize = atoll(optarg); + break; + case 's': + start_off = atoll(optarg); + break; + case 'n': + off_len = atoll(optarg); + break; + default: + usage(argv[0]); + break; + } + } + + if (optind == argc - 1) + filename = argv[optind]; + else + usage(argv[0]); + + buf = (char *)malloc(filesize); + + if ((fd = open(filename, O_RDWR|O_CREAT|O_TRUNC)) < 0) { + perror("open"); + return (1); + } + if (write(fd, buf, filesize) < filesize) { + perror("write"); + return (1); + } +#if UNSUPPORTED + fl.l_whence = SEEK_SET; + fl.l_start = start_off; + fl.l_len = off_len; + if (fcntl(fd, F_FREESP, &fl) != 0) { + perror("fcntl"); + return (1); + } +#else + fprintf(stderr, "fcntl: F_FREESP not supported\n"); + return (1); +#endif + + free(buf); + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/readmmap.c b/tests/sys/cddl/zfs/bin/readmmap.c new file mode 100644 index 00000000000..117246a8c2c --- /dev/null +++ b/tests/sys/cddl/zfs/bin/readmmap.c @@ -0,0 +1,140 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)readmmap.c 1.4 07/05/25 SMI" + +/* + * -------------------------------------------------------------- + * BugId 5047993 : Getting bad read data. + * + * Usage: readmmap + * + * where: + * filename is an absolute path to the file name. + * + * Return values: + * 1 : error + * 0 : no errors + * -------------------------------------------------------------- + */ +#include +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + char *filename = "badfile"; + size_t size = 4395; + size_t idx = 0; + char *buf = NULL; + char *map = NULL; + int fd = -1, bytes, retval = 0; + unsigned seed; + + if (argc < 2 || optind == argc) { + (void) fprintf(stderr, + "usage: %s \n", argv[0]); + exit(1); + } + + if ((buf = calloc(1, size)) == NULL) { + perror("calloc"); + exit(1); + } + + filename = argv[optind]; + + (void) remove(filename); + + fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666); + if (fd == -1) { + perror("open to create"); + retval = 1; + goto end; + } + + bytes = write(fd, buf, size); + if (bytes != size) { + (void) printf("short write: %d != %ud\n", bytes, size); + retval = 1; + goto end; + } + + map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (map == MAP_FAILED) { + perror("mmap"); + retval = 1; + goto end; + } + seed = time(NULL); + srandom(seed); + + idx = random() % size; + map[idx] = 1; + + if (msync(map, size, MS_SYNC) != 0) { + perror("msync"); + retval = 1; + goto end; + } + + if (munmap(map, size) != 0) { + perror("munmap"); + retval = 1; + goto end; + } + + bytes = pread(fd, buf, size, 0); + if (bytes != size) { + (void) printf("short read: %d != %ud\n", bytes, size); + retval = 1; + goto end; + } + + if (buf[idx] != 1) { + (void) printf( + "bad data from read! got buf[%ud]=%d, expected 1\n", + idx, buf[idx]); + retval = 1; + goto end; + } + + (void) printf("good data from read: buf[%ud]=1\n", idx); +end: + if (fd != -1) { + (void) close(fd); + } + if (buf != NULL) { + free(buf); + } + + return (retval); +} diff --git a/tests/sys/cddl/zfs/bin/rename_dir.c b/tests/sys/cddl/zfs/bin/rename_dir.c new file mode 100644 index 00000000000..3a475f2544d --- /dev/null +++ b/tests/sys/cddl/zfs/bin/rename_dir.c @@ -0,0 +1,92 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)rename_dir.c 1.1 07/05/25 SMI" + +/* + * Assertion: + * Create two directory trees in zfs filesystem, and rename + * directory across the directory structure. ZFS can handle + * the race situation. + */ + +/* + * Need to create the following directory structures before + * running this program: + * + * mkdir -p 1/2/3/4/5 a/b/c/d/e + */ + + +#include +#include +#include +#include + +int +main() +{ + int i = 1; + char buf[256]; + char *msg = "rename() fails to handle race situation\n"; + + switch (fork()) { + case -1: + perror("fork"); + exit(1); + break; + case 0: + while (i > 0) { + int c_count = 0; + if (rename("a/b/c", "1/2/3/c") == 0) + c_count++; + if (rename("1/2/3/c", "a/b/c") == 0) + c_count++; + if (c_count) { + (void) strlcat(buf, "c_count: %d,", 256); + (void) strlcat(buf, msg, 256); + (void) fprintf(stderr, buf, c_count); + } + } + break; + default: + while (i > 0) { + int p_count = 0; + if (rename("1", "a/b/c/d/e/1") == 0) + p_count++; + if (rename("a/b/c/d/e/1", "1") == 0) + p_count++; + if (p_count) { + (void) strlcat(buf, "p_count: %d,", 256); + (void) strlcat(buf, msg, 256); + (void) fprintf(stderr, buf, p_count); + } + } + break; + } + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/rm_lnkcnt_zero_file.c b/tests/sys/cddl/zfs/bin/rm_lnkcnt_zero_file.c new file mode 100644 index 00000000000..c6ebb22b3d3 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/rm_lnkcnt_zero_file.c @@ -0,0 +1,148 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)rm_lnkcnt_zero_file.c 1.3 07/05/25 SMI" + +/* + * -------------------------------------------------------------------- + * The purpose of this test is to see if the bug reported (#4723351) for + * UFS exists when using a ZFS file system. + * -------------------------------------------------------------------- + * + */ +#define _REENTRANT 1 +#include +#include +#include +#include +#include +#include +#include +#include + +static const int TRUE = 1; +static char *filebase; + +static int +pickidx() +{ + return (random() % 1000); +} + +/* ARGSUSED */ +static void * +mover(void *a) +{ + char buf[256]; + int idx, ret; + + while (TRUE) { + idx = pickidx(); + (void) sprintf(buf, "%s.%03d", filebase, idx); + ret = rename(filebase, buf); + if (ret < 0 && errno != ENOENT) + (void) perror("renaming file"); + } + + return (NULL); +} + +/* ARGSUSED */ +static void * +cleaner(void *a) +{ + char buf[256]; + int idx, ret; + + while (TRUE) { + idx = pickidx(); + (void) sprintf(buf, "%s.%03d", filebase, idx); + ret = remove(buf); + if (ret < 0 && errno != ENOENT) + (void) perror("removing file"); + } + + return (NULL); +} + +static void * +writer(void *a) +{ + int *fd = (int *)a; + + while (TRUE) { + (void) close (*fd); + *fd = open(filebase, O_APPEND | O_RDWR | O_CREAT, 0644); + if (*fd < 0) + perror("refreshing file"); + (void) write(*fd, "test\n", 5); + } + + return (NULL); +} + +int +main(int argc, char **argv) +{ + int fd; + pthread_t tid; + + if (argc == 1) { + (void) printf("Usage: %s \n", argv[0]); + exit(-1); + } + + filebase = argv[1]; + fd = open(filebase, O_APPEND | O_RDWR | O_CREAT, 0644); + if (fd < 0) { + perror("creating test file"); + exit(-1); + } + + if (pthread_setconcurrency(4)) { /* 3 threads + main */ + fprintf(stderr, "failed to set concurrency\n"); + exit(-1); + } + (void) pthread_create(&tid, NULL, mover, NULL); + (void) pthread_create(&tid, NULL, cleaner, NULL); + (void) pthread_create(&tid, NULL, writer, (void *) &fd); + + while (TRUE) { + int ret; + struct stat st; + + ret = stat(filebase, &st); + if (ret == 0 && (st.st_nlink > 2 || st.st_nlink < 1)) { + (void) printf("st.st_nlink = %d, exiting\n", \ + (int)st.st_nlink); + exit(0); + } + (void) sleep(1); + } + + return (0); +} diff --git a/tests/sys/cddl/zfs/bin/svcs.ksh b/tests/sys/cddl/zfs/bin/svcs.ksh new file mode 100644 index 00000000000..5e596ddcfd7 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/svcs.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo dummy +exit 0 diff --git a/tests/sys/cddl/zfs/bin/swap.ksh b/tests/sys/cddl/zfs/bin/swap.ksh new file mode 100644 index 00000000000..9a6cbd8040d --- /dev/null +++ b/tests/sys/cddl/zfs/bin/swap.ksh @@ -0,0 +1,5 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +swapinfo diff --git a/tests/sys/cddl/zfs/bin/testenv.ksh b/tests/sys/cddl/zfs/bin/testenv.ksh new file mode 100644 index 00000000000..9daa985475a --- /dev/null +++ b/tests/sys/cddl/zfs/bin/testenv.ksh @@ -0,0 +1,8 @@ +#!/usr/bin/env ksh93 +script=$(realpath $0) +export STF_BIN=$(dirname ${script}) +export STF_SUITE=$(dirname ${STF_BIN}) + +# $FreeBSD$ + +env ENV=${STF_SUITE}/include/testenv.kshlib ksh93 -E -l diff --git a/tests/sys/cddl/zfs/bin/useradd.ksh b/tests/sys/cddl/zfs/bin/useradd.ksh new file mode 100644 index 00000000000..fc6b177b3a5 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/useradd.ksh @@ -0,0 +1,13 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +a= +g= +for i in $* +do + a="$a $g" + g=$i +done + +/usr/sbin/pw useradd $g $a diff --git a/tests/sys/cddl/zfs/bin/userdel.ksh b/tests/sys/cddl/zfs/bin/userdel.ksh new file mode 100644 index 00000000000..9ea56d6a041 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/userdel.ksh @@ -0,0 +1,13 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +a= +g= +for i in $* +do + a="$a $g" + g=$i +done + +/usr/sbin/pw userdel $g $a diff --git a/tests/sys/cddl/zfs/bin/usermod.ksh b/tests/sys/cddl/zfs/bin/usermod.ksh new file mode 100644 index 00000000000..37c51519676 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/usermod.ksh @@ -0,0 +1,13 @@ +#! /usr/local/bin/ksh93 -p + +# $FreeBSD$ + +a= +g= +for i in $* +do + a="$a $g" + g=$i +done + +/usr/sbin/pw usermod $g $a diff --git a/tests/sys/cddl/zfs/bin/zfs.ksh b/tests/sys/cddl/zfs/bin/zfs.ksh new file mode 100644 index 00000000000..eb007024ab2 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zfs.ksh @@ -0,0 +1,44 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs.ksh 1.2 09/01/13 SMI" +# + +ZFS=/sbin/zfs + +set -A saved_options -- "$@" + +for wrapper in ${ZFS_WRAPPER} ; do + if [[ -x ${STF_SUITE}/bin/zfs_$wrapper ]]; then + options=$(${STF_SUITE}/bin/zfs_$wrapper "${saved_options[@]}") + set -A saved_options -- $options + fi +done + +$ZFS "${saved_options[@]}" +return $? diff --git a/tests/sys/cddl/zfs/bin/zfs_crypto.ksh b/tests/sys/cddl/zfs/bin/zfs_crypto.ksh new file mode 100644 index 00000000000..ebca5025932 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zfs_crypto.ksh @@ -0,0 +1,59 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_crypto.ksh 1.2 09/05/19 SMI" +# + +cmd=$1 +shift +options="$@" + +case $cmd in + create) + # Get zfs name + # eval zfsname=\${$#} + + if [[ $KEYSOURCE_DATASET == "passphrase" ]]; then + options="-o encryption=$ENCRYPTION \ +-o keysource=passphrase,file://$PASSPHRASE_FILE $options" + elif [[ $KEYSOURCE_DATASET == "raw" ]]; then + options="-o encryption=$ENCRYPTION \ +-o keysource=raw,file://$RAW_KEY_FILE $options" + elif [[ $KEYSOURCE_DATASET == "hex" ]]; then + options="-o encryption=$ENCRYPTION \ +-o keysource=hex,file://$HEX_KEY_FILE $options" + elif [[ -n $KEYSOURCE_DATASET ]]; then + log_note "Warning: invalid KEYSOURCE_DATASET \c" + log_note "value: $KEYSOURCE_DATASET, ignore it" + fi + ;; + *) + ;; +esac + +print $cmd $options diff --git a/tests/sys/cddl/zfs/bin/zfs_version.ksh b/tests/sys/cddl/zfs/bin/zfs_version.ksh new file mode 100644 index 00000000000..8c0b6bac430 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zfs_version.ksh @@ -0,0 +1,68 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_version.ksh 1.1 09/01/13 SMI" +# + +cmd=$1 +shift +options="$@" + +o_version_option="no" +V_option="no" + +while getopts :o:V: c +do + case $c in + o) + if [[ "$OPTARG" == "version="* ]]; then + o_version_option="yes" + fi + ;; + V) + V_option="yes" + ;; + *) + ;; + esac +done +shift $(($OPTIND - 1)) + +case $cmd in + create) + if [[ "$ZFS_TEST_VERSION" != "0" ]] && + [[ "$o_version_option" == "no" ]] && + [[ "$V_option" == "no" ]]; then + options="-o version=$ZFS_TEST_VERSION $options" + fi + ;; + *) + ;; +esac + +print "$cmd $options" diff --git a/tests/sys/cddl/zfs/bin/zlogin.ksh b/tests/sys/cddl/zfs/bin/zlogin.ksh new file mode 100644 index 00000000000..5e596ddcfd7 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zlogin.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo dummy +exit 0 diff --git a/tests/sys/cddl/zfs/bin/zoneadm.ksh b/tests/sys/cddl/zfs/bin/zoneadm.ksh new file mode 100644 index 00000000000..1860f6285f5 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zoneadm.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo global +exit 0 diff --git a/tests/sys/cddl/zfs/bin/zonecfg.ksh b/tests/sys/cddl/zfs/bin/zonecfg.ksh new file mode 100644 index 00000000000..5e596ddcfd7 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zonecfg.ksh @@ -0,0 +1,6 @@ +#!/usr/local/bin/ksh93 + +# $FreeBSD$ + +echo dummy +exit 0 diff --git a/tests/sys/cddl/zfs/bin/zpool.ksh b/tests/sys/cddl/zfs/bin/zpool.ksh new file mode 100644 index 00000000000..f7d8bab1646 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool.ksh @@ -0,0 +1,46 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool.ksh 1.2 09/01/13 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +ZPOOL=/sbin/zpool + +set -A saved_options -- "$@" + +for wrapper in ${ZPOOL_WRAPPER} ; do + if [[ -x ${STF_SUITE}/bin/zpool_$wrapper ]]; then + options=$(${STF_SUITE}/bin/zpool_$wrapper "${saved_options[@]}") + set -A saved_options -- $options + fi +done + +$ZPOOL "${saved_options[@]}" +return $? diff --git a/tests/sys/cddl/zfs/bin/zpool_bsd.ksh b/tests/sys/cddl/zfs/bin/zpool_bsd.ksh new file mode 100644 index 00000000000..2d0920640a2 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool_bsd.ksh @@ -0,0 +1,42 @@ +#!/usr/local/bin/ksh93 -p +# + +# $FreeBSD$ + +cmd=$1 + +if [[ -z $cmd ]]; then + return 0 +fi + +shift + + +typeset option +case $cmd in + create|add|attach|detach|replace|remove|online|offline|clear) + for arg in $@; do + if [[ $arg == "/dev/dsk/"* ]]; then + arg=${arg#/dev/dsk/} + arg="/dev/"$arg + fi + if [[ $arg == "/dev/"* ]]; then + echo $arg | egrep "*s[0-9]$" > /dev/null 2>&1 + if [ $? -eq 0 ] + then + n=`echo $arg| wc -c` + set -A map a b c d e f g h i j + s=`echo $arg | cut -c $((n-1))` + arg=${arg%s[0-9]}${map[$s]} + fi + fi + + option="${option} $arg" + done + ;; + *) + option="$@" + ;; +esac + +echo $cmd $option diff --git a/tests/sys/cddl/zfs/bin/zpool_smi.ksh b/tests/sys/cddl/zfs/bin/zpool_smi.ksh new file mode 100644 index 00000000000..d84a0330c20 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool_smi.ksh @@ -0,0 +1,138 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_smi.ksh 1.2 09/01/13 SMI" +# + +function labelvtoc +{ + typeset disk=$1 + if [[ -z $disk ]]; then + print "no disk is given." + return 1 + fi + + /usr/sbin/format $disk << _EOF >/dev/null 2>&1 +label +yes +_EOF + + labeltype=$(/usr/sbin/prtvtoc -fh /dev/rdsk/${disk}s2 | \ + awk '{print $1}' | awk -F= '{print $2}' ) + if [[ -z $labeltype ]]; then + print "${disk} not exist." + return 1 + fi + + if [[ $labeltype == "34" ]]; then + + typeset label_file=$TMPDIR/labelvtoc.${TESTCASE_ID:-$$} + typeset arch=$(uname -p) + + if [[ $arch == "i386" ]]; then + print "label" > $label_file + print "0" >> $label_file + print "" >> $label_file + print "q" >> $label_file + print "q" >> $label_file + + fdisk -B /dev/rdsk/${disk}p0 >/dev/null 2>&1 + # wait a while for fdisk finishes + /usr/sbin/devfsadm > /dev/null 2>&1 + elif [[ $arch == "sparc" ]]; then + print "label" > $label_file + print "0" >> $label_file + print "" >> $label_file + print "" >> $label_file + print "" >> $label_file + print "q" >> $label_file + else + print "unknow arch type : $arch" + return 1 + fi + + format -e -s -d $disk -f $label_file + typeset -i ret_val=$? + rm -f $label_file + # + # wait the format to finish + # + /usr/sbin/devfsadm > /dev/null 2>&1 + if (( ret_val != 0 )); then + print "unable to label $disk as VTOC." + return 1 + fi + fi + + return 0 +} + +cmd=$1 + +if [[ -z $cmd ]]; then + return 0 +fi + +shift + + +typeset option +case $cmd in + create|add|attach|detach|replace|remove|online|offline|clear) + for arg in $@; do + if [[ $arg == "/dev/dsk/"* ]]; then + arg=${arg#/dev/dsk/} + fi + + print $arg | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 + + if [[ $? -eq 0 ]] ; then + labelvtoc $arg + if [[ $? -eq 0 ]] ; then + arg=${arg}s2 + fi + fi + option="${option} $arg" + done + ;; + *) + option="$@" + ;; +esac + +case $cmd in + create|add|attach|replace) + if [[ $option != *"-f"* ]]; then + cmd="${cmd} -f" + fi + ;; + *) + ;; +esac + +print $cmd $option diff --git a/tests/sys/cddl/zfs/bin/zpool_version.ksh b/tests/sys/cddl/zfs/bin/zpool_version.ksh new file mode 100644 index 00000000000..dfec5cf53e8 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool_version.ksh @@ -0,0 +1,73 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_version.ksh 1.1 09/01/13 SMI" +# + +cmd=$1 +shift +options="$@" + +o_version_option="no" +O_version_option="no" + +while getopts :o:O: c +do + case $c in + o) + if [[ "$OPTARG" == "version="* ]]; then + o_version_option="yes" + fi + ;; + O) + if [[ "$OPTARG" == "version="* ]]; then + O_version_option="yes" + fi + ;; + *) + ;; + esac +done +shift $(($OPTIND - 1)) + +case $cmd in + create) + if [[ "$ZFS_TEST_VERSION" != "0" ]] && + [[ "$O_version_option" == "no" ]]; then + options="-O version=$ZFS_TEST_VERSION $options" + fi + if [[ "$ZPOOL_TEST_VERSION" != "0" ]] && + [[ "$o_version_option" == "no" ]]; then + options="-o version=$ZPOOL_TEST_VERSION $options" + fi + ;; + *) + ;; +esac + +print "$cmd $options" diff --git a/tests/sys/cddl/zfs/include/Makefile b/tests/sys/cddl/zfs/include/Makefile new file mode 100644 index 00000000000..76c4af9e15f --- /dev/null +++ b/tests/sys/cddl/zfs/include/Makefile @@ -0,0 +1,32 @@ +# $FreeBSD$ + +.include + +PACKAGE= tests + +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/include + +STFSUITEDIR=${TESTSBASE}/sys/cddl/zfs + +MAN= +FILESDIR= ${TESTSBASE}/sys/cddl/zfs/include +${PACKAGE}FILES+= constants.cfg +${PACKAGE}FILES+= libremote.kshlib +${PACKAGE}FILES+= libgnop.kshlib +${PACKAGE}FILES+= logapi.kshlib +${PACKAGE}FILES+= libtest.kshlib +${PACKAGE}FILES+= stf.shlib +${PACKAGE}FILES+= testenv.kshlib + +${PACKAGE}FILES+= commands.cfg +CLEANFILES+= commands.cfg +commands.cfg: translatecommands.awk commands.txt + awk -v stfsuitedir=${STFSUITEDIR} -f ${.ALLSRC} > ${.TARGET} + +${PACKAGE}FILES+= default.cfg +CLEANFILES+= default.cfg +default.cfg: default.cfg.in + sed "s:%%STFSUITEDIR%%:${STFSUITEDIR}:" ${.ALLSRC} > ${.TARGET} + +ATF_TESTS_KSH93+= libtest_test +.include diff --git a/tests/sys/cddl/zfs/include/commands.txt b/tests/sys/cddl/zfs/include/commands.txt new file mode 100644 index 00000000000..8c90e6f8f42 --- /dev/null +++ b/tests/sys/cddl/zfs/include/commands.txt @@ -0,0 +1,194 @@ +# +# 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 +# + +# $FreeBSD$ + +#!/usr/local/bin/ksh93 -p +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)commands.txt 1.8 09/01/13 SMI" +# +# All the commands in this file are converted into environment variables +# with the same name as the command e.g. +# +# /bin/df becomes export DF="/bin/df" +# finally an export CMDS="aggregation of all the environment variables" +# is created for checking in the execution environment. +# +# comments are ignored in this file, as are whitespace lines + +# General Solaris Commands +/usr/bin/awk +/usr/sbin/arp +/usr/bin/basename +/usr/bin/bzcat +/bin/cat +/usr/bin/cd +/usr/bin/chgrp +/bin/chmod +/usr/sbin/chown +/usr/bin/cksum +/sbin/clri +/usr/bin/cmp +/usr/bin/compress +/usr/bin/uncompress +#/usr/bin/coreadm +/bin/cp +/usr/bin/cpio +/usr/bin/cut +/bin/date +/bin/dd +#/usr/sbin/devfsadm +%%STFSUITEDIR%%/bin/df +/usr/bin/diff +%%STFSUITEDIR%%/bin/dircmp +/usr/bin/dirname +/usr/bin/du +#%%STFSUITEDIR%%/bin/dumpadm +/bin/echo +/usr/bin/egrep +/usr/bin/env +#%%STFSUITEDIR%%/bin/ff +/usr/bin/fgrep +/usr/bin/file +/usr/bin/find +#%%STFSUITEDIR%%/bin/fmadm +#%%STFSUITEDIR%%/bin/fmdump +#%%STFSUITEDIR%%/bin/format +/sbin/fsck +/sbin/fsdb +/sbin/fsirand +/usr/bin/fsync +/usr/sbin/fstyp +/usr/bin/id +#/usr/bin/isainfo +#/usr/sbin/iscsiadm +#/usr/sbin/iscsitadm +/usr/bin/getent +/bin/getfacl +/usr/bin/getconf +/sbin/sha1 +/sbin/gpart +/usr/bin/grep +/usr/bin/groups +%%STFSUITEDIR%%/bin/groupadd +%%STFSUITEDIR%%/bin/groupdel +%%STFSUITEDIR%%/bin/groupmod +%%STFSUITEDIR%%/bin/groupshow +/usr/bin/head +/bin/hostname +/bin/kill +/usr/local/bin/ksh93 +#/usr/sbin/labelit +#/usr/sbin/lockfs +#/usr/sbin/lofiadm +/bin/ls +/usr/bin/logname +#/usr/bin/mdb +/sbin/mdconfig +#/usr/sbin/metaclear +#/usr/sbin/metadb +#/usr/sbin/metainit +#/usr/sbin/metastat +/bin/mkdir +/sbin/mknod +#/usr/sbin/modinfo +#/usr/sbin/modunload +/sbin/mount +/bin/mv +#/usr/sbin/ncheck +/sbin/newfs +/usr/bin/nawk +#/usr/bin/pack +/usr/bin/pagesize +/bin/pax +/sbin/ping +/usr/bin/printf +#/usr/sbin/prtvtoc +#/usr/bin/pfexec +/bin/pgrep +#/usr/bin/pkginfo +/bin/pkill +/bin/ps +#/usr/sbin/psrinfo +/bin/pwd +/usr/sbin/quotaon +/bin/rcp +/sbin/reboot +/bin/rm +/bin/rmdir +/usr/bin/rsh +#/usr/bin/runat +/usr/bin/sed +#/usr/sbin/share +/bin/sleep +/usr/bin/su +/usr/bin/sum +#%%STFSUITEDIR%%/bin/svcs +#/usr/sbin/svcadm +#%%STFSUITEDIR%%/bin/swap +#/sbin/swapadd +/usr/bin/sort +/usr/bin/stat +/usr/bin/strings +/bin/sync +/usr/bin/tar +/usr/bin/tail +/usr/bin/timeout +/usr/bin/touch +/usr/bin/tr +/usr/bin/true +/usr/bin/truncate +/sbin/tunefs +#/usr/sbin/ufsdump +#/usr/sbin/ufsrestore +/usr/bin/umask +/sbin/umount +/usr/bin/uname +/usr/bin/uniq +#/usr/sbin/unshare +#/usr/bin/unpack +%%STFSUITEDIR%%/bin/useradd +%%STFSUITEDIR%%/bin/userdel +%%STFSUITEDIR%%/bin/usermod +/usr/bin/wait +/usr/bin/wc +#%%STFSUITEDIR%%/bin/zoneadm +#%%STFSUITEDIR%%/bin/zonecfg +#%%STFSUITEDIR%%/bin/zlogin +#/usr/bin/zonename +/sbin/swapon +/sbin/swapoff +/sbin/swapctl +/usr/bin/xargs +/usr/sbin/zfsd + +# ZFS Commands +/usr/sbin/zdb +/sbin/zfs +/sbin/zpool +/usr/bin/zinject + +# Test framework commands +#/opt/SUNWstc-runwattr/bin/runwattr +%%STFSUITEDIR%%/bin/bsddisks diff --git a/tests/sys/cddl/zfs/include/constants.cfg b/tests/sys/cddl/zfs/include/constants.cfg new file mode 100644 index 00000000000..74f760085f3 --- /dev/null +++ b/tests/sys/cddl/zfs/include/constants.cfg @@ -0,0 +1,113 @@ +#!/usr/bin/env ksh93 +# vim: filetype=sh +# $FreeBSD$ + +# Add test-specific binaries to PATH +export PATH=${STF_SUITE}/bin:${PATH} +export TMPDIR=${TMPDIR-/tmp} + +# Set default value of TMPDIR +export TMPDIR=${TMPDIR-/tmp} + +# Define run length constants +export RT_LONG="3" +export RT_MEDIUM="2" +export RT_SHORT="1" + +# Define macro for zone test +export ZONE_POOL="zonepool" +export ZONE_CTR="zonectr" + +# Test Suite Specific Commands +export DEVNAME2DEVID="devname2devid" +export FILE_WRITE="file_write" +export FILE_CHECK="file_check" +export LARGEST_FILE="largest_file" +export MMAPWRITE="mmapwrite" +export MKFILE="mkfile" +export READMMAP="readmmap" +export FILE_TRUNC="file_trunc" +export CHG_USR_EXEC="chg_usr_exec" +export MKTREE="mktree" +export RANDFREE_FILE="randfree_file" +export DIR_RD_UPDATE="dir_rd_update" +export RM_LNKCNT_ZERO_FILE="rm_lnkcnt_zero_file" +export RENAME_DIR="rename_dir" + +# ensure we're running in the C locale, since +# localised messages may result in test failures +export LC_ALL="C" +export LANG="C" + +# +# pattern to ignore from 'zpool list'. +# +export NO_POOLS="no pools available" + +# pattern to ignore from 'zfs list'. +export NO_DATASETS="no datasets available" + +export TEST_BASE_DIR="/" + +# Default to compression ON +export COMPRESSION_PROP=on + +# Default to using the checksum +export CHECKSUM_PROP=on + +# some common variables used by test scripts : + +export TESTCASE_ID=${TESTCASE_ID:-$$} +# some test pool names +export TESTPOOL=testpool.${TESTCASE_ID} +export TESTPOOL1=testpool1.${TESTCASE_ID} +export TESTPOOL2=testpool2.${TESTCASE_ID} +export TESTPOOL3=testpool3.${TESTCASE_ID} + +# some test file system names +export TESTCTR=testctr${TESTCASE_ID} +export TESTFS=testfs.${TESTCASE_ID} +export TESTFS1=testfs1.${TESTCASE_ID} +export TESTFS2=testfs2.${TESTCASE_ID} +export TESTFS3=testfs3.${TESTCASE_ID} + +# some test directory names +export TESTDIR=${TEST_BASE_DIR%%/}/testdir${TESTCASE_ID} +export TESTDIR0=${TEST_BASE_DIR%%/}/testdir0${TESTCASE_ID} +export TESTDIR1=${TEST_BASE_DIR%%/}/testdir1${TESTCASE_ID} +export TESTDIR2=${TEST_BASE_DIR%%/}/testdir2${TESTCASE_ID} + +# Default to limit disks to be checked +export MAX_FINDDISKSNUM=100 + +# For iscsi target support +export ISCSITGTFILE=$TMPDIR/iscsitgt_file +export ISCSITGT_FMRI=svc:/system/iscsitgt:default + +if [ -n "$SVCS" ]; then + export AUTO_SNAP=$($SVCS -a | $GREP auto-snapshot | $GREP online | $AWK '{print $3}') +fi + +# zfs upgrade should output the first line as: +# This system is currently running ZFS filesystem version 2. +# . + +ZFS_VERSION= +$ZFS upgrade -v > /dev/null 2>&1 +if [ $? -eq 0 ]; then + export ZFS_VERSION=$($ZFS upgrade | $HEAD -1 | $AWK '{print $NF}' \ + | $SED -e 's/\.//g') +fi + +if [ -n "$ZFS_VERSION" ]; then + i=1 + ZFS_ALL_VERSIONS="" + while [ "$i" -le "$ZFS_VERSION" ]; do + eval 'export ZFS_VERSION_$i="v${i}-fs"' + ZFS_ALL_VERSIONS="$ZFS_ALL_VERSIONS $i" + i=$(( i + 1 )) + done + export ZFS_ALL_VERSIONS +fi + +$TRUE diff --git a/tests/sys/cddl/zfs/include/default.cfg.in b/tests/sys/cddl/zfs/include/default.cfg.in new file mode 100644 index 00000000000..98a21725528 --- /dev/null +++ b/tests/sys/cddl/zfs/include/default.cfg.in @@ -0,0 +1,52 @@ +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)default.cfg 1.8 08/11/03 SMI" +# +# Read the user config file, if it exists +# + +export STF_SUITE=%%STFSUITEDIR%% + +. $STF_SUITE/include/libtest.kshlib + +# source the autogenerated commands.cfg file (built from the commands.txt file +. $STF_SUITE/include/commands.cfg + +# Turn ATF variables into environment variables +export DISKS=`atf_config_get disks ""` +export KEEP=`atf_config_get keep_pools "" | ${SED} -E 's/ +/|/g'` +export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") + + +. $STF_SUITE/include/constants.cfg + +# finally, if we're running in a local zone +# we take some additional actions +if ! is_global_zone; then + reexport_pool +fi diff --git a/tests/sys/cddl/zfs/include/libgnop.kshlib b/tests/sys/cddl/zfs/include/libgnop.kshlib new file mode 100644 index 00000000000..1e285bb9f02 --- /dev/null +++ b/tests/sys/cddl/zfs/include/libgnop.kshlib @@ -0,0 +1,98 @@ +# vim: filetype=sh +# +# Copyright (c) 2017 Spectra Logic Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions, and the following disclaimer, +# without modification. +# 2. Redistributions in binary form must reproduce at minimum a disclaimer +# substantially similar to the "NO WARRANTY" disclaimer below +# ("Disclaimer") and any redistribution must be conditioned upon +# including a substantially similar Disclaimer requirement for further +# binary redistribution. +# +# NO WARRANTY +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGES. +# +# $FreeBSD$ +# + +# +# Routines that use gnop(8) to simulate devices that can disappear at any time +# + +# Create a gnop device on top of a real device. Don't use the full extent; use +# a portion in the middle so that any ZFS label present on the real device +# won't be present on the gnop device and vice versa. +function create_gnop +{ + # Name of disk to use, with or without /dev/ + typeset disk=$1 + # Optional physical path to use + typeset physpath=$2 + # size of disk in bytes + typeset -li disk_size + # disk size, rounded down to multiple of 16384 + typeset -li disk_size_rounded + # size of the nop device in bytes + typeset -li nop_size + # offset of the beginning of the nop device in bytes + typeset -li nop_offset + typeset args + + disk_size=`diskinfo $disk | cut -f 3` + # Round it down so the nop device will be 4k-aligned + disk_size_rounded=$(( ${disk_size} / 16384 * 16384 )) + nop_size=$(( ${disk_size_rounded} / 4 )) + nop_offset=${nop_size} + args="-s ${nop_size} -o ${nop_offset}" + if [ -n "$physpath" ]; then + args="$args -z $physpath" + fi + + gnop create ${args} ${disk} +} + +# Create multiple gnop devices +function create_gnops +{ + typeset disk + for disk in $@; do + create_gnop "$disk" || return 1 + done + return 0 +} + +# Destroy a gnop device. +function destroy_gnop +{ + # Name of the underlying (non-gnop) device + typeset disk=$1 + + # Use "-f" so we can destroy a gnop with a consumer (like ZFS) + gnop destroy -f ${disk}.nop +} + +# Destroy multiple gnop devices. Attempt to destroy them all, ignoring errors +function destroy_gnops +{ + typeset disk + for disk in $@; do + destroy_gnop "$disk" + done + return 0 +} diff --git a/tests/sys/cddl/zfs/include/libremote.kshlib b/tests/sys/cddl/zfs/include/libremote.kshlib new file mode 100644 index 00000000000..85acf6f14c8 --- /dev/null +++ b/tests/sys/cddl/zfs/include/libremote.kshlib @@ -0,0 +1,47 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)libremote.kshlib 1.1 07/05/25 SMI" +# + +# Check if a package is installed +# $1 package name +# Return 0 if it is installed; 1 if not installed +function pkg_isinstalled +{ + /usr/bin/pkginfo -q $1 + return $? +} + +# Get the installation base for a package +# $1 package name +# Return +function pkg_getinstbase +{ + /bin/echo $(/usr/bin/pkginfo -r $1 2>/dev/null) +} diff --git a/tests/sys/cddl/zfs/include/libtest.kshlib b/tests/sys/cddl/zfs/include/libtest.kshlib new file mode 100644 index 00000000000..30589649e12 --- /dev/null +++ b/tests/sys/cddl/zfs/include/libtest.kshlib @@ -0,0 +1,3480 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)libtest.kshlib 1.15 09/08/06 SMI" +# + +. ${STF_SUITE}/include/logapi.kshlib + +ZFS=${ZFS:-/sbin/zfs} +ZPOOL=${ZPOOL:-/sbin/zpool} +os_name=`uname -s` + +# Determine if a test has the necessary requirements to run + +function test_requires +{ + integer unsupported=0 + unsupported_list="" + until [[ $# -eq 0 ]];do + var_name=$1 + cmd=$(eval echo \$${1}) + if [[ ! "$cmd" != "" ]] ; then + print $var_name is not set + unsupported_list="$var_name $unsupported_list" + ((unsupported=unsupported+1)) + fi + shift + done + if [[ unsupported -gt 0 ]] ; then + log_unsupported "$unsupported_list commands are unsupported" + else + log_note "All commands are supported" + fi +} + +# Determine whether a dataset is mounted +# +# $1 dataset name +# $2 filesystem type; optional - defaulted to zfs +# +# Return 0 if dataset is mounted; 1 if unmounted; 2 on error + +function ismounted +{ + typeset fstype=$2 + [[ -z $fstype ]] && fstype=zfs + typeset out dir name ret + + case $fstype in + zfs) + if [[ "$1" == "/"* ]] ; then + for out in $($ZFS mount | $AWK '{print $2}') ; do + [[ $1 == $out ]] && return 0 + done + else + for out in $($ZFS mount | $AWK '{print $1}') ; do + [[ $1 == $out ]] && return 0 + done + fi + ;; + ufs|nfs) + # a = device, b = "on", c = mount point", d = flags + $MOUNT | $GREP $fstype | while read a b c d + do + [[ "$1" == "$a" || "$1" == "$c" ]] && return 0 + done + ;; + esac + + return 1 +} + +# Return 0 if a dataset is mounted; 1 otherwise +# +# $1 dataset name +# $2 filesystem type; optional - defaulted to zfs + +function mounted +{ + ismounted $1 $2 + (( $? == 0 )) && return 0 + return 1 +} + +# Return 0 if a dataset is unmounted; 1 otherwise +# +# $1 dataset name +# $2 filesystem type; optional - defaulted to zfs + +function unmounted +{ + ismounted $1 $2 + (( $? == 1 )) && return 0 + return 1 +} + +# split line on "," +# +# $1 - line to split + +function splitline +{ + $ECHO $1 | $SED "s/,/ /g" +} + +function default_setup +{ + default_setup_noexit "$@" + + log_pass +} + +# +# Given a list of disks, setup storage pools and datasets. +# +function default_setup_noexit +{ + typeset disklist=$1 + typeset container=$2 + typeset volume=$3 + + if is_global_zone; then + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL + log_must $ZPOOL create -f $TESTPOOL $disklist + else + reexport_pool + fi + + $RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR + $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR + + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + if [[ -n $container ]]; then + $RM -rf $TESTDIR1 || \ + log_unresolved Could not remove $TESTDIR1 + $MKDIR -p $TESTDIR1 || \ + log_unresolved Could not create $TESTDIR1 + + log_must $ZFS create $TESTPOOL/$TESTCTR + log_must $ZFS set canmount=off $TESTPOOL/$TESTCTR + log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1 + log_must $ZFS set mountpoint=$TESTDIR1 \ + $TESTPOOL/$TESTCTR/$TESTFS1 + fi + + if [[ -n $volume ]]; then + if is_global_zone ; then + log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL + else + log_must $ZFS create $TESTPOOL/$TESTVOL + fi + + fi +} + +# +# Given a list of disks, setup a storage pool, file system and +# a container. +# +function default_container_setup +{ + typeset disklist=$1 + + default_setup "$disklist" "true" +} + +# +# Given a list of disks, setup a storage pool,file system +# and a volume. +# +function default_volume_setup +{ + typeset disklist=$1 + + default_setup "$disklist" "" "true" +} + +# +# Given a list of disks, setup a storage pool,file system, +# a container and a volume. +# +function default_container_volume_setup +{ + typeset disklist=$1 + + default_setup "$disklist" "true" "true" +} + +# +# Create a snapshot on a filesystem or volume. Defaultly create a snapshot on +# filesystem +# +# $1 Existing filesystem or volume name. Default, $TESTFS +# $2 snapshot name. Default, $TESTSNAP +# +function create_snapshot +{ + typeset fs_vol=${1:-$TESTFS} + typeset snap=${2:-$TESTSNAP} + + [[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined." + [[ -z $snap ]] && log_fail "Snapshot's name is undefined." + + if snapexists $fs_vol@$snap; then + log_fail "$fs_vol@$snap already exists." + fi + datasetexists $fs_vol || \ + log_fail "$fs_vol must exist." + + log_must $ZFS snapshot $fs_vol@$snap +} + +# +# Create a clone from a snapshot, default clone name is $TESTCLONE. +# +# $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default. +# $2 Clone name, $TESTPOOL/$TESTCLONE is default. +# +function create_clone # snapshot clone +{ + typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP} + typeset clone=${2:-$TESTPOOL/$TESTCLONE} + + [[ -z $snap ]] && \ + log_fail "Snapshot name is undefined." + [[ -z $clone ]] && \ + log_fail "Clone name is undefined." + + log_must $ZFS clone $snap $clone +} + +function default_mirror_setup +{ + default_mirror_setup_noexit $1 $2 $3 + + log_pass +} + +# +# Given a pair of disks, set up a storage pool and dataset for the mirror +# @parameters: $1 the primary side of the mirror +# $2 the secondary side of the mirror +# @uses: ZPOOL ZFS TESTPOOL TESTFS +function default_mirror_setup_noexit +{ + readonly func="default_mirror_setup_noexit" + typeset primary=$1 + typeset secondary=$2 + + [[ -z $primary ]] && \ + log_fail "$func: No parameters passed" + [[ -z $secondary ]] && \ + log_fail "$func: No secondary partition passed" + [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL + log_must $ZPOOL create -f $TESTPOOL mirror $@ + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +# +# create a number of mirrors. +# We create a number($1) of 2 way mirrors using the pairs of disks named +# on the command line. These mirrors are *not* mounted +# @parameters: $1 the number of mirrors to create +# $... the devices to use to create the mirrors on +# @uses: ZPOOL ZFS TESTPOOL +function setup_mirrors +{ + typeset -i nmirrors=$1 + + shift + while (( nmirrors > 0 )); do + log_must test -n "$1" -a -n "$2" + [[ -d /$TESTPOOL$nmirrors ]] && $RM -rf /$TESTPOOL$nmirrors + log_must $ZPOOL create -f $TESTPOOL$nmirrors mirror $1 $2 + shift 2 + (( nmirrors = nmirrors - 1 )) + done +} + +# +# create a number of raidz pools. +# We create a number($1) of 2 raidz pools using the pairs of disks named +# on the command line. These pools are *not* mounted +# @parameters: $1 the number of pools to create +# $... the devices to use to create the pools on +# @uses: ZPOOL ZFS TESTPOOL +function setup_raidzs +{ + typeset -i nraidzs=$1 + + shift + while (( nraidzs > 0 )); do + log_must test -n "$1" -a -n "$2" + [[ -d /$TESTPOOL$nraidzs ]] && $RM -rf /$TESTPOOL$nraidzs + log_must $ZPOOL create -f $TESTPOOL$nraidzs raidz $1 $2 + shift 2 + (( nraidzs = nraidzs - 1 )) + done +} + +# +# Destroy the configured testpool mirrors. +# the mirrors are of the form ${TESTPOOL}{number} +# @uses: ZPOOL ZFS TESTPOOL +function destroy_mirrors +{ + default_cleanup_noexit + + log_pass +} + +# +# Given a minimum of two disks, set up a storage pool and dataset for the raid-z +# $1 the list of disks +# +function default_raidz_setup +{ + typeset disklist="$*" + set -A disks $disklist + + if [[ ${#disks[*]} -lt 2 ]]; then + log_fail "A raid-z requires a minimum of two disks." + fi + + [[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL + log_must $ZPOOL create -f $TESTPOOL raidz $1 $2 $3 + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + log_pass +} + +# +# Common function used to cleanup storage pools and datasets. +# +# Invoked at the start of the test suite to ensure the system +# is in a known state, and also at the end of each set of +# sub-tests to ensure errors from one set of tests doesn't +# impact the execution of the next set. + +function default_cleanup +{ + default_cleanup_noexit + + log_pass +} + +function all_pools +{ + cmd="$ZPOOL list -H -o name | $GREP 'testpool'" + eval $cmd +} + +# +# Returns 0 if the system contains any pools that must not be modified by the +# ZFS tests. +# +function other_pools_exist +{ + typeset pool_count=`$ZPOOL list -H | $GREP -v '^testpool' | $WC -l` + [ "$pool_count" -ne 0 ] +} + +function default_cleanup_noexit +{ + typeset exclude="" + typeset pool="" + # + # Destroying the pool will also destroy any + # filesystems it contains. + # + if is_global_zone; then + # Here, we loop through the pools we're allowed to + # destroy, only destroying them if it's safe to do + # so. + for pool in $(all_pools); do + if safe_to_destroy_pool $pool; then + destroy_pool $pool + fi + done + else + typeset fs="" + for fs in $($ZFS list -H -o name \ + | $GREP "^$ZONE_POOL/$ZONE_CTR[01234]/"); do + datasetexists $fs && \ + log_must $ZFS destroy -Rf $fs + done + + # Need cleanup here to avoid garbage dir left. + for fs in $($ZFS list -H -o name \ + ); do + [[ $fs == /$ZONE_POOL ]] && continue + [[ -d $fs ]] && log_must $RM -rf $fs/* + done + + # + # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to + # the default value + # + for fs in $($ZFS list -H -o name \ + ); do + if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then + log_must $ZFS set reservation=none $fs + log_must $ZFS set recordsize=128K $fs + log_must $ZFS set mountpoint=/$fs $fs + typeset enc="" + enc=$(get_prop encryption $fs) + if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || \ + [[ "$enc" == "off" ]]; then + log_must $ZFS set checksum=on $fs + fi + log_must $ZFS set compression=off $fs + log_must $ZFS set atime=on $fs + log_must $ZFS set devices=off $fs + log_must $ZFS set exec=on $fs + log_must $ZFS set setuid=on $fs + log_must $ZFS set readonly=off $fs + log_must $ZFS set snapdir=hidden $fs + log_must $ZFS set aclmode=groupmask $fs + log_must $ZFS set aclinherit=secure $fs + fi + done + fi + + [[ -d $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR +} + + +# +# Common function used to cleanup storage pools, file systems +# and containers. +# +function default_container_cleanup +{ + if ! is_global_zone; then + reexport_pool + fi + + ismounted $TESTPOOL/$TESTCTR/$TESTFS1 + [[ $? -eq 0 ]] && \ + log_must $ZFS unmount $TESTPOOL/$TESTCTR/$TESTFS1 + + datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \ + log_must $ZFS destroy -R $TESTPOOL/$TESTCTR/$TESTFS1 + + datasetexists $TESTPOOL/$TESTCTR && \ + log_must $ZFS destroy -Rf $TESTPOOL/$TESTCTR + + [[ -e $TESTDIR1 ]] && \ + log_must $RM -rf $TESTDIR1 > /dev/null 2>&1 + + default_cleanup +} + +# +# Common function used to cleanup snapshot of file system or volume. Default to +# delete the file system's snapshot +# +# $1 snapshot name +# +function destroy_snapshot +{ + typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP} + + if ! snapexists $snap; then + log_fail "'$snap' does not existed." + fi + + # + # For the sake of the value which come from 'get_prop' is not equal + # to the really mountpoint when the snapshot is unmounted. So, firstly + # check and make sure this snapshot's been mounted in current system. + # + typeset mtpt="" + if ismounted $snap; then + mtpt=$(get_prop mountpoint $snap) + (( $? != 0 )) && \ + log_fail "get_prop mountpoint $snap failed." + fi + + log_must $ZFS destroy $snap + [[ $mtpt != "" && -d $mtpt ]] && \ + log_must $RM -rf $mtpt +} + +# +# Common function used to cleanup clone. +# +# $1 clone name +# +function destroy_clone +{ + typeset clone=${1:-$TESTPOOL/$TESTCLONE} + + if ! datasetexists $clone; then + log_fail "'$clone' does not existed." + fi + + # With the same reason in destroy_snapshot + typeset mtpt="" + if ismounted $clone; then + mtpt=$(get_prop mountpoint $clone) + (( $? != 0 )) && \ + log_fail "get_prop mountpoint $clone failed." + fi + + log_must $ZFS destroy $clone + [[ $mtpt != "" && -d $mtpt ]] && \ + log_must $RM -rf $mtpt +} + +# Return 0 if a snapshot exists; $? otherwise +# +# $1 - snapshot name + +function snapexists +{ + $ZFS list -H -t snapshot "$1" > /dev/null 2>&1 + return $? +} + +# +# Set a property to a certain value on a dataset. +# Sets a property of the dataset to the value as passed in. +# @param: +# $1 dataset who's property is being set +# $2 property to set +# $3 value to set property to +# @return: +# 0 if the property could be set. +# non-zero otherwise. +# @use: ZFS +# +function dataset_setprop +{ + typeset fn=dataset_setprop + + if (( $# < 3 )); then + log_note "$fn: Insufficient parameters (need 3, had $#)" + return 1 + fi + typeset output= + output=$($ZFS set $2=$3 $1 2>&1) + typeset rv=$? + if (( rv != 0 )); then + log_note "Setting property on $1 failed." + log_note "property $2=$3" + log_note "Return Code: $rv" + log_note "Output: $output" + return $rv + fi + return 0 +} + +# +# Assign suite defined dataset properties. +# This function is used to apply the suite's defined default set of +# properties to a dataset. +# @parameters: $1 dataset to use +# @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP +# @returns: +# 0 if the dataset has been altered. +# 1 if no pool name was passed in. +# 2 if the dataset could not be found. +# 3 if the dataset could not have it's properties set. +# +function dataset_set_defaultproperties +{ + typeset dataset="$1" + + [[ -z $dataset ]] && return 1 + + typeset confset= + typeset -i found=0 + for confset in $($ZFS list); do + if [[ $dataset = $confset ]]; then + found=1 + break + fi + done + [[ $found -eq 0 ]] && return 2 + if [[ -n $COMPRESSION_PROP ]]; then + dataset_setprop $dataset compression $COMPRESSION_PROP || \ + return 3 + log_note "Compression set to '$COMPRESSION_PROP' on $dataset" + fi + if [[ -n $CHECKSUM_PROP && $WRAPPER != *"crypto"* ]]; then + dataset_setprop $dataset checksum $CHECKSUM_PROP || \ + return 3 + log_note "Checksum set to '$CHECKSUM_PROP' on $dataset" + fi + return 0 +} + +# +# Check a numeric assertion +# @parameter: $@ the assertion to check +# @output: big loud notice if assertion failed +# @use: log_fail +# +function assert +{ + (( $@ )) || log_fail $@ +} + +function wipe_partition_table # [ ...] +{ + while [[ -n $* ]]; do + typeset diskname=$1 + [ ! -e $diskname ] && log_fail "ERROR: $diskname doesn't exist" + if gpart list $(basename $diskname) >/dev/null 2>&1; then + wait_for 5 1 $GPART destroy -F $diskname + else + log_note "No GPT partitions detected on $diskname" + fi + log_must $GPART create -s gpt $diskname + shift + done +} + +# +# Given a slice, size and disk, this function +# formats the slice to the specified size. +# Size should be specified with units as per +# the `format` command requirements eg. 100mb 3gb +# +function set_partition # +{ + typeset -i slicenum=$1 + typeset start=$2 + typeset size=$3 + typeset disk=$4 + set -A devmap a b c d e f g h + [[ -z $slicenum || -z $size || -z $disk ]] && \ + log_fail "The slice, size or disk name is unspecified." + + size=`$ECHO $size| sed s/mb/M/` + size=`$ECHO $size| sed s/m/M/` + size=`$ECHO $size| sed s/gb/G/` + size=`$ECHO $size| sed s/g/G/` + [[ -n $start ]] && start="-b $start" + log_must $GPART add -t efi $start -s $size -i $slicenum $disk + return 0 +} + +function get_disk_size # +{ + typeset disk=$1 + diskinfo da0 | awk '{print $3}' +} + +function get_available_disk_size # +{ + typeset disk=$1 + raw_size=`get_disk_size $disk` + (( available_size = raw_size * 95 / 100 )) + echo $available_size +} + +# +# Get the end cyl of the given slice +# #TODO: fix this to be GPT-compatible if we want to use the SMI WRAPPER. This +# function is not necessary on FreeBSD +# +function get_endslice # +{ + log_fail "get_endslice has not been updated for GPT partitions" +} + +# +# Get the first LBA that is beyond the end of the given partition +function get_partition_end # +{ + typeset disk=$1 + typeset partition_index=$2 + export partition_index + $GPART show $disk | $AWK \ + '/^[ \t]/ && $3 ~ ENVIRON["partition_index"] {print $1 + $2}' +} + + +# +# Given a size,disk and total number of partitions, this function formats the +# disk partitions from 0 to the total partition number with the same specified +# size. +# +function partition_disk # +{ + typeset -i i=1 + typeset part_size=$1 + typeset disk_name=$2 + typeset total_parts=$3 + typeset cyl + + wipe_partition_table $disk_name + while (( i <= $total_parts )); do + set_partition $i "" $part_size $disk_name + (( i = i+1 )) + done +} + +function size_of_file # fname +{ + typeset fname=$1 + sz=`stat -f '%z' $fname` + [[ -z "$sz" ]] && log_fail "stat($fname) failed" + $ECHO $sz + return 0 +} + +# +# This function continues to write to a filenum number of files into dirnum +# number of directories until either $FILE_WRITE returns an error or the +# maximum number of files per directory have been written. +# +# Usage: +# fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data] +# +# Return value: 0 on success +# non 0 on error +# +# Where : +# destdir: is the directory where everything is to be created under +# dirnum: the maximum number of subdirectories to use, -1 no limit +# filenum: the maximum number of files per subdirectory +# blocksz: number of bytes per block +# num_writes: number of blocks to write +# data: the data that will be written +# +# E.g. +# file_fs /testdir 20 25 1024 256 0 +# +# Note: blocksz * num_writes equals the size of the testfile +# +function fill_fs # destdir dirnum filenum blocksz num_writes data +{ + typeset destdir=${1:-$TESTDIR} + typeset -i dirnum=${2:-50} + typeset -i filenum=${3:-50} + typeset -i blocksz=${4:-8192} + typeset -i num_writes=${5:-10240} + typeset -i data=${6:-0} + + typeset -i retval=0 + typeset -i dn=0 # current dir number + typeset -i fn=0 # current file number + while (( retval == 0 )); do + (( dirnum >= 0 && dn >= dirnum )) && break + typeset curdir=$destdir/$dn + log_must $MKDIR -p $curdir + for (( fn = 0; $fn < $filenum && $retval == 0; fn++ )); do + log_cmd $FILE_WRITE -o create -f $curdir/$TESTFILE.$fn \ + -b $blocksz -c $num_writes -d $data + retval=$? + done + (( dn = dn + 1 )) + done + return $retval +} + +# +# Simple function to get the specified property. If unable to +# get the property then exits. +# +# Note property is in 'parsable' format (-p) +# +function get_prop # property dataset +{ + typeset prop_val + typeset prop=$1 + typeset dataset=$2 + + prop_val=$($ZFS get -pH -o value $prop $dataset 2>/dev/null) + if [[ $? -ne 0 ]]; then + log_note "Unable to get $prop property for dataset $dataset" + return 1 + fi + + $ECHO $prop_val + return 0 +} + +# +# Simple function to return the lesser of two values. +# +function min +{ + typeset first_arg=$1 + typeset second_arg=$2 + + if (( first_arg < second_arg )); then + $ECHO $first_arg + else + $ECHO $second_arg + fi + return 0 +} + +# +# Simple function to get the specified property of pool. If unable to +# get the property then exits. +# +function get_pool_prop # property pool +{ + typeset prop_val + typeset prop=$1 + typeset pool=$2 + + if poolexists $pool ; then + prop_val=$($ZPOOL get $prop $pool 2>/dev/null | $TAIL -1 | \ + $AWK '{print $3}') + if [[ $? -ne 0 ]]; then + log_note "Unable to get $prop property for pool " \ + "$pool" + return 1 + fi + else + log_note "Pool $pool not exists." + return 1 + fi + + $ECHO $prop_val + return 0 +} + +# Return 0 if a pool exists; $? otherwise +# +# $1 - pool name + +function poolexists +{ + typeset pool=$1 + + if [[ -z $pool ]]; then + log_note "No pool name given." + return 1 + fi + + $ZPOOL list -H "$pool" > /dev/null 2>&1 + return $? +} + +# Return 0 if all the specified datasets exist; $? otherwise +# +# $1-n dataset name +function datasetexists +{ + if (( $# == 0 )); then + log_note "No dataset name given." + return 1 + fi + + while (( $# > 0 )); do + $ZFS list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 || \ + return $? + shift + done + + return 0 +} + +# return 0 if none of the specified datasets exists, otherwise return 1. +# +# $1-n dataset name +function datasetnonexists +{ + if (( $# == 0 )); then + log_note "No dataset name given." + return 1 + fi + + while (( $# > 0 )); do + $ZFS list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 && \ + return 1 + shift + done + + return 0 +} + +# +# Given a mountpoint, or a dataset name, determine if it is shared. +# +# Returns 0 if shared, 1 otherwise. +# +function is_shared +{ + typeset fs=$1 + typeset mtpt + + if [[ $fs != "/"* ]] ; then + if datasetnonexists "$fs" ; then + return 1 + else + mtpt=$(get_prop mountpoint "$fs") + case $mtpt in + none|legacy|-) return 1 + ;; + *) fs=$mtpt + ;; + esac + fi + fi + + for mtpt in `$SHARE | $AWK '{print $2}'` ; do + if [[ $mtpt == $fs ]] ; then + return 0 + fi + done + + typeset stat=$($SVCS -H -o STA nfs/server:default) + if [[ $stat != "ON" ]]; then + log_note "Current nfs/server status: $stat" + fi + + return 1 +} + +# +# Given a mountpoint, determine if it is not shared. +# +# Returns 0 if not shared, 1 otherwise. +# +function not_shared +{ + typeset fs=$1 + + is_shared $fs + if (( $? == 0)); then + return 1 + fi + + return 0 +} + +# +# Helper function to unshare a mountpoint. +# +function unshare_fs #fs +{ + typeset fs=$1 + + is_shared $fs + if (( $? == 0 )); then + log_must $ZFS unshare $fs + fi + + return 0 +} + +# +# Check NFS server status and trigger it online. +# +function setup_nfs_server +{ + # Cannot share directory in non-global zone. + # + if ! is_global_zone; then + log_note "Cannot trigger NFS server by sharing in LZ." + return + fi + + typeset nfs_fmri="svc:/network/nfs/server:default" + if [[ $($SVCS -Ho STA $nfs_fmri) != "ON" ]]; then + # + # Only really sharing operation can enable NFS server + # to online permanently. + # + typeset dummy=$TMPDIR/dummy + + if [[ -d $dummy ]]; then + log_must $RM -rf $dummy + fi + + log_must $MKDIR $dummy + log_must $SHARE $dummy + + # + # Waiting for fmri's status to be the final status. + # Otherwise, in transition, an asterisk (*) is appended for + # instances, unshare will reverse status to 'DIS' again. + # + # Waiting for 1's at least. + # + log_must $SLEEP 1 + timeout=10 + while [[ timeout -ne 0 && $($SVCS -Ho STA $nfs_fmri) == *'*' ]] + do + log_must $SLEEP 1 + + (( timeout -= 1 )) + done + + log_must $UNSHARE $dummy + log_must $RM -rf $dummy + fi + + log_note "Current NFS status: '$($SVCS -Ho STA,FMRI $nfs_fmri)'" +} + +# +# To verify whether calling process is in global zone +# +# Return 0 if in global zone, 1 in non-global zone +# +function is_global_zone +{ + typeset cur_zone=$($ZONENAME 2>/dev/null) + + # Zones are not supported on FreeBSD. + if [[ $os_name == "FreeBSD" ]]; then + return 0 + fi + + if [[ $cur_zone != "global" ]]; then + return 1 + fi + return 0 +} + +# +# Verify whether test is permit to run from +# global zone, local zone, or both +# +# $1 zone limit, could be "global", "local", or "both"(no limit) +# +# Return 0 if permit, otherwise exit with log_unsupported +# +function verify_runnable # zone limit +{ + typeset limit=$1 + + [[ -z $limit ]] && return 0 + + if is_global_zone ; then + case $limit in + global|both) + break + ;; + local) log_unsupported "Test is unable to run from \ + global zone." + break + ;; + *) log_note "Warning: unknown limit $limit - use both." + ;; + esac + else + case $limit in + local|both) + break + ;; + global) log_unsupported "Test is unable to run from \ + local zone." + break + ;; + *) log_note "Warning: unknown limit $limit - use both." + ;; + esac + + reexport_pool + fi + + return 0 +} + +# Return 0 if create successfully or the pool exists; $? otherwise +# Note: In local zones, this function should return 0 silently. +# +# $1 - pool name +# $2-n - [keyword] devs_list + +function create_pool #pool devs_list +{ + typeset pool=${1%%/*} + + shift + + if [[ -z $pool ]]; then + log_note "Missing pool name." + return 1 + fi + + if poolexists $pool ; then + destroy_pool $pool + fi + + if is_global_zone ; then + [[ -d /$pool ]] && $RM -rf /$pool + log_must $ZPOOL create -f $pool $@ + fi + + return 0 +} + +# Return 0 if destroy successfully or the pool exists; $? otherwise +# Note: In local zones, this function should return 0 silently. +# +# $1 - pool name +# Destroy pool with the given parameters. + +function destroy_pool #pool +{ + typeset pool=${1%%/*} + typeset mtpt + + if [[ -z $pool ]]; then + log_note "No pool name given." + return 1 + fi + + if is_global_zone ; then + if poolexists "$pool" ; then + mtpt=$(get_prop mountpoint "$pool") + log_must $ZPOOL destroy -f $pool + + [[ -d $mtpt ]] && \ + log_must $RM -rf $mtpt + else + log_note "Pool $pool does not exist, skipping destroy." + return 1 + fi + fi + + return 0 +} + +# +# Create file vdevs. +# By default this generates sparse vdevs 10GB in size, for performance. +# +function create_vdevs # vdevs +{ + typeset vdsize=10G + + [ -n "$VDEV_SIZE" ] && vdsize=$VDEV_SIZE + rm -f $@ || return 1 + truncate -s $vdsize $@ +} + +# +# Firstly, create a pool with 5 datasets. Then, create a single zone and +# export the 5 datasets to it. In addition, we also add a ZFS filesystem +# and a zvol device to the zone. +# +# $1 zone name +# $2 zone root directory prefix +# $3 zone ip +# +function zfs_zones_setup #zone_name zone_root zone_ip +{ + typeset zone_name=${1:-$(hostname)-z} + typeset zone_root=${2:-"/zone_root"} + typeset zone_ip=${3:-"10.1.1.10"} + typeset prefix_ctr=$ZONE_CTR + typeset pool_name=$ZONE_POOL + typeset -i cntctr=5 + typeset -i i=0 + + # Create pool and 5 container within it + # + [[ -d /$pool_name ]] && $RM -rf /$pool_name + log_must $ZPOOL create -f $pool_name $DISKS + while (( i < cntctr )); do + log_must $ZFS create $pool_name/$prefix_ctr$i + (( i += 1 )) + done + + # create a zvol + log_must $ZFS create -V 1g $pool_name/zone_zvol + + # + # If current system support slog, add slog device for pool + # + typeset sdevs="$TMPDIR/sdev1 $TMPDIR/sdev2" + log_must create_vdevs $sdevs + log_must $ZPOOL add $pool_name log mirror $sdevs + + # this isn't supported just yet. + # Create a filesystem. In order to add this to + # the zone, it must have it's mountpoint set to 'legacy' + # log_must $ZFS create $pool_name/zfs_filesystem + # log_must $ZFS set mountpoint=legacy $pool_name/zfs_filesystem + + [[ -d $zone_root ]] && \ + log_must $RM -rf $zone_root/$zone_name + [[ ! -d $zone_root ]] && \ + log_must $MKDIR -p -m 0700 $zone_root/$zone_name + + # Create zone configure file and configure the zone + # + typeset zone_conf=$TMPDIR/zone_conf.${TESTCASE_ID} + $ECHO "create" > $zone_conf + $ECHO "set zonepath=$zone_root/$zone_name" >> $zone_conf + $ECHO "set autoboot=true" >> $zone_conf + i=0 + while (( i < cntctr )); do + $ECHO "add dataset" >> $zone_conf + $ECHO "set name=$pool_name/$prefix_ctr$i" >> \ + $zone_conf + $ECHO "end" >> $zone_conf + (( i += 1 )) + done + + # add our zvol to the zone + $ECHO "add device" >> $zone_conf + $ECHO "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf + $ECHO "end" >> $zone_conf + + # add a corresponding zvol rdsk to the zone + $ECHO "add device" >> $zone_conf + $ECHO "set match=/dev/zvol/rdsk/$pool_name/zone_zvol" >> $zone_conf + $ECHO "end" >> $zone_conf + + # once it's supported, we'll add our filesystem to the zone + # $ECHO "add fs" >> $zone_conf + # $ECHO "set type=zfs" >> $zone_conf + # $ECHO "set special=$pool_name/zfs_filesystem" >> $zone_conf + # $ECHO "set dir=/export/zfs_filesystem" >> $zone_conf + # $ECHO "end" >> $zone_conf + + $ECHO "verify" >> $zone_conf + $ECHO "commit" >> $zone_conf + log_must $ZONECFG -z $zone_name -f $zone_conf + log_must $RM -f $zone_conf + + # Install the zone + $ZONEADM -z $zone_name install + if (( $? == 0 )); then + log_note "SUCCESS: $ZONEADM -z $zone_name install" + else + log_fail "FAIL: $ZONEADM -z $zone_name install" + fi + + # Install sysidcfg file + # + typeset sysidcfg=$zone_root/$zone_name/root/etc/sysidcfg + $ECHO "system_locale=C" > $sysidcfg + $ECHO "terminal=dtterm" >> $sysidcfg + $ECHO "network_interface=primary {" >> $sysidcfg + $ECHO "hostname=$zone_name" >> $sysidcfg + $ECHO "}" >> $sysidcfg + $ECHO "name_service=NONE" >> $sysidcfg + $ECHO "root_password=mo791xfZ/SFiw" >> $sysidcfg + $ECHO "security_policy=NONE" >> $sysidcfg + $ECHO "timezone=US/Eastern" >> $sysidcfg + + # Boot this zone + log_must $ZONEADM -z $zone_name boot +} + +# +# Reexport TESTPOOL & TESTPOOL(1-4) +# +function reexport_pool +{ + typeset -i cntctr=5 + typeset -i i=0 + + while (( i < cntctr )); do + if (( i == 0 )); then + TESTPOOL=$ZONE_POOL/$ZONE_CTR$i + if ! ismounted $TESTPOOL; then + log_must $ZFS mount $TESTPOOL + fi + else + eval TESTPOOL$i=$ZONE_POOL/$ZONE_CTR$i + if eval ! ismounted \$TESTPOOL$i; then + log_must eval $ZFS mount \$TESTPOOL$i + fi + fi + (( i += 1 )) + done +} + +# +# Wait for something to return true, checked by the caller. +# +function wait_for_checked # timeout dt [args...] +{ + typeset timeout=$1 + typeset dt=$2 + shift; shift + typeset -i start=$(date '+%s') + typeset -i endtime + + log_note "Waiting $timeout seconds (checked every $dt seconds) for: $*" + ((endtime = start + timeout)) + while :; do + $* + [ $? -eq 0 ] && return + curtime=$(date '+%s') + [ $curtime -gt $endtime ] && return 1 + sleep $dt + done + return 0 +} + +# +# Wait for something to return true. +# +function wait_for # timeout dt [args...] +{ + typeset timeout=$1 + typeset dt=$2 + shift; shift + + wait_for_checked $timeout $dt $* || \ + log_fail "ERROR: Timed out waiting for: $*" +} + +# +# Verify a given disk is online or offline +# +# Return 0 is pool/disk matches expected state, 1 otherwise +# stateexpr is a regex like ONLINE or REMOVED|UNAVAIL +# +function check_state # pool disk stateexpr +{ + typeset pool=$1 + typeset disk=${2#/dev/dsk/} + disk=${disk#/dev/rdsk/} + disk=${disk#/dev/} + typeset stateexpr=$3 + + $ZPOOL status -v $pool | grep "$disk" \ + | egrep -i "$stateexpr" > /dev/null 2>&1 + + return $? +} + +# +# Wait for a given disk to leave a state +# +function wait_for_state_exit +{ + typeset pool=$1 + typeset disk=$2 + typeset state=$3 + + while check_state "$pool" "$disk" "$state"; do + $SLEEP 1 + done +} + +# +# Wait for a given disk to enter a state +# +function wait_for_state_enter +{ + typeset -i timeout=$1 + typeset pool=$2 + typeset disk=$3 + typeset state=$4 + + log_note "Waiting up to $timeout seconds for $disk to become $state ..." + for ((; $timeout > 0; timeout=$timeout-1)); do + check_state $pool "$disk" "$state" + [ $? -eq 0 ] && return + $SLEEP 1 + done + log_must $ZPOOL status $pool + log_fail "ERROR: Disk $disk not marked as $state in $pool" +} + +# +# Get the mountpoint of snapshot +# as its mountpoint +# +function snapshot_mountpoint +{ + typeset dataset=${1:-$TESTPOOL/$TESTFS@$TESTSNAP} + + if [[ $dataset != *@* ]]; then + log_fail "Error name of snapshot '$dataset'." + fi + + typeset fs=${dataset%@*} + typeset snap=${dataset#*@} + + if [[ -z $fs || -z $snap ]]; then + log_fail "Error name of snapshot '$dataset'." + fi + + $ECHO $(get_prop mountpoint $fs)/$(get_snapdir_name)/$snap +} + +function pool_maps_intact # pool +{ + typeset pool="$1" + + if ! $ZDB -bcv $pool; then + return 1 + fi + return 0 +} + +function filesys_has_zil # filesystem +{ + typeset filesys="$1" + + if ! $ZDB -ivv $filesys | $GREP "ZIL header"; then + return 1 + fi + return 0 +} + +# +# Given a pool and file system, this function will verify the file system +# using the zdb internal tool. Note that the pool is exported and imported +# to ensure it has consistent state. +# +function verify_filesys # pool filesystem dir +{ + typeset pool="$1" + typeset filesys="$2" + typeset zdbout="$TMPDIR/zdbout.${TESTCASE_ID}" + + shift + shift + typeset dirs=$@ + typeset search_path="" + + log_note "Calling $ZDB to verify filesystem '$filesys'" + log_must $ZPOOL export $pool + + if [[ -n $dirs ]] ; then + for dir in $dirs ; do + search_path="$search_path -d $dir" + done + fi + + log_must $ZPOOL import $search_path $pool + + $ZDB -cudi $filesys > $zdbout 2>&1 + if [[ $? != 0 ]]; then + log_note "Output: $ZDB -cudi $filesys" + $CAT $zdbout + log_fail "$ZDB detected errors with: '$filesys'" + fi + + log_must $RM -rf $zdbout +} + +# +# Given a pool, and this function list all disks in the pool +# +function get_disklist # pool +{ + typeset disklist="" + + disklist=$($ZPOOL iostat -v $1 | $NAWK '(NR >4 ) {print $1}' | \ + $GREP -v "\-\-\-\-\-" | \ + $EGREP -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$" ) + + $ECHO $disklist +} + +# +# Destroy all existing metadevices and state database +# +function destroy_metas +{ + typeset metad + + for metad in $($METASTAT -p | $AWK '{print $1}'); do + log_must $METACLEAR -rf $metad + done + + for metad in $($METADB | $CUT -f6 | $GREP dev | $UNIQ); do + log_must $METADB -fd $metad + done +} + +# /** +# This function kills a given list of processes after a time period. We use +# this in the stress tests instead of STF_TIMEOUT so that we can have processes +# run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT +# would be listed as FAIL, which we don't want : we're happy with stress tests +# running for a certain amount of time, then finishing. +# +# @param $1 the time in seconds after which we should terminate these processes +# @param $2..$n the processes we wish to terminate. +# */ +function stress_timeout +{ + typeset -i TIMEOUT=$1 + shift + typeset cpids="$@" + + log_note "Waiting for child processes($cpids). " \ + "It could last dozens of minutes, please be patient ..." + log_must $SLEEP $TIMEOUT + + log_note "Killing child processes after ${TIMEOUT} stress timeout." + typeset pid + for pid in $cpids; do + $PS -p $pid > /dev/null 2>&1 + if (( $? == 0 )); then + log_must $KILL -USR1 $pid + fi + done +} + +# +# Check whether current OS support a specified feature or not +# +# return 0 if current OS version is in unsupported list, 1 otherwise +# +# $1 unsupported target OS versions +# +function check_version # +{ + typeset unsupported_vers="$@" + typeset ver + typeset cur_ver=`$UNAME -r` + + for ver in $unsupported_vers; do + [[ "$cur_ver" == "$ver" ]] && return 0 + done + + return 1 +} + +# +# Verify a given hotspare disk is inuse or avail +# +# Return 0 is pool/disk matches expected state, 1 otherwise +# +function check_hotspare_state # pool disk state{inuse,avail} +{ + typeset pool=$1 + typeset disk=${2#/dev/dsk/} + disk=${disk#/dev/rdsk/} + disk=${disk#/dev/} + typeset state=$3 + + cur_state=$(get_device_state $pool $disk "spares") + + if [[ $state != ${cur_state} ]]; then + return 1 + fi + return 0 +} + +# +# Verify a given slog disk is inuse or avail +# +# Return 0 is pool/disk matches expected state, 1 otherwise +# +function check_slog_state # pool disk state{online,offline,unavail} +{ + typeset pool=$1 + typeset disk=${2#/dev/dsk/} + disk=${disk#/dev/rdsk/} + disk=${disk#/dev/} + typeset state=$3 + + cur_state=$(get_device_state $pool $disk "logs") + + if [[ $state != ${cur_state} ]]; then + return 1 + fi + return 0 +} + +# +# Verify a given vdev disk is inuse or avail +# +# Return 0 is pool/disk matches expected state, 1 otherwise +# +function check_vdev_state # pool disk state{online,offline,unavail} +{ + typeset pool=$1 + typeset disk=${2#/dev/dsk/} + disk=${disk#/dev/rdsk/} + disk=${disk#/dev/} + typeset state=$3 + + if [[ $WRAPPER == *"smi"* ]]; then + $ECHO $disk | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 + if (( $? == 0 )); then + disk=${disk}s2 + fi + fi + + cur_state=$(get_device_state $pool $disk) + + if [[ $state != ${cur_state} ]]; then + return 1 + fi + return 0 +} + +# +# Check the output of 'zpool status -v ', +# and to see if the content of contain the specified. +# +# Return 0 is contain, 1 otherwise +# +function check_pool_status # pool token keyword +{ + typeset pool=$1 + typeset token=$2 + typeset keyword=$3 + + $ZPOOL status -v "$pool" 2>/dev/null | \ + $NAWK -v token="$token:" '($1==token) {print $0}' | \ + $GREP -i "$keyword" >/dev/null 2>&1 + + return $? +} + +function vdev_pool_error_count +{ + typeset errs=$1 + if [ -z "$2" ]; then + test $errs -gt 0; ret=$? + else + test $errs -eq $2; ret=$? + fi + log_debug "vdev_pool_error_count: errs='$errs' \$2='$2' ret='$ret'" + return $ret +} + +# +# Generate a pool status error file suitable for pool_errors_from_file. +# If the pool is healthy, returns 0. Otherwise, the caller must handle the +# returned temporarily file appropriately. +# +function pool_error_file # +{ + typeset pool="$1" + + typeset tmpfile=$TMPDIR/pool_status.${TESTCASE_ID} + $ZPOOL status -x $pool > ${tmpfile} + echo $tmpfile +} + +# +# Evaluates counting the number of errors. If vdev specified, only +# that vdev's errors are counted. Returns the total number. will be +# deleted on exit. +# +function pool_errors_from_file # [vdev] +{ + typeset file=$1 + shift + typeset checkvdev="$2" + + typeset line + typeset -i fetchbegin=1 + typeset -i errnum=0 + typeset -i c_read=0 + typeset -i c_write=0 + typeset -i c_cksum=0 + + cat ${file} | $EGREP -v "pool:" | while read line; do + if (( $fetchbegin != 0 )); then + $ECHO $line | $GREP "NAME" >/dev/null 2>&1 + (( $? == 0 )) && (( fetchbegin = 0 )) + continue + fi + + if [[ -n $checkvdev ]]; then + $ECHO $line | $GREP $checkvdev >/dev/null 2>&1 + (( $? != 0 )) && continue + c_read=`$ECHO $line | $AWK '{print $3}'` + c_write=`$ECHO $line | $AWK '{print $4}'` + c_cksum=`$ECHO $line | $AWK '{print $5}'` + if [ $c_read != 0 ] || [ $c_write != 0 ] || \ + [ $c_cksum != 0 ] + then + (( errnum = errnum + 1 )) + fi + break + fi + + c_read=`$ECHO $line | $AWK '{print $3}'` + c_write=`$ECHO $line | $AWK '{print $4}'` + c_cksum=`$ECHO $line | $AWK '{print $5}'` + if [ $c_read != 0 ] || [ $c_write != 0 ] || \ + [ $c_cksum != 0 ] + then + (( errnum = errnum + 1 )) + fi + done + + rm -f $file + echo $errnum +} + +# +# Returns whether the vdev has the given number of errors. +# If the number is unspecified, any non-zero number returns true. +# +function vdev_has_errors # pool vdev [errors] +{ + typeset pool=$1 + typeset vdev=$2 + typeset tmpfile=$(pool_error_file $pool) + log_note "Original pool status:" + cat $tmpfile + + typeset -i errs=$(pool_errors_from_file $tmpfile $vdev) + vdev_pool_error_count $errs $3 +} + +# +# Returns whether the pool has the given number of errors. +# If the number is unspecified, any non-zero number returns true. +# +function pool_has_errors # pool [errors] +{ + typeset pool=$1 + typeset tmpfile=$(pool_error_file $pool) + log_note "Original pool status:" + cat $tmpfile + + typeset -i errs=$(pool_errors_from_file $tmpfile) + vdev_pool_error_count $errs $2 +} + +# +# Returns whether clearing $pool at $vdev (if given) succeeds. +# +function pool_clear_succeeds +{ + typeset pool="$1" + typeset vdev=$2 + + $ZPOOL clear $pool $vdev + ! pool_has_errors $pool +} + +# +# Return whether the pool is healthy +# +function is_pool_healthy # pool +{ + typeset pool=$1 + + typeset healthy_output="pool '$pool' is healthy" + typeset real_output=$($ZPOOL status -x $pool) + + if [[ "$real_output" == "$healthy_output" ]]; then + return 0 + else + typeset -i ret + $ZPOOL status -x $pool | $GREP "state:" | \ + $GREP "FAULTED" >/dev/null 2>&1 + ret=$? + (( $ret == 0 )) && return 1 + typeset l_scan + typeset errnum + l_scan=$($ZPOOL status -x $pool | $GREP "scan:") + l_scan=${l_scan##*"with"} + errnum=$($ECHO $l_scan | $AWK '{print $1}') + if [ "$errnum" != "0" ]; then + return 1 + else + return 0 + fi + fi +} + +# +# These 5 following functions are instance of check_pool_status() +# is_pool_resilvering - to check if the pool is resilver in progress +# is_pool_resilvered - to check if the pool is resilver completed +# is_pool_scrubbing - to check if the pool is scrub in progress +# is_pool_scrubbed - to check if the pool is scrub completed +# is_pool_scrub_stopped - to check if the pool is scrub stopped +# +function is_pool_resilvering #pool +{ + check_pool_status "$1" "scan" "resilver in progress" + return $? +} + +function is_pool_resilvered #pool +{ + check_pool_status "$1" "scan" "resilvered" + return $? +} + +function resilver_happened # pool +{ + typeset pool=$1 + is_pool_resilvering "$pool" || is_pool_resilvered "$pool" +} + +function is_pool_scrubbing #pool +{ + check_pool_status "$1" "scan" "scrub in progress" + return $? +} + +function is_pool_scrubbed #pool +{ + check_pool_status "$1" "scan" "scrub repaired" + return $? +} + +function is_pool_scrub_stopped #pool +{ + check_pool_status "$1" "scan" "scrub canceled" + return $? +} + +function is_pool_state # pool state +{ + check_pool_status "$1" "state" "$2" + return $? +} + +# +# Erase the partition tables and destroy any zfs labels +# +function cleanup_devices #vdevs +{ + for device in $@; do + # Labelclear must happen first, otherwise it may interfere + # with the teardown/setup of GPT labels. + $ZPOOL labelclear -f $device + # Only wipe partition tables for arguments that are disks, + # as opposed to slices (which are valid arguments here). + if camcontrol inquiry $device >/dev/null 2>&1; then + wipe_partition_table $device + fi + done + return 0 +} + +# +# Verify the rsh connectivity to each remote host in RHOSTS. +# +# Return 0 if remote host is accessible; otherwise 1. +# $1 remote host name +# $2 username +# +function verify_rsh_connect #rhost, username +{ + typeset rhost=$1 + typeset username=$2 + typeset rsh_cmd="$RSH -n" + typeset cur_user= + + $GETENT hosts $rhost >/dev/null 2>&1 + if (( $? != 0 )); then + log_note "$rhost cannot be found from" \ + "administrative database." + return 1 + fi + + $PING $rhost 3 >/dev/null 2>&1 + if (( $? != 0 )); then + log_note "$rhost is not reachable." + return 1 + fi + + if (( ${#username} != 0 )); then + rsh_cmd="$rsh_cmd -l $username" + cur_user="given user \"$username\"" + else + cur_user="current user \"`$LOGNAME`\"" + fi + + if ! $rsh_cmd $rhost $TRUE; then + log_note "$RSH to $rhost is not accessible" \ + "with $cur_user." + return 1 + fi + + return 0 +} + +# +# Verify the remote host connection via rsh after rebooting +# $1 remote host +# +function verify_remote +{ + rhost=$1 + + # + # The following loop waits for the remote system rebooting. + # Each iteration will wait for 150 seconds. there are + # total 5 iterations, so the total timeout value will + # be 12.5 minutes for the system rebooting. This number + # is an approxiate number. + # + typeset -i count=0 + while ! verify_rsh_connect $rhost; do + sleep 150 + (( count = count + 1 )) + if (( count > 5 )); then + return 1 + fi + done + return 0 +} + +# +# Replacement function for /usr/bin/rsh. This function will include +# the /usr/bin/rsh and meanwhile return the execution status of the +# last command. +# +# $1 usrname passing down to -l option of /usr/bin/rsh +# $2 remote machine hostname +# $3... command string +# + +function rsh_status +{ + typeset ruser=$1 + typeset rhost=$2 + typeset -i ret=0 + typeset cmd_str="" + typeset rsh_str="" + + shift; shift + cmd_str="$@" + + err_file=$TMPDIR/${rhost}.${TESTCASE_ID}.err + if (( ${#ruser} == 0 )); then + rsh_str="$RSH -n" + else + rsh_str="$RSH -n -l $ruser" + fi + + $rsh_str $rhost /usr/local/bin/ksh93 -c "'$cmd_str; \ + print -u 2 \"status=\$?\"'" \ + >/dev/null 2>$err_file + ret=$? + if (( $ret != 0 )); then + $CAT $err_file + $RM -f $std_file $err_file + log_fail "$RSH itself failed with exit code $ret..." + fi + + ret=$($GREP -v 'print -u 2' $err_file | $GREP 'status=' | \ + $CUT -d= -f2) + (( $ret != 0 )) && $CAT $err_file >&2 + + $RM -f $err_file >/dev/null 2>&1 + return $ret +} + +# +# Get the SUNWstc-fs-zfs package installation path in a remote host +# $1 remote host name +# +function get_remote_pkgpath +{ + typeset rhost=$1 + typeset pkgpath="" + + pkgpath=$($RSH -n $rhost "$PKGINFO -l SUNWstc-fs-zfs | $GREP BASEDIR: |\ + $CUT -d: -f2") + + $ECHO $pkgpath +} + +#/** +# A function to find and locate free disks on a system or from given +# disks as the parameter. Since the conversion to ATF, this function is +# superfluous; it is assumed that the user will supply an accurate list of +# disks to use. So we just return the arguments. +# +# $@ given disks to find which are free +# +# @return a string containing the list of available disks +#*/ +function find_disks +{ + (( first=0 )) + for disk in $@; do + [[ $first == 1 ]] && echo -n " " + (( first=1 )) + case $disk in + /dev/*) echo -n "$disk" ;; + *) echo -n "/dev/$disk" ;; + esac + done +} + +# A function to set convenience variables for disks. +function set_disks +{ + set -A disk_array $(find_disks $DISKS) + [[ -z "$DISK_ARRAY_LIMIT" ]] && typeset -i DISK_ARRAY_LIMIT=5 + + export DISK="" + typeset -i i=0 + while (( i < ${#disk_array[*]} && i <= $DISK_ARRAY_LIMIT )); do + export DISK${i}="${disk_array[$i]}" + DISKSARRAY="$DISKSARRAY ${disk_array[$i]}" + (( i = i + 1 )) + done + export DISK_ARRAY_NUM=$i + export DISKSARRAY + export disk=$DISK0 +} + +# +# Add specified user to specified group +# +# $1 group name +# $2 user name +# +function add_user # +{ + typeset gname=$1 + typeset uname=$2 + + if (( ${#gname} == 0 || ${#uname} == 0 )); then + log_fail "group name or user name are not defined." + fi + + # Check to see if the user exists. + $ID $uname > /dev/null 2>&1 && return 0 + + # Assign 1000 as the base uid + typeset -i uid=1000 + while true; do + typeset -i ret + $USERADD -u $uid -g $gname -d /var/tmp/$uname -m $uname + ret=$? + case $ret in + 0) return 0 ;; + # The uid is not unique + 65) ((uid += 1)) ;; + *) return 1 ;; + esac + if [[ $uid == 65000 ]]; then + log_fail "No user id available under 65000 for $uname" + fi + done + + return 0 +} + +# +# Delete the specified user. +# +# $1 login name +# +function del_user # +{ + typeset user=$1 + + if (( ${#user} == 0 )); then + log_fail "login name is necessary." + fi + + if $ID $user > /dev/null 2>&1; then + log_must $USERDEL $user + fi + + return 0 +} + +# +# Select valid gid and create specified group. +# +# $1 group name +# +function add_group # +{ + typeset group=$1 + + if (( ${#group} == 0 )); then + log_fail "group name is necessary." + fi + + # See if the group already exists. + $GROUPSHOW $group >/dev/null 2>&1 + [[ $? == 0 ]] && return 0 + + # Assign 100 as the base gid + typeset -i gid=100 + while true; do + $GROUPADD -g $gid $group > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + 0) return 0 ;; + # The gid is not unique + 65) ((gid += 1)) ;; + *) return 1 ;; + esac + if [[ $gid == 65000 ]]; then + log_fail "No user id available under 65000 for $group" + fi + done +} + +# +# Delete the specified group. +# +# $1 group name +# +function del_group # +{ + typeset grp=$1 + if (( ${#grp} == 0 )); then + log_fail "group name is necessary." + fi + + $GROUPDEL -n $grp > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + # Group does not exist, or was deleted successfully. + 0|6|65) return 0 ;; + # Name already exists as a group name + 9) log_must $GROUPDEL $grp ;; + *) return 1 ;; + esac + + return 0 +} + +# +# This function will return true if it's safe to destroy the pool passed +# as argument 1. It checks for pools based on zvols and files, and also +# files contained in a pool that may have a different mountpoint. +# +function safe_to_destroy_pool { # $1 the pool name + + typeset pool="" + typeset DONT_DESTROY="" + + # We check that by deleting the $1 pool, we're not + # going to pull the rug out from other pools. Do this + # by looking at all other pools, ensuring that they + # aren't built from files or zvols contained in this pool. + + for pool in $($ZPOOL list -H -o name) + do + ALTMOUNTPOOL="" + + # this is a list of the top-level directories in each of the files + # that make up the path to the files the pool is based on + FILEPOOL=$($ZPOOL status -v $pool | $GREP /$1/ | \ + $AWK '{print $1}') + + # this is a list of the zvols that make up the pool + ZVOLPOOL=$($ZPOOL status -v $pool | $GREP "/dev/zvol/dsk/$1$" | \ + $AWK '{print $1}') + + # also want to determine if it's a file-based pool using an + # alternate mountpoint... + POOL_FILE_DIRS=$($ZPOOL status -v $pool | \ + $GREP / | $AWK '{print $1}' | \ + $AWK -F/ '{print $2}' | $GREP -v "dev") + + for pooldir in $POOL_FILE_DIRS + do + OUTPUT=$($ZFS list -H -r -o mountpoint $1 | \ + $GREP "${pooldir}$" | $AWK '{print $1}') + + ALTMOUNTPOOL="${ALTMOUNTPOOL}${OUTPUT}" + done + + + if [ ! -z "$ZVOLPOOL" ] + then + DONT_DESTROY="true" + log_note "Pool $pool is built from $ZVOLPOOL on $1" + fi + + if [ ! -z "$FILEPOOL" ] + then + DONT_DESTROY="true" + log_note "Pool $pool is built from $FILEPOOL on $1" + fi + + if [ ! -z "$ALTMOUNTPOOL" ] + then + DONT_DESTROY="true" + log_note "Pool $pool is built from $ALTMOUNTPOOL on $1" + fi + done + + if [ -z "${DONT_DESTROY}" ] + then + return 0 + else + log_note "Warning: it is not safe to destroy $1!" + return 1 + fi +} + +# +# Get IP address of hostname +# $1 hostname +# +function getipbyhost +{ + typeset ip + ip=`$ARP $1 2>/dev/null | $AWK -F\) '{print $1}' \ + | $AWK -F\( '{print $2}'` + $ECHO $ip +} + +# +# Setup iSCSI initiator to target +# $1 target hostname +# +function iscsi_isetup +{ + # check svc:/network/iscsi_initiator:default state, try to enable it + # if the state is not ON + typeset ISCSII_FMRI="svc:/network/iscsi_initiator:default" + if [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) ]]; then + log_must $SVCADM enable $ISCSII_FMRI + + typeset -i retry=20 + while [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) && \ + ( $retry -ne 0 ) ]] + do + (( retry = retry - 1 )) + $SLEEP 1 + done + + if [[ "ON" != $($SVCS -H -o sta $ISCSII_FMRI) ]]; then + log_fail "$ISCSII_FMRI service can not be enabled!" + fi + fi + + log_must $ISCSIADM add discovery-address $(getipbyhost $1) + log_must $ISCSIADM modify discovery --sendtargets enable + log_must $DEVFSADM -i iscsi +} + +# +# Check whether iscsi parameter is set as remote +# +# return 0 if iscsi is set as remote, otherwise 1 +# +function check_iscsi_remote +{ + if [[ $iscsi == "remote" ]] ; then + return 0 + else + return 1 + fi +} + +# +# Check if a volume is a valide iscsi target +# $1 volume name +# return 0 if suceeds, otherwise, return 1 +# +function is_iscsi_target +{ + typeset dataset=$1 + typeset target targets + + [[ -z $dataset ]] && return 1 + + targets=$($ISCSITADM list target | $GREP "Target:" | $AWK '{print $2}') + [[ -z $targets ]] && return 1 + + for target in $targets; do + [[ $dataset == $target ]] && return 0 + done + + return 1 +} + +# +# Get the iSCSI name of a target +# $1 target name +# +function iscsi_name +{ + typeset target=$1 + typeset name + + [[ -z $target ]] && log_fail "No parameter." + + if ! is_iscsi_target $target ; then + log_fail "Not a target." + fi + + name=$($ISCSITADM list target $target | $GREP "iSCSI Name:" \ + | $AWK '{print $2}') + + return $name +} + +# +# check svc:/system/iscsitgt:default state, try to enable it if the state +# is not ON +# +function iscsitgt_setup +{ + log_must $RM -f $ISCSITGTFILE + if [[ "ON" == $($SVCS -H -o sta $ISCSITGT_FMRI) ]]; then + log_note "iscsitgt is already enabled" + return + fi + + log_must $SVCADM enable -t $ISCSITGT_FMRI + + typeset -i retry=20 + while [[ "ON" != $($SVCS -H -o sta $ISCSITGT_FMRI) && \ + ( $retry -ne 0 ) ]] + do + $SLEEP 1 + (( retry = retry - 1 )) + done + + if [[ "ON" != $($SVCS -H -o sta $ISCSITGT_FMRI) ]]; then + log_fail "$ISCSITGT_FMRI service can not be enabled!" + fi + + log_must $TOUCH $ISCSITGTFILE +} + +# +# set DISABLED state of svc:/system/iscsitgt:default +# which is the most suiteable state if $ISCSITGTFILE exists +# +function iscsitgt_cleanup +{ + if [[ -e $ISCSITGTFILE ]]; then + log_must $SVCADM disable $ISCSITGT_FMRI + log_must $RM -f $ISCSITGTFILE + fi +} + +# +# Close iSCSI initiator to target +# $1 target hostname +# +function iscsi_iclose +{ + log_must $ISCSIADM modify discovery --sendtargets disable + log_must $ISCSIADM remove discovery-address $(getipbyhost $1) + $DEVFSADM -Cv +} + +# +# Get the available ZFS compression options +# $1 option type zfs_set|zfs_compress +# +function get_compress_opts +{ + typeset COMPRESS_OPTS + typeset GZIP_OPTS="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \ + gzip-6 gzip-7 gzip-8 gzip-9" + + if [[ $1 == "zfs_compress" ]] ; then + COMPRESS_OPTS="on lzjb" + elif [[ $1 == "zfs_set" ]] ; then + COMPRESS_OPTS="on off lzjb" + fi + typeset valid_opts="$COMPRESS_OPTS" + $ZFS get 2>&1 | $GREP gzip >/dev/null 2>&1 + if [[ $? -eq 0 ]]; then + valid_opts="$valid_opts $GZIP_OPTS" + fi + $ECHO "$valid_opts" +} + +# +# Check the subcommand/option is supported +# +function check_opt_support #command, option +{ + typeset command=$1 + typeset option=$2 + + if [[ -z $command ]]; then + return 0 + elif [[ -z $option ]]; then + eval "$ZFS 2>&1 | $GREP '$command' > /dev/null 2>&1" + else + eval "$ZFS $command 2>&1 | $GREP -- '$option' | \ + $GREP -v -- 'User-defined' > /dev/null 2>&1" + fi + return $? +} + +# +# Check the zpool subcommand/option is supported +# +function check_zpool_opt_support #command, option +{ + typeset command=$1 + typeset option=$2 + + if [[ -z $command ]]; then + return 0 + elif [[ -z $option ]]; then + eval "$ZPOOL 2>&1 | $GREP '$command' > /dev/null 2>&1" + else + eval "$ZPOOL $command 2>&1 | $GREP -- '$option' > /dev/null 2>&1" + fi + return $? +} + +# +# Verify zfs operation with -p option work as expected +# $1 operation, value could be create, clone or rename +# $2 dataset type, value could be fs or vol +# $3 dataset name +# $4 new dataset name +# +function verify_opt_p_ops +{ + typeset ops=$1 + typeset datatype=$2 + typeset dataset=$3 + typeset newdataset=$4 + + if [[ $datatype != "fs" && $datatype != "vol" ]]; then + log_fail "$datatype is not supported." + fi + + # check parameters accordingly + case $ops in + create) + newdataset=$dataset + dataset="" + if [[ $datatype == "vol" ]]; then + ops="create -V $VOLSIZE" + fi + ;; + clone) + if [[ -z $newdataset ]]; then + log_fail "newdataset should not be empty" \ + "when ops is $ops." + fi + log_must datasetexists $dataset + log_must snapexists $dataset + ;; + rename) + if [[ -z $newdataset ]]; then + log_fail "newdataset should not be empty" \ + "when ops is $ops." + fi + log_must datasetexists $dataset + log_mustnot snapexists $dataset + ;; + *) + log_fail "$ops is not supported." + ;; + esac + + # make sure the upper level filesystem does not exist + if datasetexists ${newdataset%/*} ; then + log_must $ZFS destroy -rRf ${newdataset%/*} + fi + + # without -p option, operation will fail + log_mustnot $ZFS $ops $dataset $newdataset + log_mustnot datasetexists $newdataset ${newdataset%/*} + + # with -p option, operation should succeed + log_must $ZFS $ops -p $dataset $newdataset + if ! datasetexists $newdataset ; then + log_fail "-p option does not work for $ops" + fi + + # when $ops is create or clone, redo the operation still return zero + if [[ $ops != "rename" ]]; then + log_must $ZFS $ops -p $dataset $newdataset + fi + + return 0 +} + +function get_disk_guid +{ + typeset diskname=$1 + lastcwd=$(pwd) + cd /dev + guid=$($ZDB -l ${diskname} | ${AWK} '/^ guid:/ {print $2}' | head -1) + cd $lastcwd + echo $guid +} + +# +# Get cachefile for a pool. +# Prints the cache file, if there is one. +# Returns 0 for a default zpool.cache, 1 for an explicit one, and 2 for none. +# +function cachefile_for_pool +{ + typeset pool=$1 + + cachefile=$(get_pool_prop cachefile $pool) + [[ $? != 0 ]] && return 1 + + case "$cachefile" in + none) ret=2 ;; + "-") + ret=2 + for dir in /boot/zfs /etc/zfs; do + if [[ -f "${dir}/zpool.cache" ]]; then + cachefile="${dir}/zpool.cache" + ret=0 + break + fi + done + ;; + *) ret=1; + esac + [[ $ret -eq 0 || $ret -eq 1 ]] && print "$cachefile" + return $ret +} + +# +# Assert that the pool is in the appropriate cachefile. +# +function assert_pool_in_cachefile +{ + typeset pool=$1 + + cachefile=$(cachefile_for_pool $pool) + [ $? -ne 0 ] && log_fail "ERROR: Cachefile not created for '$pool'?" + log_must test -e "${cachefile}" + log_must zdb -U ${cachefile} -C ${pool} +} + +# +# Get the zdb options given the cachefile state of the pool. +# +function zdb_cachefile_opts +{ + typeset pool=$1 + typeset vdevdir=$2 + typeset opts + + if poolexists "$pool"; then + cachefile=$(cachefile_for_pool $pool) + typeset -i ret=$? + case $ret in + 0) opts="-C" ;; + 1) opts="-U $cachefile -C" ;; + 2) opts="-eC" ;; + *) log_fail "Unknown return '$ret'" ;; + esac + else + opts="-eC" + [[ -n "$vdevdir" ]] && opts="$opts -p $vdevdir" + fi + echo "$opts" +} + +# +# Get configuration of pool +# $1 pool name +# $2 config name +# +function get_config +{ + typeset pool=$1 + typeset config=$2 + typeset vdevdir=$3 + typeset alt_root + typeset zdb_opts + + zdb_opts=$(zdb_cachefile_opts $pool $vdevdir) + value=$($ZDB $zdb_opts $pool | $GREP "$config:" | $AWK -F: '{print $2}') + if [[ -n $value ]] ; then + value=${value#'} + value=${value%'} + else + return 1 + fi + echo $value + + return 0 +} + +# +# Privated function. Random select one of items from arguments. +# +# $1 count +# $2-n string +# +function _random_get +{ + typeset cnt=$1 + shift + + typeset str="$@" + typeset -i ind + ((ind = RANDOM % cnt + 1)) + + typeset ret=$($ECHO "$str" | $CUT -f $ind -d ' ') + $ECHO $ret +} + +# +# Random select one of item from arguments which include NONE string +# +function random_get_with_non +{ + typeset -i cnt=$# + ((cnt =+ 1)) + + _random_get "$cnt" "$@" +} + +# +# Random select one of item from arguments which doesn't include NONE string +# +function random_get +{ + _random_get "$#" "$@" +} + +# +# The function will generate a dataset name with specific length +# $1, the length of the name +# $2, the base string to construct the name +# +function gen_dataset_name +{ + typeset -i len=$1 + typeset basestr="$2" + typeset -i baselen=${#basestr} + typeset -i iter=0 + typeset l_name="" + + if (( len % baselen == 0 )); then + (( iter = len / baselen )) + else + (( iter = len / baselen + 1 )) + fi + while (( iter > 0 )); do + l_name="${l_name}$basestr" + + (( iter -= 1 )) + done + + $ECHO $l_name +} + +# +# Ensure that a given path has been synced, not just ZIL committed. +# +# XXX The implementation currently requires calling 'zpool history'. On +# FreeBSD, the sync(8) command (via $SYNC) calls zfs_sync() which just +# does a zil_commit(), as opposed to a txg_wait_synced(). For things that +# require writing to their final destination (e.g. for intentional +# corruption purposes), zil_commit() is not good enough. +# +function force_sync_path # path +{ + typeset path="$1" + + zfspath=$($DF $path 2>/dev/null | tail -1 | cut -d" " -f1 | cut -d/ -f1) + [ -z "$zfspath" ] && return false + log_note "Force syncing ${zfspath} for ${path} ..." + $ZPOOL history $zfspath >/dev/null 2>&1 +} + +# +# Get cksum tuple of dataset +# $1 dataset name +# +# zdb output is like below +# " Dataset pool/fs [ZPL], ID 978, cr_txg 2277, 19.0K, 5 objects, +# rootbp [L0 DMU objset] 400L/200P DVA[0]=<0:1880c00:200> +# DVA[1]=<0:341880c00:200> fletcher4 lzjb LE contiguous birth=2292 fill=5 +# cksum=989930ccf:4014fe00c83:da5e388e58b4:1f7332052252ac " +# +function datasetcksum +{ + typeset cksum + $SYNC + cksum=$($ZDB -vvv $1 | $GREP "^Dataset $1 \[" | $GREP "cksum" \ + | $AWK -F= '{print $6}') + $ECHO $cksum +} + +# +# Get cksum of file +# #1 file path +# +function checksum +{ + typeset cksum + cksum=$($CKSUM $1 | $AWK '{print $1}') + $ECHO $cksum +} + +# +# Get the given disk/slice state from the specific field of the pool +# +function get_device_state #pool disk field("", "spares","logs") +{ + typeset pool=$1 + typeset disk=${2#/dev/dsk/} + disk=${disk#/dev/rdsk/} + disk=${disk#/dev/} + typeset field=${3:-$pool} + + state=$($ZPOOL status -v "$pool" 2>/dev/null | \ + $NAWK -v device=$disk -v pool=$pool -v field=$field \ + 'BEGIN {startconfig=0; startfield=0; } + /config:/ {startconfig=1} + (startconfig==1)&&($1==field) {startfield=1; next;} + (startfield==1)&&($1==device) {print $2; exit;} + (startfield==1)&&(NF>=3)&&($(NF-1)=="was")&&($NF==device) {print $2; exit;} + (startfield==1)&&($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}') + print $state +} + + +# +# print the given directory filesystem type +# +# $1 directory name +# +function get_fstype +{ + typeset dir=$1 + + if [[ -z $dir ]]; then + log_fail "Usage: get_fstype " + fi + + $DF -T $dir | $AWK '{print $2}' +} + +# +# Given a disk, label it to VTOC regardless what label was on the disk +# $1 disk +# +function labelvtoc +{ + typeset disk=$1 + if [[ -z $disk ]]; then + log_fail "The disk name is unspecified." + fi + typeset label_file=$TMPDIR/labelvtoc.${TESTCASE_ID} + typeset arch=$($UNAME -p) + + if [[ $arch == "i386" ]]; then + $ECHO "label" > $label_file + $ECHO "0" >> $label_file + $ECHO "" >> $label_file + $ECHO "q" >> $label_file + $ECHO "q" >> $label_file + + $FDISK -B $disk >/dev/null 2>&1 + # wait a while for fdisk finishes + $SLEEP 60 + elif [[ $arch == "sparc" ]]; then + $ECHO "label" > $label_file + $ECHO "0" >> $label_file + $ECHO "" >> $label_file + $ECHO "" >> $label_file + $ECHO "" >> $label_file + $ECHO "q" >> $label_file + else + log_fail "unknown arch type" + fi + + $FORMAT -e -s -d $disk -f $label_file + typeset -i ret_val=$? + $RM -f $label_file + # + # wait the format to finish + # + $SLEEP 60 + if (( ret_val != 0 )); then + log_fail "unable to label $disk as VTOC." + fi + + return 0 +} + +# +# Detect if the given filesystem property is supported in this release +# +# 0 Yes, it is supported +# !0 No, it is not supported +# +function fs_prop_exist +{ + typeset prop=$1 + + if [[ -z $prop ]]; then + log_fail "Usage: fs_prop_exist " + + return 1 + fi + + # + # If the property is shortened column name, + # convert it to the standard name + # + case $prop in + avail) prop=available ;; + refer) prop=referenced ;; + volblock) prop=volblocksize ;; + compress) prop=compression ;; + rdonly) prop=readonly ;; + recsize) prop=recordsize ;; + reserv) prop=reservation ;; + refreserv) prop=refreservation ;; + esac + + # + # The zfs get output looks like the following + # + + # + # The following properties are supported: + # + # PROPERTY EDIT INHERIT VALUES + # + # available NO NO + # compressratio NO NO <1.00x or higher if compressed> + # creation NO NO + # ... ... + # zoned YES YES on | off + # + # Sizes are specified in bytes with standard units such as K, M, G, etc. + # + + # + # Start to extract property from the first blank line after 'PROPERTY' + # and stop at the next blank line + # + $ZFS get 2>&1 | \ + $AWK '/PROPERTY/ {start=1; next} + /Sizes/ {start=0} + start==1 {print $1}' | \ + $GREP -w "$prop" > /dev/null 2>&1 + + return $? +} + +# +# Detect if the given pool property is supported in this release +# +# 0 Yes, it is supported +# !0 No, it is not supported +# +function pool_prop_exist +{ + typeset prop=$1 + if [[ -z $prop ]]; then + log_fail "Usage: pool_prop_exist " + + return 1 + fi + # + # If the property is shortened column name, + # convert it to the standard name + # + case $prop in + avail) prop=available ;; + cap) prop=capacity ;; + replace) prop=autoreplace ;; + esac + + # + # The zpool get output looks like the following + # + + # usage: + # get <"all" | property[,...]> ... + # + # the following properties are supported: + # + # PROPERTY EDIT VALUES + # + # available NO + # capacity NO + # guid NO + # health NO + # size NO + # used NO + # altroot YES + # autoreplace YES on | off + # bootfs YES + # cachefile YES | none + # delegation YES on | off + # failmode YES wait | continue | panic + # version YES + + $ZPOOL get 2>&1 | \ + $AWK '/PROPERTY/ {start=1; next} + start==1 {print $1}' | \ + $GREP -w "$prop" > /dev/null 2>&1 + + return $? +} + +# +# check if the system was installed as zfsroot or not +# return: 0 ture, otherwise false +# +function is_zfsroot +{ + $DF -T / | $GREP -q zfs +} + +# +# get the root filesystem name if it's zfsroot system. +# +# return: root filesystem name +function get_rootfs +{ + typeset rootfs="" + rootfs=$($MOUNT | $AWK '$3 == "\/" && $4~/zfs/ {print $1}') + if [[ -z "$rootfs" ]]; then + log_fail "Can not get rootfs" + fi + $ZFS list $rootfs > /dev/null 2>&1 + if (( $? == 0 )); then + $ECHO $rootfs + else + log_fail "This is not a zfsroot system." + fi +} + +# +# get the rootfs's pool name +# return: +# rootpool name +# +function get_rootpool +{ + typeset rootfs="" + typeset rootpool="" + rootfs=$(get_rootfs) + rootpool=`$ECHO $rootfs | awk -F\/ '{print $1}'` + echo $rootpool +} + +# +# Get the sub string from specified source string +# +# $1 source string +# $2 start position. Count from 1 +# $3 offset +# +function get_substr #src_str pos offset +{ + typeset pos offset + + $ECHO $1 | \ + $NAWK -v pos=$2 -v offset=$3 '{print substr($0, pos, offset)}' +} + +# +# Get the directory path of given device +# +function get_device_dir #device +{ + typeset device=$1 + + $ECHO "/dev" +} + +# +# Get the package name +# +function get_package_name +{ + typeset dirpath=${1:-$STC_NAME} + + print "SUNWstc-${dirpath}" | /usr/bin/sed -e "s/\//-/g" +} + +# +# Get the word numbers from a string separated by white space +# +function get_word_count +{ + $ECHO $1 | $WC -w +} + +# +# To verify if the require numbers of disks is given +# +function verify_disk_count +{ + typeset -i min=${2:-1} + + typeset -i count=$(get_word_count "$1") + + if (( count < min )); then + atf_skip "A minimum of $min disks is required to run." \ + " You specified $count disk(s)" + fi +} + +# +# Verify that vfs.zfs.vol.recursive is set, so pools can be created using zvols +# as backing stores. +# +function verify_zvol_recursive +{ + if [ "`sysctl -n vfs.zfs.vol.recursive`" -ne 1 ]; then + atf_skip "Recursive ZVOLs not enabled" + fi +} + +# +# bsdmap disk/slice number to a device path +# +function bsddevmap +{ + typeset arg=$1 + echo $arg | egrep "*s[0-9]$" > /dev/null 2>&1 + if [ $? -eq 0 ] + then + n=`echo $arg| wc -c` + set -A map a b c d e f g h i j + s=`echo $arg | cut -c $((n-1))` + arg=${arg%s[0-9]}${map[$s]} + fi + echo $arg +} + +# +# Get the name of the snapshots directory. Traditionally .zfs/snapshots +# +function get_snapdir_name +{ + echo ".zfs/snapshot" +} + +# +# Unmount all ZFS filesystems except for those that are in the KEEP variable +# +function unmount_all_safe +{ + echo $(all_pools) | \ + $XARGS -n 1 $ZFS list -H -o name -t all -r | \ + $XARGS -n 1 $ZFS unmount +} + +# +# Return the highest pool version that this OS can create +# +function get_zpool_version +{ + # We assume output from zpool upgrade -v of the form: + # + # This system is currently running ZFS version 2. + # . + # . + typeset ZPOOL_VERSION=$($ZPOOL upgrade -v | $HEAD -1 | \ + $AWK '{print $NF}' | $SED -e 's/\.//g') + # Starting with version 5000, the output format changes to: + # This system supports ZFS pool feature flags. + # . + # . + if [[ $ZPOOL_VERSION = "flags" ]]; then + ZPOOL_VERSION=5000 + fi + echo $ZPOOL_VERSION +} + +# Ensures that zfsd is running, starting it if necessary. Every test that +# interacts with zfsd must call this at startup. This is intended primarily +# to eliminate interference from outside the test suite. +function ensure_zfsd_running +{ + if ! service zfsd status > /dev/null 2>&1; then + service zfsd start || service zfsd onestart + service zfsd status > /dev/null 2>&1 || + log_unsupported "Test requires zfsd" + fi +} + +# Temporarily stops ZFSD, because it can interfere with some tests. If this +# function is used, then restart_zfsd _must_ be called in the cleanup routine. +function stop_zfsd +{ + $RM -f $TMPDIR/.zfsd_enabled_during_stf_zfs_tests + if [[ -n "$ZFSD" && -x "$ZFSD" ]]; then + if /etc/rc.d/zfsd status > /dev/null; then + log_note "Stopping zfsd" + $TOUCH $TMPDIR/.zfsd_enabled_during_stf_zfs_tests + /etc/rc.d/zfsd stop || /etc/rc.d/zfsd onestop + fi + fi +} + +# Restarts zfsd after it has been stopped by stop_zfsd. Intelligently restarts +# only iff zfsd was running at the time stop_zfsd was called. +function restart_zfsd +{ + if [[ -f $TMPDIR/.zfsd_enabled_during_stf_zfs_tests ]]; then + log_note "Restarting zfsd" + /etc/rc.d/zfsd start || /etc/rc.d/zfsd onestart + fi + $RM -f $TMPDIR/.zfsd_enabled_during_stf_zfs_tests +} + +# +# Using the given , obtain the value of the property for +# the given identified by numeric id. +# +function get_tvd_prop # vdev tvd propname +{ + typeset vdev=$1 + typeset -i tvd=$2 + typeset propname=$3 + + $ZDB -l $vdev | $AWK -v tvd=$tvd -v prop="${propname}:" ' + BEGIN { start = 0; } + /^ id:/ && ($2==tvd) { start = 1; next; } + (start==0) { next; } + /^ [a-z]+/ && ($1==prop) { print $2; exit; } + /^ children/ { exit; } + ' +} + +# +# Convert a DVA into a physical block address. Prints number of blocks. +# This takes the usual printed form, in which offsets are left shifted so +# they represent bytes rather than the native sector count. +# +function dva_to_block_addr # dva +{ + typeset dva=$1 + + typeset offcol=$(echo $dva | cut -f2 -d:) + typeset -i offset="0x${offcol}" + # First add 4MB to skip the boot blocks and first two vdev labels, + # then convert to 512 byte blocks (for use with dd). Note that this + # differs from simply adding 8192 blocks, since the input offset is + # given in bytes and has the actual ashift baked in. + (( offset += 4*1024*1024 )) + (( offset >>= 9 )) + echo "$offset" +} + +# +# Convert a RAIDZ DVA into a physical block address. This has the same +# output as dva_to_block_addr (number of blocks from beginning of device), but +# is more complicated due to RAIDZ. ashift is normally always 9, but RAIDZ +# uses the actual tvd ashift instead. Furthermore, the number of vdevs changes +# the actual block for each device. +# +function raidz_dva_to_block_addr # dva ncols ashift +{ + typeset dva=$1 + typeset -i ncols=$2 + typeset -i ashift=$3 + + typeset -i offset=0x$(echo $dva | cut -f2 -d:) + (( offset >>= ashift )) + + typeset -i ioff=$(( (offset + ncols - 1) / ncols )) + + # Now add the front 4MB and return. + (( ioff += ( 4194304 >> $ashift ) )) + echo "$ioff" +} + +# +# Return the vdevs for the given toplevel vdev number. +# Child vdevs will only be included if they are ONLINE. Output format: +# +# [: ...] +# +# Valid toplevel vdev types are mirror, raidz[1-3], leaf (which can be a +# disk or a file). Note that 'nchildren' can be larger than the number of +# returned children; it represents the number of children regardless of how +# many are actually online. +# +function vdevs_for_tvd # pool tvd +{ + typeset pool=$1 + typeset -i tvd=$2 + + $ZPOOL status $pool | $AWK -v want_tvd=$tvd ' + BEGIN { + start = 0; tvd = -1; lvd = -1; + type = "UNKNOWN"; disks = ""; disk = ""; + nchildren = 0; + } + /NAME.*STATE/ { start = 1; next; } + (start==0) { next; } + + (tvd > want_tvd) { exit; } + END { print type " " nchildren " " disks; } + + length(disk) > 0 { + if (length(disks) > 0) { disks = disks " "; } + if (substr(disk, 0, 1) == "/") { + disks = disks disk; + } else { + disks = disks "/dev/" disk; + } + disk = ""; + } + + /^\t(spares|logs)/ { tvd = want_tvd + 1; next; } + /^\t (mirror|raidz[1-3])-[0-9]+/ { + tvd += 1; + (tvd == want_tvd) && type = substr($1, 0, 6); + next; + } + /^\t [\/A-Za-z]+/ { + tvd += 1; + if (tvd == want_tvd) { + (( nchildren += 1 )) + type = "leaf"; + ($2 == "ONLINE") && disk = $1; + } + next; + } + + (tvd < want_tvd) { next; } + + /^\t spare-[0-9]+/ { next; } + /^\t [\/A-Za-z]+/ { + (( nchildren += 1 )) + ($2 == "ONLINE") && disk = $1; + next; + } + + /^\t [\/A-Za-z]+/ { + (( nchildren += 1 )) + ($2 == "ONLINE") && disk = $1; + next; + } + ' +} + +# +# Get a vdev path, ashift & offset for a given pool/dataset and DVA. +# If desired, can also select the toplevel vdev child number. +# +function dva_to_vdev_ashift_off # pool/dataset dva [leaf_vdev_num] +{ + typeset poollike=$1 + typeset dva=$2 + typeset -i leaf_vdev_num=$3 + + # vdevs are normally 0-indexed while arguments are 1-indexed. + (( leaf_vdev_num += 1 )) + + # Strip any child datasets or snapshots. + pool=$(echo $poollike | sed -e 's,[/@].*,,g') + tvd=$(echo $dva | cut -d: -f1) + + set -- $(vdevs_for_tvd $pool $tvd) + log_debug "vdevs_for_tvd: $* " + tvd_type=$1; shift + nchildren=$1; shift + + lvd=$(eval echo \$$leaf_vdev_num) + log_debug "type='$tvd_type' children='$nchildren' lvd='$lvd' dva='$dva'" + case $tvd_type in + raidz*) + ashift=$(get_tvd_prop $lvd $tvd ashift) + log_debug "raidz: ashift='${ashift}'" + off=$(raidz_dva_to_block_addr $dva $nchildren $ashift) + ;; + *) + ashift=9 + off=$(dva_to_block_addr $dva) + ;; + esac + echo "${lvd}:${ashift}:${off}" +} + +# +# Get the DVA for the specified dataset's given filepath. +# +function file_dva # dataset filepath [level] [offset] [dva_num] +{ + typeset dataset=$1 + typeset filepath=$2 + typeset -i level=$3 + typeset -i offset=$4 + typeset -i dva_num=$5 + + typeset -li blksz=0 + typeset -li blknum=0 + typeset -li startoff + typeset -li inode + + eval `$STAT -s "$filepath"` + inode="$st_ino" + + # The inner match is for 'DVA[0]=<0:1b412600:200>', in which the + # text surrounding the actual DVA is a fixed size with 8 characters + # before it and 1 after. + $ZDB -P -vvvvv $dataset $inode | \ + $AWK -v level=${level} -v dva_num=${dva_num} ' + BEGIN { stage = 0; } + (stage == 0) && ($1=="Object") { stage = 1; next; } + + (stage == 1) { + print $3 " " $4; + stage = 2; next; + } + + (stage == 2) && /^Indirect blocks/ { stage=3; next; } + (stage < 3) { next; } + + match($2, /L[0-9]/) { + if (substr($2, RSTART+1, RLENGTH-1) != level) { next; } + } + match($3, /DVA\[.*>/) { + dva = substr($3, RSTART+8, RLENGTH-9); + if (substr($3, RSTART+4, 1) == dva_num) { + print $1 " " dva; + } + } + ' | \ + while read line; do + log_debug "params='$blksz/$blknum/$startoff' line='$line'" + if (( blksz == 0 )); then + typeset -i iblksz=$(echo $line | cut -d " " -f1) + typeset -i dblksz=$(echo $line | cut -d " " -f2) + + # Calculate the actual desired block starting offset. + if (( level > 0 )); then + typeset -i nbps_per_level + typeset -i indsz + typeset -i i=0 + + (( nbps_per_level = iblksz / 128 )) + (( blksz = dblksz )) + for (( i = 0; $i < $level; i++ )); do + (( blksz *= nbps_per_level )) + done + else + blksz=$dblksz + fi + + (( blknum = offset / blksz )) + (( startoff = blknum * blksz )) + continue + fi + + typeset lineoffstr=$(echo $line | cut -d " " -f1) + typeset -i lineoff=$(printf "%d" "0x${lineoffstr}") + typeset dva="$(echo $line | cut -d " " -f2)" + log_debug "str='$lineoffstr' lineoff='$lineoff' dva='$dva'" + if [[ -n "$dva" ]] && (( lineoff == startoff )); then + echo $line | cut -d " " -f2 + return 0 + fi + done + return 1 +} + +# +# Corrupt the given dataset's filepath file. This will obtain the first +# level 0 block's DVA and scribble random bits on it. +# +function corrupt_file # dataset filepath [leaf_vdev_num] +{ + typeset dataset=$1 + typeset filepath=$2 + typeset -i leaf_vdev_num="$3" + + dva=$(file_dva $dataset $filepath) + [ $? -ne 0 ] && log_fail "ERROR: Can't find file $filepath on $dataset" + + vdoff=$(dva_to_vdev_ashift_off $dataset $dva $leaf_vdev_num) + vdev=$(echo $vdoff | cut -d: -f1) + ashift=$(echo $vdoff | cut -d: -f2) + off=$(echo $vdoff | cut -d: -f3) + blocksize=$(( 1 << $ashift )) + + log_note "Corrupting ${dataset}'s $filepath on $vdev at DVA $dva with ashift $ashift" + log_must $DD if=/dev/urandom bs=$blocksize of=$vdev seek=$off count=1 conv=notrunc +} + +# +# Given a number of files, this function will iterate through +# the loop creating the specified number of files, whose names +# will start with . +# +# The argument is special: it can be "ITER", in which case +# the -d argument will be the value of the current iteration. It +# can be 0, in which case it will always be 0. Otherwise, it will +# always be the given value. +# +# If is specified, a snapshot will be taken using the +# argument as the snapshot basename. +# +function populate_dir # basename num_files write_count blocksz data snapbase +{ + typeset basename=$1 + typeset -i num_files=$2 + typeset -i write_count=$3 + typeset -i blocksz=$4 + typeset -i i + typeset data=$5 + typeset snapbase="$6" + + log_note "populate_dir: data='$data'" + for (( i = 0; i < num_files; i++ )); do + case "$data" in + 0) d=0 ;; + ITER) d=$i ;; + *) d=$data ;; + esac + + log_must $FILE_WRITE -o create -c $write_count \ + -f ${basename}.$i -b $blocksz -d $d + + [ -n "$snapbase" ] && log_must $ZFS snapshot ${snapbase}.${i} + done +} + +# Reap all children registered in $child_pids. +function reap_children +{ + [ -z "$child_pids" ] && return + for wait_pid in $child_pids; do + log_must $KILL $wait_pid + done + child_pids="" +} + +# Busy a path. Expects to be reaped via reap_children. Tries to run as +# long and slowly as possible. [num] is taken as a hint; if such a file +# already exists a different one will be chosen. +function busy_path # [num] +{ + typeset busypath=$1 + typeset -i num=$2 + + while :; do + busyfile="$busypath/busyfile.${num}" + [ ! -f "$busyfile" ] && break + done + + cmd="$DD if=/dev/urandom of=$busyfile bs=512" + ( cd $busypath && $cmd ) & + typeset pid=$! + $SLEEP 1 + log_must $PS -p $pid + child_pids="$child_pids $pid" +} diff --git a/tests/sys/cddl/zfs/include/libtest_test.sh b/tests/sys/cddl/zfs/include/libtest_test.sh new file mode 100755 index 00000000000..8e958aed1a2 --- /dev/null +++ b/tests/sys/cddl/zfs/include/libtest_test.sh @@ -0,0 +1,44 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2016 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + +atf_test_case raidz_dva_to_block_addr +raidz_dva_to_block_addr_head() +{ + atf_set "descr" "Unit tests for raidz_dva_to_block_addr" +} +raidz_dva_to_block_addr_body() +{ + . $(atf_get_srcdir)/default.cfg + + # These test cases were determined by hand on an actual filesystem + atf_check_equal 3211 `raidz_dva_to_block_addr 0:3f40000:4000 3 13` +} + +atf_init_test_cases() +{ + atf_add_test_case raidz_dva_to_block_addr +} diff --git a/tests/sys/cddl/zfs/include/logapi.kshlib b/tests/sys/cddl/zfs/include/logapi.kshlib new file mode 100644 index 00000000000..7246ceba8a2 --- /dev/null +++ b/tests/sys/cddl/zfs/include/logapi.kshlib @@ -0,0 +1,419 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)logapi.kshlib 1.2 07/03/14 SMI" +# + +# +# This is a ksh function library. It is intended to be sourced into +# other ksh scripts and not executed directly. +# + +. ${STF_SUITE}/include/stf.shlib + +# +# Send a debug message to stderr, if $STF_DEBUG set. +# +function log_debug +{ + [ -z "$STF_DEBUG" ] && return + echo "$*" >&2 +} + +# Output an assertion +# +# $@ - assertion text + +function log_assert +{ + _printline ASSERTION: "$@" +} + +# Output a comment +# +# $@ - comment text + +function log_note +{ + _printline NOTE: "$@" +} + +# Execute a positive test and exit $STF_FAIL is test fails +# +# $@ - command to execute + +function log_must +{ + log_pos "$@" + (( $? != 0 )) && log_fail +} + +# Execute a command that must exit $1 +# +# $@ - command to execute +function log_mustbe +{ + typeset exitcode_wanted=$1 + shift + + log_cmd "$@" + (( $? != $exitcode_wanted )) && log_fail +} + +# Execute a negative test and exit $STF_FAIL if test passes +# +# $@ - command to execute + +function log_mustnot +{ + log_neg "$@" + (( $? != 0 )) && log_fail +} + +# Execute a command that should only be logged if it fails. +# +# $@ - command to execute +function log_onfail +{ + eval $@ + typeset status=$? + [ $status -eq 0 ] && return + _printerror "$@" "unexpectedly exited $status" +} + +# Execute and print command with status where success equals non-zero result +# or output includes expected keyword +# +# $2-$@ - command to execute +# +# Summary: execute $@. Return 1 if any of the following hold: +# 1) The command exited 0, 127, 138, or 139 +# 2) The command's stderr included "internal error" or +# "assertion failed" +# +# return 0 if command fails, or the output contains the keyword expected, +# return 1 otherwise + +function log_neg +{ + typeset out="" + typeset logfile="$TMPDIR/log.$$" + typeset ret=1 + + while [[ -e $logfile ]]; do + logfile="$logfile.$$" + done + + "$@" 2>$logfile + typeset status=$? + out="/bin/cat $logfile" + + # unexpected status + if (( $status == 0 )); then + print -u2 $($out) + _printerror "$@" "unexpectedly exited $status" + # missing binary + elif (( $status == 127 )); then + print -u2 $($out) + _printerror "$@" "unexpectedly exited $status (File not found)" + # bus error - core dump + elif (( $status == 138 )); then + print -u2 $($out) + _printerror "$@" "unexpectedly exited $status (Bus Error)" + # segmentation violation - core dump + elif (( $status == 139 )); then + print -u2 $($out) + _printerror "$@" "unexpectedly exited $status (SEGV)" + else + $out | /usr/bin/egrep -i "internal error|assertion failed" \ + > /dev/null 2>&1 + # internal error or assertion failed + if (( $? == 0 )); then + print -u2 $($out) + _printerror "$@" "internal error or assertion failure" \ + " exited $status" + else + ret=0 + fi + + if (( $ret == 0 )); then + [[ -n $LOGAPI_DEBUG ]] && print $($out) + _printsuccess "$@" "exited $status" + fi + fi + _recursive_output $logfile "false" + return $ret +} + +# Execute and print command; unconditionally return its exit code. +# Useful for code that needs to do more specialized exit status filtering. +function log_cmd +{ + typeset logfile="$TMPDIR/log.$$" + + while [[ -e $logfile ]]; do + logfile="$logfile.$$" + done + + "$@" 2>$logfile + typeset status=$? + _printline "EXECUTED (exited $status): $@" + _recursive_output $logfile "false" + return $status +} + +# Execute and print command with status where success equals zero result +# +# $@ command to execute +# +# Summary: run $@. return 1 if its exit status was nonzero or if it printed +# "internal error" or "assertion failed" to stderr. +# print stderr on failure or if LOGAPI_DEBUG is set. +# +# return command exit status + +function log_pos +{ + typeset out="" + typeset logfile="$TMPDIR/log.$$" + + while [[ -e $logfile ]]; do + logfile="$logfile.$$" + done + + "$@" 2>$logfile + typeset status=$? + out="/bin/cat $logfile" + + if (( $status != 0 )) ; then + print -u2 $($out) + _printerror "$@" "exited $status" + else + $out | /usr/bin/egrep -i "internal error|assertion failed" \ + > /dev/null 2>&1 + # internal error or assertion failed + if [[ $? -eq 0 ]]; then + print -u2 $($out) + _printerror "$@" "internal error or assertion failure" \ + " exited $status" + status=1 + else + [[ -n $LOGAPI_DEBUG ]] && print $($out) + _printsuccess "$@" + fi + fi + _recursive_output $logfile "false" + return $status +} + +# Set an exit handler +# +# $@ - function(s) to perform on exit + +function log_onexit +{ + _CLEANUP="$@" +} + +# +# Exit functions +# + +# Perform cleanup and exit $STF_PASS +# +# $@ - message text + +function log_pass +{ + _endlog $STF_PASS "$@" +} + +# Perform cleanup and exit $STF_FAIL +# +# $@ - message text + +function log_fail +{ + _endlog $STF_FAIL "$@" +} + +# Perform cleanup and exit $STF_UNRESOLVED +# +# $@ - message text + +function log_unresolved +{ + _endlog $STF_UNRESOLVED "$@" +} + +# Perform cleanup and exit $STF_NOTINUSE +# +# $@ - message text + +function log_notinuse +{ + _endlog $STF_NOTINUSE "$@" +} + +# Perform cleanup and exit $STF_UNSUPPORTED +# +# $@ - message text + +function log_unsupported +{ + _endlog $STF_UNSUPPORTED "$@" +} + +# Perform cleanup and exit $STF_UNTESTED +# +# $@ - message text + +function log_untested +{ + _endlog $STF_UNTESTED "$@" +} + +# Perform cleanup and exit $STF_UNINITIATED +# +# $@ - message text + +function log_uninitiated +{ + _endlog $STF_UNINITIATED "$@" +} + +# Perform cleanup and exit $STF_NORESULT +# +# $@ - message text + +function log_noresult +{ + _endlog $STF_NORESULT "$@" +} + +# Perform cleanup and exit $STF_WARNING +# +# $@ - message text + +function log_warning +{ + _endlog $STF_WARNING "$@" +} + +# Perform cleanup and exit $STF_TIMED_OUT +# +# $@ - message text + +function log_timed_out +{ + _endlog $STF_TIMED_OUT "$@" +} + +# Perform cleanup and exit $STF_OTHER +# +# $@ - message text + +function log_other +{ + _endlog $STF_OTHER "$@" +} + +# +# Internal functions +# + +# Perform cleanup and exit +# +# Summary: Runs any cleanup routine registered with log_onexit. Prints a +# message and exits $1. Note: the _recursive_output does +# nothing, because the rest of this api guarantees that the +# logfile will not exist. +# $1 - stf exit code +# $2-$n - message text + +function _endlog +{ + typeset logfile="$TMPDIR/log.$$" + _recursive_output $logfile + + export STF_EXITCODE=$1 + shift + (( ${#@} > 0 )) && _printline "$@" + if [[ -n $_CLEANUP ]] ; then + typeset cleanup=$_CLEANUP + log_onexit "" + log_note "Performing local cleanup via log_onexit ($cleanup)" + $cleanup + fi + exit $STF_EXITCODE +} + +# Output a formatted line +# +# $@ - message text + +function _printline +{ + print `/bin/date +%H:%M:%S` "$@" +} + +# Output an error message +# +# $@ - message text + +function _printerror +{ + _printline ERROR: "$@" +} + +# Output a success message +# +# $@ - message text + +function _printsuccess +{ + _printline SUCCESS: "$@" +} + +# Output logfiles recursively +# +# $1 - start file +# $2 - indicate whether output the start file itself, default as yes. + +function _recursive_output #logfile +{ + typeset logfile=$1 + + while [[ -e $logfile ]]; do + if [[ -z $2 || $logfile != $1 ]]; then + /bin/cat $logfile + fi + /bin/rm -f $logfile + logfile="$logfile.$$" + done +} diff --git a/tests/sys/cddl/zfs/include/stf.shlib b/tests/sys/cddl/zfs/include/stf.shlib new file mode 100644 index 00000000000..b5e10d600bd --- /dev/null +++ b/tests/sys/cddl/zfs/include/stf.shlib @@ -0,0 +1,55 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)stf.shlib 1.2 07/04/12 SMI" +# + +STF_PASS=0 +STF_FAIL=1 +STF_UNRESOLVED=2 +STF_NOTINUSE=3 +STF_UNSUPPORTED=4 +STF_UNTESTED=5 +STF_UNINITIATED=6 +STF_NORESULT=7 +STF_WARNING=8 +STF_TIMED_OUT=9 +STF_OTHER=10 + +# do this to use the names: eval echo \$STF_RESULT_NAME_${result} +STF_RESULT_NAME_0="PASS" +STF_RESULT_NAME_1="FAIL" +STF_RESULT_NAME_2="UNRESOLVED" +STF_RESULT_NAME_3="NOTINUSE" +STF_RESULT_NAME_4="UNSUPPORTED" +STF_RESULT_NAME_5="UNTESTED" +STF_RESULT_NAME_6="UNINITIATED" +STF_RESULT_NAME_7="NORESULT" +STF_RESULT_NAME_8="WARNING" +STF_RESULT_NAME_9="TIMED_OUT" +STF_RESULT_NAME_10="OTHER" diff --git a/tests/sys/cddl/zfs/include/testenv.ksh b/tests/sys/cddl/zfs/include/testenv.ksh new file mode 100644 index 00000000000..bae66aedac3 --- /dev/null +++ b/tests/sys/cddl/zfs/include/testenv.ksh @@ -0,0 +1,21 @@ +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/include/commands.cfg + +# $FreeBSD$ + +# Environment-dependent constants. +for d in `geom disk list | awk '/Name:/ {print $3}'`; do + # Clear the GPT label first to avoid spurious create failures. + gpart destroy -F $d >/dev/null 2>&1 + if gpart create -s gpt $d >/dev/null 2>&1 ; then + gpart destroy $d >/dev/null 2>&1 || continue + DISKS=("${DISKS[@]}" "/dev/$d") #"$DISKS $d" + fi + # Don't bother testing any more if we have enough already. + # Currently we use at most 5 disks plus 1 for temporary disks. + [ ${#DISKS[@]} -eq 6 ] && break +done +export KEEP="$(zpool list -H -o name)" + +# Pull in constants. +. ${STF_SUITE}/include/constants.cfg diff --git a/tests/sys/cddl/zfs/include/testenv.kshlib b/tests/sys/cddl/zfs/include/testenv.kshlib new file mode 100644 index 00000000000..17153389203 --- /dev/null +++ b/tests/sys/cddl/zfs/include/testenv.kshlib @@ -0,0 +1,22 @@ +# vim: filetype=sh +# $FreeBSD$ + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/include/commands.cfg + +# Environment-dependent constants. +for d in `geom disk list | awk '/Name:/ {print $3}'`; do + # Clear the GPT label first to avoid spurious create failures. + gpart destroy -F $d >/dev/null 2>&1 + if gpart create -s gpt $d >/dev/null 2>&1 ; then + gpart destroy $d >/dev/null 2>&1 || continue + DISKS=("${DISKS[@]}" "/dev/$d") #"$DISKS $d" + fi + # Don't bother testing any more if we have enough already. + # Currently we use at most 5 disks plus 1 for temporary disks. + [ ${#DISKS[@]} -eq 6 ] && break +done +export KEEP="$(zpool list -H -o name)" + +# Pull in constants. +. ${STF_SUITE}/include/constants.cfg diff --git a/tests/sys/cddl/zfs/include/translatecommands.awk b/tests/sys/cddl/zfs/include/translatecommands.awk new file mode 100644 index 00000000000..b994a4b0e7a --- /dev/null +++ b/tests/sys/cddl/zfs/include/translatecommands.awk @@ -0,0 +1,40 @@ +#! /usr/bin/awk -f +# $FreeBSD$ + +BEGIN { + print "# This file is autogenerated from commands.txt. Do not edit" + cmdstring = "export CMDS=\"" + cmdch = 1 + cmd_idx=0 +} + +# Strip comments +{ + gsub(/#.*/, "", $0) +} + +# Strip blank lines +/^[ ]*$/ { + next +} + +# Process remaining lines +{ + gsub(/%%STFSUITEDIR%%/, stfsuitedir, $1) + fullcmd = $1 + cmdname = $1 + gsub(/.*\//, "", cmdname) + CMDNAME = toupper(cmdname) + allcmds[cmd_idx] = CMDNAME + cmd_idx += 1 + printf "export %s=\"%s\"\n", CMDNAME, fullcmd +} + +# Print CMDS +END { + print "" + printf "export CMDS=\"" + for (idx in allcmds) + printf "$%s ", allcmds[idx] + print "\"" +} diff --git a/tests/sys/cddl/zfs/tests/Makefile b/tests/sys/cddl/zfs/tests/Makefile new file mode 100644 index 00000000000..a6f6b3ff1d0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/Makefile @@ -0,0 +1,89 @@ +# $FreeBSD$ + +.include + +PACKAGE= tests +TESTSDIR= ${TESTSBASE}/sys/cddl/zfs/tests + +TESTS_SUBDIRS+= acl +TESTS_SUBDIRS+= atime +TESTS_SUBDIRS+= bootfs +TESTS_SUBDIRS+= cache +TESTS_SUBDIRS+= cachefile +TESTS_SUBDIRS+= clean_mirror +TESTS_SUBDIRS+= cli_root +TESTS_SUBDIRS+= cli_user +TESTS_SUBDIRS+= compression +TESTS_SUBDIRS+= ctime +TESTS_SUBDIRS+= delegate +TESTS_SUBDIRS+= devices +TESTS_SUBDIRS+= exec +TESTS_SUBDIRS+= grow_pool +TESTS_SUBDIRS+= grow_replicas +TESTS_SUBDIRS+= history +TESTS_SUBDIRS+= hotplug +TESTS_SUBDIRS+= hotspare +TESTS_SUBDIRS+= inheritance +# Not yet ported to FreeBSD +# TESTS_SUBDIRS+= interop +TESTS_SUBDIRS+= inuse +# Not yet ported to FreeBSD +# TESTS_SUBDIRS+= iscsi +TESTS_SUBDIRS+= large_files +# Not yet ported to FreeBSD +# TESTS_SUBDIRS+= largest_pool +# link_count is not yet ported to FreeBSD. I'm not sure what its purpose is. +# The assertion message contradicts with the log_fail message. +# TESTS_SUBDIRS+= link_count +TESTS_SUBDIRS+= migration +TESTS_SUBDIRS+= mmap +TESTS_SUBDIRS+= mount +TESTS_SUBDIRS+= mv_files +TESTS_SUBDIRS+= nestedfs +TESTS_SUBDIRS+= no_space +TESTS_SUBDIRS+= online_offline +TESTS_SUBDIRS+= pool_names +TESTS_SUBDIRS+= poolversion +TESTS_SUBDIRS+= quota +TESTS_SUBDIRS+= redundancy +TESTS_SUBDIRS+= refquota +TESTS_SUBDIRS+= refreserv +# Broken on every OS +# TESTS_SUBDIRS+= rename_dirs +TESTS_SUBDIRS+= replacement +TESTS_SUBDIRS+= reservation +TESTS_SUBDIRS+= rootpool +# Not yet ported to FreeBSD +# TESTS_SUBDIRS+= rsend +TESTS_SUBDIRS+= scrub_mirror +TESTS_SUBDIRS+= slog +TESTS_SUBDIRS+= snapshot +TESTS_SUBDIRS+= snapused +TESTS_SUBDIRS+= sparse +TESTS_SUBDIRS+= threadsappend +TESTS_SUBDIRS+= truncate +TESTS_SUBDIRS+= txg_integrity +TESTS_SUBDIRS+= userquota +TESTS_SUBDIRS+= utils_test +TESTS_SUBDIRS+= write_dirs +# Not yet ported to FreeBSD +# TESTS_SUBDIRS+= xattr +TESTS_SUBDIRS+= zfsd +TESTS_SUBDIRS+= zil +# Not yet ported to FreeBSD +# TESTS_SUBDIRS+= zinject +# Not yet ported to FreeBSD +# TESTS_SUBDIRS+= zones +TESTS_SUBDIRS+= zvol +TESTS_SUBDIRS+= zvol_thrash + +# This is primarily useful for identifying which test a testid corresponds to. +# Sometimes all you might have is a pool name like 'testpool.1316'. +testids: + for i in `find ${.CURDIR} -name '*.sh' | xargs grep '^atf_test_case '|awk '{print $$2}'`; do \ + echo "$${i}: $$(echo $$i | cksum -o 2 | cut -d" " -f1)"; \ + done + +.PHONY: testids + +.include diff --git a/tests/sys/cddl/zfs/tests/acl/Makefile b/tests/sys/cddl/zfs/tests/acl/Makefile new file mode 100644 index 00000000000..fb42da2d333 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/acl +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= acl.cfg +${PACKAGE}FILES+= acl_common.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +TESTS_SUBDIRS+= cifs +TESTS_SUBDIRS+= trivial +TESTS_SUBDIRS+= nontrivial + +.include diff --git a/tests/sys/cddl/zfs/tests/acl/acl.cfg b/tests/sys/cddl/zfs/tests/acl/acl.cfg new file mode 100644 index 00000000000..e8216ee4bfa --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/acl.cfg @@ -0,0 +1,72 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)acl.cfg 1.3 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +export NISSTAFILE=$TMPDIR/nis_state +export TESTFILE=testfile${TESTCASE_ID} +export TESTFILE0=testfile0.${TESTCASE_ID} +export TESTFILE2=testfile2.${TESTCASE_ID} + +# Define super user 'admin' +export ZFS_ACL_ADMIN=admin + +export ZFS_ACL_STAFF_GROUP=zfsgrp +export ZFS_ACL_STAFF1=staff1 +export ZFS_ACL_STAFF2=staff2 + +export ZFS_ACL_OTHER_GROUP=othergrp +export ZFS_ACL_OTHER1=other1 +export ZFS_ACL_OTHER2=other2 + +# Define the current user who run 'usr_exec' +export ZFS_ACL_CUR_USER="" + +# Define global error string +export ZFS_ACL_ERR_STR="" + +# Define test file and test directory which will be operated by chmod +export testfile=$TESTDIR/testfile +export testdir=$TESTDIR/testdir + +# Define several directories for trivial ACLs function test. +export RES_DIR=$TESTDIR/RES +export INI_DIR=$TESTDIR/INIT +export TST_DIR=$TESTDIR/TEST +export TMP_DIR=$TESTDIR/TMP + +# Define test files and their attributes files number for trivial +# ACLs function test +export NUM_FILE=5 +export NUM_ATTR=10 + +# Enlarge STF_TIMEOUT +export STF_TIMEOUT=1800 diff --git a/tests/sys/cddl/zfs/tests/acl/acl_common.kshlib b/tests/sys/cddl/zfs/tests/acl/acl_common.kshlib new file mode 100644 index 00000000000..fa3a12e61dc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/acl_common.kshlib @@ -0,0 +1,638 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)acl_common.kshlib 1.4 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# FreeBSD doesn't support ZFS extended attributes. It also doesn't support the +# same ACL mechanisms Solaris does for testing. +if [[ $os_name != "FreeBSD" ]]; then + export ZFS_XATTR="true" + export ZFS_ACL="true" +else + log_note "On FreeBSD most xattr and ACL tests are disabled" +fi + +# +# Get the given file/directory access mode +# +# $1 object -- file or directroy +# +function get_mode # +{ + typeset obj=$1 + if (( ${#obj} == 0 )); then + return 1 + fi + + $LS -ld $obj | $AWK '{print $1}' +} + +# +# Get the given file/directory ACL +# +# $1 object -- file or directroy +# +function get_acl # +{ + typeset obj=$1 + if (( ${#obj} == 0 )); then + return 1 + fi + + $LS -vd $obj | $NAWK '(NR != 1) {print $0}' +} + +# +# Get the given file/directory ACL +# +# $1 object -- file or directroy +# +function get_compact_acl # +{ + typeset obj=$1 + if (( ${#obj} == 0 )); then + return 1 + fi + + $LS -Vd $obj | $NAWK '(NR != 1) {print $0}' +} + +# +# Check the given two files/directories have the same ACLs +# +# Return 0, if source object acl is equal to target object acl. +# +# $1 source object +# $2 target object +# +function compare_acls # +{ + typeset src=$1 + typeset tgt=$2 + + (( ${#src} == 0 || ${#tgt} == 0 )) && return 1 + [[ $src == $tgt ]] && return 0 + + typeset tmpsrc=$TMPDIR/compare_acls.src.${TESTCASE_ID} + typeset tmptgt=$TMPDIR/compare_acls.tgt.${TESTCASE_ID} + + get_acl $src > $tmpsrc + get_acl $tgt > $tmptgt + typeset -i ret=0 + $DIFF $tmpsrc $tmptgt > /dev/null 2>&1 + ret=$? + $RM -f $tmpsrc $tmptgt + + if (( ret != 0 )); then + return $ret + fi + + get_compact_acl $src > $tmpsrc + get_compact_acl $tgt > $tmptgt + $DIFF $tmpsrc $tmptgt > /dev/null 2>&1 + ret=$? + $RM -f $tmpsrc $tmptgt + + return $ret +} + +# +# Check that the given two objects have the same modes. +# Return 0, if their modes are equal with each other. Otherwise, return 1. +# +# $1 source object +# $2 target object +# +function compare_modes # +{ + typeset src=$1 + typeset tgt=$2 + typeset -i i=0 + set -A mode + + (( ${#src} == 0 || ${#tgt} == 0 )) && return 1 + [[ $src == $tgt ]] && return 0 + + typeset obj + for obj in $src $tgt + do + mode[i]=$(get_mode $obj) + + (( i = i + 1 )) + done + + [[ ${mode[0]} != ${mode[1]} ]] && return 1 + + return 0 +} + +# +# Check that the given two objects have the same xattrs. +# Return 0, if their xattrs are equal with each other. Otherwise, return 1. +# +# $1 source object +# $2 target object +# +function compare_xattrs # +{ + typeset src=$1 + typeset tgt=$2 + + (( ${#src} == 0 || ${#tgt} == 0 )) && return 1 + [[ $src == $tgt ]] && return 0 + + typeset tmpsrc=$TMPDIR/compare_xattrs.src.${TESTCASE_ID} + typeset tmptgt=$TMPDIR/compare_xattrs.tgt.${TESTCASE_ID} + + get_xattr $src > $tmpsrc + get_xattr $tgt > $tmptgt + typeset -i ret=0 + $DIFF $tmpsrc $tmptgt > /dev/null 2>&1 + ret=$? + $RM -f $tmpsrc $tmptgt + + return $ret +} + +# +# Check '+' is set for a given file/directory with 'ls [-l]' command +# +# $1 object -- file or directory. +# +function plus_sign_check_l # +{ + typeset obj=$1 + if (( ${#obj} == 0 )); then + return 1 + fi + + $LS -ld $obj | $AWK '{print $1}' | $GREP "+\>" > /dev/null + + return $? +} + +# +# Check '+' is set for a given file/directory with 'ls [-v]' command +# +# $1 object -- file or directory. +# +function plus_sign_check_v # +{ + typeset obj=$1 + if (( ${#obj} == 0 )); then + return 1 + fi + + $LS -vd $obj | $NAWK '(NR == 1) {print $1}' | $GREP "+\>" > /dev/null + + return $? +} + +# +# A wrapper function of c program +# +# $1 legal login name +# $2-n commands and options +# +function chgusr_exec # [...] +{ + $CHG_USR_EXEC $@ + return $? +} + +# +# Export the current user for the following usr_exec operating. +# +# $1 legal login name +# +function set_cur_usr # +{ + export ZFS_ACL_CUR_USER=$1 +} + +# +# Run commands by $ZFS_ACL_CUR_USER +# +# $1-n commands and options +# +function usr_exec # [...] +{ + $CHG_USR_EXEC "$ZFS_ACL_CUR_USER" $@ + return $? +} + +# +# Count how many ACEs for the specified file or directory. +# +# $1 file or directroy name +# +function count_ACE # +{ + if [[ ! -e $1 ]]; then + log_note "Need input file or directroy name." + return 1 + fi + + $LS -vd $1 | $NAWK 'BEGIN {count=0} + (NR != 1)&&(/[0-9]:/) {count++} + END {print count}' + + return 0 +} + +# +# Get specified number ACE content of specified file or directory. +# +# $1 file or directory name +# $2 specified number +# +function get_ACE # +{ + if [[ ! -e $1 || $2 -ge $(count_ACE $1) ]]; then + return 1 + fi + + typeset file=$1 + typeset -i num=$2 + typeset format=${3:-verbose} + typeset -i next_num=-1 + + typeset tmpfile=$TMPDIR/tmp_get_ACE.${TESTCASE_ID} + typeset line="" + typeset args + + case $format in + verbose) args="-vd" + ;; + compact) args="-Vd" + ;; + *) log_fail "Invalid parameter as ($format), " \ + "only verbose|compact is supported." + ;; + esac + + $LS $args $file > $tmpfile + (( $? != 0 )) && log_fail "FAIL: $LS $args $file > $tmpfile" + while read line; do + [[ -z $line ]] && continue + if [[ $args == -vd ]]; then + if [[ $line == "$num":* ]]; then + (( next_num = num + 1 )) + fi + if [[ $line == "$next_num":* ]]; then + break + fi + if (( next_num != -1 )); then + print -n $line + fi + else + if (( next_num == num )); then + print -n $line + fi + (( next_num += 1 )) + fi + done < $tmpfile + + $RM -f $tmpfile + (( $? != 0 )) && log_fail "FAIL: $RM -f $tmpfile" +} + +# +# Cleanup exist user/group. +# +function cleanup_user_group +{ + del_user $ZFS_ACL_ADMIN + + del_user $ZFS_ACL_STAFF1 + del_user $ZFS_ACL_STAFF2 + del_group $ZFS_ACL_STAFF_GROUP + + del_user $ZFS_ACL_OTHER1 + del_user $ZFS_ACL_OTHER2 + del_group $ZFS_ACL_OTHER_GROUP + + return 0 +} + +# +# Clean up testfile and test directory +# +function cleanup +{ + if [[ -d $TESTDIR ]]; then + cd $TESTDIR + $RM -rf $TESTDIR/* + fi +} + +# +# According to specified access or acl_spec, do relevant operating by using the +# specified user. +# +# $1 specified user +# $2 node +# $3 acl_spec or access +# +function rwx_node #user node acl_spec|access +{ + typeset user=$1 + typeset node=$2 + typeset acl_spec=$3 + + if [[ $user == "" || $node == "" || $acl_spec == "" ]]; then + log_note "node or acl_spec are not defined." + return 1 + fi + + if [[ -d $node ]]; then + case $acl_spec in + *:read_data:*|read_data) + chgusr_exec $user $LS -l $node > /dev/null 2>&1 + return $? ;; + *:write_data:*|write_data) + if [[ -f ${node}/tmpfile ]]; then + log_must $RM -f ${node}/tmpfile + fi + chgusr_exec $user $TOUCH ${node}/tmpfile > \ + /dev/null 2>&1 + return $? ;; + *"execute:"*|execute) + chgusr_exec $user $FIND $node > /dev/null 2>&1 + return $? ;; + esac + else + case $acl_spec in + *:read_data:*|read_data) + chgusr_exec $user $CAT $node > /dev/null 2>&1 + return $? ;; + *:write_data:*|write_data) + chgusr_exec $user $DD if=/bin/ls of=$node > \ + /dev/null 2>&1 + return $? ;; + *"execute:"*|execute) + ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1) + return $? ;; + esac + fi +} + +# +# Get the given file/directory xattr +# +# $1 object -- file or directroy +# +function get_xattr # +{ + typeset obj=$1 + typeset xattr + if (( ${#obj} == 0 )); then + return 1 + fi + + for xattr in `$RUNAT $obj $LS | \ + /usr/bin/egrep -v -e SUNWattr_ro -e SUNWattr_rw` ; do + $RUNAT $obj $SUM $xattr + done +} + +# +# Get the owner of a file/directory +# +function get_owner #node +{ + typeset node=$1 + typeset value + + if [[ -z $node ]]; then + log_fail "node are not defined." + fi + + if [[ -d $node ]]; then + value=$($LS -dl $node | $AWK '{print $3}') + elif [[ -e $node ]]; then + value=$($LS -l $node | $AWK '{print $3}') + fi + + $ECHO $value +} + +# +# Get the group of a file/directory +# +function get_group #node +{ + typeset node=$1 + typeset value + + if [[ -z $node ]]; then + log_fail "node are not defined." + fi + + if [[ -d $node ]]; then + value=$($LS -dl $node | $AWK '{print $4}') + elif [[ -e $node ]]; then + value=$($LS -l $node | $AWK '{print $4}') + fi + + $ECHO $value +} + + +# +# Get the group name that a UID belongs to +# +function get_user_group #uid +{ + typeset uid=$1 + typeset value + + if [[ -z $uid ]]; then + log_fail "UID not defined." + fi + + value=$(id $uid) + + if [[ $? -eq 0 ]]; then + value=${value##*\(} + value=${value%%\)*} + $ECHO $value + else + log_fail "Invalid UID (uid)." + fi +} + +# +# Get the specified item of the specified string +# +# $1: Item number, count from 0. +# $2-n: strings +# +function getitem +{ + typeset -i n=$1 + shift + + (( n += 1 )) + eval print \${$n} +} + +# +# This function calculate the specified directory files checksum and write +# to the specified array. +# +# $1 directory in which the files will be cksum. +# $2 file array name which was used to store file cksum information. +# $3 attribute array name which was used to store attribute information. +# +function cksum_files # +{ + typeset dir=$1 + typeset farr_name=$2 + typeset aarr_name=$3 + + [[ ! -d $dir ]] && return + typeset oldpwd=$PWD + cd $dir + typeset files=$($LS file*) + + typeset -i i=0 + typeset -i n=0 + while (( i < NUM_FILE )); do + typeset f=$(getitem $i $files) + eval $farr_name[$i]=\$\(\$CKSUM $f\) + + typeset -i j=0 + while (( j < NUM_ATTR )); do + eval $aarr_name[$n]=\$\(\$RUNAT \$f \$CKSUM \ + attribute.$j\) + + (( j += 1 )) + (( n += 1 )) + done + + (( i += 1 )) + done + + cd $oldpwd +} + +# +# This function compare two cksum results array. +# +# $1 The array name which stored the cksum before operation. +# $2 The array name which stored the cksum after operation. +# +function compare_cksum # +{ + typeset before=$1 + typeset after=$2 + eval typeset -i count=\${#$before[@]} + + typeset -i i=0 + while (( i < count )); do + eval typeset var1=\${$before[$i]} + eval typeset var2=\${$after[$i]} + + if [[ $var1 != $var2 ]]; then + return 1 + fi + + (( i += 1 )) + done + + return 0 +} + +# +# This function calculate all the files cksum information in current directory +# and output them to the specified file. +# +# $1 directory from which the files will be cksum. +# $2 cksum output file +# +function record_cksum # +{ + typeset dir=$1 + typeset outfile=$2 + + [[ ! -d ${outfile%/*} ]] && usr_exec $MKDIR -p ${outfile%/*} + + usr_exec cd $dir ; $FIND . -depth -type f -exec cksum {} \\\; | $SORT > $outfile + usr_exec cd $dir ; $FIND . -depth -type f -xattr -exec runat {} \ + cksum attribute* \\\; | $SORT >> $outfile +} + +# +# The function create_files creates the directories and files that the script +# will operate on to test extended attribute functionality. +# +# $1 The base directory in which to create directories and files. +# +function create_files # +{ + typeset basedir=$1 + + [[ ! -d $basedir ]] && usr_exec $MKDIR -m 777 $basedir + [[ ! -d $RES_DIR ]] && usr_exec $MKDIR -m 777 $RES_DIR + [[ ! -d $INI_DIR ]] && usr_exec $MKDIR -m 777 $INI_DIR + [[ ! -d $TST_DIR ]] && usr_exec $MKDIR -m 777 $TST_DIR + [[ ! -d $TMP_DIR ]] && usr_exec $MKDIR -m 777 $TMP_DIR + + # + # Create the original file and its attribute files. + # + [[ ! -a $RES_DIR/file ]] && \ + usr_exec $FILE_WRITE -o create -f $RES_DIR/file \ + -b 1024 -d 0 -c 1 + [[ ! -a $RES_DIR/attribute ]] && \ + usr_exec $CP $RES_DIR/file $RES_DIR/attribute + + typeset oldpwd=$PWD + cd $INI_DIR + + typeset -i i=0 + while (( i < NUM_FILE )); do + typeset dstfile=$INI_DIR/file.${TESTCASE_ID}.$i + usr_exec $CP $RES_DIR/file $dstfile + + typeset -i j=0 + while (( j < NUM_ATTR )); do + usr_exec $RUNAT $dstfile \ + $CP $RES_DIR/attribute ./attribute.$j + (( j += 1 )) + done + + (( i += 1 )) + done + + cd $oldpwd +} diff --git a/tests/sys/cddl/zfs/tests/acl/cifs/Makefile b/tests/sys/cddl/zfs/tests/acl/cifs/Makefile new file mode 100644 index 00000000000..e317fb94176 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/cifs/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/acl/cifs +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= cifs.kshlib +${PACKAGE}FILES+= cifs_attr_001_pos.ksh +${PACKAGE}FILES+= cifs_attr_002_pos.ksh +${PACKAGE}FILES+= cifs_attr_003_pos.ksh + +ATF_TESTS_KSH93+= cifs_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +.include diff --git a/tests/sys/cddl/zfs/tests/acl/cifs/cifs.kshlib b/tests/sys/cddl/zfs/tests/acl/cifs/cifs.kshlib new file mode 100644 index 00000000000..74bc430e602 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/cifs/cifs.kshlib @@ -0,0 +1,91 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cifs.kshlib 1.4 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +function cifs_supported +{ + if check_version "5.11" ; then + fs_prop_exist "sharesmb" + return $? + fi + return 1 +} + +# +# Create a file or direcotry +# +# $1: The type specified, "file" or "dir" +# $2: The given node name +# $3: Owner of the node +# +function create_object +{ + typeset type=$1 + typeset object=$2 + typeset owner=$3 + + destroy_object $object + + case $type in + dir) + $MKDIR -p $object + ;; + file) + $ECHO "ZFS test suites" > $object + ;; + esac + + if [[ -n $owner ]]; then + $CHOWN $owner $object + fi + return 0 +} + +# +# Destroy the given node(s) +# +# $@: The node(s) need to be destroyed +# +function destroy_object +{ + for object in $@ ; do + if [[ -e $object ]]; then + + # clear_attribute is a common function name, + # but each case should have their own implement. + log_must clear_attribute $object + log_must $RM -rf $object + fi + done + return 0 +} + diff --git a/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_001_pos.ksh new file mode 100644 index 00000000000..308f55efbce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_001_pos.ksh @@ -0,0 +1,262 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cifs_attr_001_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib +. $STF_SUITE/tests/acl/cifs/cifs.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cifs_attr_001_pos +# +# DESCRIPTION: +# Verify the user with write_attributes permission or +# PRIV_FILE_OWNER privilege could set/clear DOS attributes. +# (Readonly, Hidden, Archive, System) +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Grant user has write_attributes permission or +# PRIV_FILE_OWNER privilege +# 4. Verify set/clear DOS attributes should succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! cifs_supported ; then + log_unsupported "CIFS not supported on current system." +fi + +test_requires ZFS_ACL ZFS_XATTR + +function cleanup +{ + for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do + mtpt=$(get_prop mountpoint $fs) + log_must $RM -rf $mtpt/file.* $mtpt/dir.* + done +} + +# +# Set the special attribute to the given node +# +# $1: The given node (file/dir) +# $2: The special attribute to be set +# $3: Execute username +# +function set_attribute +{ + typeset object=$1 + typeset attr=${2:-AHRS} + typeset user=$3 + typeset ret=0 + + if [[ -z $object ]]; then + log_fail "Object not defined." + fi + + if [[ -n $user ]]; then + $RUNWATTR -u $user "$CHMOD S+c${attr} $object" + ret=$? + else + $CHMOD S+c${attr} $object + ret=$? + fi + + return $ret +} + +# +# Clear the special attribute to the given node +# +# $1: The given node (file/dir) +# $2: The special attribute to be cleared +# $3: Execute username +# +function clear_attribute +{ + typeset object=$1 + typeset attr=${2:-AHRS} + typeset user=$3 + typeset ret=0 + + if [[ -z $object ]]; then + log_fail "Object not defined." + fi + + if [[ -n $user ]]; then + $RUNWATTR -u $user "$CHMOD S-c${attr} $object" + ret=$? + else + $CHMOD S-c${attr} $object + ret=$? + fi + + return $ret +} + +# +# Grant the ace of write_attributes to the given user +# +# $1: The given user +# $2: The given node (file/dir) +# +function grant_attr +{ + typeset user=$1 + typeset object=$2 + + if [[ -z $user || -z $object ]]; then + log_fail "User($user), Object($object) not defined." + fi + + # To increase the coverage, here we set 'deny' against + # superuser and owner. + # Only grant the user explicitly while it's not root neither owner. + + if [[ $user == "root" ]]; then + log_must chmod A+user:root:write_attributes:deny $object + elif [[ $user == $(get_owner $object) ]]; then + if (( ( RANDOM % 2 ) == 0 )); then + log_must chmod A+owner@:write_attributes:deny $object + else + log_must chmod A+user:$user:write_attributes:deny \ + $object + fi + else + log_must chmod A+user:$user:write_attributes:allow $object + fi + attr_mod="write_attributes" +} + +# +# Revoke the ace of write_attributes from the given user +# +# $1: The given user +# $2: The given node (file/dir) +# +function revoke_attr +{ + typeset user=$1 + typeset object=$2 + + if [[ -z $user || -z $object ]]; then + log_fail "User($user), Object($object) not defined." + fi + + log_must chmod A0- $object + attr_mod= +} + +# +# Invoke the function and verify whether its return code as expected +# +# $1: Function be invoked +# $2: The given node (file/dir) +# $3: Execute user +# $4: Option +# +function verify_attr +{ + typeset func=$1 + typeset object=$2 + typeset opt=$3 + typeset user=$4 + typeset expect="log_mustnot" + + if [[ -z $func || -z $object ]]; then + log_fail "Func($func), Object($object), User($user), \ + Opt($opt) not defined." + fi + + # If user is superuser or has write_attributes permission or + # PRIV_FILE_OWNER privilege, it should log_must, + # otherwise log_mustnot. + + if [[ -z $user || $user == "root" || \ + $user == $(get_owner $object) || \ + $attr_mod == *"write_attributes"* ]] ; then + expect="log_must" + fi + + $expect $func $object $opt $user +} + +log_assert "Verify set/clear DOS attributes will succeed while user has " \ + "write_attributes permission or PRIV_FILE_OWNER privilege" +log_onexit cleanup + +file="file.0" +dir="dir.0" +XATTROPTIONS="H S R A" + +for fs in $TESTPOOL $TESTPOOL/$TESTFS ; do + mtpt=$(get_prop mountpoint $fs) + for owner in root $ZFS_ACL_STAFF1 ; do + + create_object "file" $mtpt/$file $owner + create_object "dir" $mtpt/$dir $owner + + for object in $mtpt/$file $mtpt/$dir ; do + for user in root $ZFS_ACL_STAFF2 ; do + for opt in $XATTROPTIONS ; do + verify_attr set_attribute \ + $object $opt $user + verify_attr clear_attribute \ + $object $opt $user + done + log_must grant_attr $user $object + for opt in $XATTROPTIONS ; do + verify_attr set_attribute \ + $object $opt $user + verify_attr clear_attribute \ + $object $opt $user + done + log_must revoke_attr $user $object + done + done + destroy_object $mtpt/$file $mtpt/$dir + done +done + +log_pass "Set/Clear DOS attributes succeed while user has " \ + "write_attributes permission or PRIV_FILE_OWNER privilege" diff --git a/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_002_pos.ksh new file mode 100644 index 00000000000..450366cd89a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_002_pos.ksh @@ -0,0 +1,280 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cifs_attr_002_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib +. $STF_SUITE/tests/acl/cifs/cifs.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cifs_attr_002_pos +# +# DESCRIPTION: +# Verify the user with PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR +# could set/clear BSD'ish attributes. +# (Immutable, nounlink, and appendonly) +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Grant user has PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR separately. +# 4. Verify set/clear BSD'ish attributes should succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +if ! cifs_supported ; then + log_unsupported "CIFS not supported on current system." +fi + +test_requires ZFS_ACL ZFS_XATTR + +function cleanup +{ + if [[ -n $gobject ]]; then + destroy_object $gobject + fi + + for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do + mtpt=$(get_prop mountpoint $fs) + log_must $RM -rf $mtpt/file.* $mtpt/dir.* + done +} + +# +# Set the special attribute to the given node +# +# $1: The given node (file/dir) +# $2: The special attribute to be set +# $3: Execute username +# +function set_attribute +{ + typeset object=$1 + typeset attr=$2 + typeset user=$3 + typeset ret=0 + + if [[ -z $object ]]; then + log_fail "Object not defined." + fi + + if [[ -z $attr ]]; then + attr="uiadm" + if [[ -f $object ]]; then + attr="${attr}q" + fi + fi + + if [[ -n $user ]]; then + $RUNWATTR -u $user -p =basic${priv_mod} \ + "$CHMOD S+c${attr} $object" + ret=$? + else + $CHMOD S+c${attr} $object + ret=$? + fi + + return $ret +} + +# +# Clear the special attribute to the given node +# +# $1: The given node (file/dir) +# $2: The special attribute to be cleared +# $3: Execute username +# +function clear_attribute +{ + typeset object=$1 + typeset attr=$2 + typeset user=$3 + typeset ret=0 + + if [[ -z $object ]]; then + log_fail "Object($object) not defined." + fi + + if [[ -z $attr ]]; then + attr="uiadm" + if [[ -f $object ]]; then + attr="${attr}q" + fi + fi + + if [[ -n $user ]]; then + $RUNWATTR -u $user -p =basic${priv_mod} \ + "$CHMOD S-c${attr} $object" + ret=$? + else + $CHMOD S-c${attr} $object + ret=$? + fi + + return $ret +} + +# +# Grant the privset to the given user +# +# $1: The given user +# $2: The given privset +# +function grant_priv +{ + typeset user=$1 + typeset priv=$2 + + if [[ -z $user || -z $priv ]]; then + log_fail "User($user), Priv($priv) not defined." + fi + priv_mod=",$priv" + return $? +} + +# +# Revoke the all additional privset from the given user +# +# $1: The given user +# +function revoke_priv +{ + typeset user=$1 + + if [[ -z $user ]]; then + log_fail "User not defined." + fi + priv_mod= + return $? +} + +# +# Invoke the function and verify whether its return code as expected +# +# $1: Function be invoked +# $2: The given node (file/dir) +# $3: Execute user +# $4: Option +# +function verify_op +{ + typeset func=$1 + typeset object=$2 + typeset opt=$3 + typeset user=$4 + typeset expect="log_mustnot" + + if [[ -z $func || -z $object ]]; then + log_fail "Func($func), Object($object) not defined." + fi + + # If user has PRIV_FILE_FLAG_SET, it could permit to set_attribute, + # And If has PRIV_FILE_FLAG_CLEAR, it could permit to clear_attribute, + # otherwise log_mustnot. + if [[ -z $user || $user == "root" ]] || \ + [[ $priv_mod == *"file_flag_set"* ]] || \ + [[ $priv_mod == *"all"* ]] ; then + expect="log_must" + fi + if [[ -d $object ]] && \ + [[ $opt == *"q"* ]] ; then + expect="log_mustnot" + fi + + if [[ $func == clear_attribute ]]; then + if [[ $expect == "log_mustnot" ]]; then + expect="log_must" + elif [[ -z $user || $user == "root" ]] || \ + [[ $priv_mod == *"all"* ]] ; then + expect="log_must" + else + expect="log_mustnot" + fi + fi + + $expect $func $object $opt $user +} + +log_assert "Verify set/clear BSD'ish attributes will succeed while user has " \ + "PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR privilege" +log_onexit cleanup + +file="file.0" +dir="dir.0" +FLAGOPTIONS="u i a d q m" + +typeset gobject +for fs in $TESTPOOL $TESTPOOL/$TESTFS ; do + mtpt=$(get_prop mountpoint $fs) + for owner in root $ZFS_ACL_STAFF1 ; do + + create_object "file" $mtpt/$file $owner + create_object "dir" $mtpt/$dir $owner + + for object in $mtpt/$file $mtpt/$dir ; do + gobject=$object + for user in root $ZFS_ACL_STAFF2 ; do + log_must grant_priv $user file_flag_set + for opt in $FLAGOPTIONS ; do + verify_op set_attribute \ + $object $opt $user + verify_op clear_attribute \ + $object $opt $user + done + log_must revoke_priv $user + + log_must grant_priv $user all + for opt in $FLAGOPTIONS ; do + verify_op set_attribute \ + $object $opt $user + verify_op clear_attribute \ + $object $opt $user + done + log_must revoke_priv $user + done + done + destroy_object $mtpt/$file $mtpt/$dir + done +done + +log_pass "Set/Clear BSD'ish attributes succeed while user has " \ + "PRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR privilege" diff --git a/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_003_pos.ksh b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_003_pos.ksh new file mode 100644 index 00000000000..5edd2dee931 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_attr_003_pos.ksh @@ -0,0 +1,622 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cifs_attr_003_pos.ksh 1.4 09/05/19 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib +. $STF_SUITE/tests/acl/cifs/cifs.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cifs_attr_003_pos +# +# DESCRIPTION: +# Verify the DOS attributes (Readonly, Hidden, Archive, System) +# and BSD'ish attributes (Immutable, nounlink, and appendonly) +# will provide the proper access limitation as expected. +# +# Readonly means that the content of a file can't be modified, but +# timestamps, mode and so on can. +# +# Archive - Indicates if a file should be included in the next backup +# of the file system. ZFS will set this bit whenever a file is +# modified. +# +# Hidden and System (ZFS does nothing special with these, other than +# letting a user/application set them. +# +# Immutable (The data can't, change nor can mode, ACL, size and so on) +# The only attribute that can be updated is the access time. +# +# Nonunlink - Sort of like immutable except that a file/dir can't be +# removed. +# This will also effect a rename operation, since that involes a +# remove. +# +# Appendonly - File can only be appended to. +# +# nodump, settable, opaque (These are for the MacOS port) we will +# allow them to be set, but have no semantics tied to them. +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Set the file/dir with each kind of special attribute. +# 4. Verify the access limitation works as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! cifs_supported ; then + log_unsupported "CIFS not supported on current system." +fi + +test_requires ZFS_ACL ZFS_XATTR + +function cleanup +{ + if [[ -n $gobject ]]; then + destroy_object $gobject + fi + + for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do + mtpt=$(get_prop mountpoint $fs) + log_must $RM -rf $mtpt/file.* $mtpt/dir.* + done +} + +# +# Set the special attribute to the given node +# +# $1: The given node (file/dir) +# $2: The special attribute to be set +# +function set_attribute +{ + typeset object=$1 + typeset attr=$2 + + if [[ -z $attr ]]; then + attr="AHRSadimu" + if [[ -f $object ]]; then + attr="${attr}q" + fi + fi + + $CHMOD S+c${attr} $object + return $? +} + +# +# Clear the special attribute to the given node +# +# $1: The given node (file/dir) +# $2: The special attribute to be cleared +# +function clear_attribute +{ + typeset object=$1 + typeset attr=$2 + + if [[ -z $attr ]]; then + if is_global_zone ; then + attr="AHRSadimu" + if [[ -f $object ]]; then + attr="${attr}q" + fi + else + attr="AHRS" + fi + fi + + $CHMOD S-c${attr} $object + return $? +} + +# +# A wrapper function to call test function according to the given attr +# +# $1: The given node (file/dir) +# $2: The special attribute to be test +# +function test_wrapper +{ + typeset object=$1 + typeset attr=$2 + + if [[ -z $object || -z $attr ]]; then + log_fail "Object($object), Attr($attr) not defined." + fi + + case $attr in + R) func=test_readonly + ;; + i) func=test_immutable + ;; + u) func=test_nounlink + ;; + a) func=test_appendonly + ;; + esac + + if [[ -n $func ]]; then + $func $object + fi +} + +# +# Invoke the function and verify whether its return code as expected +# +# $1: Expect value +# $2-$n: Function and args need to be invoked +# +function verify_expect +{ + typeset -i expect=$1 + typeset status + + shift + + "$@" > /dev/null 2>&1 + status=$? + if [[ $status -eq 0 ]]; then + if (( expect != 0 )); then + log_fail "$@ unexpect return 0" + fi + else + if (( expect == 0 )); then + log_fail "$@ unexpect return $status" + fi + fi +} + +# +# Unit testing function against overwrite file +# +# $1: The given file node +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_writefile +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + if [[ -f $object ]]; then + verify_expect $expect $CHG_USR_EXEC $user \ + $CP $TESTFILE $object + verify_expect $expect $CHG_USR_EXEC $user \ + $EVAL "$ECHO '$TESTSTR' > $object" + fi +} + +# +# Unit testing function against write new stuffs into a directory +# +# $1: The given directory node +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_writedir +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + if [[ -d $object ]]; then + verify_expect $expect $CHG_USR_EXEC $user \ + $CP $TESTFILE $object + verify_expect $expect $CHG_USR_EXEC $user \ + $MKDIR -p $object/$TESTDIR + fi +} + +function unit_appenddata +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + if [[ ! -d $object ]]; then + verify_expect $expect $CHG_USR_EXEC $user \ + $EVAL "$ECHO '$TESTSTR' >> $object" + fi +} + +# +# Unit testing function against delete content from a directory +# +# $1: The given node, dir +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_deletecontent +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + if [[ -d $object ]]; then + for target in $object/${TESTFILE##*/} $object/$TESTDIR ; do + if [[ -e $target ]]; then + verify_expect $expect $CHG_USR_EXEC $user \ + $EVAL "$MV $target $target.new" + verify_expect $expect $CHG_USR_EXEC $user \ + $EVAL "$ECHO y | $RM -r $target.new" + fi + done + fi +} + +# +# Unit testing function against delete a node +# +# $1: The given node, file/dir +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_deletedata +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + verify_expect $expect $CHG_USR_EXEC $user \ + $EVAL "$ECHO y | $RM -r $object" + +} + +# +# Unit testing function against write xattr to a node +# +# $1: The given node, file/dir +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_writexattr +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + verify_expect $expect $CHG_USR_EXEC $user \ + $RUNAT $object "$CP $TESTFILE $TESTATTR" + verify_expect $expect $CHG_USR_EXEC $user \ + $EVAL "$RUNAT $object \"$ECHO '$TESTSTR' > $TESTATTR\"" + verify_expect $expect $CHG_USR_EXEC $user \ + $EVAL "$RUNAT $object \"$ECHO '$TESTSTR' >> $TESTATTR\"" + if [[ $expect -eq 0 ]]; then + verify_expect $expect $CHG_USR_EXEC $user \ + $RUNAT $object "$RM -f $TESTATTR" + fi +} + +# +# Unit testing function against modify accesstime of a node +# +# $1: The given node, file/dir +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_accesstime +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + if [[ -d $object ]]; then + verify_expect $expect $CHG_USR_EXEC $user $LS $object + else + verify_expect $expect $CHG_USR_EXEC $user $CAT $object + fi +} + +# +# Unit testing function against modify updatetime of a node +# +# $1: The given node, file/dir +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_updatetime +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + verify_expect $expect $CHG_USR_EXEC $user $TOUCH $object + verify_expect $expect $CHG_USR_EXEC $user $TOUCH -a $object + verify_expect $expect $CHG_USR_EXEC $user $TOUCH -m $object +} + +# +# Unit testing function against write acl of a node +# +# $1: The given node, file/dir +# $2: Execute user +# $3: Expect value, default to be zero +# +function unit_writeacl +{ + typeset object=$1 + typeset user=$2 + typeset expect=${3:-0} + + verify_expect $expect $CHG_USR_EXEC $user chmod A+$TESTACL $object + verify_expect $expect $CHG_USR_EXEC $user chmod A+$TESTACL $object + verify_expect $expect $CHG_USR_EXEC $user chmod A0- $object + verify_expect $expect $CHG_USR_EXEC $user chmod A0- $object + oldmode=$(get_mode $object) + verify_expect $expect $CHG_USR_EXEC $user chmod $TESTMODE $object +} + +# +# Testing function to verify the given node is readonly +# +# $1: The given node, file/dir +# +function test_readonly +{ + typeset object=$1 + + if [[ -z $object ]]; then + log_fail "Object($object) not defined." + fi + + log_note "Testing readonly of $object" + + for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do + if [[ -d $object ]]; then + log_must usr_exec chmod \ + A+user:$user:${ace_dir}:allow $object + else + log_must usr_exec chmod \ + A+user:$user:${ace_file}:allow $object + fi + + log_must set_attribute $object "R" + + unit_writefile $object $user 1 + unit_writedir $object $user + unit_appenddata $object $user 1 + + if [[ -d $object ]]; then + unit_writexattr $object $user + else + unit_writexattr $object $user 1 + fi + + unit_accesstime $object $user + unit_updatetime $object $user + unit_writeacl $object $user + unit_deletecontent $object $user + unit_deletedata $object $user + + if [[ -d $object ]] ;then + create_object "dir" $object $ZFS_ACL_CUR_USER + else + create_object "file" $object $ZFS_ACL_CUR_USER + fi + done +} + +# +# Testing function to verify the given node is immutable +# +# $1: The given node, file/dir +# +function test_immutable +{ + typeset object=$1 + + if [[ -z $object ]]; then + log_fail "Object($object) not defined." + fi + + log_note "Testing immutable of $object" + + for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do + if [[ -d $object ]]; then + log_must usr_exec chmod \ + A+user:$user:${ace_dir}:allow $object + else + log_must usr_exec chmod \ + A+user:$user:${ace_file}:allow $object + fi + log_must set_attribute $object "i" + + unit_writefile $object $user 1 + unit_writedir $object $user 1 + unit_appenddata $object $user 1 + unit_writexattr $object $user 1 + unit_accesstime $object $user + unit_updatetime $object $user 1 + unit_writeacl $object $user 1 + unit_deletecontent $object $user 1 + unit_deletedata $object $user 1 + + if [[ -d $object ]] ;then + create_object "dir" $object $ZFS_ACL_CUR_USER + else + create_object "file" $object $ZFS_ACL_CUR_USER + fi + done +} + +# +# Testing function to verify the given node is nounlink +# +# $1: The given node, file/dir +# +function test_nounlink +{ + typeset object=$1 + + if [[ -z $object ]]; then + log_fail "Object($object) not defined." + fi + + $ECHO "Testing nounlink of $object" + + for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do + if [[ -d $object ]]; then + log_must usr_exec chmod \ + A+user:$user:${ace_dir}:allow $object + else + log_must usr_exec chmod \ + A+user:$user:${ace_file}:allow $object + fi + log_must set_attribute $object "u" + + unit_writefile $object $user + unit_writedir $object $user + unit_appenddata $object $user + unit_writexattr $object $user + unit_accesstime $object $user + unit_updatetime $object $user + unit_writeacl $object $user + unit_deletecontent $object $user 1 + unit_deletedata $object $user 1 + + if [[ -d $object ]] ;then + create_object "dir" $object $ZFS_ACL_CUR_USER + else + create_object "file" $object $ZFS_ACL_CUR_USER + fi + done +} + +# +# Testing function to verify the given node is appendonly +# +# $1: The given node, file/dir +# +function test_appendonly +{ + typeset object=$1 + + if [[ -z $object ]]; then + log_fail "Object($object) not defined." + fi + + log_note "Testing appendonly of $object" + + for user in $ZFS_ACL_CUR_USER root $ZFS_ACL_STAFF2; do + if [[ -d $object ]]; then + log_must usr_exec chmod \ + A+user:$user:${ace_dir}:allow $object + else + log_must usr_exec chmod \ + A+user:$user:${ace_file}:allow $object + fi + log_must set_attribute $object "a" + + unit_writefile $object $user 1 + unit_writedir $object $user + unit_appenddata $object $user + unit_writexattr $object $user + unit_accesstime $object $user + unit_updatetime $object $user + unit_writeacl $object $user + unit_deletecontent $object $user + unit_deletedata $object $user + + if [[ -d $object ]] ;then + create_object "dir" $object $ZFS_ACL_CUR_USER + else + create_object "file" $object $ZFS_ACL_CUR_USER + fi + done +} + +FILES="file.0 file.1" +DIRS="dir.0 dir.1" +XATTRS="attr.0 attr.1" +FS="$TESTPOOL $TESTPOOL/$TESTFS" + +if is_global_zone ; then + ATTRS="R i u a" +else + ATTRS="R" +fi + +TESTFILE=$TMPDIR/tfile +TESTDIR=tdir +TESTATTR=tattr +TESTACL=user:$ZFS_ACL_OTHER1:write_data:allow +TESTMODE=777 +TESTSTR="ZFS test suites" + +ace_file="write_data/append_data/write_xattr/write_acl/write_attributes" +ace_dir="add_file/add_subdirectory/${ace_file}" + +log_assert "Verify DOS & BSD'ish attributes will provide the " \ + "access limitation as expected." +log_onexit cleanup + +$ECHO "$TESTSTR" > $TESTFILE + +typeset gobject +typeset gattr +for gattr in $ATTRS ; do + for fs in $FS ; do + mtpt=$(get_prop mountpoint $fs) + $CHMOD 777 $mtpt + for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + for file in $FILES ; do + gobject=$mtpt/$file + create_object "file" $gobject $ZFS_ACL_CUR_USER + test_wrapper $gobject $gattr + destroy_object $gobject + done + + for dir in $DIRS ; do + gobject=$mtpt/$dir + create_object "dir" $gobject $ZFS_ACL_CUR_USER + test_wrapper $gobject $gattr + destroy_object $gobject + done + done + done +done + +log_pass "DOS & BSD'ish attributes provide the access limitation as expected." diff --git a/tests/sys/cddl/zfs/tests/acl/cifs/cifs_test.sh b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_test.sh new file mode 100755 index 00000000000..01a14aac61e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/cifs/cifs_test.sh @@ -0,0 +1,116 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case cifs_attr_001_pos cleanup +cifs_attr_001_pos_head() +{ + atf_set "descr" "Verify set/clear DOS attributes will succeed while user haswrite_attributes permission or PRIV_FILE_OWNER privilege" + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" runwattr +} +cifs_attr_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/cifs.kshlib + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cifs_attr_001_pos.ksh || atf_fail "Testcase failed" +} +cifs_attr_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/cifs.kshlib + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cifs_attr_002_pos cleanup +cifs_attr_002_pos_head() +{ + atf_set "descr" "Verify set/clear BSD'ish attributes will succeed while user hasPRIV_FILE_FLAG_SET/PRIV_FILE_FLAG_CLEAR privilege" + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" runwattr +} +cifs_attr_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/cifs.kshlib + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cifs_attr_002_pos.ksh || atf_fail "Testcase failed" +} +cifs_attr_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/cifs.kshlib + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cifs_attr_003_pos cleanup +cifs_attr_003_pos_head() +{ + atf_set "descr" "Verify DOS & BSD'ish attributes will provide theaccess limitation as expected." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" runat +} +cifs_attr_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/cifs.kshlib + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cifs_attr_003_pos.ksh || atf_fail "Testcase failed" +} +cifs_attr_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/cifs.kshlib + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case cifs_attr_001_pos + atf_add_test_case cifs_attr_002_pos + atf_add_test_case cifs_attr_003_pos +} diff --git a/tests/sys/cddl/zfs/tests/acl/cleanup.ksh b/tests/sys/cddl/zfs/tests/acl/cleanup.ksh new file mode 100644 index 00000000000..c0b6d1dc8c7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/cleanup.ksh @@ -0,0 +1,44 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/acl/acl_common.kshlib + + +cleanup_user_group + +# restore the state of svc:/network/nis/client:default +if [[ -e $NISSTAFILE ]]; then + log_must $SVCADM enable svc:/network/nis/client:default + log_must $RM -f $NISSTAFILE +fi + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/Makefile b/tests/sys/cddl/zfs/tests/acl/nontrivial/Makefile new file mode 100644 index 00000000000..c77190f6a64 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/Makefile @@ -0,0 +1,40 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/acl/nontrivial +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= zfs_acl_chmod_001_neg.ksh +${PACKAGE}FILES+= zfs_acl_chmod_002_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_aclmode_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_compact_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_delete_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_inherit_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_inherit_002_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_inherit_003_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_inherit_004_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_owner_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_rwacl_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_rwx_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_rwx_002_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_rwx_003_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_rwx_004_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_xattr_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_chmod_xattr_002_pos.ksh +${PACKAGE}FILES+= zfs_acl_cp_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_cp_002_pos.ksh +${PACKAGE}FILES+= zfs_acl_cpio_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_cpio_002_pos.ksh +${PACKAGE}FILES+= zfs_acl_find_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_ls_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_mv_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_tar_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_tar_002_pos.ksh + +ATF_TESTS_KSH93+= nontrivial_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +.include diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/nontrivial_test.sh b/tests/sys/cddl/zfs/tests/acl/nontrivial/nontrivial_test.sh new file mode 100755 index 00000000000..01abe61d532 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/nontrivial_test.sh @@ -0,0 +1,695 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_acl_chmod_001_neg cleanup +zfs_acl_chmod_001_neg_head() +{ + atf_set "descr" "Verify illegal operating to ACL, it will fail." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_002_pos cleanup +zfs_acl_chmod_002_pos_head() +{ + atf_set "descr" "Verify acl after upgrading." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs +} +zfs_acl_chmod_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_aclmode_001_pos cleanup +zfs_acl_chmod_aclmode_001_pos_head() +{ + atf_set "descr" "Verify chmod have correct behaviour to directory and file whenfilesystem has the different aclmode setting." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs +} +zfs_acl_chmod_aclmode_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_aclmode_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_aclmode_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_compact_001_pos cleanup +zfs_acl_chmod_compact_001_pos_head() +{ + atf_set "descr" "chmod A{+|=} should set compact ACL correctly." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_compact_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_compact_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_compact_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_delete_001_pos cleanup +zfs_acl_chmod_delete_001_pos_head() +{ + atf_set "descr" "Verify that the combined delete_child/delete permission forowner/group/everyone are correct." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_delete_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_delete_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_delete_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_inherit_001_pos cleanup +zfs_acl_chmod_inherit_001_pos_head() +{ + atf_set "descr" "Verify chmod have correct behaviour to directory and file whensetting different inherit strategies to them." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_inherit_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_inherit_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_inherit_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_inherit_002_pos cleanup +zfs_acl_chmod_inherit_002_pos_head() +{ + atf_set "descr" "Verify chmod have correct behaviour to directory and file whenfilesystem has the different aclinherit setting." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs +} +zfs_acl_chmod_inherit_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_inherit_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_inherit_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_inherit_003_pos cleanup +zfs_acl_chmod_inherit_003_pos_head() +{ + atf_set "descr" "Verify chmod have correct behaviour to directory and file whenfilesystem has the different aclinherit setting." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs +} +zfs_acl_chmod_inherit_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_inherit_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_inherit_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_inherit_004_pos cleanup +zfs_acl_chmod_inherit_004_pos_head() +{ + atf_set "descr" "Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs zpool +} +zfs_acl_chmod_inherit_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_inherit_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_inherit_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_owner_001_pos cleanup +zfs_acl_chmod_owner_001_pos_head() +{ + atf_set "descr" "Verify that the chown/chgrp could take owner/groupwhile permission is granted." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_owner_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_owner_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_owner_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_rwacl_001_pos cleanup +zfs_acl_chmod_rwacl_001_pos_head() +{ + atf_set "descr" "Verify chmod A[number]{+|-|=} read_acl/write_acl have correctbehaviour to access permission." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_rwacl_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_rwacl_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_rwacl_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_rwx_001_pos cleanup +zfs_acl_chmod_rwx_001_pos_head() +{ + atf_set "descr" "chmod A{+|-|=} have the correct behaviour to the ACL list." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_rwx_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_rwx_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_rwx_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_rwx_002_pos cleanup +zfs_acl_chmod_rwx_002_pos_head() +{ + atf_set "descr" "chmod A{+|-|=} read_data|write_data|execute for owner@, group@or everyone@ correctly alters mode bits." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_rwx_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_rwx_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_rwx_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_rwx_003_pos cleanup +zfs_acl_chmod_rwx_003_pos_head() +{ + atf_set "descr" "Verify that the read_data/write_data/execute permission forowner/group/everyone are correct." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_rwx_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_rwx_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_rwx_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_rwx_004_pos cleanup +zfs_acl_chmod_rwx_004_pos_head() +{ + atf_set "descr" "Verify that explicit ACL setting to specified user or group willoverride existed access rule." + atf_set "require.config" zfs_acl +} +zfs_acl_chmod_rwx_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_rwx_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_rwx_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_xattr_001_pos cleanup +zfs_acl_chmod_xattr_001_pos_head() +{ + atf_set "descr" "Verify that the permission of read_xattr/write_xattr forowner/group/everyone are correct." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" runat +} +zfs_acl_chmod_xattr_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_xattr_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_xattr_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_chmod_xattr_002_pos cleanup +zfs_acl_chmod_xattr_002_pos_head() +{ + atf_set "descr" "Verify that the permission of write_xattr forowner/group/everyone while remove extended attributes are correct." + atf_set "require.config" zfs_xattr + atf_set "require.progs" runat +} +zfs_acl_chmod_xattr_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_xattr_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_xattr_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_cp_001_pos cleanup +zfs_acl_cp_001_pos_head() +{ + atf_set "descr" "Verify that '$CP [-p]' supports ZFS ACLs." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs +} +zfs_acl_cp_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_cp_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_cp_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_cp_002_pos cleanup +zfs_acl_cp_002_pos_head() +{ + atf_set "descr" "Verify that '$CP [-p]' supports ZFS ACLs." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" zfs runat +} +zfs_acl_cp_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_cp_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_cp_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_cpio_001_pos cleanup +zfs_acl_cpio_001_pos_head() +{ + atf_set "descr" "Verify that '$CPIO' command supports to archive ZFS ACLs." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs +} +zfs_acl_cpio_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_cpio_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_cpio_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_cpio_002_pos cleanup +zfs_acl_cpio_002_pos_head() +{ + atf_set "descr" "Verify that '$CPIO' command supports to archive ZFS ACLs & xattrs." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" zfs runat +} +zfs_acl_cpio_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_cpio_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_cpio_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_find_001_pos cleanup +zfs_acl_find_001_pos_head() +{ + atf_set "descr" "Verify that '$FIND' command supports ZFS ACLs." + atf_set "require.config" zfs_acl +} +zfs_acl_find_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_find_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_find_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_ls_001_pos cleanup +zfs_acl_ls_001_pos_head() +{ + atf_set "descr" "Verify that '$LS' command supports ZFS ACLs." + atf_set "require.config" zfs_acl +} +zfs_acl_ls_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_ls_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_ls_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_mv_001_pos cleanup +zfs_acl_mv_001_pos_head() +{ + atf_set "descr" "Verify that '$MV' supports ZFS ACLs." + atf_set "require.config" zfs_acl +} +zfs_acl_mv_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_mv_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_mv_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_tar_001_pos cleanup +zfs_acl_tar_001_pos_head() +{ + atf_set "descr" "Verify that '$TAR' command supports to archive ZFS ACLs." + atf_set "require.config" zfs_acl + atf_set "require.progs" zfs +} +zfs_acl_tar_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_tar_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_tar_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_tar_002_pos cleanup +zfs_acl_tar_002_pos_head() +{ + atf_set "descr" "Verify that '$TAR' command supports to archive ZFS ACLs & xattrs." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" zfs runat +} +zfs_acl_tar_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_tar_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_tar_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_acl_chmod_001_neg + atf_add_test_case zfs_acl_chmod_002_pos + atf_add_test_case zfs_acl_chmod_aclmode_001_pos + atf_add_test_case zfs_acl_chmod_compact_001_pos + atf_add_test_case zfs_acl_chmod_delete_001_pos + atf_add_test_case zfs_acl_chmod_inherit_001_pos + atf_add_test_case zfs_acl_chmod_inherit_002_pos + atf_add_test_case zfs_acl_chmod_inherit_003_pos + atf_add_test_case zfs_acl_chmod_inherit_004_pos + atf_add_test_case zfs_acl_chmod_owner_001_pos + atf_add_test_case zfs_acl_chmod_rwacl_001_pos + atf_add_test_case zfs_acl_chmod_rwx_001_pos + atf_add_test_case zfs_acl_chmod_rwx_002_pos + atf_add_test_case zfs_acl_chmod_rwx_003_pos + atf_add_test_case zfs_acl_chmod_rwx_004_pos + atf_add_test_case zfs_acl_chmod_xattr_001_pos + atf_add_test_case zfs_acl_chmod_xattr_002_pos + atf_add_test_case zfs_acl_cp_001_pos + atf_add_test_case zfs_acl_cp_002_pos + atf_add_test_case zfs_acl_cpio_001_pos + atf_add_test_case zfs_acl_cpio_002_pos + atf_add_test_case zfs_acl_find_001_pos + atf_add_test_case zfs_acl_ls_001_pos + atf_add_test_case zfs_acl_mv_001_pos + atf_add_test_case zfs_acl_tar_001_pos + atf_add_test_case zfs_acl_tar_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_001_neg.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_001_neg.ksh new file mode 100644 index 00000000000..1bf213a30bd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_001_neg.ksh @@ -0,0 +1,151 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_001_neg.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_001_neg +# +# DESCRIPTION: +# Verify 1) Illegal options to chmod should fail. +# 2) Delete all the ACE will lead to fail. +# 3) Add ACE exceed 1024 will cause to fail. +# +# STRATEGY: +# 1. Loop root and non-root users +# 2. Verify all kinds of illegal option will lead to chmod failed. +# 3. Verify 'chmod A0-' will fail when try to delete all the ACE. +# 4. Verify 'chmod A+' will succeed when the ACE number exceed 1024. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-14) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify illegal operating to ACL, it will fail." +log_onexit cleanup + +test_requires ZFS_ACL + +function err_opts #node +{ + typeset A_opts="+A@ -A#- +A% =A^ =A# =A@ +A#\ asd \ + A+@ A-#- A+% A=^ A=# A=@ A+#" + + log_note "Illegal option to chmod should fail." + for A in ${A_opts[@]}; do + log_mustnot usr_exec $CHMOD ${A}owner@:read_data:allow $node + log_mustnot usr_exec $CHMOD A+ asd owner@:execute:deny $node + done + + typeset type_opts="everyone groups owner user@ users" + for tp in ${type_opts[@]}; do + log_mustnot usr_exec $CHMOD A+$tp:read_data:deny $node + done + + return 0 +} + +function del_all_ACE #node +{ + typeset node=$1 + typeset -i cnt + + cnt=$(count_ACE $node) + while (( cnt > 0 )); do + if (( cnt == 1 )); then + log_mustnot $CHMOD A0- $node + else + log_must $CHMOD A0- $node + fi + + (( cnt -= 1 )) + done + + return 0 +} + +function exceed_max_ACE #node +{ + typeset node=$1 + typeset -i max=1024 + typeset -i cnt + + cnt=$(count_ACE $node) + + # One more ACE exceed the max limitation. + (( max = max - cnt + 1 )) + while (( max > 0 )); do + if (( max == 1 )); then + log_mustnot $CHMOD A+owner@:read_data:allow $node + else + $CHMOD A+owner@:read_data:allow $node + if (($? != 0)); then + ((cnt = 1024 - max)) + log_fail "Add No.$cnt ACL item failed." + fi + fi + + (( max -= 1 )) + done + + return 0 +} + +typeset node +typeset func_name="err_opts del_all_ACE exceed_max_ACE" + +for usr in "root" "$ZFS_ACL_STAFF1"; do + log_must set_cur_usr $usr + + for node in $testfile $testdir; do + log_must usr_exec $TOUCH $testfile + log_must usr_exec $MKDIR $testdir + + for func in $func_name; do + log_must eval "$func $node" + done + + log_must usr_exec $RM -rf $testfile $testdir + done +done + +log_pass "Verify illegal operating to ACL passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_002_pos.ksh new file mode 100644 index 00000000000..f814e5cbef7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_002_pos.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_002_pos.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_002_pos +# +# DESCRIPTION: +# Verify acl after upgrading. +# STRATEGY: +# 1. Create a low version fs. +# 2. Create a directory and chmod it. +# 3. Upgrade the fs. +# 4. Create a file under the directory and list it. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-06-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function acl_upgrade_cleannup +{ + datasetexists $ACL_UPGRADE_FS && \ + log_must $ZFS destroy -rR $ACL_UPGRADE_FS +} + +log_assert "Verify acl after upgrading." +log_onexit acl_upgrade_cleannup + +ACL_UPGRADE_FS=$TESTPOOL/acl_upgrade_fs.${TESTCASE_ID} + +test_requires ZFS_ACL + +log_must $ZFS create -o version=2 $ACL_UPGRADE_FS +mntpnt=$(get_prop mountpoint $ACL_UPGRADE_FS) +log_must $MKDIR $mntpnt/dir.${TESTCASE_ID} +log_must $CHMOD A+owner@:rwxp:f:allow,group@:rwxp:f:allow $mntpnt/dir.${TESTCASE_ID} +log_must $ZFS upgrade $ACL_UPGRADE_FS +log_must $TOUCH $mntpnt/dir.${TESTCASE_ID}/file.${TESTCASE_ID} +log_must eval "$LS -V $mntpnt/dir.${TESTCASE_ID}/file.${TESTCASE_ID} > /dev/null 2>&1" + +log_pass "Verify acl after upgrading." + diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_aclmode_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_aclmode_001_pos.ksh new file mode 100644 index 00000000000..42582de43b4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_aclmode_001_pos.ksh @@ -0,0 +1,490 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_aclmode_001_pos.ksh 1.3 08/08/15 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_aclmode_001_pos +# +# DESCRIPTION: +# Verify chmod have correct behaviour to directory and file when +# filesystem has the different aclmode setting +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Separately chmod basedir with different aclmode options, +# combine with the variable setting of aclmode: +# "discard", "groupmask", or "passthrough". +# 4. Verify each directories and files have the correct access control +# capability. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-03-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +test_requires ZFS_ACL + +function cleanup +{ + # Cleanup tarfile & basedir. + + (( ${#cwd} != 0 )) && cd $cwd + + if [[ -f $TARFILE ]]; then + log_must $RM -f $TARFILE + fi + + if [[ -d $basedir ]]; then + log_must $RM -rf $basedir + fi +} + +log_assert "Verify chmod have correct behaviour to directory and file when " \ + "filesystem has the different aclmode setting." +log_onexit cleanup + +# Define aclmode flag +set -A aclmode_flag discard groupmask passthrough + +set -A ace_prefix "user:$ZFS_ACL_OTHER1" \ + "user:$ZFS_ACL_OTHER2" \ + "group:$ZFS_ACL_STAFF_GROUP" \ + "group:$ZFS_ACL_OTHER_GROUP" + +set -A argv "000" "444" "644" "777" "755" "231" "562" "413" + +set -A ace_file_preset "read_data" \ + "write_data" \ + "append_data" \ + "execute" \ + "read_data/write_data" \ + "read_data/write_data/append_data" \ + "write_data/append_data" \ + "read_data/execute" \ + "write_data/append_data/execute" \ + "read_data/write_data/append_data/execute" + +# Defile the based directory and file +basedir=$TESTDIR/basedir; ofile=$basedir/ofile; odir=$basedir/odir +nfile=$basedir/nfile; ndir=$basedir/ndir + +TARFILE=$TESTDIR/tarfile + +# Verify all the node have expected correct access control +allnodes="$nfile $ndir" + +# +# According to the original bits, the input ACE access and ACE type, return the +# expect bits after 'chmod A0{+|=}'. +# +# $1 isdir indicate if the target is a directory +# $1 bits which was make up of three bit 'rwx' +# $2 bits_limit which was make up of three bit 'rwx' +# $3 ACE access which is read_data, write_data or execute +# $4 ACE type which is allow or deny +# +function cal_bits #isdir bits bits_limit acl_access ctrl +{ + typeset -i isdir=$1 + typeset -i bits=$2 + typeset -i bits_limit=$3 + typeset acl_access=$4 + typeset -i ctrl=${5:-0} + typeset flagr=0; flagw=0; flagx=0 + typeset tmpstr + + if (( ctrl == 0 )); then + if (( (( bits & 4 )) == 0 )); then + flagr=1 + fi + if (( (( bits & 2 )) == 0 )); then + flagw=1 + fi + if (( (( bits & 1 )) == 0 )); then + flagx=1 + fi + else + # + # Tricky here: + # (1) flagr is always set to be 1, + # (2) flagw & flagx is set to be 0 only while + # bits_limit has lower permissions than bits + # + + flagr=1 + flagw=1 + flagx=1 + + if (( (( bits & 2 )) != 0 )) && \ + (( (( bits_limit & 2 )) == 0 )) ; then + flagw=0 + fi + if (( (( bits & 1 )) != 0 )) && \ + (( (( bits_limit & 1 )) == 0 )) ; then + flagx=0 + fi + fi + + if (( flagr != 0 )); then + if [[ $acl_access == *"read_data"* ]]; then + if (( isdir == 0 )) ; then + tmpstr=${tmpstr}/read_data + else + tmpstr=${tmpstr}/list_directory/read_data + fi + fi + fi + + if (( flagw != 0 )); then + if [[ $acl_access == *"write_data"* ]]; then + if (( isdir == 0 )); then + tmpstr=${tmpstr}/write_data + else + tmpstr=${tmpstr}/add_file/write_data + fi + fi + + if [[ $acl_access == *"append_data"* ]]; then + if (( isdir == 0 )); then + tmpstr=${tmpstr}/append_data + else + tmpstr=${tmpstr}/add_subdirectory/append_data + fi + fi + fi + if (( flagx != 0 )); then + [[ $acl_access == *"execute"* ]] && \ + tmpstr=${tmpstr}/execute + fi + + tmpstr=${tmpstr#/} + + $ECHO "$tmpstr" +} + +# +# To translate an ace if the node is dir +# +# $1 isdir indicate if the target is a directory +# $2 acl to be translated +# +function translate_acl #isdir acl +{ + typeset -i isdir=$1 + typeset acl=$2 + typeset who prefix acltemp action + + if (( isdir != 0 )); then + who=${acl%%:*} + prefix=$who + acltemp=${acl#*:} + acltemp=${acltemp%%:*} + prefix=$prefix:$acltemp + action=${acl##*:} + + acl=$prefix:$(cal_bits $isdir 7 7 $acl 1):$action + fi + $ECHO "$acl" +} + +# +# According to inherited flag, verify subdirectories and files within it has +# correct inherited access control. +# +function verify_aclmode # +{ + # Define the nodes which will be affected by inherit. + typeset aclmode=$1 + typeset node=$2 + typeset newmode=$3 + + # count: the ACE item to fetch + # pass: to mark if the current ACE should apply to the target + # passcnt: counter, if it achieves to maxnumber, + # then no additional ACE should apply. + # step: indicate if the ACE be split during aclmode. + + typeset -i count=0 pass=0 passcnt=0 step=0 + typeset -i bits=0 obits=0 bits_owner=0 isdir=0 + + if [[ -d $node ]]; then + (( isdir = 1 )) + fi + + (( i = maxnumber - 1 )) + count=0 + passcnt=0 + while (( i >= 0 )); do + pass=0 + step=0 + expect1=${acls[$i]} + expect2="" + + # + # aclmode=passthrough, + # no changes will be made to the ACL other than + # generating the necessary ACL entries to represent + # the new mode of the file or directory. + # + # aclmode=discard, + # delete all ACL entries that don't represent + # the mode of the file. + # + # aclmode=groupmask, + # reduce user or group permissions. The permissions are + # reduced, such that they are no greater than the group + # permission bits, unless it is a user entry that has the + # same UID as the owner of the file or directory. + # Then, the ACL permissions are reduced so that they are + # no greater than owner permission bits. + # + + case $aclmode in + passthrough) + expect1=$(translate_acl $isdir $expect1) + ;; + groupmask) + if [[ $expect1 == *":allow" ]]; then + expect2=$expect1 + who=${expect1%%:*} + prefix=$who + acltemp="" + reduce=0 + + # To determine the mask bits + # according to the entry type. + + case $who in + owner@) + pos=1 + ;; + group@) + pos=2 + ;; + everyone@) + pos=3 + ;; + user) + acltemp=${expect1#*:} + acltemp=${acltemp%%:*} + owner=$(get_owner $node) + group=$(get_group $node) + if [[ $acltemp == $owner ]]; then + pos=1 + else + pos=2 + fi + prefix=$prefix:$acltemp + ;; + group) + acltemp=${expect1#*:} + acltemp=${acltemp%%:*} + pos=2 + prefix=$prefix:$acltemp + reduce=1 + ;; + esac + + obits=$(get_substr $newmode $pos 1) + (( bits = obits )) + # + # permission should no greater than the group permission bits + # + if (( reduce != 0 )); then + (( bits &= $(get_substr $newmode 2 1) )) + + # The ACL permissions are reduced so that they are + # no greater than owner permission bits. + + (( bits_owner = $(get_substr $newmode 1 1) )) + (( bits &= bits_owner )) + fi + + if (( bits < obits )) && [[ -n $acltemp ]]; then + expect2=$prefix:$(cal_bits $isdir $obits $bits_owner $expect2 1):allow + else + expect2=$prefix:$(cal_bits $isdir $obits $obits $expect2 1):allow + + fi + + priv=$(cal_bits $isdir $obits $bits_owner $expect2 0) + expect1=$prefix:$priv:deny + step=1 + else + expect1=$(translate_acl $isdir $expect1) + fi + ;; + discard) + passcnt=maxnumber + break + ;; + esac + + if (( pass == 0 )) ; then + # Get the first ACE to do comparison + + aclcur=$(get_ACE $node $count) + aclcur=${aclcur#$count:} + if [[ -n $expect1 && $expect1 != $aclcur ]]; then + $LS -vd $node + log_fail "$i #$count " \ + "ACE: $aclcur, expect to be " \ + "$expect1" + fi + + # Get the second ACE (if should have) to do comparison + + if (( step > 0 )); then + (( count = count + step )) + + aclcur=$(get_ACE $node $count) + aclcur=${aclcur#$count:} + if [[ -n $expect2 && \ + $expect2 != $aclcur ]]; then + + $LS -vd $node + log_fail "$i #$count " \ + "ACE: $aclcur, expect to be " \ + "$expect2" + fi + fi + (( count = count + 1 )) + fi + (( i = i - 1 )) + done + + # + # If there's no any ACE be checked, it should be identify as + # an normal file/dir, verify it. + # + + if (( passcnt == maxnumber )); then + if [[ -d $node ]]; then + compare_acls $node $odir + elif [[ -f $node ]]; then + compare_acls $node $ofile + fi + + if [[ $? -ne 0 ]]; then + $LS -vd $node + log_fail "Unexpect acl: $node, $aclmode ($newmode)" + fi + fi +} + + + +typeset -i maxnumber=0 +typeset acl +typeset target + +cwd=$PWD +cd $TESTDIR + +for mode in "${aclmode_flag[@]}"; do + + # + # Set different value of aclmode + # + + log_must $ZFS set aclmode=$mode $TESTPOOL/$TESTFS + + for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must usr_exec $MKDIR $basedir + + log_must usr_exec $MKDIR $odir + log_must usr_exec $TOUCH $ofile + log_must usr_exec $MKDIR $ndir + log_must usr_exec $TOUCH $nfile + + for obj in $allnodes ; do + maxnumber=0 + for preset in "${ace_file_preset[@]}"; do + for prefix in "${ace_prefix[@]}"; do + acl=$prefix:$preset + + case $(( maxnumber % 2 )) in + 0) + acl=$acl:deny + ;; + 1) + acl=$acl:allow + ;; + esac + + # + # Place on the target should succeed. + # + log_must usr_exec $CHMOD A+$acl $obj + acls[$maxnumber]=$acl + + (( maxnumber = maxnumber + 1 )) + done + done + + # Archive the file and directory + log_must $TAR cpf@ $TARFILE basedir + + if [[ -d $obj ]]; then + target=$odir + elif [[ -f $obj ]]; then + target=$ofile + fi + + for newmode in "${argv[@]}" ; do + log_must usr_exec $CHMOD $newmode $obj + log_must usr_exec $CHMOD $newmode $target + verify_aclmode $mode $obj $newmode + + # Restore the tar archive + log_must $TAR xpf@ $TARFILE + done + done + + log_must usr_exec $RM -rf $basedir $TARFILE + done +done + +log_pass "Verify chmod behaviour co-op with aclmode setting passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_compact_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_compact_001_pos.ksh new file mode 100644 index 00000000000..1f2bd53dd94 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_compact_001_pos.ksh @@ -0,0 +1,274 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_compact_001_pos.ksh 1.5 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib +. $STF_SUITE/tests/acl/cifs/cifs.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_compact_001_pos +# +# DESCRIPTION: +# chmod A{+|-|=} could set compact ACL correctly. +# +# STRATEGY: +# 1. Loop root and non-root user. +# 2. Get the random compact ACL string. +# 4. Separately chmod +|-|= +# 5. Check compact ACL display as expected +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +test_requires ZFS_ACL + +log_assert "chmod A{+|=} should set compact ACL correctly." +log_onexit cleanup + +set -A a_flag owner group everyone +set -A a_access r w x p d D a A R W c C o s +set -A a_inherit_object f d +set -A a_inherit_strategy i n +set -A a_type allow deny + +typeset cifs="" + +if cifs_supported ; then + cifs="true" +fi + +# +# Get a random item from an array. +# +# $1 the base set +# +function random_select #array_name +{ + typeset arr_name=$1 + typeset -i ind + + eval typeset -i cnt=\${#${arr_name}[@]} + (( ind = $RANDOM % cnt )) + + eval print \${${arr_name}[$ind]} +} + +# +# Create a random string according to array name, the item number and +# separated tag. +# +# $1 array name where the function get the elements +# $2 the items number which you want to form the random string +# $3 the separated tag +# +function form_random_str # +{ + typeset arr_name=$1 + typeset -i count=${2:-1} + typeset sep=${3:-""} + + typeset str="" + while (( count > 0 )); do + str="${str}$(random_select $arr_name)${sep}" + + (( count -= 1 )) + done + + print $str +} + +# +# According to the input ACE access,ACE type, and inherit flags, return the +# expect compact ACE that could be used by chmod A0{+|=}'. +# +# $1 ACE flag which is owner, group, or everyone +# $2 ACE access generated by the element of a_access +# $3 ACE inherit_object generated by the element of a_inherit_object +# $4 ACE inherit_strategy generated by the element of a_inherit_strategy +# $5 ACE type which is allow or deny +# +function cal_ace # acl_flag acl_access \ + # acl_inherit_object acl_inherit_strategy acl_type +{ + typeset acl_flag=$1 + typeset acl_access=$2 + typeset acl_inherit_object=$3 + typeset acl_inherit_strategy=$4 + typeset acl_type=$5 + + tmp_ace=${acl_flag}@: + + for element in ${a_access[@]} ; do + if [[ $acl_access == *"$element"* ]]; then + tmp_ace="${tmp_ace}${element}" + else + tmp_ace="${tmp_ace}-" + fi + done + tmp_ace=${tmp_ace}: + + for element in ${a_inherit_object[@]} ; do + if [[ $acl_inherit_object == *"$element"* ]]; then + tmp_ace="${tmp_ace}${element}" + else + tmp_ace="${tmp_ace}-" + fi + done + for element in ${a_inherit_strategy[@]} ; do + if [[ $acl_inherit_strategy == *"$element"* ]]; then + tmp_ace="${tmp_ace}${element}" + else + tmp_ace="${tmp_ace}-" + fi + done + + if [[ -n $cifs ]]; then + tmp_ace=${tmp_ace}---:${acl_type} + else + tmp_ace=${tmp_ace}--:${acl_type} + fi + + print "${tmp_ace}" +} + +# +# Check if chmod set the compact ACE correctly. +# +function check_test_result # node acl_flag acl_access \ + # acl_inherit_object acl_inherit_strategy acl_type +{ + typeset node=$1 + typeset acl_flag=$2 + typeset acl_access=$3 + typeset acl_inherit_object=$4 + typeset acl_inherit_strategy=$5 + typeset acl_type=$6 + + typeset expect_ace=$(cal_ace "$acl_flag" "$acl_access" \ + "$acl_inherit_object" "$acl_inherit_strategy" "$acl_type") + + typeset cur_ace=$(get_ACE $node 0 "compact") + + if [[ $cur_ace != $expect_ace ]]; then + log_fail "FAIL: Current map($cur_ace) != \ + expected ace($expect_ace)" + fi +} + +function test_chmod_map # +{ + typeset node=$1 + typeset acl_flag acl_access acl_inherit_object acl_inherit_strategy acl_type + typeset -i cnt + + if (( ${#node} == 0 )); then + log_fail "FAIL: file name or directroy name is not defined." + fi + + # Get ACL flag, access & type + acl_flag=$(form_random_str a_flag) + (( cnt = ($RANDOM % ${#a_access[@]}) + 1 )) + acl_access=$(form_random_str a_access $cnt) + acl_access=${acl_access%/} + acl_type=$(form_random_str a_type 1) + + acl_spec=${acl_flag}@:${acl_access} + if [[ -d $node ]]; then + # Get ACL inherit_object & inherit_strategy + (( cnt = ($RANDOM % ${#a_inherit_object[@]}) + 1 )) + acl_inherit_object=$(form_random_str a_inherit_object $cnt) + (( cnt = ($RANDOM % ${#a_inherit_strategy[@]}) + 1 )) + acl_inherit_strategy=$(form_random_str a_inherit_strategy $cnt) + acl_spec=${acl_spec}:${acl_inherit_object}${acl_inherit_strategy} + fi + acl_spec=${acl_spec}:${acl_type} + + # Set the initial map and back the initial ACEs + typeset orig_ace=$TMPDIR/orig_ace.${TESTCASE_ID} + typeset cur_ace=$TMPDIR/cur_ace.${TESTCASE_ID} + + for operator in "A0+" "A0="; do + log_must usr_exec eval "$LS -Vd $node > $orig_ace" + + # To "A=", firstly add one ACE which can't modify map + if [[ $operator == "A0=" ]]; then + log_must $CHMOD A0+user:$ZFS_ACL_OTHER1:execute:deny \ + $node + fi + log_must usr_exec $CHMOD ${operator}${acl_spec} $node + + check_test_result \ + "$node" "$acl_flag" "$acl_access" \ + "$acl_inherit_object" "$acl_inherit_strategy" \ + "$acl_type" + + # Check "chmod A-" + log_must usr_exec $CHMOD A0- $node + log_must usr_exec eval "$LS -Vd $node > $cur_ace" + + $DIFF $orig_ace $cur_ace + [[ $? -ne 0 ]] && \ + log_fail "FAIL: 'chmod A-' failed." + done + + [[ -f $orig_ace ]] && log_must usr_exec $RM -f $orig_ace + [[ -f $cur_ace ]] && log_must usr_exec $RM -f $cur_ace +} + +for user in root $ZFS_ACL_STAFF1; do + set_cur_usr $user + + typeset -i loop_cnt=2 + while (( loop_cnt > 0 )); do + log_must usr_exec $TOUCH $testfile + test_chmod_map $testfile + log_must $RM -f $testfile + + log_must usr_exec $MKDIR $testdir + test_chmod_map $testdir + log_must $RM -rf $testdir + + (( loop_cnt -= 1 )) + done +done + +log_pass "chmod A{+|=} set compact ACL correctly." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_delete_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_delete_001_pos.ksh new file mode 100644 index 00000000000..4b78634f283 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_delete_001_pos.ksh @@ -0,0 +1,321 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_delete_001_pos.ksh 1.6 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_delete_001_pos +# +# DESCRIPTION: +# Verify that the combined delete_child/delete permission for +# owner/group/everyone are correct. +# +# ------------------------------------------------------- +# | Parent Dir | Target Object Permissions | +# | permissions | | +# ------------------------------------------------------- +# | | ACL Allows | ACL Denies| Delete | +# | | Delete | Delete | unspecified| +# ------------------------------------------------------- +# | ACL Allows | Permit | Permit | Permit | +# | DELETE_CHILD | | +# ------------------------------------------------------- +# | ACL Denies | Permit | Deny | Deny | +# | DELETE_CHILD | | | | +# ------------------------------------------------------- +# | ACL specifies | | | | +# | only allows | Permit | Permit | Permit | +# | write and | | | | +# | execute | | | | +# ------------------------------------------------------- +# | ACL denies | | | | +# | write and | Permit | Deny | Deny | +# | execute | | | | +# ------------------------------------------------------- +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Set special ACE combination to the file and directory +# 3. Try to remove the file +# 4. Verify that combined permissions for owner/group/everyone are correct. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + [[ ! -e $TESTDIR/$ARCHIVEFILE ]] && return 0 + + if [[ ! -e $target ]]; then + log_must $TAR xpf $TESTDIR/$ARCHIVEFILE + fi + + (( ${#cwd} != 0 )) && cd $cwd + cleanup_test_files $TESTDIR/basedir + log_must $RM -f $TESTDIR/$ARCHIVEFILE + return 0 +} + +#owner@ group group_users other_users +set -A users \ +"root" "root" "$ZFS_ACL_ADMIN" "$ZFS_ACL_OTHER1" \ +"$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF_GROUP" "$ZFS_ACL_STAFF2" "$ZFS_ACL_OTHER1" + +set -A access_parent \ + "delete_child:allow" \ + "delete_child:deny" \ + "write_data:allow" \ + "write_data:deny" \ + "delete_child:deny write_data:allow" \ + "delete_child:allow write_data:deny" + +set -A access_target \ + "delete:allow" \ + "delete:deny" \ + "" + +set -A a_flag "owner@" "group@" "everyone@" "user:$ZFS_ACL_STAFF1" + +log_assert "Verify that the combined delete_child/delete permission for" \ + "owner/group/everyone are correct." +log_onexit cleanup + +function operate_node #user node +{ + typeset user=$1 + typeset node=$2 + typeset ret + + if [[ $user == "" || $node == "" ]]; then + log_fail "user, node are not defined." + fi + if [[ -d $node ]]; then + chgusr_exec $user $RM -rf $node ; ret=$? + else + chgusr_exec $user $RM -f $node ; ret=$? + fi + + if [[ -e $node ]]; then + if [[ $ret -eq 0 ]]; then + log_note "$node not removed, but return code is 0." + return 1 + fi + else + log_must $TAR xpf $TESTDIR/$ARCHIVEFILE + if [[ $ret -ne 0 ]]; then + log_note "$node removed, but return code is $ret." + return 1 + fi + fi + return $ret +} + +function logname #acl_parent acl_target user +{ + typeset acl_parent=$1 + typeset acl_target=$2 + typeset user=$3 + + # To super user, read and write deny permission was override. + if [[ $user == root || $acl_target == *:allow ]]; then + print "log_must" + elif [[ $acl_parent == *"delete_child"* ]]; then + if [[ $acl_parent == *"delete_child:allow"* ]]; then + print "log_must" + else + print "log_mustnot" + fi + elif [[ $acl_parent == *"write_data"* ]]; then + if [[ $acl_parent == *"write_data:allow"* ]]; then + print "log_must" + else + print "log_mustnot" + fi + else + print "log_mustnot" + fi +} + +function check_chmod_results #node flag acl_parent acl_target g_usr o_usr +{ + typeset node=$1 + typeset flag=$2 + typeset acl_parent=$3 + typeset acl_target=$2:$4 + typeset g_usr=$5 + typeset o_usr=$6 + typeset log acl_tmp + + for acl in $acl_parent ; do + acl_tmp="$2:$acl $acl_tmp" + done + acl_parent=$acl_tmp + + if [[ $flag == "owner@" || $flag == "everyone@" ]]; then + log=$(logname "$acl_parent" $acl_target $ZFS_ACL_CUR_USER) + $log operate_node $ZFS_ACL_CUR_USER $node + fi + if [[ $flag == "group@" || $flag == "everyone@" ]]; then + log=$(logname "$acl_parent" $acl_target $g_usr) + $log operate_node $g_usr $node + fi + if [[ $flag == "everyone@" ]]; then + log=$(logname "$acl_parent" $acl_target $o_usr) + $log operate_node $o_usr $node + fi + if [[ $flag == "user:"* ]]; then + typeset user=${flag#user:} + log=$(logname "$acl_parent" $acl_target $user) + $log operate_node $user $node + fi +} + +function test_chmod_basic_access #node g_usr o_usr +{ + typeset node=${1%/} + typeset g_usr=$2 + typeset o_usr=$3 + typeset flag acl_p acl_t parent + typeset -i i=0 + + parent=${node%/*} + + for flag in ${a_flag[@]}; do + for acl_p in "${access_parent[@]}"; do + i=0 + for acl in $acl_p ; do + log_must usr_exec $CHMOD A+$flag:$acl $parent + (( i = i + 1)) + done + + for acl_t in "${access_target[@]}"; do + [[ -n $acl_t ]] && \ + log_must usr_exec $CHMOD A+$flag:$acl_t $node + + log_must $TAR cpf $TESTDIR/$ARCHIVEFILE basedir + + check_chmod_results "$node" "$flag" \ + "$acl_p" "$acl_t" "$g_usr" "$o_usr" + + [[ -n $acl_t ]] && \ + log_must usr_exec $CHMOD A0- $node + done + + while (( i > 0 )); do + log_must usr_exec $CHMOD A0- $parent + (( i = i - 1 )) + done + done + done +} + +function setup_test_files #base_node user group +{ + typeset base_node=$1 + typeset user=$2 + typeset group=$3 + + cleanup_test_files $base_node + + log_must $MKDIR -p $base_node + log_must $CHOWN $user:$group $base_node + + log_must set_cur_usr $user + + # Prepare all files/sub-dirs for testing. + file0=$base_node/testfile_rm + dir0=$base_node/testdir_rm + + log_must usr_exec $TOUCH $file0 + log_must usr_exec $CHMOD 444 $file0 + + log_must usr_exec $MKDIR -p $dir0 + log_must usr_exec $CHMOD 444 $dir0 + + log_must usr_exec $CHMOD 555 $base_node + return 0 +} + +function cleanup_test_files #base_node +{ + typeset base_node=$1 + + if [[ -d $base_node ]]; then + log_must $RM -rf $base_node + elif [[ -e $base_node ]]; then + log_must $RM -f $base_node + fi + + return 0 +} + +typeset cwd=$PWD +typeset ARCHIVEFILE=archive.tar + +test_requires ZFS_ACL + +typeset -i i=0 +typeset -i j=0 +typeset target +cd $TESTDIR +while (( i < ${#users[@]} )); do + setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]} + + j=0 + while (( j < 1 )); do + eval target=\$file$j + test_chmod_basic_access $target \ + "${users[((i+2))]}" "${users[((i+3))]}" + + eval target=\$dir$j + test_chmod_basic_access $target \ + "${users[((i+2))]}" "${users[((i+3))]}" + + (( j = j + 1 )) + done + + (( i += 4 )) +done + +log_pass "Verify that the combined delete_child/delete permission for" \ + "owner/group/everyone are correct." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_001_pos.ksh new file mode 100644 index 00000000000..d5a8020548e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_001_pos.ksh @@ -0,0 +1,193 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_inherit_001_pos.ksh 1.5 09/05/19 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_inherit_001_pos +# +# DESCRIPTION: +# Verify chmod have correct behaviour to directory and file when setting +# different inherit strategy to them. +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Separately chmod basedir with different inherite options. +# 4. Then create nested directories and files like the following. +# +# _ odir4 +# |_ ofile4 +# _ odir3 _| +# |_ ofile3 +# _ odir1 _| +# |_ ofile2 +# basefile | +# chmod --> basedir -| +# |_ nfile1 +# |_ ndir1 _ +# |_ nfile2 +# |_ ndir2 _ +# |_ nfile3 +# |_ ndir3 +# +# 5. Verify each directories and files have the correct access control +# capability. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-11-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if [[ -f $basefile ]]; then + log_must $RM -f $basefile + fi + if [[ -d $basedir ]]; then + log_must $RM -rf $basedir + fi +} + +log_assert "Verify chmod have correct behaviour to directory and file when " \ + "setting different inherit strategies to them." +log_onexit cleanup + +# Define inherit flag +set -A object_flag file_inherit dir_inherit file_inherit/dir_inherit +set -A strategy_flag "" inherit_only no_propagate inherit_only/no_propagate + +# Defile the based directory and file +basedir=$TESTDIR/basedir; basefile=$TESTDIR/basefile + +test_requires ZFS_ACL + +# Define the existed files and directories before chmod +odir1=$basedir/odir1; odir2=$odir1/odir2; odir3=$odir2/odir3 +ofile1=$basedir/ofile1; ofile2=$odir1/ofile2; ofile3=$odir2/ofile3 + +# Define the files and directories will be created after chmod +ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3 +nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3 + +# Verify all the node have expected correct access control +allnodes="$basedir $ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3" +allnodes="$allnodes $odir1 $odir2 $odir3 $ofile1 $ofile2 $ofile3" + +# +# According to inherited flag, verify subdirectories and files within it has +# correct inherited access control. +# +function verify_inherit # [strategy] +{ + # Define the nodes which will be affected by inherit. + typeset inherit_nodes + typeset obj=$1 + typeset str=$2 + + log_must usr_exec $MKDIR -p $ndir3 + log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3 + + # Except for inherit_only, the basedir was affected always. + if [[ $str != *"inherit_only"* ]]; then + inherit_nodes="$inherit_nodes $basedir" + fi + # Get the files which inherited ACE. + if [[ $obj == *"file_inherit"* ]]; then + inherit_nodes="$inherit_nodes $nfile1" + + if [[ $str != *"no_propagate"* ]]; then + inherit_nodes="$inherit_nodes $nfile2 $nfile3" + fi + fi + # Get the directores which inherited ACE. + if [[ $obj == *"dir_inherit"* ]]; then + inherit_nodes="$inherit_nodes $ndir1" + + if [[ $str != *"no_propagate"* ]]; then + inherit_nodes="$inherit_nodes $ndir2 $ndir3" + fi + fi + + for node in $allnodes; do + if [[ " $inherit_nodes " == *" $node "* ]]; then + log_mustnot chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \ + > /dev/null 2>&1 + else + log_must chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \ + > /dev/null 2>&1 + fi + done +} + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + for obj in "${object_flag[@]}"; do + for str in "${strategy_flag[@]}"; do + typeset inh_opt=$obj + (( ${#str} != 0 )) && inh_opt=$inh_opt/$str + aclspec="A+user:$ZFS_ACL_OTHER1:read_acl:$inh_opt:deny" + + log_must usr_exec $MKDIR $basedir + log_must usr_exec $TOUCH $basefile + log_must usr_exec $MKDIR -p $odir3 + log_must usr_exec $TOUCH $ofile1 $ofile2 $ofile3 + + # + # Inherit flag can only be placed on a directory, + # otherwise it will fail. + # + log_must usr_exec $CHMOD $aclspec $basefile + + # + # Place on a directory should succeed. + # + log_must usr_exec $CHMOD $aclspec $basedir + + verify_inherit $obj $str + + log_must usr_exec $RM -rf $basefile $basedir + done + done +done + +log_pass "Verify chmod inherit behaviour passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_002_pos.ksh new file mode 100644 index 00000000000..6c250e98f35 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_002_pos.ksh @@ -0,0 +1,415 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_inherit_002_pos.ksh 1.3 08/02/27 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib +. $STF_SUITE/tests/acl/cifs/cifs.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_inherit_002_pos +# +# DESCRIPTION: +# Verify chmod have correct behaviour to directory and file when +# filesystem has the different aclinherit setting +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Separately chmod basedir with different inherite options, +# combine with the variable setting of aclinherit: +# "discard", "noallow", "secure" or "passthrough". +# 4. Then create nested directories and files like the following. +# +# ofile +# odir +# chmod --> basedir -| +# |_ nfile1 +# |_ ndir1 _ +# |_ nfile2 +# |_ ndir2 _ +# |_ nfile3 +# |_ ndir3 +# +# 5. Verify each directories and files have the correct access control +# capability. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-03-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset dir + + # Cleanup basedir, compared file and dir. + + if [[ -f $ofile ]]; then + log_must $RM -f $ofile + fi + + for dir in $odir $basedir ; do + if [[ -d $dir ]]; then + log_must $RM -rf $dir + fi + done +} + +log_assert "Verify chmod have correct behaviour to directory and file when " \ + "filesystem has the different aclinherit setting." +log_onexit cleanup + +# Define inherit flag +set -A aclinherit_flag discard noallow secure passthrough +set -A object_flag file_inherit dir_inherit file_inherit/dir_inherit +set -A strategy_flag "" inherit_only no_propagate inherit_only/no_propagate + +typeset ace_prefix1="user:$ZFS_ACL_OTHER1" +typeset ace_prefix2="user:$ZFS_ACL_OTHER2" +typeset ace_discard ace_noallow ace_secure ace_passthrough +typeset ace_secure_new + +# Defile the based directory and file +basedir=$TESTDIR/basedir; ofile=$TESTDIR/ofile; odir=$TESTDIR/odir + +test_requires ZFS_ACL + +# Define the files and directories will be created after chmod +ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3 +nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3 + +# Verify all the node have expected correct access control +allnodes="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3" + +typeset cifs="" +if cifs_supported ; then + cifs="true" +fi + +# +# According to inherited flag, verify subdirectories and files within it has +# correct inherited access control. +# +function verify_inherit # [strategy] +{ + # Define the nodes which will be affected by inherit. + typeset inherit_nodes + typeset inherit=$1 + typeset obj=$2 + typeset str=$3 + + # count: the ACE item to fetch + # pass: to mark if the current ACE should apply to the target + # maxnumber: predefine as 4 + # passcnt: counter, if it achieves to maxnumber, + # then no additional ACE should apply. + # isinherit: indicate if the current target is in the inherit list. + # step: indicate if the ACE be split during inherit. + + typeset -i count=0 pass=0 passcnt=0 isinherit=0 maxnumber=4 step=0 + + log_must usr_exec $MKDIR -p $ndir3 + log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3 + + # Get the files which inherited ACE. + if [[ $obj == *"file_inherit"* ]]; then + inherit_nodes="$inherit_nodes $nfile1" + + if [[ $str != *"no_propagate"* ]]; then + inherit_nodes="$inherit_nodes $nfile2 $nfile3" + fi + fi + # Get the directores which inherited ACE. + if [[ $obj == *"dir_inherit"* ]]; then + inherit_nodes="$inherit_nodes $ndir1" + + if [[ $str != *"no_propagate"* ]]; then + inherit_nodes="$inherit_nodes $ndir2 $ndir3" + fi + fi + + for node in $allnodes; do + step=0 + if [[ " $inherit_nodes " == *" $node "* ]]; then + isinherit=1 + if [[ -d $node ]] ; then + step=1 + fi + else + isinherit=0 + fi + + i=0 + count=0 + passcnt=0 + while (( i < maxnumber )); do + pass=0 + eval expect1=\$acl$i + expect2=$expect1 + + # + # aclinherit=passthrough, + # inherit all inheritable ACL entries without any + # modifications made to the ACL entries when they + # are inherited. + # + # aclinherit=secure, + # any inheritable ACL entries will remove + # write_acl and write_owner permissions when the ACL entry is + # inherited. + # + # aclinherit=noallow, + # only inherit inheritable ACE that specify "deny" permissions + # + # aclinherit=discard + # will not inherit any ACL entries + # + + case $inherit in + passthrough) + ;; + secure) + if [[ $expect1 == *":allow" ]] ; then + eval expect2=\$acls$i + fi + ;; + noallow) + if [[ $expect1 == *":allow" ]] ; then + pass=1 + (( passcnt = passcnt + 1 )) + fi + ;; + discard) + passcnt=maxnumber + break + ;; + esac + + if (( pass == 0 )) ; then + acltemp=${expect2%:*} + acltemp=${acltemp%:*} + aclaction=${expect2##*:} + + if [[ -n $cifs ]]; then + expect2=${acltemp}:inherited:${aclaction} + else + expect2=${acltemp}:${aclaction} + fi + + acltemp=${expect1%:*} + + if [[ -d $node ]]; then + if [[ $expect1 == *"no_propagate"* ]] ; then + + # + # if no_propagate is set, + # then clear all inherit flags, + # only one ACE should left. + # + + step=0 + expect1="" + + elif [[ $expect1 != *"inherit_only"* ]]; then + + # + # directory should append + # "inherit_only" if not have + # + + if [[ -n $cifs ]]; then + + expect1=${acltemp}/inherit_only/inherited:${aclaction} + else + expect1=${acltemp}/inherit_only:${aclaction} + fi + elif [[ -n $cifs ]]; then + expect1=${acltemp}/inherited:${aclaction} + fi + + # + # cleanup the first ACE if the directory + # not in inherit list + # + + if (( isinherit == 0 )); then + expect1="" + fi + elif [[ -f $node ]] ; then + expect1="" + fi + + # Get the first ACE to do comparison + + aclcur=$(get_ACE $node $count) + aclcur=${aclcur#$count:} + if [[ -n $expect1 && $expect1 != $aclcur ]]; then + $LS -vd $basedir + $LS -vd $node + log_fail "$inherit $i #$count " \ + "ACE: $aclcur, expect to be " \ + "$expect1" + fi + + # Get the second ACE (if should have) to do comparison + + if (( step > 0 )); then + (( count = count + step )) + + aclcur=$(get_ACE $node $count) + aclcur=${aclcur#$count:} + if [[ -n $expect2 && \ + $expect2 != $aclcur ]]; then + + $LS -vd $basedir + $LS -vd $node + log_fail "$inherit $i #$count " \ + "ACE: $aclcur, expect to be " \ + "$expect2" + fi + fi + (( count = count + 1 )) + fi + (( i = i + 1 )) + done + + # + # If there's no any ACE be checked, it should be identify as + # an normal file/dir, verify it. + # + + if (( passcnt == maxnumber )); then + if [[ -d $node ]]; then + compare_acls $node $odir + elif [[ -f $node ]]; then + compare_acls $node $ofile + fi + + if [[ $? -ne 0 ]]; then + $LS -vd $basedir + $LS -vd $node + log_fail "Unexpect acl: $node, $inherit ($str)" + fi + fi + done +} + +typeset -i i=0 +typeset acl0 acl1 acl2 acl3 +typeset acls0 acls1 acls2 acls3 + +# +# Set aclmode=passthrough to make sure +# the acl will not change during chmod. +# A general testing should verify the combination of +# aclmode/aclinherit works well, +# here we just simple test them separately. +# + +log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS + +for inherit in "${aclinherit_flag[@]}"; do + + # + # Set different value of aclinherit + # + + log_must $ZFS set aclinherit=$inherit $TESTPOOL/$TESTFS + + for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + for obj in "${object_flag[@]}"; do + for str in "${strategy_flag[@]}"; do + typeset inh_opt=$obj + (( ${#str} != 0 )) && inh_opt=$inh_opt/$str + + # + # Prepare 4 ACES, which should include : + # deny -> to verify "noallow" + # write_acl/write_owner -> to verify "secure" + # + + acl0="$ace_prefix1:read_xattr/write_acl/write_owner:$inh_opt:deny" + acl1="$ace_prefix2:read_xattr/write_acl/write_owner:$inh_opt:allow" + acl2="$ace_prefix1:read_xattr:$inh_opt:deny" + acl3="$ace_prefix2:read_xattr:$inh_opt:allow" + + # + # The ACE filtered by write_acl/write_owner + # + + acls0="$ace_prefix1:read_xattr:$inh_opt:deny" + acls1="$ace_prefix2:read_xattr:$inh_opt:allow" + acls2=$acl2 + acls3=$acl3 + + + # + # Create basedir and tmp dir/file + # for comparison. + # + + log_note "$user: $CHMOD $acl $basedir" + log_must usr_exec $MKDIR $basedir + log_must usr_exec $MKDIR $odir + log_must usr_exec $TOUCH $ofile + + i=3 + while (( i >= 0 )); do + eval acl=\$acl$i + + # + # Place on a directory should succeed. + # + log_must usr_exec $CHMOD A+$acl $basedir + + (( i = i - 1 )) + done + + verify_inherit $inherit $obj $str + + log_must usr_exec $RM -rf $ofile $odir $basedir + done + done + done +done + +log_pass "Verify chmod inherit behaviour co-op with aclinherit setting passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_003_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_003_pos.ksh new file mode 100644 index 00000000000..8a398a676d6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_003_pos.ksh @@ -0,0 +1,449 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_inherit_003_pos.ksh 1.1 08/08/15 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib +. $STF_SUITE/tests/acl/cifs/cifs.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_inherit_003_pos +# +# DESCRIPTION: +# Verify chmod have correct behaviour to directory and file when +# filesystem has the different aclinherit setting +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Separately chmod basedir with different inherite options, +# combine with the variable setting of aclinherit: +# "discard", "noallow", "secure" or "passthrough". +# 4. Then create nested directories and files like the following. +# +# ofile +# odir +# chmod --> basedir -| +# |_ nfile1 +# |_ ndir1 _ +# |_ nfile2 +# |_ ndir2 _ +# |_ nfile3 +# |_ ndir3 +# +# 5. Verify each directories and files have the correct access control +# capability. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset dir + + # Cleanup basedir, compared file and dir. + + if [[ -f $ofile ]]; then + log_must $RM -f $ofile + fi + + for dir in $odir $basedir ; do + if [[ -d $dir ]]; then + log_must $RM -rf $dir + fi + done +} + +log_assert "Verify chmod have correct behaviour to directory and file when " \ + "filesystem has the different aclinherit setting." +log_onexit cleanup + +# Define inherit flag +set -A aclinherit_flag discard noallow secure passthrough +set -A object_flag "f-" "-d" "fd" +set -A strategy_flag "--" "i-" "-n" "in" + +typeset ace_prefix1="owner@" +typeset ace_prefix2="group@" +typeset ace_prefix3="everyone@" +typeset ace_discard ace_noallow ace_secure ace_passthrough +typeset ace_secure_new + +# Defile the based directory and file +basedir=$TESTDIR/basedir; ofile=$TESTDIR/ofile; odir=$TESTDIR/odir + +test_requires ZFS_ACL + +# Define the files and directories will be created after chmod +ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3 +nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3 + +# Verify all the node have expected correct access control +allnodes="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3" + +typeset cifs="" +if cifs_supported ; then + cifs="true" +fi + +# +# According to inherited flag, verify subdirectories and files within it has +# correct inherited access control. +# +function verify_inherit # [strategy] +{ + # Define the nodes which will be affected by inherit. + typeset inherit_nodes + typeset inherit=$1 + typeset obj=$2 + typeset str=$3 + + # count: the ACE item to fetch + # pass: to mark if the current ACE should apply to the target + # maxnumber: predefine as 4 + # passcnt: counter, if it achieves to maxnumber, + # then no additional ACE should apply. + # isinherit: indicate if the current target is in the inherit list. + # step: indicate if the ACE be split during inherit. + + typeset -i count=0 pass=0 passcnt=0 isinherit=0 maxnumber=4 step=0 + + log_must usr_exec $MKDIR -p $ndir3 + log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3 + + # Get the files which inherited ACE. + if [[ $(get_substr $obj 1 1) == f ]]; then + inherit_nodes="$inherit_nodes $nfile1" + + if [[ $(get_substr $str 2 1) != n ]]; then + inherit_nodes="$inherit_nodes $nfile2 $nfile3" + fi + fi + # Get the directores which inherited ACE. + if [[ $(get_substr $obj 2 1) == d ]]; then + inherit_nodes="$inherit_nodes $ndir1" + + if [[ $(get_substr $str 2 1) != n ]]; then + inherit_nodes="$inherit_nodes $ndir2 $ndir3" + fi + fi + + for node in $allnodes; do + step=0 + if [[ " $inherit_nodes " == *" $node "* ]]; then + isinherit=1 + if [[ -d $node ]] ; then + step=1 + fi + else + isinherit=0 + fi + + i=0 + count=0 + passcnt=0 + while (( i < maxnumber )); do + pass=0 + eval expect1=\$acl$i + expect2=$expect1 + + # + # aclinherit=passthrough, + # inherit all inheritable ACL entries without any + # modifications made to the ACL entries when they + # are inherited. + # + # aclinherit=secure, + # any inheritable ACL entries will remove + # write_acl and write_owner permissions when the ACL entry is + # inherited. + # + # aclinherit=noallow, + # only inherit inheritable ACE that specify "deny" permissions + # + # aclinherit=discard + # will not inherit any ACL entries + # + + case $inherit in + passthrough) + if [[ -z $cifs ]]; then + break + fi + + action=${expect1##*:} + expect1=${expect1%:$action} + expect1=${expect1%-} + expect1=${expect1%I} + expect1=${expect1}I:$action + ;; + secure) + eval expect2=\$acls$i + ;; + noallow) + if [[ $expect1 == *":allow" ]] ; then + pass=1 + (( passcnt = passcnt + 1 )) + else + eval expect2=\$acls$i + fi + ;; + discard) + passcnt=maxnumber + break + ;; + esac + + if (( pass == 0 )) ; then + acltemp=${expect2%:*} + acltemp=${acltemp%:*} + aclaction=${expect2##*:} + + if [[ -n $cifs ]]; then + expect2=${acltemp}:------I:${aclaction} + else + expect2=${acltemp}:------:${aclaction} + fi + + acltemp=${expect1%:*} + inh=${acltemp##*:} + + if [[ -d $node ]]; then + if [[ $(get_substr $inh 4 1) == n ]]; then + + # + # if no_propagate is set, + # then clear all inherit flags, + # only one ACE should left. + # + + step=0 + expect1="" + + elif [[ $(get_substr $inh 3 1) != i ]]; then + + # + # directory should append + # "inherit_only" if not have + # + acltemp=${acltemp%i*} + if [[ -n $cifs ]]; then + + expect1=${acltemp}i---I:${aclaction} + else + expect1=${acltemp}i---:${aclaction} + fi + elif [[ -n $cifs ]]; then + acltemp=${acltemp%-} + acltemp=${acltemp%I} + expect1=${acltemp}I:${aclaction} + fi + + # + # cleanup the first ACE if the directory + # not in inherit list + # + + if (( isinherit == 0 )); then + expect1="" + fi + elif [[ -f $node ]] ; then + expect1="" + fi + + # Get the first ACE to do comparison + + aclcur=$(get_ACE $node $count compact) + aclcur=${aclcur#$count:} + if [[ -n $expect1 && $expect1 != $aclcur ]]; then + $LS -Vd $basedir + $LS -Vd $node + log_fail "$inherit $i #$count " \ + "ACE: $aclcur, expect to be " \ + "$expect1" + fi + + # Get the second ACE (if should have) to do comparison + + if (( step > 0 )); then + (( count = count + step )) + + aclcur=$(get_ACE $node $count compact) + aclcur=${aclcur#$count:} + if [[ -n $expect2 && \ + $expect2 != $aclcur ]]; then + + $LS -Vd $basedir + $LS -Vd $node + log_fail "$inherit $i #$count " \ + "ACE: $aclcur, expect to be " \ + "$expect2" + fi + fi + (( count = count + 1 )) + fi + (( i = i + 1 )) + done + + # + # If there's no any ACE be checked, it should be identify as + # an normal file/dir, verify it. + # + + if (( passcnt == maxnumber )); then + if [[ -d $node ]]; then + compare_acls $node $odir + elif [[ -f $node ]]; then + compare_acls $node $ofile + fi + + if [[ $? -ne 0 ]]; then + $LS -Vd $basedir + $LS -Vd $node + log_fail "Unexpect acl: $node, $inherit ($str)" + fi + fi + done +} + +typeset -i i=0 +typeset acl0 acl1 acl2 acl3 +typeset acls0 acls1 acls2 acls3 + +# +# Set aclmode=passthrough to make sure +# the acl will not change during chmod. +# A general testing should verify the combination of +# aclmode/aclinherit works well, +# here we just simple test them separately. +# + +log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS + +for inherit in "${aclinherit_flag[@]}"; do + + # + # Set different value of aclinherit + # + + log_must $ZFS set aclinherit=$inherit $TESTPOOL/$TESTFS + + for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + for obj in "${object_flag[@]}"; do + for str in "${strategy_flag[@]}"; do + typeset inh_opt=$obj + (( ${#str} != 0 )) && inh_opt=${inh_opt}${str}-- + + if [[ -n $cifs ]]; then + inh_a=${inh_opt}- + inh_b=${inh_opt}I + else + inh_a=${inh_opt} + inh_b=${inh_opt} + fi + + # + # Prepare 4 ACES, which should include : + # deny -> to verify "noallow" + # write_acl/write_owner -> to verify "secure" + # + + acl0="$ace_prefix1:rwxp---A-W-Co-:${inh_a}:allow" + acl1="$ace_prefix2:rwxp---A-W-Co-:${inh_a}:deny" + acl2="$ace_prefix3:rwxp---A-W-Co-:${inh_a}:allow" + acl3="$ace_prefix1:-------A-W----:${inh_a}:deny" + acl4="$ace_prefix2:-------A-W----:${inh_a}:allow" + acl5="$ace_prefix3:-------A-W----:${inh_a}:deny" + + + # + # The ACE filtered by write_acl/write_owner + # + + if [[ $inheri == "passthrough" ]]; then + acls0="$ace_prefix1:rwxp---A-W----:${inh_b}:allow" + acls1="$ace_prefix2:rwxp---A-W----:${inh_b}:deny" + acls2="$ace_prefix3:rwxp---A-W----:${inh_b}:allow" + acls3="$ace_prefix1:rwxp---A-W----:${inh_b}:deny" + acls4="$ace_prefix2:rwxp---A-W----:${inh_b}:allow" + acls5="$ace_prefix3:rwxp---A-W----:${inh_b}:deny" + else + acls0="$ace_prefix1:-------A-W----:${inh_b}:allow" + acls1="$ace_prefix2:-------A-W-Co-:${inh_b}:deny" + acls2="$ace_prefix3:-------A-W----:${inh_b}:allow" + acls3="$ace_prefix1:-------A-W----:${inh_b}:deny" + acls4="$ace_prefix2:-------A-W----:${inh_b}:allow" + acls5="$ace_prefix3:-------A-W----:${inh_b}:deny" + fi + + # + # Create basedir and tmp dir/file + # for comparison. + # + + log_note "$user: $CHMOD $acl $basedir" + log_must usr_exec $MKDIR $basedir + log_must usr_exec $MKDIR $odir + log_must usr_exec $TOUCH $ofile + + i=5 + while (( i >= 0 )); do + eval acl=\$acl$i + + # + # Place on a directory should succeed. + # + log_must usr_exec $CHMOD A+$acl $basedir + + (( i = i - 1 )) + done + + verify_inherit $inherit $obj $str + + log_must usr_exec $RM -rf $ofile $odir $basedir + done + done + done +done + +log_pass "Verify chmod inherit behaviour co-op with aclinherit setting passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_004_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_004_pos.ksh new file mode 100644 index 00000000000..5a74471d9e4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_inherit_004_pos.ksh @@ -0,0 +1,162 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_inherit_004_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_inherit_004_pos +# +# DESCRIPTION: +# Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request. +# +# STRATEGY: +# 1. Loop super user and non-super user to run the test case. +# 2. Create basedir and a set of subdirectores and files within it. +# 3. Set aclinherit=passthrough-x +# 4. Verify only passthrough-x will inherit the 'x' bits while mode request. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if [[ -d $basedir ]]; then + log_must $RM -rf $basedir + fi +} + +$ZPOOL upgrade -v | $GREP "passthrough\-x aclinherit support" > /dev/null 2>&1 +if (( $? != 0 )) ; then + log_unsupported "passthrough-x aclinherit not supported." +fi + +log_assert "Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request." +log_onexit cleanup + +set -A aces "owner@:read_data/write_data/add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \ + "owner@:read_data/write_data/add_subdirectory/append_data/execute::allow" \ + "group@:add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \ + "group@:add_subdirectory/append_data/execute::allow" \ + "everyone@:add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \ + "everyone@:add_subdirectory/append_data/execute::allow" \ + "owner@:read_data/write_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow" \ + "group@:read_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow" \ + "everyone@:read_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow" + +# Defile the based directory and file +basedir=$TESTDIR/basedir + +test_requires ZFS_ACL + +# +# According to inherited flag, verify subdirectories and files within it has +# correct inherited access control. +# +function verify_inherit # +{ + typeset obj=$1 + + # Define the files and directories will be created after chmod + ndir1=$obj/ndir1; ndir2=$ndir1/ndir2 + nfile1=$ndir1/nfile1.c; nfile2=$ndir1/nfile2 + + log_must usr_exec $MKDIR -p $ndir1 + + typeset -i i=0 + while (( i < ${#aces[*]} )) ; do + if (( i < 6 )) ; then + log_must usr_exec $CHMOD A$i=${aces[i]} $ndir1 + else + log_must usr_exec $CHMOD A$i+${aces[i]} $ndir1 + fi + (( i = i + 1 )) + done + log_must usr_exec $MKDIR -p $ndir2 + log_must usr_exec $TOUCH $nfile1 + + $CAT > $nfile1 < +#include +int main() +{ return 0; } +EOF + + mode=$(get_mode $ndir2) + if [[ $mode != "drwx--x--x"* ]] ; then + log_fail "Unexpect mode of $ndir2, expect: drwx--x--x, current: $mode" + fi + + mode=$(get_mode $nfile1) + if [[ $mode != "-rw-r--r--"* ]] ; then + log_fail "Unexpect mode of $nfile1, expect: -rw-r--r--, current: $mode" + fi + + if [[ -x /usr/sfw/bin/gcc ]] ; then + log_must /usr/sfw/bin/gcc -o $nfile2 $nfile1 + mode=$(get_mode $nfile2) + if [[ $mode != "-rwxr-xr-x"* ]] ; then + log_fail "Unexpect mode of $nfile2, expect: -rwxr-xr-x, current: $mode" + fi + fi +} + +# +# Set aclmode=passthrough to make sure +# the acl will not change during chmod. +# A general testing should verify the combination of +# aclmode/aclinherit works well, +# here we just simple test them separately. +# + +log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS +log_must $ZFS set aclinherit=passthrough-x $TESTPOOL/$TESTFS + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + verify_inherit $basedir + + cleanup +done + +log_pass "Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_owner_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_owner_001_pos.ksh new file mode 100644 index 00000000000..f8d71f407b1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_owner_001_pos.ksh @@ -0,0 +1,402 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_owner_001_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_owner_001_pos +# +# DESCRIPTION: +# Verify that the write_owner for +# owner/group/everyone are correct. +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Set special write_owner ACE to the file and directory +# 3. Try to chown/chgrp of the file and directory to take owner/group +# 4. Verify that the owner/group are correct. Follow these rules: +# (1) If uid is granted the write_owner permission, +# then it can only do chown to its own uid, +# or a group that they are a member of. +# (2) Owner will ignore permission of (1) even write_owner not granted. +# (3) Superuser will always permit whatever they do. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + [[ ! -e $TESTDIR/$ARCHIVEFILE ]] && return 0 + + if [[ ! -e $target ]]; then + log_must $TAR xpf $TESTDIR/$ARCHIVEFILE + fi + + (( ${#cwd} != 0 )) && cd $cwd + cleanup_test_files $TESTDIR/basedir + log_must $RM -f $TESTDIR/$ARCHIVEFILE + return 0 +} + +#owner@ group group_users other_users +set -A users \ +"root" "root" "$ZFS_ACL_ADMIN" "$ZFS_ACL_OTHER1" \ +"$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF_GROUP" "$ZFS_ACL_STAFF2" "$ZFS_ACL_OTHER1" + +set -A a_access \ + "write_owner:allow" \ + "write_owner:deny" + +set -A a_flag "owner@" "group@" "everyone@" + +log_assert "Verify that the chown/chgrp could take owner/group " \ + "while permission is granted." +log_onexit cleanup + +# +# Get the owner of a file/directory +# +function get_owner #node +{ + typeset node=$1 + typeset value + + if [[ -z $node ]]; then + log_fail "node are not defined." + fi + + if [[ -d $node ]]; then + value=$($LS -dl $node | $AWK '{print $3}') + elif [[ -e $node ]]; then + value=$($LS -l $node | $AWK '{print $3}') + fi + + $ECHO $value +} + +# +# Get the group of a file/directory +# +function get_group #node +{ + typeset node=$1 + typeset value + + if [[ -z $node ]]; then + log_fail "node are not defined." + fi + + if [[ -d $node ]]; then + value=$($LS -dl $node | $AWK '{print $4}') + elif [[ -e $node ]]; then + value=$($LS -l $node | $AWK '{print $4}') + fi + + $ECHO $value +} + + +# +# Get the group name that a UID belongs to +# +function get_user_group #uid +{ + typeset uid=$1 + typeset value + + if [[ -z $uid ]]; then + log_fail "UID not defined." + fi + + value=$(id $uid) + + if [[ $? -eq 0 ]]; then + value=${value##*\(} + value=${value%%\)*} + $ECHO $value + else + log_fail "Invalid UID (uid)." + fi +} + +function operate_node_owner #user node old_owner expect_owner +{ + typeset user=$1 + typeset node=$2 + typeset old_owner=$3 + typeset expect_owner=$4 + typeset ret new_owner + + if [[ $user == "" || $node == "" ]]; then + log_fail "user, node are not defined." + fi + + chgusr_exec $user $CHOWN $expect_owner $node ; ret=$? + new_owner=$(get_owner $node) + + if [[ $new_owner != $old_owner ]]; then + $TAR xpf $TESTDIR/$ARCHIVEFILE + fi + + if [[ $ret -eq 0 ]]; then + if [[ $new_owner != $expect_owner ]]; then + log_note "Owner not changed as expected " \ + "($old_owner|$new_owner|$expect_owner), " \ + "but return code is $ret." + return 1 + fi + elif [[ $ret -ne 0 && $new_owner != $old_owner ]]; then + log_note "Owner changed ($old_owner|$new_owner), " \ + "but return code is $ret." + return 2 + fi + + return $ret +} + +function operate_node_group #user node old_group expect_group +{ + typeset user=$1 + typeset node=$2 + typeset old_group=$3 + typeset expect_group=$4 + typeset ret new_group + + if [[ $user == "" || $node == "" ]]; then + log_fail "user, node are not defined." + fi + + chgusr_exec $user $CHGRP $expect_group $node ; ret=$? + new_group=$(get_group $node) + + if [[ $new_group != $old_group ]]; then + $TAR xpf $TESTDIR/$ARCHIVEFILE + fi + + if [[ $ret -eq 0 ]]; then + if [[ $new_group != $expect_group ]]; then + log_note "Group not changed as expected " \ + "($old_group|$new_group|$expect_group), " \ + "but return code is $ret." + return 1 + fi + elif [[ $ret -ne 0 && $new_group != $old_group ]]; then + log_note "Group changed ($old_group|$new_group), " \ + "but return code is $ret." + return 2 + fi + + return $ret +} + +function logname #acl_target user old new +{ + typeset acl_target=$1 + typeset user=$2 + typeset old=$3 + typeset new=$4 + typeset ret="log_mustnot" + + # To super user, read and write deny permission was override. + if [[ $user == root ]]; then + ret="log_must" + elif [[ $user == $new ]] ; then + if [[ $user == $old || $acl_target == *:allow ]]; then + ret="log_must" + fi + fi + + print $ret +} + +function check_chmod_results #node flag acl_target g_usr o_usr +{ + typeset node=$1 + typeset flag=$2 + typeset acl_target=$2:$3 + typeset g_usr=$4 + typeset o_usr=$5 + typeset log old_owner old_group new_owner new_group + + old_owner=$(get_owner $node) + old_group=$(get_group $node) + + if [[ $flag == "owner@" || $flag == "everyone@" ]]; then + for new_owner in $ZFS_ACL_CUR_USER "nobody"; do + new_group=$(get_user_group $new_owner) + + log=$(logname $acl_target $ZFS_ACL_CUR_USER \ + $old_owner $new_owner) + + $log operate_node_owner $ZFS_ACL_CUR_USER $node \ + $old_owner $new_owner + + $log operate_node_group $ZFS_ACL_CUR_USER $node \ + $old_group $new_group + done + fi + if [[ $flag == "group@" || $flag == "everyone@" ]]; then + for new_owner in $g_usr "nobody"; do + new_group=$(get_user_group $new_owner) + + log=$(logname $acl_target $g_usr $old_owner \ + $new_owner) + + $log operate_node_owner $g_usr $node \ + $old_owner $new_owner + + $log operate_node_group $g_usr \ + $node $old_group $new_group + done + fi + if [[ $flag == "everyone@" ]]; then + for new_owner in $g_usr "nobody"; do + new_group=$(get_user_group $new_owner) + + log=$(logname $acl_target $o_usr $old_owner \ + $new_owner) + + $log operate_node_owner $o_usr $node \ + $old_owner $new_owner + + $log operate_node_group $o_usr $node \ + $old_group $new_group + done + fi +} + +function test_chmod_basic_access #node g_usr o_usr +{ + typeset node=${1%/} + typeset g_usr=$2 + typeset o_usr=$3 + typeset flag acl_p acl_t parent + + parent=${node%/*} + + for flag in ${a_flag[@]}; do + for acl_t in "${a_access[@]}"; do + log_must usr_exec $CHMOD A+$flag:$acl_t $node + + $TAR cpf $TESTDIR/$ARCHIVEFILE basedir + + check_chmod_results "$node" "$flag" \ + "$acl_t" "$g_usr" "$o_usr" + + log_must usr_exec $CHMOD A0- $node + done + done +} + +function setup_test_files #base_node user group +{ + typeset base_node=$1 + typeset user=$2 + typeset group=$3 + + cleanup_test_files $base_node + + log_must $MKDIR -p $base_node + log_must $CHOWN $user:$group $base_node + + log_must set_cur_usr $user + + # Prepare all files/sub-dirs for testing. + + file0=$base_node/testfile_rm + + dir0=$base_node/testdir_rm + + log_must usr_exec $TOUCH $file0 + log_must usr_exec $CHMOD 444 $file0 + + log_must usr_exec $MKDIR -p $dir0 + log_must usr_exec $CHMOD 444 $dir0 + + log_must usr_exec $CHMOD 555 $base_node + return 0 +} + +function cleanup_test_files #base_node +{ + typeset base_node=$1 + + if [[ -d $base_node ]]; then + log_must $RM -rf $base_node + elif [[ -e $base_node ]]; then + log_must $RM -f $base_node + fi + + return 0 +} + +typeset cwd=$PWD +typeset ARCHIVEFILE=archive.tar + +test_requires ZFS_ACL + +typeset -i i=0 +typeset -i j=0 +typeset target +cd $TESTDIR +while (( i < ${#users[@]} )); do + setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]} + + j=0 + while (( j < 1 )); do + eval target=\$file$j + test_chmod_basic_access $target \ + "${users[((i+2))]}" "${users[((i+3))]}" + + eval target=\$dir$j + test_chmod_basic_access $target \ + "${users[((i+2))]}" "${users[((i+3))]}" + + (( j = j + 1 )) + done + + (( i += 4 )) +done + +log_pass "Verify that the chown/chgrp could take owner/group " \ + "while permission is granted." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwacl_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwacl_001_pos.ksh new file mode 100644 index 00000000000..15a7ad9ffdd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwacl_001_pos.ksh @@ -0,0 +1,262 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_rwacl_001_pos.ksh 1.5 09/05/19 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_rwacl_001_pos +# +# DESCRIPTION: +# Verify assigned read_acl/write_acl to owner@/group@/everyone@, +# specificied user and group. File have the correct access permission. +# +# STRATEGY: +# 1. Separatedly verify file and directory was assigned read_acl/write_acl +# by root and non-root user. +# 2. Verify owner always can read and write acl, even deny. +# 3. Verify group access permission, when group was assigned +# read_acl/write_acl. +# 4. Verify access permission, after everyone was assigned read_acl/write. +# 5. Verify everyone@ was deny except specificied user, this user can read +# and write acl. +# 6. Verify the group was deny except specified user, this user can read +# and write acl +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify chmod A[number]{+|-|=} read_acl/write_acl have correct " \ + "behaviour to access permission." +log_onexit cleanup + +function read_ACL # ... +{ + typeset node=$1 + typeset user + typeset -i ret + + shift + for user in $@; do + chgusr_exec $user $LS -vd $node > /dev/null 2>&1 + ret=$? + (( ret != 0 )) && return $ret + + shift + done + + return 0 +} + +function write_ACL # ... +{ + typeset node=$1 + typeset user + typeset -i ret before_cnt after_cnt + + shift + for user in "$@"; do + before_cnt=$(count_ACE $node) + ret=$?; + (( ret != 0 )) && return $ret + + chgusr_exec $user $CHMOD A0+owner@:read_data:allow $node + ret=$? + (( ret != 0 )) && return $ret + + after_cnt=$(count_ACE $node) + ret=$? + (( ret != 0 )) && return $ret + + chgusr_exec $user $CHMOD A0- $node + ret=$? + (( ret != 0 )) && return $ret + + if (( after_cnt - before_cnt != 1 )); then + return 1 + fi + + shift + done + + return 0 +} + +function check_owner # +{ + typeset node=$1 + + for acc in allow deny; do + log_must usr_exec \ + $CHMOD A0+owner@:read_acl/write_acl:$acc $node + log_must read_ACL $node $ZFS_ACL_CUR_USER + log_must write_ACL $node $ZFS_ACL_CUR_USER + log_must usr_exec $CHMOD A0- $node + done +} + +function check_group # +{ + typeset node=$1 + + typeset grp_usr="" + if [[ $ZFS_ACL_CUR_USER == root ]]; then + grp_usr=$ZFS_ACL_ADMIN + elif [[ $ZFS_ACL_CUR_USER == $ZFS_ACL_STAFF1 ]]; then + grp_usr=$ZFS_ACL_STAFF2 + fi + + log_must usr_exec $CHMOD A0+group@:read_acl/write_acl:allow $node + log_must read_ACL $node $grp_usr + log_must write_ACL $node $grp_usr + log_must usr_exec $CHMOD A0- $node + + log_must usr_exec $CHMOD A0+group@:read_acl/write_acl:deny $node + log_mustnot read_ACL $node $grp_usr + log_mustnot write_ACL $node $grp_usr + log_must usr_exec $CHMOD A0- $node +} + +function check_everyone # +{ + typeset node=$1 + + typeset flag + for flag in allow deny; do + if [[ $flag == allow ]]; then + log=log_must + else + log=log_mustnot + fi + + log_must usr_exec \ + $CHMOD A0+everyone@:read_acl/write_acl:$flag $node + + $log read_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2 + $log write_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2 + + log_must usr_exec $CHMOD A0- $node + done +} + +function check_spec_user # +{ + typeset node=$1 + + log_must usr_exec $CHMOD A0+everyone@:read_acl/write_acl:deny $node + log_must usr_exec \ + $CHMOD A0+user:$ZFS_ACL_OTHER1:read_acl/write_acl:allow $node + + # The specified user can read and write acl + log_must read_ACL $node $ZFS_ACL_OTHER1 + log_must write_ACL $node $ZFS_ACL_OTHER1 + + # All the other user can't read and write acl + log_mustnot \ + read_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER2 + log_mustnot \ + write_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 $ZFS_ACL_OTHER2 + + log_must usr_exec $CHMOD A0- $node + log_must usr_exec $CHMOD A0- $node +} + +function check_spec_group # +{ + typeset node=$1 + + log_must usr_exec $CHMOD A0+everyone@:read_acl/write_acl:deny $node + log_must usr_exec $CHMOD \ + A0+group:$ZFS_ACL_OTHER_GROUP:read_acl/write_acl:allow $node + + # The specified group can read and write acl + log_must read_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2 + log_must write_ACL $node $ZFS_ACL_OTHER1 $ZFS_ACL_OTHER2 + + # All the other user can't read and write acl + log_mustnot read_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 + log_mustnot write_ACL $node $ZFS_ACL_ADMIN $ZFS_ACL_STAFF2 +} + +function check_user_in_group # +{ + typeset node=$1 + + log_must usr_exec $CHMOD \ + A0+group:$ZFS_ACL_OTHER_GROUP:read_acl/write_acl:deny $node + log_must usr_exec $CHMOD \ + A0+user:$ZFS_ACL_OTHER1:read_acl/write_acl:allow $node + log_must read_ACL $node $ZFS_ACL_OTHER1 + log_must write_ACL $node $ZFS_ACL_OTHER1 + log_mustnot read_ACL $node $ZFS_ACL_OTHER2 + log_mustnot write_ACL $node $ZFS_ACL_OTHER2 + + log_must usr_exec $CHMOD A0- $node + log_must usr_exec $CHMOD A0- $node +} + +set -A func_name check_owner \ + check_group \ + check_everyone \ + check_spec_user \ + check_spec_group \ + check_user_in_group + +test_requires ZFS_ACL + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must usr_exec $TOUCH $testfile + log_must usr_exec $MKDIR $testdir + + typeset func node + for func in ${func_name[@]}; do + for node in $testfile $testdir; do + eval $func \$node + done + done + + log_must usr_exec $RM -rf $testfile $testdir +done + +log_pass "Verify chmod A[number]{+|-|=} read_acl/write_acl passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_001_pos.ksh new file mode 100644 index 00000000000..8f739da96ac --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_001_pos.ksh @@ -0,0 +1,141 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_rwx_001_pos.ksh 1.3 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_rwx_001_pos +# +# DESCRIPTION: +# chmod A{+|-|=} have the correct behaviour to the ACL list. +# +# STRATEGY: +# 1. loop check root and non-root users +# 2. chmod file or dir with specified options +# 3. get ACE after behaviours of chmod +# 4. compare specified ACE and excpect ACE +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "chmod A{+|-|=} have the correct behaviour to the ACL list." +log_onexit cleanup + +typeset -i trival_count=6 head=0 mid end +((mid = RANDOM % $trival_count)) +((end = trival_count - 1)) + +opts="+ - =" +nums="$head $mid $end" +set -A file_ACEs \ + "user:$ZFS_ACL_STAFF1:read_data:allow" \ + "user:$ZFS_ACL_STAFF2:write_data:allow" \ + "user:$ZFS_ACL_OTHER1:execute:allow" +set -A dir_ACEs \ + "user:$ZFS_ACL_STAFF1:list_directory/read_data:allow" \ + "user:$ZFS_ACL_STAFF2:add_file/write_data:allow" \ + "user:$ZFS_ACL_OTHER1:execute:allow" + +function test_chmod_ACE_list #$opt $num $ace-spec $node +{ + typeset opt=A$2$1 + typeset -i num=$2 + typeset ace=$3 + typeset node=$4 + typeset -i expect_count=0 + + # Get expect ACE count + case $opt in + A[0-9]*+) (( expect_count = trival_count + 1 )) ;; + A[0-9]*-) (( expect_count = trival_count - 1 )) ;; + A[0-9]*=) (( expect_count = trival_count )) ;; + *) log_fail "Error option: '$opt'" ;; + esac + + # Invoke chmod A[number]{+|-|=} file|dir + if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then + log_must usr_exec $CHMOD "$opt$ace" "$node" + else + log_must usr_exec $CHMOD "$opt" "$node" + fi + + # Get the current ACE count and specified ACE + typeset cur_ace cur_count + cur_ace=$(get_ACE $node $num) + cur_count=$(count_ACE $node) + + # Compare with expected results + if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then + if [[ "$num:$ace" != "$cur_ace" ]]; then + log_fail "FAIL: $CHMOD $opt$ace $node" + fi + fi + if [[ "$expect_count" != "$cur_count" ]]; then + log_fail "FAIL: '$expect_count' != '$cur_count'" + fi +} + +test_requires ZFS_ACL + +for user in root $ZFS_ACL_STAFF1 $ZFS_ACL_OTHER1; do + log_must set_cur_usr $user + + for opt in $opts; do + for num in $nums; do + for ace in $file_ACEs; do + ls -l $TESTDIR + log_must usr_exec $TOUCH $testfile + test_chmod_ACE_list $opt $num $ace $testfile + log_must $RM -f $testfile + done + for ace in $dir_ACEs; do + ls -l $TESTDIR + log_must usr_exec $MKDIR -p $testdir + test_chmod_ACE_list $opt $num $ace $testdir + log_must $RM -rf $testdir + done + done + done +done + +log_pass "chmod A{+|-|=} behave to the ACL list passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_002_pos.ksh new file mode 100644 index 00000000000..44b668ccb26 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_002_pos.ksh @@ -0,0 +1,261 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_rwx_002_pos.ksh 1.5 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_rwx_002_pos +# +# DESCRIPTION: +# chmod A{+|-|=} read_data|write_data|execute for owner@ group@ or everyone@ +# correctly alters mode bits . +# +# STRATEGY: +# 1. Loop root and non-root user. +# 2. Get the random initial map. +# 3. Get the random ACL string. +# 4. Separately chmod +|-|= read_data|write_data|execute +# 5. Check map bits +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "chmod A{+|-|=} read_data|write_data|execute for owner@, group@ " \ + "or everyone@ correctly alters mode bits." +log_onexit cleanup + +set -A bits 0 1 2 3 4 5 6 7 +set -A a_flag owner group everyone +set -A a_access read_data write_data execute +set -A a_type allow deny + +# +# Get a random item from an array. +# +# $1 the base set +# +function random_select #array_name +{ + typeset arr_name=$1 + typeset -i ind + + eval typeset -i cnt=\${#${arr_name}[@]} + (( ind = $RANDOM % cnt )) + + eval print \${${arr_name}[$ind]} +} + +# +# Create a random string according to array name, the item number and +# separated tag. +# +# $1 array name where the function get the elements +# $2 the items number which you want to form the random string +# $3 the separated tag +# +function form_random_str # +{ + typeset arr_name=$1 + typeset -i count=${2:-1} + typeset sep=${3:-""} + + typeset str="" + while (( count > 0 )); do + str="${str}$(random_select $arr_name)${sep}" + + (( count -= 1 )) + done + + print $str +} + +# +# According to the original bits, the input ACE access and ACE type, return the +# expect bits after 'chmod A0{+|=}'. +# +# $1 bits which was make up of three bit 'rwx' +# $2 ACE access which is read_data, write_data or execute +# $3 ACE type which is allow or deny +# +function cal_bits #bits acl_access acl_type +{ + typeset bits=$1 + typeset acl_access=$2 + typeset acl_type=$3 + set -A bit r w x + + typeset tmpbits="" + typeset -i i=0 j + while (( i < 3 )); do + if [[ $acl_access == *"${a_access[i]}"* ]]; then + if [[ $acl_type == "allow" ]]; then + tmpbits="$tmpbits${bit[i]}" + elif [[ $acl_type == "deny" ]]; then + tmpbits="${tmpbits}-" + fi + else + (( j = i + 1 )) + tmpbits="$tmpbits$(get_substr $bits $j 1)" + fi + + (( i += 1 )) + done + + print "$tmpbits" +} + +# +# Based on the initial node map before chmod and the ace-spec, check if chmod +# has the correct behaven to map bits. +# +function check_test_result #init_mode node acl_flag acl_access a_type +{ + typeset init_mode=$1 + typeset node=$2 + typeset acl_flag=$3 + typeset acl_access=$4 + typeset acl_type=$5 + + typeset -3L u_bits=$init_mode + typeset g_bits=$(get_substr $init_mode 4 3) + typeset -3R o_bits=$init_mode + + if [[ $acl_flag == "owner" || $acl_flag == "everyone" ]]; then + u_bits=$(cal_bits $u_bits $acl_access $acl_type) + fi + if [[ $acl_flag == "group" || $acl_flag == "everyone" ]]; then + g_bits=$(cal_bits $g_bits $acl_access $acl_type) + fi + if [[ $acl_flag == "everyone" ]]; then + o_bits=$(cal_bits $o_bits $acl_access $acl_type) + fi + + typeset cur_mode=$(get_mode $node) + cur_mode=$(get_substr $cur_mode 2 9) + + if [[ $cur_mode == $u_bits$g_bits$o_bits ]]; then + log_note "SUCCESS: Current map($cur_mode) ==" \ + "expected map($u_bits$g_bits$o_bits)" + else + log_fail "FAIL: Current map($cur_mode) != " \ + "expected map($u_bits$g_bits$o_bits)" + fi +} + +function test_chmod_map # +{ + typeset node=$1 + typeset init_mask acl_flag acl_access acl_type + typeset -i cnt + + if (( ${#node} == 0 )); then + log_fail "FAIL: file name or directroy name is not defined." + fi + + # Get the initial map + init_mask=$(form_random_str bits 3) + # Get ACL flag, access & type + acl_flag=$(form_random_str a_flag) + (( cnt = ($RANDOM % ${#a_access[@]}) + 1 )) + acl_access=$(form_random_str a_access $cnt '/') + acl_access=${acl_access%/} + acl_type=$(form_random_str a_type) + + typeset acl_spec=${acl_flag}@:${acl_access}:${acl_type} + + # Set the initial map and back the initial ACEs + typeset orig_ace=$TMPDIR/orig_ace.${TESTCASE_ID} + typeset cur_ace=$TMPDIR/cur_ace.${TESTCASE_ID} + + for operator in "A0+" "A0="; do + log_must usr_exec $CHMOD $init_mask $node + init_mode=$(get_mode $node) + init_mode=$(get_substr $init_mode 2 9) + log_must usr_exec eval "$LS -vd $node > $orig_ace" + + # To "A=", firstly add one ACE which can't modify map + if [[ $operator == "A0=" ]]; then + log_must $CHMOD A0+user:$ZFS_ACL_OTHER1:execute:deny \ + $node + fi + log_must usr_exec $CHMOD $operator$acl_spec $node + check_test_result \ + $init_mode $node $acl_flag $acl_access $acl_type + + # Check "chmod A-" + log_must usr_exec $CHMOD A0- $node + log_must usr_exec eval "$LS -vd $node > $cur_ace" + + if $DIFF $orig_ace $cur_ace; then + log_note "SUCCESS: original ACEs equivalence the " \ + "current ACEs. 'chmod A-' succeeded." + else + log_fail "FAIL: 'chmod A-' failed." + fi + done + + [[ -f $orig_ace ]] && log_must usr_exec $RM -f $orig_ace + [[ -f $cur_ace ]] && log_must usr_exec $RM -f $cur_ace +} + +test_requires ZFS_ACL + +for user in root $ZFS_ACL_STAFF1; do + set_cur_usr $user + + typeset -i loop_cnt=20 + while (( loop_cnt > 0 )); do + log_must usr_exec $TOUCH $testfile + test_chmod_map $testfile + log_must $RM -f $testfile + + log_must usr_exec $MKDIR $testdir + test_chmod_map $testdir + log_must $RM -rf $testdir + + (( loop_cnt -= 1 )) + done +done + +log_pass "chmod A{+|-|=} read_data|write_data|execute for owner@, group@ " \ + "oreveryone@ correctly alters mode bits passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_003_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_003_pos.ksh new file mode 100644 index 00000000000..7fd3f38e51f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_003_pos.ksh @@ -0,0 +1,152 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_rwx_003_pos.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_rwx_003_pos +# +# DESCRIPTION: +# Verify that the read_data/write_data/execute permission for +# owner/group/everyone are correct. +# +# STRATEGY: +# 1. Loop root and non-root user. +# 2. Separated verify type@:access:allow|deny to file and directory +# 3. To super user, read and write deny was override. +# 4. According to ACE list and override rule, expect that +# read/write/execute file or directory succeed or fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-09) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# owner@ group_users other_users +set -A users \ + "root" "$ZFS_ACL_ADMIN" "$ZFS_ACL_OTHER1" \ + "$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF2" "$ZFS_ACL_OTHER1" + +# In order to test execute permission, read_data was need firstly. +set -A a_access "read_data" "write_data" "read_data/execute" +set -A a_flag "owner@" "group@" "everyone@" + +log_assert "Verify that the read_data/write_data/execute permission for" \ + "owner/group/everyone are correct." +log_onexit cleanup + +function logname #node acl_spec user +{ + typeset node=$1 + typeset acl_spec=$2 + typeset user=$3 + + # To super user, read and write deny permission was override. + if [[ $acl_spec == *:allow ]] || \ + [[ $user == root && -d $node ]] || \ + [[ $user == root && $acl_spec != *"execute"* ]] + then + print "log_must" + elif [[ $acl_spec == *:deny ]]; then + print "log_mustnot" + fi +} + +function check_chmod_results #node acl_spec g_usr o_usr +{ + typeset node=$1 + typeset acl_spec=$2 + typeset g_usr=$3 + typeset o_usr=$4 + typeset log + + if [[ $acl_spec == "owner@:"* || $acl_spec == "everyone@:"* ]]; then + log=$(logname $node $acl_spec $ZFS_ACL_CUR_USER) + $log rwx_node $ZFS_ACL_CUR_USER $node $acl_spec + fi + if [[ $acl_spec == "group@:"* || $acl_spec == "everyone@:"* ]]; then + log=$(logname $node $acl_spec $g_usr) + $log rwx_node $g_usr $node $acl_spec + fi + if [[ $acl_spec == "everyone@"* ]]; then + log=$(logname $node $acl_spec $o_usr) + $log rwx_node $o_usr $node $acl_spec + fi +} + +function test_chmod_basic_access #node group_user other_user +{ + typeset node=$1 + typeset g_usr=$2 + typeset o_usr=$3 + typeset flag access acl_spec + + for flag in ${a_flag[@]}; do + for access in ${a_access[@]}; do + for tp in allow deny; do + acl_spec="$flag:$access:$tp" + log_must usr_exec $CHMOD A+$acl_spec $node + check_chmod_results \ + $node $acl_spec $g_usr $o_usr + log_must usr_exec $CHMOD A0- $node + done + done + done +} + +test_requires ZFS_ACL + +typeset -i i=0 +while (( i < ${#users[@]} )); do + log_must set_cur_usr ${users[i]} + + log_must usr_exec $TOUCH $testfile + test_chmod_basic_access $testfile ${users[((i+1))]} ${users[((i+2))]} + log_must usr_exec $MKDIR $testdir + test_chmod_basic_access $testdir ${users[((i+1))]} ${users[((i+2))]} + + log_must usr_exec $RM -rf $testfile $testdir + + (( i += 3 )) +done + +log_pass "Verify that the read_data/write_data/execute permission for" \ + "owner/group/everyone passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_004_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_004_pos.ksh new file mode 100644 index 00000000000..1c54151348e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_rwx_004_pos.ksh @@ -0,0 +1,155 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_rwx_004_pos.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_rwx_004_pos +# +# DESCRIPTION: +# Verify that explicit ACL setting to specified user or group will +# override existed access rule. +# +# STRATEGY: +# 1. Loop root and non-root user. +# 2. Loop the specified access one by one. +# 3. Loop verify explicit ACL set to specified user and group. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-14) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function check_access #log user node access rflag +{ + typeset log=$1 + typeset user=$2 + typeset node=$3 + typeset access=$4 + typeset rflag=$5 + + if [[ $rflag == "allow" && $access == execute ]]; then + rwx_node $user $node $access + # + # When everyone@ were deny, this file can't execute. + # So,'cannot execute' means user has the permission to + # execute, just the file can't be execute. + # + if [[ $ZFS_ACL_ERR_STR == *"cannot execute" ]]; then + log_note "SUCCESS: rwx_node $user $node $access" + else + log_fail "FAIL: rwx_node $user $node $access" + fi + else + $log rwx_node $user $node $access + fi +} + +function verify_explicit_ACL_rule #node access flag +{ + set -A a_access "read_data" "write_data" "execute" + typeset node=$1 + typeset access=$2 + typeset flag=$3 + typeset log rlog rflag + + # Get the expect log check + if [[ $flag == allow ]]; then + log=log_mustnot + rlog=log_must + rflag=deny + else + log=log_must + rlog=log_mustnot + rflag=allow + fi + + log_must usr_exec $CHMOD A+everyone@:$access:$flag $node + log_must usr_exec $CHMOD A+user:$ZFS_ACL_OTHER1:$access:$rflag $node + check_access $log $ZFS_ACL_OTHER1 $node $access $rflag + log_must usr_exec $CHMOD A0- $node + + log_must usr_exec \ + $CHMOD A+group:$ZFS_ACL_OTHER_GROUP:$access:$rflag $node + check_access $log $ZFS_ACL_OTHER1 $node $access $rflag + check_access $log $ZFS_ACL_OTHER2 $node $access $rflag + log_must usr_exec $CHMOD A0- $node + log_must usr_exec $CHMOD A0- $node + + log_must usr_exec \ + $CHMOD A+group:$ZFS_ACL_OTHER_GROUP:$access:$flag $node + log_must usr_exec $CHMOD A+user:$ZFS_ACL_OTHER1:$access:$rflag $node + $log rwx_node $ZFS_ACL_OTHER1 $node $access + $rlog rwx_node $ZFS_ACL_OTHER2 $node $access + log_must usr_exec $CHMOD A0- $node + log_must usr_exec $CHMOD A0- $node +} + +log_assert "Verify that explicit ACL setting to specified user or group will" \ + "override existed access rule." +log_onexit cleanup + +set -A a_access "read_data" "write_data" "execute" +set -A a_flag "allow" "deny" +typeset node + +test_requires ZFS_ACL + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must usr_exec $TOUCH $testfile + log_must usr_exec $MKDIR $testdir + log_must usr_exec $CHMOD 755 $testfile $testdir + + for node in $testfile $testdir; do + for access in ${a_access[@]}; do + for flag in ${a_flag[@]}; do + verify_explicit_ACL_rule $node $access $flag + done + done + done + + log_must usr_exec $RM -rf $testfile $testdir +done + +log_pass "Explicit ACL setting to specified user or group will override " \ + "existed access rule passed." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_xattr_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_xattr_001_pos.ksh new file mode 100644 index 00000000000..71c20e473c1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_xattr_001_pos.ksh @@ -0,0 +1,257 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_xattr_001_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_xattr_001_pos +# +# DESCRIPTION: +# Verify that the read_xattr/write_xattr for +# owner/group/everyone are correct. +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Set special read_xattr ACE to the file and directory +# 3. Try to list the extended attributes of the file and directory +# 4. Set special write_xattr ACE to the file and directory +# 5. Try to add new extended attributes to the file and directory +# 6. Verify above operation is successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-11-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + cd $cwd + + cleanup_test_files $TESTDIR/basedir + + if [[ -e $TESTDIR/$ARCHIVEFILE ]]; then + log_must $RM -f $TESTDIR/$ARCHIVEFILE + fi + + return 0 +} + +# owner@ group group_users other_users +set -A users \ + "root" "root" "$ZFS_ACL_ADMIN" "$ZFS_ACL_OTHER1" \ + "$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF_GROUP" "$ZFS_ACL_STAFF2" "$ZFS_ACL_OTHER1" + +set -A a_access \ + "read_xattr:allow" \ + "read_xattr:deny" \ + "write_xattr:allow" \ + "write_xattr:deny" + +set -A a_flag "owner@" "group@" "everyone@" + +MYTESTFILE=$STF_SUITE/include/default.cfg + +log_assert "Verify that the permission of read_xattr/write_xattr for " \ + "owner/group/everyone are correct." +log_onexit cleanup + +function operate_node #user node acl +{ + typeset user=$1 + typeset node=$2 + typeset acl_t=$3 + typeset ret + + if [[ $user == "" || $node == "" ]]; then + log_fail "user, node are not defined." + fi + + if [[ $acl_t == *read_xattr* ]]; then + chgusr_exec $user $RUNAT $node $LS > /dev/null 2>&1; ret=$? + elif [[ $acl_t == *write_xattr* ]]; then + chgusr_exec $user $RUNAT $node $CP $MYTESTFILE attr.1 ; ret=$? + + if [[ $ret -eq 0 ]]; then + log_must cleanup_test_files $TESTDIR/basedir + log_must $TAR xpf@ $TESTDIR/$ARCHIVEFILE + fi + fi + + return $ret +} + +function logname #acl_target user +{ + typeset acl_target=$1 + typeset user=$2 + typeset ret="log_mustnot" + + # To super user, read and write deny permission was override. + if [[ $user == root || $acl_target == *:allow ]] then + ret="log_must" + fi + + print $ret +} + +function check_chmod_results #node flag acl_target g_usr o_usr +{ + typeset node=$1 + typeset flag=$2 + typeset acl_target=$2:$3 + typeset g_usr=$4 + typeset o_usr=$5 + typeset log + + if [[ $flag == "owner@" || $flag == "everyone@" ]]; then + log=$(logname $acl_target $ZFS_ACL_CUR_USER) + $log operate_node $ZFS_ACL_CUR_USER $node $acl_target + fi + if [[ $flag == "group@" || $flag == "everyone@" ]]; then + log=$(logname $acl_target $g_usr) + $log operate_node $g_usr $node $acl_target + fi + if [[ $flag == "everyone@" ]]; then + log=$(logname $acl_target $o_usr) + $log operate_node $o_usr $node $acl_target + fi +} + +function test_chmod_basic_access #node g_usr o_usr +{ + typeset node=${1%/} + typeset g_usr=$2 + typeset o_usr=$3 + typeset flag acl_p acl_t parent + + parent=${node%/*} + + for flag in ${a_flag[@]}; do + for acl_t in "${a_access[@]}"; do + log_must usr_exec $CHMOD A+$flag:$acl_t $node + + log_must $TAR cpf@ $TESTDIR/$ARCHIVEFILE basedir + + check_chmod_results "$node" "$flag" \ + "$acl_t" "$g_usr" "$o_usr" + + log_must usr_exec $CHMOD A0- $node + done + done +} + +function setup_test_files #base_node user group +{ + typeset base_node=$1 + typeset user=$2 + typeset group=$3 + + cleanup_test_files $base_node + + log_must $MKDIR -p $base_node + log_must $CHOWN $user:$group $base_node + + log_must set_cur_usr $user + + # Prepare all files/sub-dirs for testing. + + file0=$base_node/testfile_rm + + dir0=$base_node/testdir_rm + + log_must usr_exec $TOUCH $file0 + log_must usr_exec $CHMOD 444 $file0 + + log_must usr_exec $RUNAT $file0 $CP $MYTESTFILE attr.0 + + log_must usr_exec $MKDIR -p $dir0 + log_must usr_exec $CHMOD 555 $dir0 + + log_must usr_exec $RUNAT $dir0 $CP $MYTESTFILE attr.0 + + log_must usr_exec $CHMOD 777 $base_node + return 0 +} + +function cleanup_test_files #base_node +{ + typeset base_node=$1 + + if [[ -d $base_node ]]; then + log_must $RM -rf $base_node + elif [[ -e $base_node ]]; then + log_must $RM -f $base_node + fi + + return 0 +} + +typeset cwd=$PWD +typeset ARCHIVEFILE=archive.tar + +test_requires RUNAT ZFS_ACL ZFS_XATTR + +typeset -i i=0 +typeset -i j=0 +typeset target + +while (( i < ${#users[@]} )); do + setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]} + cd $TESTDIR + + j=0 + while (( j < 1 )); do + eval target=\$file$j + test_chmod_basic_access $target \ + "${users[((i+2))]}" "${users[((i+3))]}" + + eval target=\$dir$j + test_chmod_basic_access $target \ + "${users[((i+2))]}" "${users[((i+3))]}" + + (( j = j + 1 )) + done + + (( i += 4 )) +done + +log_pass "Verify that the permission of read_xattr/write_xattr for " \ + "owner/group/everyone are correct." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_xattr_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_xattr_002_pos.ksh new file mode 100644 index 00000000000..0fa8abdbaf8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_chmod_xattr_002_pos.ksh @@ -0,0 +1,252 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_xattr_002_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_xattr_002_pos +# +# DESCRIPTION: +# Verify that the write_xattr for remove the extended attributes of +# owner/group/everyone are correct. +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Set special write_xattr ACE to the file and directory +# 3. Try to remove the extended attributes of the file and directory +# 4. Verify above operation is successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-11-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + cd $cwd + + cleanup_test_files $TESTDIR/basedir + + if [[ -e $TESTDIR/$ARCHIVEFILE ]]; then + log_must $RM -f $TESTDIR/$ARCHIVEFILE + fi + + return 0 +} + +# owner@ group group_users other_users +set -A users \ + "root" "root" "$ZFS_ACL_ADMIN" "$ZFS_ACL_OTHER1" \ + "$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF_GROUP" "$ZFS_ACL_STAFF2" "$ZFS_ACL_OTHER1" + +set -A a_access \ + "write_xattr:allow" \ + "write_xattr:deny" + +set -A a_flag "owner@" "group@" "everyone@" + +MYTESTFILE=$STF_SUITE/include/default.cfg + +log_assert "Verify that the permission of write_xattr for " \ + "owner/group/everyone while remove extended attributes are correct." +log_onexit cleanup + +function operate_node #user node acl +{ + typeset user=$1 + typeset node=$2 + typeset acl_t=$3 + typeset ret + + if [[ $user == "" || $node == "" ]]; then + log_fail "user, node are not defined." + fi + + chgusr_exec $user $RUNAT $node $RM -f attr.0 ; ret=$? + + if [[ $ret -eq 0 ]]; then + log_must cleanup_test_files $TESTDIR/basedir + log_must $TAR xpf@ $TESTDIR/$ARCHIVEFILE + fi + + return $ret +} + +function logname #acl_target owner user +{ + typeset acl_target=$1 + typeset owner=$2 + typeset user=$3 + typeset ret="log_mustnot" + + # To super user, read and write deny permission was override. + if [[ $user == root || $owner == $user ]] then + ret="log_must" + fi + + print $ret +} + +function check_chmod_results #node flag acl_target owner g_usr o_usr +{ + typeset node=$1 + typeset flag=$2 + typeset acl_target=$2:$3 + typeset owner=$4 + typeset g_usr=$5 + typeset o_usr=$6 + typeset log + + if [[ $flag == "owner@" || $flag == "everyone@" ]]; then + log=$(logname $acl_target $owner $ZFS_ACL_CUR_USER) + $log operate_node $ZFS_ACL_CUR_USER $node $acl_target + fi + if [[ $flag == "group@" || $flag == "everyone@" ]]; then + log=$(logname $acl_target $owner $g_usr) + $log operate_node $g_usr $node $acl_target + fi + if [[ $flag == "everyone@" ]]; then + log=$(logname $acl_target $owner $o_usr) + $log operate_node $o_usr $node $acl_target + fi +} + +function test_chmod_basic_access #node owner g_usr o_usr +{ + typeset node=${1%/} + typeset owner=$2 + typeset g_usr=$3 + typeset o_usr=$4 + typeset flag acl_p acl_t parent + + parent=${node%/*} + + for flag in ${a_flag[@]}; do + for acl_t in "${a_access[@]}"; do + log_must usr_exec $CHMOD A+$flag:$acl_t $node + + log_must $TAR cpf@ $TESTDIR/$ARCHIVEFILE basedir + + check_chmod_results "$node" "$flag" \ + "$acl_t" "$owner" "$g_usr" "$o_usr" + + log_must usr_exec $CHMOD A0- $node + done + done +} + +function setup_test_files #base_node user group +{ + typeset base_node=$1 + typeset user=$2 + typeset group=$3 + + cleanup_test_files $base_node + + log_must $MKDIR -p $base_node + log_must $CHOWN $user:$group $base_node + + log_must set_cur_usr $user + + # Prepare all files/sub-dirs for testing. + + file0=$base_node/testfile_rm + + dir0=$base_node/testdir_rm + + log_must usr_exec $TOUCH $file0 + log_must usr_exec $CHMOD 444 $file0 + + log_must usr_exec $RUNAT $file0 $CP $MYTESTFILE attr.0 + + log_must usr_exec $MKDIR -p $dir0 + log_must usr_exec $CHMOD 555 $dir0 + + log_must usr_exec $RUNAT $dir0 $CP $MYTESTFILE attr.0 + + log_must usr_exec $CHMOD 555 $base_node + return 0 +} + +function cleanup_test_files #base_node +{ + typeset base_node=$1 + + if [[ -d $base_node ]]; then + log_must $RM -rf $base_node + elif [[ -e $base_node ]]; then + log_must $RM -f $base_node + fi + + return 0 +} + +typeset cwd=$PWD +typeset ARCHIVEFILE=archive.tar + +test_requires RUNAT ZFS_XATTR + +typeset -i i=0 +typeset -i j=0 +typeset target + +while (( i < ${#users[@]} )); do + setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]} + cd $TESTDIR + + j=0 + while (( j < 1 )); do + eval target=\$file$j + test_chmod_basic_access $target ${users[i]} \ + "${users[((i+2))]}" "${users[((i+3))]}" + + eval target=\$dir$j + test_chmod_basic_access $target ${users[i]} \ + "${users[((i+2))]}" "${users[((i+3))]}" + + (( j = j + 1 )) + done + + (( i += 4 )) +done + +log_pass "Verify that the permission of write_xattr for " \ + "owner/group/everyone while remove extended attributes are correct." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cp_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cp_001_pos.ksh new file mode 100644 index 00000000000..e51c6a05c49 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cp_001_pos.ksh @@ -0,0 +1,115 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_cp_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_cp_001_pos +# +# DESCRIPTION: +# Verify that '/bin/cp [-p]' supports ZFS ACL +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Set special ACE to the file and directory +# 3. Copy the file/directory within and across zfs file system +# 4. Verify that the ACL of file/directroy is not changed, when you are +# inserting an ACL with a user: or group: entry on the top. +# (abstractions entry are treated special, since they represent the +# traditional permission bit mapping.) +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + fi + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1 + [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Verify that '$CP [-p]' supports ZFS ACLs." +log_onexit cleanup + +test_requires ZFS_ACL + +log_note "Create the second zfs file system: $TESTPOOL/$TESTFS1." +log_must $ZFS create $TESTPOOL/$TESTFS1 +log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 +log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS1 +log_must $CHMOD 777 $TESTDIR1 + +# Define target directory. +dstdir=$TESTDIR1/dstdir.${TESTCASE_ID} + +for user in root $ZFS_ACL_STAFF1; do + # Set the current user + log_must set_cur_usr $user + + for obj in $testfile $testdir; do + # Create source object and target directroy + log_must usr_exec $TOUCH $testfile + log_must usr_exec $MKDIR $testdir $dstdir + + # Add the new ACE on the head. + log_must usr_exec $CHMOD \ + A0+user:$ZFS_ACL_OTHER1:read_acl:deny $obj + + cmd_str="$CP -p" + [[ -d $obj ]] && cmd_str="$CP -rp" + log_must usr_exec $cmd_str $obj $dstdir + log_must usr_exec $cmd_str $obj $TESTDIR1 + + for dir in $dstdir $TESTDIR1; do + log_must compare_modes $obj $dir/${obj##*/} + log_must compare_acls $obj $dir/${obj##*/} + done + + # Delete all the test file and directory + log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/* + done +done + +log_pass "'$CP [-p]' succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cp_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cp_002_pos.ksh new file mode 100644 index 00000000000..67846fee18b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cp_002_pos.ksh @@ -0,0 +1,121 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_cp_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_cp_002_pos +# +# DESCRIPTION: +# Verify that '/bin/cp [-p@]' supports ZFS ACL & xattrs +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Set special ACE to the file and directory +# 3. Create xattr of the file and directory +# 4. Copy the file/directory within and across zfs file system +# 5. Verify that the ACL & xattrs of the file/directroy is not changed, +# when you are inserting an ACL with user: or group: entry on the top. +# (abstractions entry are treated special, since they represent the +# traditional permission bit mapping.) +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + fi + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1 + [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Verify that '$CP [-p]' supports ZFS ACLs." +log_onexit cleanup + +test_requires RUNAT ZFS_ACL ZFS_XATTR + +log_note "Create the second zfs file system: $TESTPOOL/$TESTFS1." +log_must $ZFS create $TESTPOOL/$TESTFS1 +log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 +log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS1 +log_must $CHMOD 777 $TESTDIR1 + +# Define target directory. +dstdir=$TESTDIR1/dstdir.${TESTCASE_ID} +MYTESTFILE=$STF_SUITE/include/default.cfg + +for user in root $ZFS_ACL_STAFF1; do + # Set the current user + log_must set_cur_usr $user + + for obj in $testfile $testdir; do + # Create source object and target directroy + log_must usr_exec $TOUCH $testfile + log_must usr_exec $MKDIR $testdir $dstdir + + log_must usr_exec $RUNAT $testfile $CP $MYTESTFILE attr.0 + log_must usr_exec $RUNAT $testdir $CP $MYTESTFILE attr.0 + + # Add the new ACE on the head. + log_must usr_exec $CHMOD \ + A0+user:$ZFS_ACL_OTHER1:read_acl:deny $obj + + cmd_str="$CP -p@" + [[ -d $obj ]] && cmd_str="$CP -rp@" + log_must usr_exec $cmd_str $obj $dstdir + log_must usr_exec $cmd_str $obj $TESTDIR1 + + for dir in $dstdir $TESTDIR1; do + log_must compare_modes $obj $dir/${obj##*/} + log_must compare_acls $obj $dir/${obj##*/} + log_must compare_xattrs $obj $dir/${obj##*/} + done + + # Delete all the test file and directory + log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/* + done +done + +log_pass "'$CP [-p@]' succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cpio_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cpio_001_pos.ksh new file mode 100644 index 00000000000..461a4031236 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cpio_001_pos.ksh @@ -0,0 +1,140 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_cpio_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_cpio_001_pos +# +# DESCRIPTION: +# Verify that '$CPIO' command with -P option supports to archive ZFS ACLs +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Add new ACE in ACL or change mode of file and directory +# 3. Use $CPIO to archive file and directory +# 4. Extract the archive file +# 5. Verify that the restored ACLs of file and directory identify +# with the origional ones. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + fi + if (( ${#orig_dir} != 0 )); then + cd $orig_dir + fi + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1 + [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Verify that '$CPIO' command supports to archive ZFS ACLs." +log_onexit cleanup + +test_requires ZFS_ACL + +set -A ops "A+everyone@:execute:allow" \ + "A3+user:$ZFS_ACL_OTHER1:write_data:deny" \ + "A5+group:$ZFS_ACL_OTHER_GROUP:read_data:deny" \ + "A0+user:$ZFS_ACL_OTHER1:write_data:deny" \ + "A1=user:$ZFS_ACL_STAFF1:write_data:deny" \ + "A5=group:$ZFS_ACL_STAFF_GROUP:write_data:deny" + +log_note "Create second zfs file system to restore the cpio archive." +log_must $ZFS create $TESTPOOL/$TESTFS1 +log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 +log_must $CHMOD 777 $TESTDIR1 + +# Define test fine and record the original directory. +CPIOFILE=cpiofile.${TESTCASE_ID} +file=$TESTFILE0 +dir=dir.${TESTCASE_ID} +orig_dir=$PWD + +typeset user +for user in root $ZFS_ACL_STAFF1; do + # Set the current user + log_must set_cur_usr $user + + typeset -i i=0 + while (( i < ${#ops[*]} )); do + log_note "Create file $file and directory $dir " \ + "in zfs filesystem. " + cd $TESTDIR + log_must usr_exec $TOUCH $file + log_must usr_exec $MKDIR $dir + + log_note "Change the ACLs of file and directory with " \ + "'$CHMOD ${ops[i]}'." + for obj in $file $dir; do + log_must usr_exec $CHMOD ${ops[i]} $obj + done + + log_note "Archive the file and directory." + cd $TESTDIR + log_must eval "usr_exec $LS | " \ + "usr_exec $CPIO -ocP -O $CPIOFILE > /dev/null 2>&1" + + log_note "Restore the cpio archive." + log_must usr_exec $MV $CPIOFILE $TESTDIR1 + cd $TESTDIR1 + log_must eval "usr_exec $CAT $CPIOFILE | " \ + "usr_exec $CPIO -icP > /dev/null 2>&1" + + log_note "Verify that the ACLs of restored file/directory " \ + "have no changes." + for obj in $file $dir; do + log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj + log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj + done + + log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/* + + (( i = i + 1 )) + done +done + +log_pass "'$CPIO' command succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cpio_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cpio_002_pos.ksh new file mode 100644 index 00000000000..68d03f6f76e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_cpio_002_pos.ksh @@ -0,0 +1,144 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_cpio_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_cpio_002_pos +# +# DESCRIPTION: +# Verify that '$CPIO' command with -P@ option supports to archive ZFS ACLs +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Add new ACE in ACL or change mode of file and directory +# 3. Create xattr of the file and directory +# 4. Use $CPIO to archive file and directory +# 5. Extract the archive file +# 6. Verify that the restored ACLs of file and directory identify +# with the origional ones. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + fi + if (( ${#orig_dir} != 0 )); then + cd $orig_dir + fi + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1 + [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Verify that '$CPIO' command supports to archive ZFS ACLs & xattrs." +log_onexit cleanup + +test_requires RUNAT ZFS_ACL ZFS_XATTR + +set -A ops "A+everyone@:execute:allow" \ + "A3+user:$ZFS_ACL_OTHER1:write_data:deny" \ + "A5+group:$ZFS_ACL_OTHER_GROUP:read_data:deny" \ + "A0+user:$ZFS_ACL_OTHER1:write_data:deny" + +log_note "Create second zfs file system to restore the cpio archive." +log_must $ZFS create $TESTPOOL/$TESTFS1 +log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 +log_must $CHMOD 777 $TESTDIR1 + +# Define test fine and record the original directory. +CPIOFILE=cpiofile.${TESTCASE_ID} +file=$TESTFILE0 +dir=dir.${TESTCASE_ID} +orig_dir=$PWD +MYTESTFILE=$STF_SUITE/include/default.cfg + +typeset user +for user in root $ZFS_ACL_STAFF1; do + # Set the current user + log_must set_cur_usr $user + + typeset -i i=0 + while (( i < ${#ops[*]} )); do + log_note "Create file $file and directory $dir " \ + "in zfs filesystem. " + cd $TESTDIR + log_must usr_exec $TOUCH $file + log_must usr_exec $MKDIR $dir + log_must usr_exec $RUNAT $file $CP $MYTESTFILE attr.0 + log_must usr_exec $RUNAT $dir $CP $MYTESTFILE attr.0 + + log_note "Change the ACLs of file and directory with " \ + "'$CHMOD ${ops[i]}'." + for obj in $file $dir; do + log_must usr_exec $CHMOD ${ops[i]} $obj + done + + log_note "Archive the file and directory." + cd $TESTDIR + log_must eval "usr_exec $LS | " \ + "usr_exec $CPIO -ocP@ -O $CPIOFILE > /dev/null 2>&1" + + log_note "Restore the cpio archive." + log_must usr_exec $MV $CPIOFILE $TESTDIR1 + cd $TESTDIR1 + log_must eval "usr_exec $CAT $CPIOFILE | " \ + "usr_exec $CPIO -icP@ > /dev/null 2>&1" + + log_note "Verify that the ACLs of restored file/directory " \ + "have no changes." + for obj in $file $dir; do + log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj + log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj + log_must compare_xattrs $TESTDIR/$obj $TESTDIR1/$obj + done + + log_must usr_exec $RM -rf $TESTDIR/* $TESTDIR1/* + + (( i = i + 1 )) + done +done + +log_pass "'$CPIO' command succeeds to support ZFS ACLs & xattrs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_find_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_find_001_pos.ksh new file mode 100644 index 00000000000..ab17aa89b72 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_find_001_pos.ksh @@ -0,0 +1,144 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_find_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_find_001_pos +# +# DESCRIPTION: +# Verify that '$FIND' command with '-ls' and '-acl' options supports ZFS ACL +# +# STRATEGY: +# 1. Create 5 files and 5 directories in zfs filesystem +# 2. Select a file or directory and add a few ACEs to it +# 3. Use $FIND -ls to check the "+" existen only with the selected file or +# directory +# 4. Use $FIND -acl to check only the selected file/directory in the list +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + [[ -d $TESTDIR ]] && $RM -rf $TESTDIR/* + (( ${#cwd} != 0 )) && cd $cwd + (( ${#mask} != 0 )) && $UMASK $mask +} + +function find_ls_acl # +{ + typeset opt=$1 # -ls or -acl + typeset obj=$2 + typeset rst_str="" + + if [[ $opt == "ls" ]]; then + rst_str=`$FIND . -ls | $GREP "+" | $AWK '{print $11}'` + else + rst_str=`$FIND . -acl` + fi + + if [[ $rst_str == "./$obj" ]]; then + return 0 + else + return 1 + fi +} + +log_assert "Verify that '$FIND' command supports ZFS ACLs." +log_onexit cleanup + +test_requires ZFS_ACL + +set -A ops " A+everyone@:read_data:allow" \ + " A+owner@:write_data:allow" + +f_base=testfile.${TESTCASE_ID} # Base file name for tested files +d_base=testdir.${TESTCASE_ID} # Base directory name for tested directory +cwd=$PWD +mask=`$UMASK` + +log_note "Create five files and directories in the zfs filesystem. " +cd $TESTDIR +$UMASK 0777 +typeset -i i=0 +while (( i < 5 )) +do + log_must $TOUCH ${f_base}.$i + log_must $MKDIR ${d_base}.$i + + (( i = i + 1 )) +done + +for obj in ${f_base}.3 ${d_base}.3 +do + i=0 + while (( i < ${#ops[*]} )) + do + log_must $CHMOD ${ops[i]} $obj + + (( i = i + 1 )) + done + + for opt in "ls" "acl" + do + log_must find_ls_acl $opt $obj + done + + log_note "Check the file access permission according to the added ACEs" + if [[ ! -r $obj || ! -w $obj ]]; then + log_fail "The added ACEs for $obj cannot be represented in " \ + "mode." + fi + + log_note "Remove the added ACEs from ACL." + i=0 + while (( i < ${#ops[*]} )) + do + log_must $CHMOD A0- $obj + + (( i = i + 1 )) + done +done + +log_pass "'$FIND' command succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_ls_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_ls_001_pos.ksh new file mode 100644 index 00000000000..d9f1cd83bbb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_ls_001_pos.ksh @@ -0,0 +1,124 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_ls_001_pos.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_ls_001_pos +# +# DESCRIPTION: +# Verify that '/bin/ls' command option supports ZFS ACL +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Verify that 'ls [-dv]' can list the ACEs of ACL of +# file/directroy +# 3. Change the file/directory's acl +# 4. Verify that 'ls -l' can use the '+' to indicate the non-trivial +# acl. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + (( ${#cwd} != 0 )) && cd $cwd + [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/* + (( ${#mask} != 0 )) && log_must $UMASK $mask +} + +log_assert "Verify that '$LS' command supports ZFS ACLs." +log_onexit cleanup + +test_requires ZFS_ACL + +file=$TESTFILE0 +dir=dir.${TESTCASE_ID} +cwd=$PWD +mask=`$UMASK` +spec_ace="everyone@:write_acl:allow" + +$UMASK 0022 + +log_note "Create file and directory in the zfs filesystem. " +cd $TESTDIR +log_must $TOUCH $file +log_must $MKDIR $dir + +log_note "Verify that '$LS [-dv]' can list file/directory ACEs of its acl." + +typeset -i ace_num=0 +for obj in $file $dir +do + typeset ls_str="" + if [[ -f $obj ]]; then + ls_str="$LS -v" + else + ls_str="$LS -dv" + fi + + for ace_type in "owner@" "group@" "everyone@" + do + $ls_str $obj | $GREP $ace_type > /dev/null 2>&1 + (( $? == 0 )) && (( ace_num += 1 )) + done + + (( ace_num < 1 )) && \ + log_fail "'$LS [-dv] fails to list file/directroy acls." +done + +log_note "Verify that '$LS [-dl] [-dv]' can output '+' to indicate " \ + "the acl existent." + +for obj in $file $dir +do + $CHMOD A0+$spec_ace $obj + + log_must eval "$LS -ld -vd $obj | $GREP "+" > /dev/null" + log_must plus_sign_check_v $obj + + log_must eval "$LS -ld -vd $obj | $GREP $spec_ace > /dev/null" + log_must plus_sign_check_l $obj +done + +log_pass "'$LS' command succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_mv_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_mv_001_pos.ksh new file mode 100644 index 00000000000..7718d1e2142 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_mv_001_pos.ksh @@ -0,0 +1,190 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_mv_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_mv_001_pos +# +# DESCRIPTION: +# Verify that '/bin/mv' supports ZFS ACL +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Set special ACE to the file and directory +# 3. Copy the file/directory within and across zfs file system +# 4. Verify that the ACL of file/directroy is not changed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + (( ${#cwd} != 0 )) && cd $cwd + [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/* + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1 + (( ${#mask} != 0 )) && log_must $UMASK $mask +} + +function testing_mv # +{ + typeset flag=$1 + set -A obj $2 $3 + typeset -i i=0 + typeset orig_acl="" + typeset orig_mode="" + typeset dst_acl="" + typeset dst_mode="" + + if [[ $flag == "f" ]]; then + while (( i < ${#obj[*]} )) + do + orig_acl="$(get_acl ${obj[i]})" + orig_mode="$(get_mode ${obj[i]})" + if (( i < 1 )); then + log_must $MV ${obj[i]} $dst_file + dst_acl=$(get_acl $dst_file) + dst_mode=$(get_mode $dst_file) + else + log_must $MV ${obj[i]} $TESTDIR1 + dst_acl=$(get_acl $TESTDIR1/${obj[i]}) + dst_mode=$(get_mode $TESTDIR1/${obj[i]}) + fi + + if [[ "$dst_mode" != "$orig_mode" ]] || \ + [[ "$dst_acl" != "$orig_acl" ]]; then + log_fail "$MV fails to keep the acl for file." + fi + + (( i = i + 1 )) + done + else + while (( i < ${#obj[*]} )) + do + typeset orig_nested_acl="" + typeset orig_nested_mode="" + typeset dst_nested_acl="" + typeset dst_nested_mode="" + + orig_acl=$(get_acl ${obj[i]}) + orig_mode=$(get_mode ${obj[i]}) + orig_nested_acl=$(get_acl ${obj[i]}/$nestedfile) + orig_nested_mode=$(get_mode ${obj[i]}/$nestedfile) + if (( i < 1 )); then + log_must $MV ${obj[i]} $dst_dir + dst_acl=$(get_acl $dst_dir) + dst_mode=$(get_mode $dst_dir) + dst_nested_acl=$(get_acl $dst_dir/$nestedfile) + dst_nested_mode=$(get_mode $dst_dir/$nestedfile) + else + log_must $MV ${obj[i]} $TESTDIR1 + dst_acl=$(get_acl $TESTDIR1/${obj[i]}) + dst_mode=$(get_mode $TESTDIR1/${obj[i]}) + dst_nested_acl=$(get_acl \ + $TESTDIR1/${obj[i]}/$nestedfile) + dst_nested_mode=$(get_mode \ + $TESTDIR1/${obj[i]}/$nestedfile) + fi + + if [[ "$orig_mode" != "$dst_mode" ]] || \ + [[ "$orig_acl" != "$dst_acl" ]] || \ + [[ "$dst_nested_mode" != "$orig_nested_mode" ]] || \ + [[ "$dst_nested_acl" != "$orig_nested_acl" ]]; then + log_fail "$MV fails to recursively keep the acl for " \ + "directory." + fi + + (( i = i + 1 )) + done + fi +} + +log_assert "Verify that '$MV' supports ZFS ACLs." +log_onexit cleanup + +test_requires ZFS_ACL + +spec_ace="everyone@:execute:allow" +set -A orig_file "origfile1.${TESTCASE_ID}" "origfile2.${TESTCASE_ID}" +set -A orig_dir "origdir1.${TESTCASE_ID}" "origdir2.${TESTCASE_ID}" +nestedfile="nestedfile.${TESTCASE_ID}" +dst_file=dstfile.${TESTCASE_ID} +dst_dir=dstdir.${TESTCASE_ID} +cwd=$PWD +mask=`$UMASK` +$UMASK 0022 + +# +# This assertion should only test 'mv' within the same filesystem +# +TESTDIR1=$TESTDIR/testdir1${TESTCASE_ID} + +[[ ! -d $TESTDIR1 ]] && \ + log_must $MKDIR -p $TESTDIR1 + +log_note "Create files and directories and set special ace on them for testing. " +cd $TESTDIR +typeset -i i=0 +while (( i < ${#orig_file[*]} )) +do + log_must $TOUCH ${orig_file[i]} + log_must $CHMOD A0+$spec_ace ${orig_file[i]} + + (( i = i + 1 )) +done +i=0 +while (( i < ${#orig_dir[*]} )) +do + log_must $MKDIR ${orig_dir[i]} + log_must $TOUCH ${orig_dir[i]}/$nestedfile + + for obj in ${orig_dir[i]} ${orig_dir[i]}/$nestedfile; do + log_must $CHMOD A0+$spec_ace $obj + done + + (( i = i + 1 )) +done + +testing_mv "f" ${orig_file[0]} ${orig_file[1]} +testing_mv "d" ${orig_dir[0]} ${orig_dir[1]} + +log_pass "'$MV' succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_tar_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_tar_001_pos.ksh new file mode 100644 index 00000000000..6916253d26f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_tar_001_pos.ksh @@ -0,0 +1,124 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_tar_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_tar_001_pos +# +# DESCRIPTION: +# Verify that '$TAR' command with -p option supports to archive ZFS ACLs +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Add new ACE in ACL of file and directory +# 3. Use $TAR to archive file and directory +# 4. Extract the archive file +# 5. Verify that the restored ACLs of file and directory identify +# with the origional ones. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + fi + + (( ${#cwd} != 0 )) && cd $cwd + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1 + [[ -d $TESTDIR/ ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Verify that '$TAR' command supports to archive ZFS ACLs." +log_onexit cleanup + +test_requires ZFS_ACL + +set -A ops " A+everyone@:execute:allow" "a-x" "777" + +TARFILE=tarfile.${TESTCASE_ID}.tar +file=$TESTFILE0 +dir=dir.${TESTCASE_ID} +cwd=$PWD + +log_note "Create second zfs file system to restore the tar archive." +log_must $ZFS create $TESTPOOL/$TESTFS1 +[[ ! -d $TESTDIR1 ]] && \ + log_must $MKDIR -p $TESTDIR1 +log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 + +log_note "Create a file: $file, and directory: $dir, in zfs filesystem. " +cd $TESTDIR +log_must $TOUCH $file +log_must $MKDIR $dir + +typeset -i i=0 +while (( i < ${#ops[*]} )) +do + log_note "Change the ACLs of file and directory with " \ + "'$CHMOD ${ops[i]}'." + cd $TESTDIR + for obj in $file $dir; do + log_must $CHMOD ${ops[i]} $obj + done + log_note "Archive the file and directory." + log_must $TAR cpf $TARFILE $file $dir + + log_note "Restore the tar archive." + log_must $MV $TARFILE $TESTDIR1 + cd $TESTDIR1 + log_must $TAR xpf $TARFILE + + log_note "Verify the ACLs of restored file/directory have no changes." + for obj in $file $dir; do + log_must compare_modes $TESTDIR/$obj $TESTDIR1/$obj + log_must compare_acls $TESTDIR/$obj $TESTDIR1/$obj + done + + log_must $RM -rf $TESTDIR1/* + + (( i = i + 1 )) +done + +log_pass "'$TAR' command succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_tar_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_tar_002_pos.ksh new file mode 100644 index 00000000000..8a5c95ce09f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/nontrivial/zfs_acl_tar_002_pos.ksh @@ -0,0 +1,131 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_tar_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_acl_tar_002_pos +# +# DESCRIPTION: +# Verify that '$TAR' command with -p@ option supports to archive ZFS ACLs +# & xattrs +# +# STRATEGY: +# 1. Create file and directory in zfs filesystem +# 2. Add new ACE in ACL of file and directory +# 3. Create xattr of the file and directory +# 4. Use $TAR cf@ to archive file and directory +# 5. Use $TAR xf@ to extract the archive file +# 6. Verify that the restored ACLs & xttrs of file and directory identify +# with the origional ones. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-12-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + fi + + (( ${#cwd} != 0 )) && cd $cwd + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1 + [[ -d $TESTDIR/ ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Verify that '$TAR' command supports to archive ZFS ACLs & xattrs." +log_onexit cleanup + +test_requires RUNAT ZFS_ACL ZFS_XATTR + +set -A ops " A+everyone@:execute:allow" "a-x" "777" +MYTESTFILE=$STF_SUITE/include/default.cfg + +TARFILE=tarfile.${TESTCASE_ID}.tar +cwd=$PWD + +log_note "Create second zfs file system to restore the tar archive." +log_must $ZFS create $TESTPOOL/$TESTFS1 +[[ ! -d $TESTDIR1 ]] && \ + log_must $MKDIR -p $TESTDIR1 +log_must $ZFS set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1 + +log_note "Create a file: $testfile, and directory: $testdir, in zfs filesystem. " \ + "And prepare for there xattr files." + +for user in root $ZFS_ACL_STAFF1; do + # Set the current user + log_must set_cur_usr $user + + # Create source object and target directroy + cd $TESTDIR + log_must usr_exec $TOUCH $testfile + log_must usr_exec $MKDIR $testdir + + log_must usr_exec $RUNAT $testfile $CP $MYTESTFILE attr.0 + log_must usr_exec $RUNAT $testdir $CP $MYTESTFILE attr.0 + + # Add the new ACE on the head. + log_note "Change the ACLs of file and directory with " \ + "'$CHMOD ${ops[0]}'." + log_must usr_exec $CHMOD ${ops[0]} $testfile + log_must usr_exec $CHMOD ${ops[0]} $testdir + + log_note "Archive the file and directory." + log_must $TAR cpf@ $TARFILE ${testfile#$TESTDIR/} ${testdir#$TESTDIR/} + + log_note "Restore the tar archive." + cd $TESTDIR1 + log_must $TAR xpf@ $TESTDIR/$TARFILE + + log_note "Verify the ACLs of restored file/directory have no changes." + for obj in $testfile $testdir; do + log_must compare_modes $obj $TESTDIR1/${obj##*/} + log_must compare_acls $obj $TESTDIR1/${obj##*/} + log_must compare_xattrs $obj $TESTDIR1/${obj##*/} + done + + log_must $RM -rf $TESTDIR/* $TESTDIR1/* +done + +log_pass "'$TAR' command succeeds to support ZFS ACLs." diff --git a/tests/sys/cddl/zfs/tests/acl/setup.ksh b/tests/sys/cddl/zfs/tests/acl/setup.ksh new file mode 100644 index 00000000000..db7041d0325 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/setup.ksh @@ -0,0 +1,66 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/acl/acl_common.kshlib + + +# check svc:/network/nis/client:default state +# disable it if the state is ON +# and the state will be restored during cleanup.ksh +if [[ `$UNAME -s` != "FreeBSD" ]]; then + log_must $RM -f $NISSTAFILE + if [[ "ON" == $($SVCS -H -o sta svc:/network/nis/client:default) ]]; then + log_must $SVCADM disable -t svc:/network/nis/client:default + log_must $TOUCH $NISSTAFILE + fi +fi + +cleanup_user_group + +# Add wheel group user +log_must add_user wheel $ZFS_ACL_ADMIN + +# Create staff group and add two user to it +log_must add_group $ZFS_ACL_STAFF_GROUP +log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF1 +log_must add_user $ZFS_ACL_STAFF_GROUP $ZFS_ACL_STAFF2 + +# Create other group and add two user to it +log_must add_group $ZFS_ACL_OTHER_GROUP +log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER1 +log_must add_user $ZFS_ACL_OTHER_GROUP $ZFS_ACL_OTHER2 + +DISK=${DISKS%% *} +default_setup_noexit $DISK +log_must $CHMOD 777 $TESTDIR + +log_pass diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/Makefile b/tests/sys/cddl/zfs/tests/acl/trivial/Makefile new file mode 100644 index 00000000000..dc85ac3f7c6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/Makefile @@ -0,0 +1,33 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/acl/trivial +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= zfs_acl_chmod_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_compress_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_cp_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_cp_002_neg.ksh +${PACKAGE}FILES+= zfs_acl_cp_003_neg.ksh +${PACKAGE}FILES+= zfs_acl_find_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_find_002_neg.ksh +${PACKAGE}FILES+= zfs_acl_ls_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_ls_002_neg.ksh +${PACKAGE}FILES+= zfs_acl_mv_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_pack_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_pax_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_pax_002_pos.ksh +${PACKAGE}FILES+= zfs_acl_pax_003_pos.ksh +${PACKAGE}FILES+= zfs_acl_pax_004_pos.ksh +${PACKAGE}FILES+= zfs_acl_pax_005_pos.ksh +${PACKAGE}FILES+= zfs_acl_pax_006_pos.ksh +${PACKAGE}FILES+= zfs_acl_tar_001_pos.ksh +${PACKAGE}FILES+= zfs_acl_tar_002_neg.ksh + +ATF_TESTS_KSH93+= trivial_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +.include diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/trivial_test.sh b/tests/sys/cddl/zfs/tests/acl/trivial/trivial_test.sh new file mode 100755 index 00000000000..f979cc30c14 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/trivial_test.sh @@ -0,0 +1,516 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_acl_chmod_001_pos cleanup +zfs_acl_chmod_001_pos_head() +{ + atf_set "descr" "Verify chmod permission settings on files and directories" +} +zfs_acl_chmod_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_chmod_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_chmod_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_compress_001_pos cleanup +zfs_acl_compress_001_pos_head() +{ + atf_set "descr" "Compress will keep file attribute intact after the file iscompressed and uncompressed" + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_compress_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_compress_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_compress_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_cp_001_pos cleanup +zfs_acl_cp_001_pos_head() +{ + atf_set "descr" "Verifies that cp will include file attribute when using the -@ flag" + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_cp_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_cp_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_cp_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_cp_002_neg cleanup +zfs_acl_cp_002_neg_head() +{ + atf_set "descr" "Verifies that cp will not include file attribute when the -@ flagis not present." + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_cp_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_cp_002_neg.ksh || atf_fail "Testcase failed" +} +zfs_acl_cp_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_cp_003_neg cleanup +zfs_acl_cp_003_neg_head() +{ + atf_set "descr" "Verifies that cp won't be able to include file attribute whenattribute is unreadable (except root)" + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" runat +} +zfs_acl_cp_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_cp_003_neg.ksh || atf_fail "Testcase failed" +} +zfs_acl_cp_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_find_001_pos cleanup +zfs_acl_find_001_pos_head() +{ + atf_set "descr" "Verifies ability to find files with attribute with-xattr flag and using '-exec runat ls'" + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_find_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_find_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_find_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_find_002_neg cleanup +zfs_acl_find_002_neg_head() +{ + atf_set "descr" "verifies -xattr doesn't include files withoutattribute and using '-exec runat ls'" + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" runat +} +zfs_acl_find_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_find_002_neg.ksh || atf_fail "Testcase failed" +} +zfs_acl_find_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_ls_001_pos cleanup +zfs_acl_ls_001_pos_head() +{ + atf_set "descr" "Verifies that ls displays @ in the file permissions using ls -@for files with attribute." + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_ls_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_ls_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_ls_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_ls_002_neg cleanup +zfs_acl_ls_002_neg_head() +{ + atf_set "descr" "Verifies that ls doesn't display @ in the filepermissions using ls -@ for files without attribute." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" runat +} +zfs_acl_ls_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_ls_002_neg.ksh || atf_fail "Testcase failed" +} +zfs_acl_ls_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_mv_001_pos cleanup +zfs_acl_mv_001_pos_head() +{ + atf_set "descr" "Verifies that mv will include file attribute." + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_mv_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_mv_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_mv_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_pack_001_pos cleanup +zfs_acl_pack_001_pos_head() +{ + atf_set "descr" "Verifies that pack will keep file attribute intact after the fileis packed and unpacked" + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" unpack pack +} +zfs_acl_pack_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_pack_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_pack_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_pax_001_pos cleanup +zfs_acl_pax_001_pos_head() +{ + atf_set "descr" "Verify include attribute in pax archive and restore with paxshould succeed." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" pax +} +zfs_acl_pax_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_pax_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_pax_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_pax_002_pos cleanup +zfs_acl_pax_002_pos_head() +{ + atf_set "descr" "Verify include attribute in pax archive and restore with tarshould succeed." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" pax +} +zfs_acl_pax_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_pax_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_pax_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_pax_003_pos cleanup +zfs_acl_pax_003_pos_head() +{ + atf_set "descr" "Verify include attribute in pax archive and restore with cpioshould succeed." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" pax +} +zfs_acl_pax_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_pax_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_pax_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_pax_004_pos cleanup +zfs_acl_pax_004_pos_head() +{ + atf_set "descr" "Verify files include attribute in pax archive and restore with paxshould succeed." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" pax +} +zfs_acl_pax_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_pax_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_pax_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_pax_005_pos cleanup +zfs_acl_pax_005_pos_head() +{ + atf_set "descr" "Verify files include attribute in cpio archive and restore withcpio should succeed." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" pax +} +zfs_acl_pax_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_pax_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_pax_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_pax_006_pos cleanup +zfs_acl_pax_006_pos_head() +{ + atf_set "descr" "Verify files include attribute in tar archive and restore withtar should succeed." + atf_set "require.config" zfs_acl zfs_xattr + atf_set "require.progs" pax +} +zfs_acl_pax_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_pax_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_pax_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_tar_001_pos cleanup +zfs_acl_tar_001_pos_head() +{ + atf_set "descr" "Verifies that tar will include file attribute when @ flag ispresent." + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_tar_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_tar_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_acl_tar_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_acl_tar_002_neg cleanup +zfs_acl_tar_002_neg_head() +{ + atf_set "descr" "Verifies that tar will not include files attribute when @ flag isnot present" + atf_set "require.config" zfs_acl zfs_xattr +} +zfs_acl_tar_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/../setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_acl_tar_002_neg.ksh || atf_fail "Testcase failed" +} +zfs_acl_tar_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/../acl.cfg + + ksh93 $(atf_get_srcdir)/../cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_acl_chmod_001_pos + atf_add_test_case zfs_acl_compress_001_pos + atf_add_test_case zfs_acl_cp_001_pos + atf_add_test_case zfs_acl_cp_002_neg + atf_add_test_case zfs_acl_cp_003_neg + atf_add_test_case zfs_acl_find_001_pos + atf_add_test_case zfs_acl_find_002_neg + atf_add_test_case zfs_acl_ls_001_pos + atf_add_test_case zfs_acl_ls_002_neg + atf_add_test_case zfs_acl_mv_001_pos + atf_add_test_case zfs_acl_pack_001_pos + atf_add_test_case zfs_acl_pax_001_pos + atf_add_test_case zfs_acl_pax_002_pos + atf_add_test_case zfs_acl_pax_003_pos + atf_add_test_case zfs_acl_pax_004_pos + atf_add_test_case zfs_acl_pax_005_pos + atf_add_test_case zfs_acl_pax_006_pos + atf_add_test_case zfs_acl_tar_001_pos + atf_add_test_case zfs_acl_tar_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_chmod_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_chmod_001_pos.ksh new file mode 100644 index 00000000000..48ef92f5486 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_chmod_001_pos.ksh @@ -0,0 +1,151 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_chmod_001_pos.ksh 1.5 09/01/13 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_chmod_001_pos +# +# DESCRIPTION: +# Verify chmod permission settings on files and directories, as both root +# and non-root users. +# +# STRATEGY: +# 1. Loop root and $ZFS_ACL_STAFF1 as root and non-root users. +# 2. Create test file and directory in zfs filesystem. +# 3. Execute 'chmod' with specified options. +# 4. Check 'ls -l' output and compare with expect results. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# "init_map" "options" "expect_map" +set -A argv \ + "000" "a+rw" "rw-rw-rw-" "000" "a+rwx" "rwxrwxrwx" \ + "000" "u+xr" "r-x------" "000" "gu-xw" "---------" \ + "644" "a-r" "-w-------" "644" "augo-x" "rw-r--r--" \ + "644" "=x" "--x--x--x" "644" "u-rw" "---r--r--" \ + "644" "uo+x" "rwxr--r-x" "644" "ga-wr" "---------" \ + "777" "augo+x" "rwxrwxrwx" "777" "go-xr" "rwx-w--w-" \ + "777" "o-wx" "rwxrwxr--" "777" "ou-rx" "-w-rwx-w-" \ + "777" "a+rwx" "rwxrwxrwx" "777" "u=rw" "rw-rwxrwx" \ + "000" "123" "--x-w--wx" "000" "412" "r----x-w-" \ + "231" "562" "r-xrw--w-" "712" "000" "---------" \ + "777" "121" "--x-w---x" "123" "775" "rwxrwxr-x" + +log_assert " Verify chmod permission settings on files and directories" +log_onexit cleanup + +# +# Verify file or directory have correct map after chmod +# +# $1 file or directory +# +function test_chmod_mapping # +{ + typeset node=$1 + typeset -i i=0 + + while (( i < ${#argv[@]} )); do + usr_exec $CHMOD ${argv[i]} $node + if (($? != 0)); then + log_note "usr_exec $CHMOD ${argv[i]} $node" + return 1 + fi + + usr_exec $CHMOD ${argv[((i + 1))]} $node + if (($? != 0)); then + log_note "usr_exec $CHMOD ${argv[((i + 1))]} $node" + return 1 + fi + + typeset mode + mode=$(get_mode ${node}) + + if [[ $mode != "-${argv[((i + 2))]}"* && \ + $mode != "d${argv[((i + 2))]}"* ]] + then + log_fail "FAIL: '${argv[i]}' '${argv[((i + 1))]}' \ + '${argv[((i + 2))]}'" + fi + + (( i += 3 )) + done + + return 0 +} + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + # Test file + log_must usr_exec $TOUCH $testfile + log_must test_chmod_mapping $testfile + + if [ "$ZFS_ACL" != "" ] ; then + log_must $CHMOD A+user:$ZFS_ACL_STAFF2:write_acl:allow $testfile + fi + log_must set_cur_usr $ZFS_ACL_STAFF2 + + # Test directory + log_must usr_exec $MKDIR $testdir + log_must test_chmod_mapping $testdir + + if [ "$ZFS_ACL" != "" ] ; then + # Grant privileges of write_acl and retest the chmod commands. + acl="user:$ZFS_ACL_STAFF2:write_acl:allow" + log_must usr_exec $CHMOD A+${acl} $testfile + log_must usr_exec $CHMOD A+${acl} $testdir + + log_must set_cur_usr $ZFS_ACL_STAFF2 + log_must test_chmod_mapping $testfile + log_must test_chmod_mapping $testdir + fi + + log_must set_cur_usr $user + + log_must usr_exec $RM $testfile + log_must usr_exec $RM -rf $testdir +done + +log_pass "Setting permissions using 'chmod' completed successfully." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_compress_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_compress_001_pos.ksh new file mode 100644 index 00000000000..bae12eb9b19 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_compress_001_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_compress_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_compress_001_pos +# +# DESCRIPTION: +# The function verifies that compress will keep file attribute intact +# after the file is compressed and uncompressed. +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. Save all files and their attribute files cksum value, then compress +# all the files. +# 3. Move them to another directory B. +# 4. Uncompress them and calculate all the files and attribute files cksum +# 5. Verify all the cksum are identical +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Compress will keep file attribute intact after the file is " \ + "compressed and uncompressed" +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + log_must usr_exec $COMPRESS $INI_DIR/* + log_must usr_exec $MV $INI_DIR/* $TST_DIR + log_must usr_exec $UNCOMPRESS $TST_DIR/* + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "compress/uncompress test passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_001_pos.ksh new file mode 100644 index 00000000000..8bd0f21239b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_001_pos.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_cp_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_cp_001_pos +# +# DESCRIPTION: +# Verifies that cp will include file attribute when using the -@ flag +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. Save all files and their attribute files cksum value, then 'cp -@p' +# all the files to to another directory B. +# 3. Calculate all the cksum in directory B. +# 4. Verify all the cksum are identical +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that cp will include file attribute when using the -@ flag" +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + + initfiles=$($LS -R $INI_DIR/*) + typeset -i i=0 + while ((i < NUM_FILE)); do + f=$(getitem $i $initfiles) + + usr_exec $CP -@p $f $TST_DIR + + ((i += 1)) + done + + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "'cp -@' include file attribute passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_002_neg.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_002_neg.ksh new file mode 100644 index 00000000000..37170f2ecc9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_002_neg.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_cp_002_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_cp_002_neg +# +# DESCRIPTION: +# Verifies that cp will not include file attribute when the -@ flag is not +# present. +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. Implement cp to files without '-@' +# 3. Verify attribute files will not include file attribute +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that cp will not include file attribute when the -@ flag "\ + "is not present." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + initfiles=$($LS -R $INI_DIR/*) + typeset -i i=0 + while (( i < NUM_FILE )); do + typeset f=$(getitem $i $initfiles) + usr_exec $CP $f $TST_DIR + + testfiles=$($LS -R $TST_DIR/*) + tf=$(getitem $i $testfiles) + ls_attr=$($LS -@ $tf | $AWK '{print substr($1, 11, 1)}') + if [[ $ls_attr == "@" ]]; then + log_fail "cp of attribute should fail without " \ + "-@ or -p option" + fi + + (( i += 1 )) + done + + log_must cleanup +done + +log_pass "'cp' won't include file attribute passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_003_neg.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_003_neg.ksh new file mode 100644 index 00000000000..8bf36b58b5a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_cp_003_neg.ksh @@ -0,0 +1,138 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_cp_003_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_cp_003_neg +# +# DESCRIPTION: +# Verifies that cp will not be able to include file attribute when +# attribute is unreadable (unless the user is root) +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. chmod all files'the attribute files to '000'. +# 3. Implement 'cp -@p' to files. +# 4. Verify attribute files are not existing for non-root user. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that cp won't be able to include file attribute when " \ + "attribute is unreadable (except root)" +log_onexit cleanup + +test_requires RUNAT ZFS_ACL ZFS_XATTR + +function test_unreadable_attr +{ + typeset initfiles=$($LS -R $INI_DIR/*) + + typeset -i i=0 + while (( i < NUM_FILE )); do + typeset f=$(getitem $i $initfiles) + typeset -i j=0 + while (( j < NUM_ATTR )); do + # chmod all the attribute files to '000'. + usr_exec $RUNAT $f $CHMOD 000 attribute.$j + + (( j += 1 )) + done + + # + # Implement 'cp -@p' to the file whose attribute files + # models are '000'. + # + usr_exec $CP -@p $f $TST_DIR > /dev/null 2>&1 + + typeset testfiles=$($LS -R $TST_DIR/*) + typeset tf=$(getitem $i $testfiles) + typeset ls_attr=$(usr_exec $LS -@ $tf | \ + $AWK '{print substr($1, 11, 1)}') + + case $ZFS_ACL_CUR_USER in + root) + case $ls_attr in + @) + log_note "SUCCESS: root enable to cp attribute"\ + "when attribute files is unreadable" + break ;; + *) + log_fail "root should enable to cp attribute " \ + "when attribute files is unreadable" + break ;; + esac + ;; + $ZFS_ACL_STAFF1) + case $ls_attr in + @) + log_fail "non-root shouldn't enable to cp " \ + "attribute when attribute files is " \ + "unreadable." + break ;; + *) + log_note "SUCCESS: non-root doesn't enable to "\ + "cp attribute when attribute files is "\ + "unreadable." + break ;; + esac + ;; + *) + esac + + + (( i += 1 )) + done +} + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + test_unreadable_attr + + log_must cleanup +done + +log_pass "'cp -@p' won't include file attribute passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_find_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_find_001_pos.ksh new file mode 100644 index 00000000000..74fd5e93904 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_find_001_pos.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_find_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_find_001_pos +# +# DESCRIPTION: +# Verifies ability to find files with attribute with -xattr flag and using +# "-exec runat ls". +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. Verify all the specified files can be found with '-xattr', +# 3. Verify all the attribute files can be found with '-exec runat ls' +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies ability to find files with attribute with" \ + "-xattr flag and using '-exec runat ls'" +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + initfiles=$($LS -R $INI_DIR/*) + + typeset -i i=0 + while (( i < NUM_FILE )); do + f=$(getitem $i $initfiles) + ff=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \ + -xattr -print) + if [[ $ff != $f ]]; then + log_fail "find file containing attribute fail." + else + log_note "find $f by '-xattr'." + fi + + typeset -i j=0 + while (( j < NUM_ATTR )); do + typeset af=attribute.$j + fa=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \ + -xattr -exec runat {} ls $af \\\;) + if [[ $fa != $af ]]; then + log_fail "find file attribute fail" + fi + (( j += 1 )) + done + (( i += 1 )) + log_note "find all attribute files of $f" + done + + log_must cleanup +done + +log_pass "find files with -xattr passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_find_002_neg.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_find_002_neg.ksh new file mode 100644 index 00000000000..ad67ddc0812 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_find_002_neg.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_find_002_neg.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_find_002_neg +# +# DESCRIPTION: +# Verifies ability to find files with attribute with -xattr flag and using +# "-exec runat ls". +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. Delete all the attribute files. +# 2. Verify all the specified files can not be found with '-xattr', +# 3. Verify all the attribute files can not be found with '-exec runat ls' +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "verifies -xattr doesn't include files without " \ + "attribute and using '-exec runat ls'" +log_onexit cleanup + +test_requires RUNAT ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + initfiles=$($LS -R $INI_DIR/*) + typeset -i i=0 + while (( i < NUM_FILE )); do + f=$(getitem $i $initfiles) + usr_exec $RUNAT $f $RM attribute* + (( i += 1 )) + done + + i=0 + while (( i < NUM_FILE )); do + f=$(getitem $i $initfiles) + ff=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \ + -xattr -print) + if [[ $ff == $f ]]; then + log_fail "find not containing attribute should fail." + fi + + typeset -i j=0 + while (( j < NUM_ATTR )); do + fa=$(usr_exec $FIND $INI_DIR -type f -name ${f##*/} \ + -xattr -exec $RUNAT {} $LS attribute.$j \\\;) + if [[ $fa == attribute.$j ]]; then + log_fail "find file attribute should fail." + fi + (( j += 1 )) + done + log_note "Failed to find $f and its attribute file as expected." + + (( i += 1 )) + done + + log_must cleanup +done + +log_pass "find files which have no attrabute files with -xattr passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_ls_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_ls_001_pos.ksh new file mode 100644 index 00000000000..18dbf490703 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_ls_001_pos.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_ls_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_ls_001_pos +# +# DESCRIPTION: +# Verifies that ls displays @ in the file permissions using ls -@ +# for files with attribute. +# +# STRATEGY: +# 1. Create files with attribute files in directory A. +# 2. Verify 'ls -l' can display @ in file permissions. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that ls displays @ in the file permissions using ls -@ " \ + "for files with attribute." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + initfiles=$($LS -R $INI_DIR/*) + typeset -i i=0 + while (( i < NUM_FILE )); do + f=$(getitem $i $initfiles) + ls_attr=$(usr_exec $LS -@ $f | $AWK '{print substr($1, 11, 1)}') + if [[ $ls_attr != "@" ]]; then + log_fail "ls -@ $f with attribute should success." + else + log_note "ls -@ $f with attribute success." + fi + + (( i += 1 )) + done + + log_must cleanup +done + +log_pass "ls display @ in file permission passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_ls_002_neg.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_ls_002_neg.ksh new file mode 100644 index 00000000000..d99f60fa580 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_ls_002_neg.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_ls_002_neg.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_ls_002_neg +# +# DESCRIPTION: +# Verifies that ls doesn't display @ in the file permissions using ls -@ +# for files without attribute. +# +# STRATEGY: +# 1. Create files with attribute files in directory A. +# 2. Removed all attribute files. +# 3. Verify 'ls -l' can't display @ in file permission. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that ls doesn't display @ in the file " \ + "permissions using ls -@ for files without attribute." +log_onexit cleanup + +test_requires RUNAT ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + initfiles=$($LS -R $INI_DIR/*) + typeset -i i=0 + while (( i < NUM_FILE )); do + f=$(getitem $i $initfiles) + log_must usr_exec $RUNAT $f $RM attribute* + + ls_attr=$(usr_exec $LS -l $f | $AWK '{print substr($1, 11, 1)}') + if [[ $ls_attr == "@" ]]; then + log_fail "ls with attribute shouldn't success." + fi + + (( i += 1 )) + done + + log_must cleanup +done + +log_pass "ls doesn't display @ in file permissions passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_mv_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_mv_001_pos.ksh new file mode 100644 index 00000000000..b221fe0d1b3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_mv_001_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_mv_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_mv_001_pos +# +# DESCRIPTION: +# Verifies that mv will include file attribute. +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. Save all files and their attribute files cksum value +# 3. Move them to another directory B. +# 4. Calculate all the files and attribute files cksum +# 5. Verify all the cksum are identical +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that mv will include file attribute." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + log_must usr_exec $MV $INI_DIR/* $TST_DIR + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "mv file include attribute passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pack_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pack_001_pos.ksh new file mode 100644 index 00000000000..d2eeef3a179 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pack_001_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_pack_001_pos.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_pack_001_pos +# +# DESCRIPTION: +# Verifies that pack will keep file attribute intact afterthe file is +# packed and unpacked. +# +# STRATEGY: +# 1. In directory A, create several files and add attribute files for them +# 2. Save all files and their attribute files cksum value, then pack +# all the files. +# 3. Move them to another directory B. +# 4. Unpack them and calculate all the files and attribute files cksum +# 5. Verify all the cksum are identical +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that pack will keep file attribute intact after the file "\ + "is packed and unpacked" +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + log_must eval "usr_exec $PACK -f $INI_DIR/* > /dev/null 2>&1" + log_must usr_exec $MV $INI_DIR/* $TST_DIR + log_must eval "usr_exec $UNPACK $TST_DIR/* > /dev/null 2>&1" + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "pack/unpack test passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_001_pos.ksh new file mode 100644 index 00000000000..f14b6f97941 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_001_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_pax_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_pax_001_pos +# +# DESCRIPTION: +# Verify directories include attribute in pax archive and restore with pax +# should succeed. +# +# STRATEGY: +# 1. Use mktree create a set of directories in directory A. +# 2. Enter into directory A and record all directory information. +# 3. pax all the files to directory B. +# 4. Then pax the pax file to directory C. +# 5. Record all the directories informat in derectory C. +# 6. Verify the two records should be identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify include attribute in pax archive and restore with pax " \ + "should succeed." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + [[ ! -d $INI_DIR ]] && log_must usr_exec $MKDIR -m 777 -p $INI_DIR + log_must usr_exec $MKTREE -b $INI_DIR -l 6 -d 2 -f 2 + + # + # Enter into initial directory and record all directory information, + # then pax all the files to $TMP_DIR/files.pax. + # + [[ ! -d $TMP_DIR ]] && log_must usr_exec $MKDIR $TMP_DIR + initout=$TMP_DIR/initout.${TESTCASE_ID} + paxout=$TMP_DIR/files.pax + + cd $INI_DIR + log_must eval "record_cksum $INI_DIR $initout > /dev/null 2>&1" + log_must eval "usr_exec $PAX -w -@ -f $paxout * > /dev/null 2>&1" + + # + # Enter into test directory and pax $TMP_DIR/files.pax to current + # directory. Record all directory information and compare with initial + # directory record. + # + [[ ! -d $TST_DIR ]] && log_must usr_exec $MKDIR -m 777 $TST_DIR + testout=$TMP_DIR/testout.${TESTCASE_ID} + cd $TST_DIR + log_must eval "usr_exec $PAX -r -@ -f $paxout > /dev/null 2>&1" + log_must eval "record_cksum $TST_DIR $testout > /dev/null 2>&1" + + log_must usr_exec $DIFF $initout $testout + + log_must cleanup +done + +log_pass "Directories pax archive and restre with pax passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_002_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_002_pos.ksh new file mode 100644 index 00000000000..0ed59d1c98b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_002_pos.ksh @@ -0,0 +1,103 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_pax_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_pax_002_pos +# +# DESCRIPTION: +# Verify directories which include attribute in pax archive and restore +# with tar should succeed. +# +# STRATEGY: +# 1. Use mktree create a set of directories in directory A. +# 2. Enter into directory A and record all directory information. +# 3. pax all the files to directory B. +# 4. Then tar the pax file to directory C. +# 5. Record all the directories informat in derectory C. +# 6. Verify the two records should be identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify include attribute in pax archive and restore with tar " \ + "should succeed." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + [[ ! -d $INI_DIR ]] && log_must usr_exec $MKDIR -m 777 $INI_DIR + log_must usr_exec $MKTREE -b $INI_DIR -l 6 -d 2 -f 2 + + # + # Enter into initial directory and record all directory information, + # then pax all the files to $TMP_DIR/files.pax. + # + [[ ! -d $TMP_DIR ]] && log_must usr_exec $MKDIR -m 777 $TMP_DIR + initout=$TMP_DIR/initout.${TESTCASE_ID} + paxout=$TMP_DIR/files.tar + cd $INI_DIR + log_must eval "record_cksum $INI_DIR $initout > /dev/null 2>&1" + log_must eval "usr_exec $PAX -w -x ustar -@ -f $paxout *>/dev/null 2>&1" + + # + # Enter into test directory and tar $TMP_DIR/files.pax to current + # directory. Record all directory information and compare with initial + # directory record. + # + [[ ! -d $TST_DIR ]] && log_must usr_exec $MKDIR -m 777 $TST_DIR + testout=$TMP_DIR/testout.${TESTCASE_ID} + cd $TST_DIR + log_must eval "usr_exec $TAR xpf@ $paxout > /dev/null 2>&1" + log_must eval "record_cksum $TST_DIR $testout > /dev/null 2>&1" + + log_must usr_exec $DIFF $initout $testout + + log_must cleanup +done + +log_pass "Directories pax archive and restore with pax passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_003_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_003_pos.ksh new file mode 100644 index 00000000000..9f37d294b03 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_003_pos.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_pax_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_pax_003_pos +# +# DESCRIPTION: +# Verify directories which include attribute in pax archive and restore +# with cpio should succeed. +# +# STRATEGY: +# 1. Create several files in directory A. +# 2. Enter into directory A and record all directory cksum. +# 3. pax all the files to directory B. +# 4. Then cpio the pax file to directory C. +# 5. Record all the files cksum in derectory C. +# 6. Verify the two records should be identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify include attribute in pax archive and restore with cpio " \ + "should succeed." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + [[ ! -d $INI_DIR ]] && log_must usr_exec $MKDIR -m 777 -p $INI_DIR + log_must usr_exec $MKTREE -b $INI_DIR -l 6 -d 2 -f 2 + + initout=$TMP_DIR/initout.${TESTCASE_ID} + paxout=$TMP_DIR/files.cpio + cd $INI_DIR + log_must eval "record_cksum $INI_DIR $initout > /dev/null 2>&1" + log_must eval "usr_exec $PAX -w -x cpio -@ -f $paxout * >/dev/null 2>&1" + + # + # Enter into test directory and cpio $TMP_DIR/files.pax to current + # directory. Record all directory information and compare with initial + # directory record. + # + [[ ! -d $TST_DIR ]] && log_must usr_exec $MKDIR -m 777 $TST_DIR + testout=$TMP_DIR/testout.${TESTCASE_ID} + cd $TST_DIR + log_must eval "usr_exec $CPIO -ivd@ < $paxout" > /dev/null 2>&1 + log_must eval "record_cksum $TST_DIR $testout > /dev/null 2>&1" + + log_must usr_exec $DIFF $initout $testout + + log_must cleanup +done + +log_pass "Directories pax archive and restore with cpio passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_004_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_004_pos.ksh new file mode 100644 index 00000000000..a7527b41d04 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_004_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_pax_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_pax_004_pos +# +# DESCRIPTION: +# Verify files include attribute in pax archive and restore with pax +# should succeed. +# +# STRATEGY: +# 1. Create several files which contains contribute files in directory A. +# 2. Enter into directory A and record all files cksum. +# 3. pax all the files to directory B. +# 4. Then pax the pax file to directory C. +# 5. Record all the files cksum in derectory C. +# 6. Verify the two records should be identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify files include attribute in pax archive and restore with pax " \ + "should succeed." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + # + # Enter into initial directory and record all files cksum, + # then pax all the files to $TMP_DIR/files.pax. + # + paxout=$TMP_DIR/files.pax + cd $INI_DIR + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + log_must eval "usr_exec $PAX -w -@ -f $paxout * > /dev/null 2>&1" + + # + # Enter into test directory and pax $TMP_DIR/files.pax to current + # directory. Record all directory information and compare with initial + # directory record. + # + cd $TST_DIR + log_must eval "usr_exec $PAX -r -@ -f $paxout > /dev/null 2>&1" + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "Files pax archive and restre with pax passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_005_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_005_pos.ksh new file mode 100644 index 00000000000..53bc024c451 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_005_pos.ksh @@ -0,0 +1,111 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_pax_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_pax_005_pos +# +# DESCRIPTION: +# Verify files include attribute in cpio archive and restore with cpio +# should succeed. +# +# STRATEGY: +# 1. Create several files which contains contribute files in directory A. +# 2. Enter into directory A and record all files cksum. +# 3. pax all the files to directory B. +# 4. Then pax the pax file to directory C. +# 5. Record all the files cksum in derectory C. +# 6. Verify the two records should be identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify files include attribute in cpio archive and restore with " \ + "cpio should succeed." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + # + # Enter into initial directory and record all files cksum, + # then pax all the files to $TMP_DIR/files.pax. + # + paxout=$TMP_DIR/files.cpio + cd $INI_DIR + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + log_must eval "usr_exec $PAX -w -x cpio -@ -f $paxout * >/dev/null 2>&1" + + # + # Enter into test directory and pax $TMP_DIR/files.cpio to current + # directory. Record all directory information and compare with initial + # directory record. + # + cd $TST_DIR + log_must eval "usr_exec $PAX -r -x cpio -@ -f $paxout > /dev/null 2>&1" + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must usr_exec $RM -rf * + log_must eval "usr_exec $CPIO -iv@ < $paxout > /dev/null 2>&1" + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "Files 'pax cpio' archive and restre with 'pax cpio' passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_006_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_006_pos.ksh new file mode 100644 index 00000000000..a59e7858312 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_pax_006_pos.ksh @@ -0,0 +1,111 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_pax_006_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_pax_006_pos +# +# DESCRIPTION: +# Verify files include attribute in tar archive and restore with tar +# should succeed. +# +# STRATEGY: +# 1. Create several files which contains contribute files in directory A. +# 2. Enter into directory A and record all files cksum. +# 3. 'pax ustar' all the files to directory B. +# 4. Then 'pax ustar' the pax file to directory C. +# 5. Record all the files cksum in derectory C. +# 6. Verify the two records should be identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify files include attribute in tar archive and restore with " \ + "tar should succeed." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + # + # Enter into initial directory and record all files cksum, + # then pax all the files to $TMP_DIR/files.pax. + # + paxout=$TMP_DIR/files.tar + cd $INI_DIR + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + log_must eval "usr_exec $PAX -w -x ustar -@ -f $paxout *>/dev/null 2>&1" + + # + # Enter into test directory and pax $TMP_DIR/files.tar to current + # directory. Record all directory information and compare with initial + # directory record. + # + cd $TST_DIR + log_must eval "usr_exec $PAX -r -x ustar -@ -f $paxout > /dev/null 2>&1" + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must usr_exec $RM -rf * + log_must usr_exec $TAR xf@ $paxout + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_must compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "Files 'pax tar' archive and restre with 'pax tar' passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_tar_001_pos.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_tar_001_pos.ksh new file mode 100644 index 00000000000..60f344e7286 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_tar_001_pos.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_tar_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_tar_001_pos +# +# DESCRIPTION: +# Verifies that tar will include file attribute when @ flag is present. +# +# STRATEGY: +# 1. Use mktree create a set of directories in directory A. +# 2. Enter into directory A and record all directory information. +# 3. tar all the files to directory B. +# 4. Then tar the tar file to directory C. +# 5. Record all the directories informat in derectory C. +# 6. Verify the two records should be identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that tar will include file attribute when @ flag is " \ + "present." +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + [[ ! -d $INI_DIR ]] && $MKDIR -m 777 -p $INI_DIR + log_must usr_exec $MKTREE -b $INI_DIR -l 5 -d 2 -f 2 + + # + # Enter into initial directory and record all directory information, + # then tar all the files to $TMP_DIR/files.tar. + # + [[ ! -d $TMP_DIR ]] && usr_exec $MKDIR $TMP_DIR + initout=$TMP_DIR/initout.${TESTCASE_ID} + tarout=$TMP_DIR/files.tar + cd $INI_DIR + log_must record_cksum $INI_DIR $initout + log_must usr_exec $TAR cpf@ $tarout * + + # + # Enter into test directory and tar $TMP_DIR/files.tar to current + # directory. Record all directory information and compare with initial + # directory record. + # + [[ ! -d $TST_DIR ]] && $MKDIR -m 777 $TST_DIR + testout=$TMP_DIR/testout.${TESTCASE_ID} + cd $TST_DIR + log_must usr_exec $TAR xpf@ $tarout + log_must record_cksum $TST_DIR $testout + + log_must usr_exec $DIFF $initout $testout + + log_must cleanup +done + +log_pass "Verify tar with @ passed." diff --git a/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_tar_002_neg.ksh b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_tar_002_neg.ksh new file mode 100644 index 00000000000..7dc96448c81 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/acl/trivial/zfs_acl_tar_002_neg.ksh @@ -0,0 +1,118 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_acl_tar_002_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/acl/acl_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_acl_tar_002_neg +# +# DESCRIPTION: +# Verifies that tar will not include files attribute when @ flag is not +# present. +# +# STRATEGY: +# 1. Create several files with attribute files. +# 2. Enter into directory A and record all files cksum +# 3. tar all the files to directory B. +# 4. Then tar the tar file to directory C. +# 5. Record all the files cksum in derectory C. +# 6. Verify the two records should be not identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verifies that tar will not include files attribute when @ flag is "\ + "not present" +log_onexit cleanup + +test_requires ZFS_ACL ZFS_XATTR + +set -A BEFORE_FCKSUM +set -A BEFORE_ACKSUM +set -A AFTER_FCKSUM +set -A AFTER_ACKSUM + +for user in root $ZFS_ACL_STAFF1; do + log_must set_cur_usr $user + + log_must create_files $TESTDIR + + # + # Enter into initial directory and record all directory information, + # then tar all the files to $TMP_DIR/files.tar. + # + tarout=$TMP_DIR/files.tar + cd $INI_DIR + log_must cksum_files $INI_DIR BEFORE_FCKSUM BEFORE_ACKSUM + log_must usr_exec $TAR cpf $tarout * + + # + # Enter into test directory and tar $TMP_DIR/files.tar to current + # directory. Record all directory information and compare with initial + # directory record. + # + cd $TST_DIR + log_must usr_exec $CP $tarout $TST_DIR + log_must usr_exec $TAR xpf $tarout + + testfiles=$($LS -R $TST_DIR/*) + typeset -i i=0 + while (( i < NUM_FILE )); do + f=$(getitem $i $testfiles) + ls_attr=$($LS -@ $f | $AWK '{print substr($1, 11, 1)}') + if [[ $ls_attr == "@" ]]; then + log_fail "extraction of attribute successful w/ -@ flag" + fi + + (( i += 1 )) + done + + log_must cksum_files $TST_DIR AFTER_FCKSUM AFTER_ACKSUM + + log_must compare_cksum BEFORE_FCKSUM AFTER_FCKSUM + log_mustnot compare_cksum BEFORE_ACKSUM AFTER_ACKSUM + + log_must cleanup +done + +log_pass "Verify tar without @ passed." diff --git a/tests/sys/cddl/zfs/tests/atime/Makefile b/tests/sys/cddl/zfs/tests/atime/Makefile new file mode 100644 index 00000000000..3779549eca8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/atime +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= atime.cfg +${PACKAGE}FILES+= atime_001_pos.ksh +${PACKAGE}FILES+= atime_002_neg.ksh +${PACKAGE}FILES+= atime_common.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +ATF_TESTS_KSH93+= atime_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +.include diff --git a/tests/sys/cddl/zfs/tests/atime/atime.cfg b/tests/sys/cddl/zfs/tests/atime/atime.cfg new file mode 100644 index 00000000000..005a4c3642c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/atime.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)atime.cfg 1.3 08/08/15 SMI" +# + +export TESTCLONE=testclone${TESTCASE_ID} +export TESTSNAP=testsnap${TESTCASE_ID} + +export TESTFILE=testfile diff --git a/tests/sys/cddl/zfs/tests/atime/atime_001_pos.ksh b/tests/sys/cddl/zfs/tests/atime/atime_001_pos.ksh new file mode 100644 index 00000000000..f7f81d036cb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/atime_001_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)atime_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/atime/atime_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: atime_001_pos +# +# DESCRIPTION: +# When atime=on, verify the access time for files is updated when read. It +# is available to fs and clone. To snapshot, it is unavailable. +# +# STRATEGY: +# 1. Create pool and fs. +# 2. Create '$TESTFILE' for fs. +# 3. Create snapshot and clone. +# 4. Setting atime=on on datasets except snapshot, and read '$TESTFILE'. +# 5. Expect the access time is updated on datasets except snapshot. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Setting atime=on, the access time for files is updated when read." +log_onexit cleanup + +# +# Create $TESTFILE, snapshot and clone. +# +setup_snap_clone + +for dst in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTFS@$TESTSNAP +do + typeset mtpt=$(get_prop mountpoint $dst) + + if [[ $dst == $TESTPOOL/$TESTFS@$TESTSNAP ]]; then + mtpt=$(snapshot_mountpoint $dst) + log_mustnot check_atime_updated $mtpt/$TESTFILE + else + log_must $ZFS set atime=on $dst + log_must check_atime_updated $mtpt/$TESTFILE + fi +done + +log_pass "Verify the property atime=on passed." diff --git a/tests/sys/cddl/zfs/tests/atime/atime_002_neg.ksh b/tests/sys/cddl/zfs/tests/atime/atime_002_neg.ksh new file mode 100644 index 00000000000..0f9aeaf45ee --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/atime_002_neg.ksh @@ -0,0 +1,86 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)atime_002_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/atime/atime_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: atime_002_neg +# +# DESCRIPTION: +# When atime=off, verify the access time for files is not updated when read. +# It is available to pool, fs snapshot and clone. +# +# STRATEGY: +# 1. Create pool, fs. +# 2. Create '$TESTFILE' for fs. +# 3. Create snapshot and clone. +# 4. Setting atime=off on dataset and read '$TESTFILE'. +# 5. Verify the access time is not updated. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Setting atime=off, the access time for files will not be updated \ + when read." +log_onexit cleanup + +# +# Create $TESTFILE, snapshot and clone. +# +setup_snap_clone + +for dst in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTFS@$TESTSNAP +do + typeset mtpt=$(get_prop mountpoint $dst) + + if [[ $dst == $TESTPOOL/$TESTFS@$TESTSNAP ]]; then + mtpt=$(snapshot_mountpoint $dst) + else + log_must $ZFS set atime=off $dst + fi + + log_mustnot check_atime_updated $mtpt/$TESTFILE +done + +log_pass "Verify the property atime=off passed." diff --git a/tests/sys/cddl/zfs/tests/atime/atime_common.kshlib b/tests/sys/cddl/zfs/tests/atime/atime_common.kshlib new file mode 100644 index 00000000000..01f2f6b9887 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/atime_common.kshlib @@ -0,0 +1,72 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)atime_common.kshlib 1.3 07/03/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Check if the access time for specified file is updated. +# +# $1 Given an absolute path to a file name +# +# Return value: +# 0 -> The access time is updated. +# 1 -> The access time is not updated. +# +function check_atime_updated +{ + typeset filename=$1 + + typeset before=$($LS -luD "%Y-%m-%d %R.%s" $filename | $AWK '{print $7}') + sleep 2 + log_must $CAT $filename + typeset after=$($LS -luD "%Y-%m-%d %R.%s" $filename | $AWK '{print $7}') + + if [[ $before != $after ]]; then + return 0 + else + return 1 + fi +} + +function setup_snap_clone +{ + # Create two file to verify snapshot. + log_must $TOUCH $TESTDIR/$TESTFILE + + create_snapshot $TESTPOOL/$TESTFS $TESTSNAP + create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE +} + +function cleanup +{ + destroy_clone $TESTPOOL/$TESTCLONE + destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP +} diff --git a/tests/sys/cddl/zfs/tests/atime/atime_test.sh b/tests/sys/cddl/zfs/tests/atime/atime_test.sh new file mode 100755 index 00000000000..a36fc5c2eee --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/atime_test.sh @@ -0,0 +1,86 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case atime_001_pos cleanup +atime_001_pos_head() +{ + atf_set "descr" "Setting atime=on, the access time for files is updated when read." + atf_set "require.progs" zfs +} +atime_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/atime_common.kshlib + . $(atf_get_srcdir)/atime.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/atime_001_pos.ksh || atf_fail "Testcase failed" +} +atime_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/atime_common.kshlib + . $(atf_get_srcdir)/atime.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case atime_002_neg cleanup +atime_002_neg_head() +{ + atf_set "descr" "Setting atime=off, the access time for files will not be updatedwhen read." + atf_set "require.progs" zfs +} +atime_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/atime_common.kshlib + . $(atf_get_srcdir)/atime.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/atime_002_neg.ksh || atf_fail "Testcase failed" +} +atime_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/atime_common.kshlib + . $(atf_get_srcdir)/atime.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case atime_001_pos + atf_add_test_case atime_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/atime/cleanup.ksh b/tests/sys/cddl/zfs/tests/atime/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/atime/setup.ksh b/tests/sys/cddl/zfs/tests/atime/setup.ksh new file mode 100644 index 00000000000..3ea12f3fce9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/atime/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/bootfs/Makefile b/tests/sys/cddl/zfs/tests/bootfs/Makefile new file mode 100644 index 00000000000..e4d6570b81f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/Makefile @@ -0,0 +1,24 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/bootfs +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= bootfs.cfg +${PACKAGE}FILES+= bootfs_001_pos.ksh +${PACKAGE}FILES+= bootfs_002_neg.ksh +${PACKAGE}FILES+= bootfs_003_pos.ksh +${PACKAGE}FILES+= bootfs_004_neg.ksh +${PACKAGE}FILES+= bootfs_005_neg.ksh +${PACKAGE}FILES+= bootfs_006_pos.ksh +${PACKAGE}FILES+= bootfs_007_pos.ksh +${PACKAGE}FILES+= bootfs_008_neg.ksh +${PACKAGE}FILES+= bootfs_009_neg.ksh + +ATF_TESTS_KSH93+= bootfs_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +.include diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs.cfg b/tests/sys/cddl/zfs/tests/bootfs/bootfs.cfg new file mode 100644 index 00000000000..40f0e79f2ba --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs.cfg 1.1 07/05/25 SMI" +# + +FS=fs +export FS diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_001_pos.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_001_pos.ksh new file mode 100644 index 00000000000..0a96e110280 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_001_pos.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_001_pos.ksh 1.4 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_001_pos +# +# DESCRIPTION: +# +# Valid datasets are accepted as bootfs property values +# +# STRATEGY: +# 1. Create a set of datasets in a test pool +# 2. Try setting them as boot filesystems +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + destroy_pool $TESTPOOL + + if [[ -f $VDEV ]]; then + log_must $RM -f $VDEV + fi +} + +$ZPOOL set 2>&1 | $GREP bootfs > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "bootfs pool property not supported on this release." +fi + +log_assert "Valid datasets are accepted as bootfs property values" +log_onexit cleanup + +typeset VDEV=$TMPDIR/bootfs_001_pos_a.${TESTCASE_ID}.dat + +log_must create_vdevs $VDEV +create_pool "$TESTPOOL" "$VDEV" +log_must $ZFS create $TESTPOOL/$FS + +enc=$(get_prop encryption $TESTPOOL/$FS) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + log_unsupported "bootfs pool property not supported when \ +encryption is set to on." +fi + +log_must $ZFS snapshot $TESTPOOL/$FS@snap +log_must $ZFS clone $TESTPOOL/$FS@snap $TESTPOOL/clone + +log_must $ZPOOL set bootfs=$TESTPOOL/$FS $TESTPOOL +log_must $ZPOOL set bootfs=$TESTPOOL/$FS@snap $TESTPOOL +log_must $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL + +log_must $ZFS promote $TESTPOOL/clone +log_must $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL +log_pass "Valid datasets are accepted as bootfs property values" diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_002_neg.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_002_neg.ksh new file mode 100644 index 00000000000..5c9aa2c10e9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_002_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_002_neg.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_002_neg +# +# DESCRIPTION: +# +# Invalid datasets are rejected as boot property values +# +# STRATEGY: +# +# 1. Create a zvol +# 2. Verify that we can't set the bootfs to those datasets +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + destroy_pool $TESTPOOL +} + + +$ZPOOL set 2>&1 | $GREP bootfs > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "bootfs pool property not supported on this release." +fi + +log_assert "Invalid datasets are rejected as boot property values" +log_onexit cleanup + +DISK=${DISKS%% *} + +log_must $ZPOOL create $TESTPOOL $DISK +log_must $ZFS create -V 10m $TESTPOOL/vol +log_mustnot $ZPOOL set bootfs=$TESTPOOL/vol $TESTPOOL + +log_pass "Invalid datasets are rejected as boot property values" diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_003_pos.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_003_pos.ksh new file mode 100644 index 00000000000..6c6fa1544ae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_003_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_003_pos.ksh 1.2 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_003_pos +# +# DESCRIPTION: +# +# Valid pool names are accepted +# +# STRATEGY: +# 1. Using a list of valid pool names +# 2. Create a filesystem in that pool +# 2. Verify we can set the bootfs to that filesystem +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A pools "pool.${TESTCASE_ID}" "pool123" "mypool" +typeset VDEV=$TMPDIR/bootfs_003.${TESTCASE_ID}.dat + +function cleanup { + typeset -i i=0 + while [ $i -lt "${#pools[@]}" ]; do + destroy_pool ${pools[$i]} + i=$(( $i + 1 )) + done + $RM $VDEV +} + + +$ZPOOL set 2>&1 | $GREP bootfs > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "bootfs pool property not supported on this release." +fi + +log_onexit cleanup + +log_assert "Valid pool names are accepted by zpool set bootfs" +create_vdevs $VDEV + +typeset -i i=0; + +while [ $i -lt "${#pools[@]}" ] +do + POOL=${pools[$i]} + log_must $ZPOOL create $POOL $VDEV + log_must $ZFS create $POOL/$FS + + enc=$(get_prop encryption $POOL/$FS) + if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + log_unsupported "bootfs pool property not supported \ +when encryption is set to on." + fi + + log_must $ZPOOL set bootfs=$POOL/$FS $POOL + RES=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' ) + if [ $RES != "$POOL/$FS" ] + then + log_fail "Expected $RES == $POOL/$FS" + fi + log_must $ZPOOL destroy -f $POOL + i=$(( $i + 1 )) +done + +log_pass "Valid pool names are accepted by zpool set bootfs" diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_004_neg.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_004_neg.ksh new file mode 100644 index 00000000000..21eca27bb2f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_004_neg.ksh @@ -0,0 +1,110 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_004_neg.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_004_neg +# +# DESCRIPTION: +# +# Invalid pool names are rejected by zpool set bootfs +# +# STRATEGY: +# 1. Try to set bootfs on some non-existent pools +# +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A pools "pool//${TESTCASE_ID}" "pool%d123" "mirror" "c0t0d0s0" "pool*23*" "*po!l" \ + "%s££%^" +typeset VDEV=$TMPDIR/bootfs_004.${TESTCASE_ID}.dat + +function cleanup { + typeset -i=0 + while [ $i -lt "${#pools[@]}" ]; do + destroy_pool ${pools[$i]} + i=$(( $i + 1 )) + done + $RM $VDEV +} + + +$ZPOOL set 2>&1 | $GREP bootfs > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "bootfs pool property not supported on this release." +fi + +log_assert "Invalid pool names are rejected by zpool set bootfs" +log_onexit cleanup + +# here, we build up a large string and add it to the list of pool names +# a word to the ksh-wary, ${#array[@]} gives you the +# total number of entries in an array, so array[${#array[@]}] +# will index the last entry+1, ksh arrays start at index 0. +COUNT=0 +while [ $COUNT -le 1025 ] +do + bigname="${bigname}o" + COUNT=$(( $COUNT + 1 )) +done +pools[${#pools[@]}]="$bigname" + + +create_vdevs $VDEV +typeset -i i=0; + +while [ $i -lt "${#pools[@]}" ] +do + POOL=${pools[$i]}/$FS + log_mustnot $ZPOOL create $POOL $VDEV + log_mustnot $ZFS create $POOL/$FS + log_mustnot $ZPOOL set bootfs=$POOL/$FS $POOL + + i=$(( $i + 1 )) +done + +log_pass "Invalid pool names are rejected by zpool set bootfs" diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_005_neg.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_005_neg.ksh new file mode 100644 index 00000000000..76cb7e5e651 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_005_neg.ksh @@ -0,0 +1,103 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_005_neg.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.cfg +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_005_neg +# +# DESCRIPTION: +# +# Boot properties cannot be set on pools with older versions +# +# STRATEGY: +# 1. Copy and import some pools of older versions +# 2. Create a filesystem on each +# 3. Verify that zpool set bootfs fails on each +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + + # + # we need destroy pools that created on top of $TESTPOOL first + # + typeset pool_name + for config in $CONFIGS; do + pool_name=$($ENV| $GREP "ZPOOL_VERSION_${config}_NAME"\ + | $AWK -F= '{print $2}') + if poolexists $pool_name; then + log_must $ZPOOL destroy -f $pool_name + fi + done + destroy_pool $TESTPOOL +} + +$ZPOOL set 2>&1 | $GREP bootfs > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "bootfs pool property not supported on this release." +fi + +log_assert "Boot properties cannot be set on pools with older versions" + +# These are configs from zpool_upgrade.cfg - see that file for more info. +CONFIGS="1 2 3" + +log_onexit cleanup +log_must $ZPOOL create -f $TESTPOOL $DISKS + +for config in $CONFIGS +do + create_old_pool $config + POOL_NAME=$($ENV| $GREP "ZPOOL_VERSION_${config}_NAME"\ + | $AWK -F= '{print $2}') + log_must $ZFS create $POOL_NAME/$FS + log_mustnot $ZPOOL set bootfs=$POOL_NAME/$FS $POOL_NAME + log_must destroy_upgraded_pool $config +done + +log_pass "Boot properties cannot be set on pools with older versions" diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_006_pos.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_006_pos.ksh new file mode 100644 index 00000000000..b63cb32b246 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_006_pos.ksh @@ -0,0 +1,162 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_006_pos.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_006_pos +# +# DESCRIPTION: +# +# Pools of correct vdev types accept boot property +# +# STRATEGY: +# 1. create pools of each vdev type (raid, raidz, raidz2, mirror + hotspares) +# 2. verify we can set bootfs on each pool type according to design +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +$ZPOOL set 2>&1 | $GREP bootfs > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "bootfs pool property not supported on this release." +fi + +VDEV1=$TMPDIR/bootfs_006_pos_a.${TESTCASE_ID}.dat +VDEV2=$TMPDIR/bootfs_006_pos_b.${TESTCASE_ID}.dat +VDEV3=$TMPDIR/bootfs_006_pos_c.${TESTCASE_ID}.dat +VDEV4=$TMPDIR/bootfs_006_pos_d.${TESTCASE_ID}.dat + +function verify_bootfs { # $POOL + POOL=$1 + log_must $ZFS create $POOL/$FS + + enc=$(get_prop encryption $POOL/$FS) + if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + log_unsupported "bootfs pool property not supported \ +when encryption is set to on." + fi + + log_must $ZPOOL set bootfs=$POOL/$FS $POOL + VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' ) + if [ $VAL != "$POOL/$FS" ] + then + log_must $ZPOOL status -v $POOL + log_fail "set/get failed on $POOL - expected $VAL == $POOL/$FS" + fi + log_must $ZPOOL destroy $POOL +} + +function verify_no_bootfs { # $POOL + POOL=$1 + log_must $ZFS create $POOL/$FS + log_mustnot $ZPOOL set bootfs=$POOL/$FS $POOL + VAL=$($ZPOOL get bootfs $POOL | $TAIL -1 | $AWK '{print $3}' ) + if [ $VAL == "$POOL/$FS" ] + then + log_must $ZPOOL status -v $POOL + log_fail "set/get unexpectedly failed $VAL != $POOL/$FS" + fi + log_must $ZPOOL destroy $POOL +} + +function cleanup { + destroy_pool $TESTPOOL + log_must $RM $VDEV1 $VDEV2 $VDEV3 $VDEV4 +} + +log_assert "Pools of correct vdev types accept boot property" + + + +log_onexit cleanup +log_must create_vdevs $VDEV1 $VDEV2 $VDEV3 $VDEV4 + + +## the following configurations are supported bootable pools + +# normal +log_must $ZPOOL create $TESTPOOL $VDEV1 +verify_bootfs $TESTPOOL + +# normal + hotspare +log_must $ZPOOL create $TESTPOOL $VDEV1 spare $VDEV2 +verify_bootfs $TESTPOOL + +# mirror +log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2 +verify_bootfs $TESTPOOL + +# mirror + hotspare +log_must $ZPOOL create $TESTPOOL mirror $VDEV1 $VDEV2 spare $VDEV3 +verify_bootfs $TESTPOOL + +## the following configurations are not supported as bootable pools in Solaris, +## but they are in FreeBSD + +# stripe +log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2 +verify_bootfs $TESTPOOL + +# stripe + hotspare +log_must $ZPOOL create $TESTPOOL $VDEV1 $VDEV2 spare $VDEV3 +verify_bootfs $TESTPOOL + +# raidz +log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2 +verify_bootfs $TESTPOOL + +# raidz + hotspare +log_must $ZPOOL create $TESTPOOL raidz $VDEV1 $VDEV2 spare $VDEV3 +verify_bootfs $TESTPOOL + +# raidz2 +log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 +verify_bootfs $TESTPOOL + +# raidz2 + hotspare +log_must $ZPOOL create $TESTPOOL raidz2 $VDEV1 $VDEV2 $VDEV3 spare $VDEV4 +verify_bootfs $TESTPOOL + +log_pass "Pools of correct vdev types accept boot property" diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_007_pos.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_007_pos.ksh new file mode 100644 index 00000000000..bc49f5e1c30 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_007_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_007_neg.ksh 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_007_neg +# +# DESCRIPTION: +# +# Setting bootfs on a pool which was configured with the whole disk +# (i.e. EFI) will succeed. This is only supported on FreeBSD, not Solaris. +# +# STRATEGY: +# 1. create a pool with a whole disk +# 2. create a filesystem on this pool +# 3. verify we can set bootfs on the filesystem we just created. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-07-08) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + if poolexists $TESTPOOL ; then + destroy_pool "$TESTPOOL" + fi +} + +log_onexit cleanup + +DISK=${DISKS%% *} +typeset EFI_BOOTFS=$TESTPOOL/efs +typeset assert_mesg="setting bootfs on a pool which was configured with the \ + whole disk will succeed" + +log_assert $assert_mesg +create_pool "$TESTPOOL" "$DISK" +log_must $ZFS create $EFI_BOOTFS + +log_must $ZPOOL set bootfs=$EFI_BOOTFS $TESTPOOL + +log_pass $assert_mesg diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_008_neg.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_008_neg.ksh new file mode 100644 index 00000000000..a007aabcc8b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_008_neg.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_008_neg.ksh 1.2 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_008_neg +# +# DESCRIPTION: +# +# setting bootfs on a dataset which has gzip compression enabled will fail +# +# STRATEGY: +# 1. create pools based on a valid vdev +# 2. create a filesytem on this pool and set the compression property to gzip1-9 +# 3. set the pool's bootfs property to filesystem we just configured which should +# fail +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-07-08) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + if poolexists $TESTPOOL ; then + destroy_pool "$TESTPOOL" + fi + + if [[ -f $VDEV ]]; then + log_must $RM -f $VDEV + fi +} + +typeset assert_msg="setting bootfs on a dataset which has gzip \ + compression enabled will fail" + +typeset VDEV=$TMPDIR/bootfs_008_neg_a.${TESTCASE_ID}.dat +typeset COMP_FS=$TESTPOOL/COMP_FS + +log_onexit cleanup +log_assert $assert_msg + +log_must create_vdevs $VDEV +log_must $ZPOOL create $TESTPOOL $VDEV +log_must $ZFS create $COMP_FS + +typeset -i i=0 +set -A gtype "gzip" "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" \ + "gzip-6" "gzip-7" "gzip-8" "gzip-9" "zle" + +while (( i < ${#gtype[@]} )); do + log_must $ZFS set compression=${gtype[i]} $COMP_FS + log_mustnot $ZPOOL set bootfs=$COMP_FS $TESTPOOL + log_must $ZFS set compression=off $COMP_FS + (( i += 1 )) +done + +log_pass $assert_msg diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_009_neg.ksh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_009_neg.ksh new file mode 100644 index 00000000000..e2909423ae8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_009_neg.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)bootfs_009_neg.ksh 1.1 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: bootfs_009_neg +# +# DESCRIPTION: +# +# Valid encrypted datasets can't be set bootfs property values +# +# STRATEGY: +# 1. Create encrypted datasets in a test pool +# 2. Try setting encrypted datasets as boot filesystems +# 3. Verify failures. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-07-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + destroy_pool $TESTPOOL +} + +$ZPOOL set 2>&1 | $GREP bootfs > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "bootfs pool property not supported on this release." +fi + +log_assert "Valid encrypted datasets can't be set bootfs property values" +log_onexit cleanup + +DISK=${DISKS%% *} + +log_must $ZPOOL create $TESTPOOL $DISK +log_must $ZFS create $TESTPOOL/$FS + +enc=$(get_prop encryption $TESTPOOL/$FS) +if [ $? -ne 0 ]; then + log_unsupported "get_prop encryption $TESTPOOL/$FS failed." +else + if [ -z "$enc" ] || [ "$enc" = "off" ]; then + log_unsupported "encryption isn't set to on, this test case \ +is not supported." + else + log_mustnot $ZPOOL set bootfs=$TESTPOOL/$FS $TESTPOOL + fi +fi + + +log_must $ZFS snapshot $TESTPOOL/$FS@snap +log_must $ZFS clone $TESTPOOL/$FS@snap $TESTPOOL/clone +log_must $ZFS promote $TESTPOOL/clone +log_mustnot $ZPOOL set bootfs=$TESTPOOL/clone $TESTPOOL + +log_pass "Encrypted datasets can't be set bootfs property" diff --git a/tests/sys/cddl/zfs/tests/bootfs/bootfs_test.sh b/tests/sys/cddl/zfs/tests/bootfs/bootfs_test.sh new file mode 100755 index 00000000000..b6a9feb0f3b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/bootfs/bootfs_test.sh @@ -0,0 +1,180 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case bootfs_001_pos +bootfs_001_pos_head() +{ + atf_set "descr" "Valid datasets are accepted as bootfs property values" + atf_set "require.progs" zpool zfs +} +bootfs_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + ksh93 $(atf_get_srcdir)/bootfs_001_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_002_neg +bootfs_002_neg_head() +{ + atf_set "descr" "Invalid datasets are rejected as boot property values" + atf_set "require.progs" zfs zpool +} +bootfs_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/bootfs_002_neg.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_003_pos +bootfs_003_pos_head() +{ + atf_set "descr" "Valid pool names are accepted by zpool set bootfs" + atf_set "require.progs" zpool zfs +} +bootfs_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + ksh93 $(atf_get_srcdir)/bootfs_003_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_004_neg +bootfs_004_neg_head() +{ + atf_set "descr" "Invalid pool names are rejected by zpool set bootfs" + atf_set "require.progs" zpool zfs +} +bootfs_004_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + ksh93 $(atf_get_srcdir)/bootfs_004_neg.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_005_neg +bootfs_005_neg_head() +{ + atf_set "descr" "Boot properties cannot be set on pools with older versions" + atf_set "require.progs" zfs zpool +} +bootfs_005_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/bootfs_005_neg.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_006_pos +bootfs_006_pos_head() +{ + atf_set "descr" "Pools of correct vdev types accept boot property" + atf_set "require.progs" zfs zpool +} +bootfs_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + ksh93 $(atf_get_srcdir)/bootfs_006_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_007_pos +bootfs_007_pos_head() +{ + atf_set "descr" "setting bootfs on a pool which was configured with the whole disk will succeed" + atf_set "require.progs" zfs zpool +} +bootfs_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/bootfs_007_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_008_neg +bootfs_008_neg_head() +{ + atf_set "descr" "setting bootfs on a dataset which has gzip compression enabled will fail" + atf_set "require.progs" zpool zfs +} +bootfs_008_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + ksh93 $(atf_get_srcdir)/bootfs_008_neg.ksh || atf_fail "Testcase failed" +} + + +atf_test_case bootfs_009_neg +bootfs_009_neg_head() +{ + atf_set "descr" "Valid encrypted datasets can't be set bootfs property values" + atf_set "require.config" zfs_encryption + atf_set "require.progs" zfs zpool +} +bootfs_009_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/bootfs.cfg + + ksh93 $(atf_get_srcdir)/bootfs_009_neg.ksh || atf_fail "Testcase failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case bootfs_001_pos + atf_add_test_case bootfs_002_neg + atf_add_test_case bootfs_003_pos + atf_add_test_case bootfs_004_neg + atf_add_test_case bootfs_005_neg + atf_add_test_case bootfs_006_pos + atf_add_test_case bootfs_007_pos + atf_add_test_case bootfs_008_neg + atf_add_test_case bootfs_009_neg +} diff --git a/tests/sys/cddl/zfs/tests/cache/Makefile b/tests/sys/cddl/zfs/tests/cache/Makefile new file mode 100644 index 00000000000..0cd3d64ef83 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/Makefile @@ -0,0 +1,29 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cache +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= cache_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cache_005_neg.ksh +${PACKAGE}FILES+= cache.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= cache_011_pos.ksh +${PACKAGE}FILES+= cache_010_neg.ksh +${PACKAGE}FILES+= cache_008_neg.ksh +${PACKAGE}FILES+= cache_004_neg.ksh +${PACKAGE}FILES+= cache_009_pos.ksh +${PACKAGE}FILES+= cache_001_pos.ksh +${PACKAGE}FILES+= cache_003_pos.ksh +${PACKAGE}FILES+= cache_007_neg.ksh +${PACKAGE}FILES+= cache_002_pos.ksh +${PACKAGE}FILES+= cache_006_pos.ksh +${PACKAGE}FILES+= cache.cfg +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cache/cache.cfg b/tests/sys/cddl/zfs/tests/cache/cache.cfg new file mode 100644 index 00000000000..072c7851237 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache.cfg @@ -0,0 +1,47 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache.cfg 1.2 09/01/13 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +. $STF_SUITE/include/libtest.kshlib + +set_disks + +export SIZE=64M + +export VDIR=$TMPDIR/disk.${TESTCASE_ID} +export VDIR2=$TMPDIR/disk2.${TESTCASE_ID} + +export VDEV="$VDIR/a $VDIR/b $VDIR/c" +export LDEV="$DISK0" +export VDEV2="$VDIR2/a $VDIR2/b $VDIR2/c" +export LDEV2="$DISK1" + +export STF_TIMEOUT=1200 diff --git a/tests/sys/cddl/zfs/tests/cache/cache.kshlib b/tests/sys/cddl/zfs/tests/cache/cache.kshlib new file mode 100644 index 00000000000..62e53ea21fd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache.kshlib @@ -0,0 +1,182 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache.kshlib 1.4 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +function cleanup +{ + log_note "Final pool configurations:" + poolexists $TESTPOOL && log_must $ZPOOL status -v $TESTPOOL + poolexists $TESTPOOL2 && log_must $ZPOOL status -v $TESTPOOL2 + destroy_pool $TESTPOOL + destroy_pool $TESTPOOL2 +} + +# +# Try zpool status/iostat for given pool +# +# $1 pool +# +function display_status +{ + typeset pool=$1 + + typeset -i ret=0 + $ZPOOL status -xv $pool > /dev/null 2>&1 + ret=$? + + $ZPOOL iostat > /dev/null 2>&1 + ((ret |= $?)) + + typeset mntpnt=$(get_prop mountpoint $pool) + $DD if=/dev/random of=$mntpnt/testfile.${TESTCASE_ID} & + typeset pid=$! + + $ZPOOL iostat -v 1 3 > /dev/null + ((ret |= $?)) + + kill -9 $pid + + return $ret +} + +# +# Verify the give cache device have correct type and status +# +# $1 pool name +# $2 device name +# $3 device status +# $4 device type +# +function verify_cache_device +{ + typeset pool=$1 + typeset device=$2 + typeset status=$3 + typeset type=$4 + + if [[ -z $pool || -z $device || -z $status ]]; then + log_fail "Usage: verify_cache_device " \ + " [type]" + fi + + # Zpool status returns on the device name sans the /dev, so + # if the device contains /dev/ remove it. + if [[ $device =~ "^/dev/" ]]; then + device=`basename ${device}` + fi + + if [[ $WRAPPER == *"smi"* ]]; then + $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 + if (( $? == 0 )); then + device=${device}s2 + fi + fi + + # + # Get all the cache devices and status table like below + # + # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE + # + set -A dev_stat_tab $($ZPOOL status -v $pool | $NAWK ' + function parse_name(status) + { + if (status == "OFFLINE") + return substr($7,6) + else if (status == "UNAVAIL") + return substr($7,6) + else + return $1 + } + + BEGIN {in_cache=0} + /\tcache/ {in_cache=1} + /\tlog/ || /\tspares/ || /^$/ {in_cache=0} + + # Skip if not in a cache section + (in_cache==0) { next; } + + /\t (\/|[0-9a-zA-Z])/ { + print "stripe:" parse_name($2) " " $2; + } + + /\t (\/|[a-zA-Z])/ { + print "mirror:" parse_name($2) " " $2; + } + + # When hotspare is replacing + /\t (\/|[a-zA-Z])/ { + print "mirror:" parse_name($2) " " $2; + } + ') + + typeset -i i=0 + typeset find=0 + while (( i < ${#dev_stat_tab[@]} )); do + typeset dev=${dev_stat_tab[$i]} + typeset stat=${dev_stat_tab[((i+1))]} + + case $dev in + stripe:$device) + if [[ "$type" == 'mirror' ]]; then + log_note "Unexpected type: mirror" + return 1 + else + if [[ $stat != $status ]]; then + log_note "Status($stat) " \ + "!= Expected stat($status)" + return 1 + fi + return 0 + fi + ;; + mirror:$device) + if [[ -z "$type" || $type == 'stripe' ]]; then + log_note "Unexpected type: stripe" + return 1 + else + if [[ $stat != $status ]]; then + log_note "Status($stat) " \ + "!= Expected stat($status)" + return 1 + fi + return 0 + fi + ;; + esac + + ((i += 2)) + done + + log_note "Can not find device: $device" + + return 1 +} diff --git a/tests/sys/cddl/zfs/tests/cache/cache_001_pos.ksh b/tests/sys/cddl/zfs/tests/cache/cache_001_pos.ksh new file mode 100644 index 00000000000..837deeb626e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_001_pos.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_001_pos.ksh 1.1 08/05/14 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_001_pos +# +# DESCRIPTION: +# Creating a pool with a cache device succeeds. +# +# STRATEGY: +# 1. Create pool with separated cache devices. +# 2. Display pool status +# 3. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Creating a pool with a cache device succeeds." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV + log_must display_status $TESTPOOL + + ldev=$(random_get $LDEV) + log_must verify_cache_device $TESTPOOL $ldev 'ONLINE' + + log_must $ZPOOL remove $TESTPOOL $ldev + log_must check_vdev_state $TESTPOOL $ldev "" + + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Creating a pool with a cache device succeeds." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_002_pos.ksh b/tests/sys/cddl/zfs/tests/cache/cache_002_pos.ksh new file mode 100644 index 00000000000..bd27a02af00 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_002_pos.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_002_pos.ksh 1.1 08/05/14 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_002_pos +# +# DESCRIPTION: +# Adding a cache device to normal pool works. +# +# STRATEGY: +# 1. Create pool +# 2. Add cache devices with different configuration +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Adding a cache device to normal pool works." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV + log_must $ZPOOL add $TESTPOOL cache $LDEV + log_must display_status $TESTPOOL + typeset ldev=$(random_get $LDEV) + log_must verify_cache_device $TESTPOOL $ldev 'ONLINE' + + log_must $ZPOOL remove $TESTPOOL $ldev + log_must check_vdev_state $TESTPOOL $ldev "" + + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Adding a cache device to normal pool works." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_003_pos.ksh b/tests/sys/cddl/zfs/tests/cache/cache_003_pos.ksh new file mode 100644 index 00000000000..009a92f912e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_003_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_003_pos.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_003_pos +# +# DESCRIPTION: +# Adding an extra cache device works +# +# STRATEGY: +# 1. Create pool with separated cache devices. +# 2. Add an extra cache devices +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Adding an extra cache device works." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV + log_must $ZPOOL add $TESTPOOL \ + cache $LDEV2 + + log_must display_status $TESTPOOL + ldev=$(random_get $LDEV2) + log_must verify_cache_device $TESTPOOL $ldev 'ONLINE' + + log_must $ZPOOL remove $TESTPOOL $ldev + log_must check_vdev_state $TESTPOOL $ldev "" + + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Adding an extra cache device works." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_004_neg.ksh b/tests/sys/cddl/zfs/tests/cache/cache_004_neg.ksh new file mode 100644 index 00000000000..229a2727bef --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_004_neg.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_004_neg.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_004_neg +# +# DESCRIPTION: +# Attaching a cache device fails. +# +# STRATEGY: +# 1. Create pool with separated cache devices. +# 2. Attaching a cache device for existing cache device +# 3. Verify the operation fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Attaching a cache device fails." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV + + ldev=$(random_get $LDEV) + typeset ldev2=$(random_get $LDEV2) + log_mustnot $ZPOOL attach $TESTPOOL $ldev $ldev2 + log_must check_vdev_state $TESTPOOL $ldev2 "" + + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Attaching a cache device fails." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_005_neg.ksh b/tests/sys/cddl/zfs/tests/cache/cache_005_neg.ksh new file mode 100644 index 00000000000..6c3c864af99 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_005_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_005_neg.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_005_neg +# +# DESCRIPTION: +# Replacing a cache device fails. +# +# STRATEGY: +# 1. Create pool with cache devices. +# 2. Replacing one cache device +# 3. Verify replace fails +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Replacing a cache device fails." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV + sdev=$(random_get $LDEV) + tdev=$(random_get $LDEV2) + log_mustnot $ZPOOL replace $TESTPOOL $sdev $tdev + log_must verify_cache_device $TESTPOOL $sdev 'ONLINE' + log_must check_vdev_state $TESTPOOL $tdev "" + + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Replacing a cache device fails." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_006_pos.ksh b/tests/sys/cddl/zfs/tests/cache/cache_006_pos.ksh new file mode 100644 index 00000000000..55e9ece06a4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_006_pos.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_006_pos.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_006_pos +# +# DESCRIPTION: +# Exporting and importing pool with cache devices passes. +# +# STRATEGY: +# 1. Create pool with cache devices. +# 2. Export and import the pool +# 3. Display pool status +# 4. Destroy and import the pool again +# 5. Display pool status +# 6. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Exporting and importing pool with cache devices passes." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV $LDEV2 + ldev=$(random_get $LDEV $LDEV2) + log_must verify_cache_device \ + $TESTPOOL $ldev 'ONLINE' + + # + # Nomal export/import operating + # + log_must $ZPOOL export $TESTPOOL + log_must $ZPOOL import -d $VDIR $TESTPOOL + log_must display_status $TESTPOOL + ldev=$(random_get $LDEV $LDEV2) + log_must verify_cache_device \ + $TESTPOOL $ldev 'ONLINE' + + # + # Destroy the pool and import again + # + log_must $ZPOOL destroy $TESTPOOL + log_must $ZPOOL import -Df -d $VDIR $TESTPOOL + log_must display_status $TESTPOOL + ldev=$(random_get $LDEV $LDEV2) + log_must verify_cache_device \ + $TESTPOOL $ldev 'ONLINE' + + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Exporting and importing pool with cache devices passes." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_007_neg.ksh b/tests/sys/cddl/zfs/tests/cache/cache_007_neg.ksh new file mode 100644 index 00000000000..1bb044c0249 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_007_neg.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_007_neg.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_007_neg +# +# DESCRIPTION: +# A mirror/raidz/raidz2 cache is not supported. +# +# STRATEGY: +# 1. Try to create pool with unsupported type +# 2. Verify failed to create pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A mirror/raidz/raidz2 cache is not supported." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + for cachetype in "mirror" "raidz" "raidz1" "raidz2" + do + log_mustnot $ZPOOL create $TESTPOOL $type $VDEV \ + cache $cachetype $LDEV $LDEV2 + ldev=$(random_get $LDEV $LDEV2) + log_mustnot verify_cache_device \ + $TESTPOOL $ldev 'ONLINE' $cachetype + log_must datasetnonexists $TESTPOOL + done +done + +log_pass "A mirror/raidz/raidz2 cache is not supported." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh b/tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh new file mode 100644 index 00000000000..0d528f86940 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_008_neg.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_008_neg +# +# DESCRIPTION: +# A mirror/raidz/raidz2 cache can not be added to existed pool. +# +# STRATEGY: +# 1. Create pool with or without cache. +# 2. Add a mirror/raidz/raidz2 cache to this pool. +# 3. Verify failed to add. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A raidz/raidz2 cache can not be added to existed pool." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + for cachetype in "mirror" "raidz" "raidz1" "raidz2" + do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV + + log_mustnot $ZPOOL add $TESTPOOL cache $cachetype $LDEV2 + ldev=$(random_get $LDEV2) + log_mustnot verify_cache_device \ + $TESTPOOL $ldev 'ONLINE' $cachetype + + log_must $ZPOOL destroy -f $TESTPOOL + done +done + +log_pass "A mirror/raidz/raidz2 cache can not be added to existed pool." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_009_pos.ksh b/tests/sys/cddl/zfs/tests/cache/cache_009_pos.ksh new file mode 100644 index 00000000000..543f4cf7dc9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_009_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_009_pos.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_009_pos +# +# DESCRIPTION: +# Offline and online a cache device succeed. +# +# STRATEGY: +# 1. Create pool with mirror cache devices. +# 2. Offine and online a cache device +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Offline and online a cache device succeed." +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV $LDEV2 + + ldev=$(random_get $LDEV $LDEV2) + log_must $ZPOOL offline $TESTPOOL $ldev + log_must display_status $TESTPOOL + log_must verify_cache_device $TESTPOOL $ldev 'OFFLINE' '' + log_note "Offline pool configuration, for reference:" + log_must $ZPOOL status -v $TESTPOOL + + log_must $ZPOOL online $TESTPOOL $ldev + log_must display_status $TESTPOOL + log_must verify_cache_device $TESTPOOL $ldev 'ONLINE' '' + + log_note "Final pool configuration, for reference:" + log_must $ZPOOL status -v $TESTPOOL + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Offline and online a cache device succeed." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_010_neg.ksh b/tests/sys/cddl/zfs/tests/cache/cache_010_neg.ksh new file mode 100644 index 00000000000..6489148d254 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_010_neg.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_010_neg.ksh 1.1 08/05/14 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_010_neg +# +# DESCRIPTION: +# Verify cache device can only be disk or slice. +# +# STRATEGY: +# 1. Create a pool +# 2. Loop to add different object as cache +# 3. Verify it fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup_testenv +{ + cleanup + if [[ -n $mdconfig_unit ]]; then + $MDCONFIG -d -u $mdconfig_unit + fi +} + +log_assert "Cache device can only be disk or slice." +log_onexit cleanup_testenv + +log_must $ZPOOL create $TESTPOOL $VDEV + +# Add nomal disk +log_must $ZPOOL add $TESTPOOL cache ${LDEV} +log_must verify_cache_device $TESTPOOL ${LDEV} 'ONLINE' +# Add nomal file +log_mustnot $ZPOOL add $TESTPOOL cache $VDEV2 + +# Add md +mdconfig_dev=${VDEV2%% *} +mdconfig_unit=$($MDCONFIG $mdconfig_dev) +log_note "$MDCONFIG $mdconfig_dev" +if [[ $? -eq 0 ]]; then + log_note "$mdconfig_unit is created." +else + log_fail "Failed to execute mdconfig." +fi + +log_must $ZPOOL add $TESTPOOL cache $mdconfig_unit +log_must verify_cache_device $TESTPOOL $mdconfig_unit 'ONLINE' +log_must $ZPOOL destroy $TESTPOOL +if [[ -n $mdconfig_unit ]]; then + log_must $MDCONFIG -d -u $mdconfig_unit + mdconfig_unit="" +fi + +#Add zvol +log_must $ZPOOL create $TESTPOOL2 $VDEV2 +log_must $ZFS create -V $SIZE $TESTPOOL2/$TESTVOL +log_mustnot $ZPOOL add $TESTPOOL cache /dev/zvol/$TESTPOOL2/$TESTVOL + +log_pass "Cache device can only be disk or slice." diff --git a/tests/sys/cddl/zfs/tests/cache/cache_011_pos.ksh b/tests/sys/cddl/zfs/tests/cache/cache_011_pos.ksh new file mode 100644 index 00000000000..3091dcafc12 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_011_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_011_pos.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cache_011_pos +# +# DESCRIPTION: +# Remove cache device from pool with spare device should succeed. +# +# STRATEGY: +# 1. Create pool with cache devices and spare devices +# 2. Remove cache device from the pool +# 3. The upper action should succeed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + if datasetexists $TESTPOOL ; then + log_must $ZPOOL destroy -f $TESTPOOL + fi +} + +log_assert "Remove cache device from pool with spare device should succeed" +log_onexit cleanup + +for type in "" "mirror" "raidz" "raidz2" +do + log_must $ZPOOL create $TESTPOOL $type $VDEV \ + cache $LDEV spare $LDEV2 + + log_must $ZPOOL remove $TESTPOOL $LDEV + log_must display_status $TESTPOOL + + log_must $ZPOOL destroy -f $TESTPOOL +done + +log_pass "Remove cache device from pool with spare device should succeed" diff --git a/tests/sys/cddl/zfs/tests/cache/cache_test.sh b/tests/sys/cddl/zfs/tests/cache/cache_test.sh new file mode 100755 index 00000000000..f722dbf0efd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cache_test.sh @@ -0,0 +1,340 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case cache_001_pos cleanup +cache_001_pos_head() +{ + atf_set "descr" "Creating a pool with a cache device succeeds." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_001_pos.ksh || atf_fail "Testcase failed" +} +cache_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_002_pos cleanup +cache_002_pos_head() +{ + atf_set "descr" "Adding a cache device to normal pool works." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_002_pos.ksh || atf_fail "Testcase failed" +} +cache_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_003_pos cleanup +cache_003_pos_head() +{ + atf_set "descr" "Adding an extra cache device works." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_003_pos.ksh || atf_fail "Testcase failed" +} +cache_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_004_neg cleanup +cache_004_neg_head() +{ + atf_set "descr" "Attaching a cache device fails." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_004_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_004_neg.ksh || atf_fail "Testcase failed" +} +cache_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_005_neg cleanup +cache_005_neg_head() +{ + atf_set "descr" "Replacing a cache device fails." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_005_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_005_neg.ksh || atf_fail "Testcase failed" +} +cache_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_006_pos cleanup +cache_006_pos_head() +{ + atf_set "descr" "Exporting and importing pool with cache devices passes." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_006_pos.ksh || atf_fail "Testcase failed" +} +cache_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_007_neg cleanup +cache_007_neg_head() +{ + atf_set "descr" "A mirror/raidz/raidz2 cache is not supported." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_007_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_007_neg.ksh || atf_fail "Testcase failed" +} +cache_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_008_neg cleanup +cache_008_neg_head() +{ + atf_set "descr" "A raidz/raidz2 cache can not be added to existed pool." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_008_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_008_neg.ksh || atf_fail "Testcase failed" +} +cache_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_009_pos cleanup +cache_009_pos_head() +{ + atf_set "descr" "Offline and online a cache device succeed." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_009_pos.ksh || atf_fail "Testcase failed" +} +cache_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_010_neg cleanup +cache_010_neg_head() +{ + atf_set "descr" "Cache device can only be disk or slice." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1200 +} +cache_010_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_010_neg.ksh || atf_fail "Testcase failed" +} +cache_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_011_pos cleanup +cache_011_pos_head() +{ + atf_set "descr" "Remove cache device from pool with spare device should succeed" + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +cache_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_011_pos.ksh || atf_fail "Testcase failed" +} +cache_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cache.kshlib + . $(atf_get_srcdir)/cache.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case cache_001_pos + atf_add_test_case cache_002_pos + atf_add_test_case cache_003_pos + atf_add_test_case cache_004_neg + atf_add_test_case cache_005_neg + atf_add_test_case cache_006_pos + atf_add_test_case cache_007_neg + atf_add_test_case cache_008_neg + atf_add_test_case cache_009_pos + atf_add_test_case cache_010_neg + atf_add_test_case cache_011_pos +} diff --git a/tests/sys/cddl/zfs/tests/cache/cleanup.ksh b/tests/sys/cddl/zfs/tests/cache/cleanup.ksh new file mode 100644 index 00000000000..bfc4bd10df8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/cleanup.ksh @@ -0,0 +1,44 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 08/05/14 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +verify_runnable "global" + +cleanup +if [[ -d $VDIR ]]; then + log_must $RM -rf $VDIR +fi +if [[ -d $VDIR2 ]]; then + log_must $RM -rf $VDIR2 +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cache/setup.ksh b/tests/sys/cddl/zfs/tests/cache/setup.ksh new file mode 100644 index 00000000000..b6539068b7c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cache/setup.ksh @@ -0,0 +1,45 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 09/01/13 SMI" +# + +. $STF_SUITE/tests/cache/cache.kshlib + +verify_runnable "global" + +if [[ -d $VDEV ]]; then + log_must $RM -rf $VDIR +fi +if [[ -d $VDEV2 ]]; then + log_must $RM -rf $VDIR2 +fi +log_must $MKDIR -p $VDIR $VDIR2 +log_must create_vdevs $VDEV $VDEV2 + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cachefile/Makefile b/tests/sys/cddl/zfs/tests/cachefile/Makefile new file mode 100644 index 00000000000..a6d6e2303a6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cachefile +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= cachefile_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cachefile_002_pos.ksh +${PACKAGE}FILES+= cachefile_003_pos.ksh +${PACKAGE}FILES+= cachefile_001_pos.ksh +${PACKAGE}FILES+= cachefile.cfg +${PACKAGE}FILES+= cachefile.kshlib +${PACKAGE}FILES+= cachefile_004_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cachefile/cachefile.cfg b/tests/sys/cddl/zfs/tests/cachefile/cachefile.cfg new file mode 100644 index 00000000000..a27bfb22c81 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/cachefile.cfg @@ -0,0 +1,38 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cachefile.cfg 1.1 08/02/29 SMI" +# + +if [[ $os_name == "FreeBSD" ]]; then + export CPATH="/boot/zfs/zpool.cache" +else + export CPATH="/etc/zfs/zpool.cache" +fi +export CPATH1=$TMPDIR/cachefile.1.${TESTCASE_ID} +export CPATH2=$TMPDIR/cachefile.2.${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/cachefile/cachefile.kshlib b/tests/sys/cddl/zfs/tests/cachefile/cachefile.kshlib new file mode 100644 index 00000000000..79c8359d66d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/cachefile.kshlib @@ -0,0 +1,53 @@ +#!/usr/local/bin/ksh93 -p +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cachefile.kshlib 1.1 08/02/29 SMI" +# + + +# +# A function to determine if a given pool name has an entry in cachefile +# returns 1 if the pool is not in the cache, 0 otherwise. +function pool_in_cache { + + # checking for the pool name in the strings output of + # the given cachefile, default is /etc/zfs/zpool.cache + typeset cachefile=${2:-$CPATH} + + if [[ -f $cachefile ]]; then + RESULT=$($STRINGS $cachefile | $GREP -w $1) + if [ -z "$RESULT" ] + then + return 1 + fi + return 0 + else + return 1 + fi +} diff --git a/tests/sys/cddl/zfs/tests/cachefile/cachefile_001_pos.ksh b/tests/sys/cddl/zfs/tests/cachefile/cachefile_001_pos.ksh new file mode 100644 index 00000000000..0d365e9e02c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/cachefile_001_pos.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cachefile_001_pos.ksh 1.1 08/02/29 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cachefile/cachefile.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: cachefile_001_pos +# +# DESCRIPTION: +# +# Creating a pool with "cachefile" set doesn't update zpool.cache +# +# STRATEGY: +# 1. Create a pool with the cachefile property set +# 2. Verify that the pool doesn't have an entry in zpool.cache +# 3. Verify the cachefile property is set +# 4. Create a pool without the cachefile property +# 5. Verify the cachefile property isn't set +# 6. Verify that zpool.cache contains an entry for the pool +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-09-05) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + typeset file + + destroy_pool $TESTPOOL + for file in $CPATH1 $CPATH2 ; do + if [[ -f $file ]] ; then + log_must $RM $file + fi + done +} + +verify_runnable "global" + +log_assert "Creating a pool with \"cachefile\" set doesn't update zpool.cache" +log_onexit cleanup + +CPATHARG="-" +set -A opts "none" "false" "none" \ + "$CPATH" "true" "$CPATHARG" \ + "$CPATH1" "true" "$CPATH1" \ + "$CPATH2" "true" "$CPATH2" + +typeset -i i=0 + +while (( i < ${#opts[*]} )); do + log_must $ZPOOL create -o cachefile=${opts[i]} $TESTPOOL $DISKS + case ${opts[((i+1))]} in + false) log_mustnot pool_in_cache $TESTPOOL + ;; + true) log_must pool_in_cache $TESTPOOL ${opts[i]} + ;; + esac + + PROP=$(get_pool_prop cachefile $TESTPOOL) + if [[ $PROP != ${opts[((i+2))]} ]]; then + log_fail "cachefile property not set as expected. " \ + "Expect: ${opts[((i+2))]}, Current: $PROP" + fi + log_must $ZPOOL destroy $TESTPOOL + (( i = i + 3 )) +done + +log_pass "Creating a pool with \"cachefile\" set doesn't update zpool.cache" + diff --git a/tests/sys/cddl/zfs/tests/cachefile/cachefile_002_pos.ksh b/tests/sys/cddl/zfs/tests/cachefile/cachefile_002_pos.ksh new file mode 100644 index 00000000000..55a5972ab82 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/cachefile_002_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cachefile_002_pos.ksh 1.2 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cachefile/cachefile.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: cachefile_002_pos +# +# DESCRIPTION: +# +# Importing a pool with "cachefile" set doesn't update zpool.cache +# +# STRATEGY: +# 1. Create a pool with the cachefile property set +# 2. Verify the pool doesn't have an entry in zpool.cache +# 3. Export the pool +# 4. Import the pool +# 5. Verify the pool does have an entry in zpool.cache +# 6. Export the pool +# 7. Import the pool -o cachefile= +# 8. Verify the pool doesn't have an entry in zpool.cache +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-09-05) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + destroy_pool $TESTPOOL +} + +verify_runnable "global" + +log_assert "Importing a pool with \"cachefile\" set doesn't update zpool.cache" +log_onexit cleanup + +log_must $ZPOOL create -o cachefile=none $TESTPOOL $DISKS +typeset DEVICEDIR=$(get_device_dir $DISKS) +log_mustnot pool_in_cache $TESTPOOL + +log_must $ZPOOL export $TESTPOOL +log_must $ZPOOL import -d $DEVICEDIR $TESTPOOL +log_must pool_in_cache $TESTPOOL + +log_must $ZPOOL export $TESTPOOL +log_must $ZPOOL import -o cachefile=none -d $DEVICEDIR $TESTPOOL +log_mustnot pool_in_cache $TESTPOOL + +log_must $ZPOOL export $TESTPOOL +log_must $ZPOOL import -o cachefile=$CPATH -d $DEVICEDIR $TESTPOOL +log_must pool_in_cache $TESTPOOL + +log_pass "Importing a pool with \"cachefile\" set doesn't update zpool.cache" + diff --git a/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh b/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh new file mode 100644 index 00000000000..30ae1e7afd6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cachefile_003_pos.ksh 1.1 08/02/29 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cachefile/cachefile.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: cachefile_003_pos +# +# DESCRIPTION: +# +# Setting altroot= and cachefile=$CPATH for zpool create is succeed +# +# STRATEGY: +# 1. Attempt to create a pool with -o altroot= -o cachefile= +# 2. Verify the command succeed +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-09-10) +# +# __stc_assertion_end +# +################################################################################ + +TESTDIR=/altdir.${TESTCASE_ID} + +function cleanup +{ + typeset file + + destroy_pool $TESTPOOL + + for file in $CPATH1 $CPATH2 ; do + if [[ -f $file ]] ; then + log_must $RM $file + fi + done + + if [ -d $TESTDIR ] + then + $RMDIR $TESTDIR + fi +} + +verify_runnable "global" + +log_assert "Setting altroot=path and cachefile=$CPATH for zpool create succeed." +log_onexit cleanup + +typeset -i i=0 + +CPATHARG="-" +set -A opts "none" "none" \ + "$CPATH" "$CPATHARG" \ + "$CPATH1" "$CPATH1" \ + "$CPATH2" "$CPATH2" + + +while (( i < ${#opts[*]} )); do + log_must $ZPOOL create -o altroot=$TESTDIR -o cachefile=${opts[i]} \ + $TESTPOOL $DISKS + if [[ ${opts[i]} != none ]]; then + log_must pool_in_cache $TESTPOOL ${opts[i]} + else + log_mustnot pool_in_cache $TESTPOOL + fi + + PROP=$(get_pool_prop cachefile $TESTPOOL) + if [[ $PROP != ${opts[((i+1))]} ]]; then + log_fail "cachefile property not set as expected. " \ + "Expect: ${opts[((i+1))]}, Current: $PROP" + fi + log_must $ZPOOL destroy -f $TESTPOOL + (( i = i + 2 )) +done + +log_pass "Setting altroot=path and cachefile=$CPATH for zpool create succeed." + diff --git a/tests/sys/cddl/zfs/tests/cachefile/cachefile_004_pos.ksh b/tests/sys/cddl/zfs/tests/cachefile/cachefile_004_pos.ksh new file mode 100644 index 00000000000..74c93155bef --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/cachefile_004_pos.ksh @@ -0,0 +1,136 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cachefile_004_pos.ksh 1.2 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cachefile/cachefile.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: cachefile_004_pos +# +# DESCRIPTION: +# Verify set, export and destroy when cachefile is set on pool. +# +# STRATEGY: +# 1. Create two pools with one same cahcefile1. +# 2. Set cachefile of the two pools to another same cachefile2. +# 3. Verify cachefile1 not exist. +# 4. Export the two pools. +# 5. Verify cachefile2 not exist. +# 6. Import the two pools and set cachefile to cachefile2. +# 7. Destroy the two pools. +# 8. Verify cachefile2 not exist. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL2 + + mntpnt=$(get_prop mountpoint $TESTPOOL) + typeset -i i=0 + while ((i < 2)); do + if [[ -e $mntpnt/vdev$i ]]; then + log_must $RM -f $mntpnt/vdev$i + fi + ((i += 1)) + done + + destroy_pool $TESTPOOL + + for file in $CPATH1 $CPATH2 ; do + if [[ -f $file ]] ; then + log_must $RM $file + fi + done +} + + +log_assert "Verify set, export and destroy when cachefile is set on pool." +log_onexit cleanup + +log_must $ZPOOL create $TESTPOOL $DISKS + +mntpnt=$(get_prop mountpoint $TESTPOOL) +typeset -i i=0 +while ((i < 2)); do + log_must create_vdevs $mntpnt/vdev$i + eval vdev$i=$mntpnt/vdev$i + ((i += 1)) +done + +log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL1 $vdev0 +log_must pool_in_cache $TESTPOOL1 $CPATH1 +log_must $ZPOOL create -o cachefile=$CPATH1 $TESTPOOL2 $vdev1 +log_must pool_in_cache $TESTPOOL2 $CPATH1 + +log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1 +log_must pool_in_cache $TESTPOOL1 $CPATH2 +log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2 +log_must pool_in_cache $TESTPOOL2 $CPATH2 +if [[ -f $CPATH1 ]]; then + log_fail "Verify set when cachefile is set on pool." +fi + +log_must $ZPOOL export $TESTPOOL1 +log_must $ZPOOL export $TESTPOOL2 +if [[ -f $CPATH2 ]]; then + log_fail "Verify export when cachefile is set on pool." +fi + +log_must $ZPOOL import -d $mntpnt $TESTPOOL1 +log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL1 +log_must pool_in_cache $TESTPOOL1 $CPATH2 +log_must $ZPOOL import -d $mntpnt $TESTPOOL2 +log_must $ZPOOL set cachefile=$CPATH2 $TESTPOOL2 +log_must pool_in_cache $TESTPOOL2 $CPATH2 + +log_must $ZPOOL destroy $TESTPOOL1 +log_must $ZPOOL destroy $TESTPOOL2 +if [[ -f $CPATH2 ]]; then + log_fail "Verify destroy when cachefile is set on pool." +fi + +log_pass "Verify set, export and destroy when cachefile is set on pool." + diff --git a/tests/sys/cddl/zfs/tests/cachefile/cachefile_test.sh b/tests/sys/cddl/zfs/tests/cachefile/cachefile_test.sh new file mode 100755 index 00000000000..04e7dc09f7e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cachefile/cachefile_test.sh @@ -0,0 +1,104 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case cachefile_001_pos +cachefile_001_pos_head() +{ + atf_set "descr" "Creating a pool with \cachefile\ set doesn't update zpool.cache" + atf_set "require.progs" zpool +} +cachefile_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cachefile.kshlib + . $(atf_get_srcdir)/cachefile.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/cachefile_001_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case cachefile_002_pos +cachefile_002_pos_head() +{ + atf_set "descr" "Importing a pool with \cachefile\ set doesn't update zpool.cache" + atf_set "require.progs" zpool +} +cachefile_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cachefile.kshlib + . $(atf_get_srcdir)/cachefile.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/cachefile_002_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case cachefile_003_pos +cachefile_003_pos_head() +{ + atf_set "descr" "Setting altroot=path and cachefile=$CPATH for zpool create succeed." + atf_set "require.progs" zpool +} +cachefile_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cachefile.kshlib + . $(atf_get_srcdir)/cachefile.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/cachefile_003_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case cachefile_004_pos +cachefile_004_pos_head() +{ + atf_set "descr" "Verify set, export and destroy when cachefile is set on pool." + atf_set "require.progs" zpool +} +cachefile_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/cachefile.kshlib + . $(atf_get_srcdir)/cachefile.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/cachefile_004_pos.ksh || atf_fail "Testcase failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case cachefile_001_pos + atf_add_test_case cachefile_002_pos + atf_add_test_case cachefile_003_pos + atf_add_test_case cachefile_004_pos +} diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/Makefile b/tests/sys/cddl/zfs/tests/clean_mirror/Makefile new file mode 100644 index 00000000000..065c726de95 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/clean_mirror +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= clean_mirror_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= clean_mirror_001_pos.ksh +${PACKAGE}FILES+= clean_mirror_002_pos.ksh +${PACKAGE}FILES+= clean_mirror_003_pos.ksh +${PACKAGE}FILES+= clean_mirror_004_pos.ksh +${PACKAGE}FILES+= clean_mirror_common.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= default.cfg +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_001_pos.ksh b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_001_pos.ksh new file mode 100644 index 00000000000..fd215372086 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_001_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)clean_mirror_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/clean_mirror/clean_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: clean_mirror_001_pos +# +# DESCRIPTION: +# The primary side of a zpool mirror can be zeroed without causing damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem mirror +# 2) dd from /dev/zero over the primary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely wiped" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $SIDE_PRIMARY /dev/zero + +log_pass "The overwrite had no effect on the data" diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_002_pos.ksh b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_002_pos.ksh new file mode 100644 index 00000000000..7aef5af64e7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_002_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)clean_mirror_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/clean_mirror/clean_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: clean_mirror_002_pos +# +# DESCRIPTION: +# The secondary side of a zpool mirror can be zeroed without causing damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem in the mirrored pool +# 2) dd from /dev/zero over the secondary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely wiped" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $SIDE_SECONDARY /dev/zero + +log_pass "The overwrite had no effect on the data" diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_003_pos.ksh b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_003_pos.ksh new file mode 100644 index 00000000000..7e998f6d285 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_003_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)clean_mirror_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/clean_mirror/clean_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: clean_mirror_003_pos +# +# DESCRIPTION: +# The primary side of a zpool mirror can be mangled without causing damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem mirror +# 2) dd from /dev/urandom over the primary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely mangled" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $SIDE_PRIMARY /dev/urandom + +log_pass "The overwrite did not have any effect on the data" diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_004_pos.ksh b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_004_pos.ksh new file mode 100644 index 00000000000..abecf001be2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_004_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)clean_mirror_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/clean_mirror/clean_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: clean_mirror_004_pos +# +# DESCRIPTION: +# The secondary side of a zpool mirror can be mangled without causing damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem in the mirrored pool +# 2) dd from /dev/urandom over the secondary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely mangled" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $SIDE_SECONDARY /dev/urandom + +log_pass "The overwrite had no effect on the data" diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_common.kshlib b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_common.kshlib new file mode 100644 index 00000000000..a3e47da7d7d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_common.kshlib @@ -0,0 +1,79 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)clean_mirror_common.kshlib 1.4 07/10/09 SMI" +# + +# Most of the code related to the clearing of mirrors is duplicated in all +# the test cases below this directory, barring a few minor changes +# involving the device to be affected and the 'object' to use to mangle +# the contents of the mirror. +# This code is sourced into each of these test cases. + +function overwrite_verify_mirror +{ + typeset AFFECTED_DEVICE=$1 + typeset OVERWRITING_DEVICE=$2 + + typeset atfile=0 + set -A cksums + set -A newcksums + + populate_dir $TESTDIR/file $FILE_COUNT $WRITE_COUNT $BLOCKSZ 0 + while (( atfile < FILE_COUNT )); do + cksums[$atfile]=$($CKSUM ${TESTDIR}/file.${atfile}) + (( atfile = atfile + 1 )) + done + + # unmount and export before dd + log_must $UMOUNT $TESTDIR + log_must $ZPOOL export $TESTPOOL + + # dd the primary side of the mirror + log_must $DD if=$OVERWRITING_DEVICE of=$(bsddevmap $AFFECTED_DEVICE) \ + seek=8 bs=$DD_BLOCK count=$(( DD_COUNT - 8 )) conv=notrunc + + # now remount + log_must $ZPOOL import $TESTPOOL + + atfile=0 + typeset -i failedcount=0 + while (( atfile < FILE_COUNT )); do + newcksum=$($CKSUM $TESTDIR/file.${atfile}) + if [[ $newcksum != ${cksums[$atfile]} ]]; then + (( failedcount = failedcount + 1 )) + fi + $RM -f ${files[$atfile]} + (( atfile = atfile + 1 )) + done + + if (( $failedcount > 0 )); then + log_fail "of the $FILE_COUNT files $failedcount did not " \ + "have the same checksum before and after." + fi +} diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_test.sh b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_test.sh new file mode 100755 index 00000000000..f7c3bf51ffe --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/clean_mirror_test.sh @@ -0,0 +1,133 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2018 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case clean_mirror_001_pos cleanup +clean_mirror_001_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely wipedwithout affecting the content of the pool" +} +clean_mirror_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/clean_mirror_001_pos.ksh || atf_fail "Testcase failed" +} +clean_mirror_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case clean_mirror_002_pos cleanup +clean_mirror_002_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely wipedwithout affecting the content of the pool" +} +clean_mirror_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/clean_mirror_002_pos.ksh || atf_fail "Testcase failed" +} +clean_mirror_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case clean_mirror_003_pos cleanup +clean_mirror_003_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely mangledwithout affecting the content of the pool" +} +clean_mirror_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/clean_mirror_003_pos.ksh || atf_fail "Testcase failed" +} +clean_mirror_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case clean_mirror_004_pos cleanup +clean_mirror_004_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely mangledwithout affecting the content of the pool" +} +clean_mirror_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/clean_mirror_004_pos.ksh || atf_fail "Testcase failed" +} +clean_mirror_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/clean_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case clean_mirror_001_pos + atf_add_test_case clean_mirror_002_pos + atf_add_test_case clean_mirror_003_pos + atf_add_test_case clean_mirror_004_pos +} diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/cleanup.ksh b/tests/sys/cddl/zfs/tests/clean_mirror/cleanup.ksh new file mode 100644 index 00000000000..c5476609abb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/cleanup.ksh @@ -0,0 +1,47 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +$DF -t zfs -h | $GREP "$TESTFS " >/dev/null +[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR +destroy_pool $TESTPOOL + +# Erase the partition table that we made +if [[ -n $SINGLE_DISK ]]; then + log_must cleanup_devices $MIRROR_PRIMARY +else + log_must cleanup_devices $MIRROR_PRIMARY $MIRROR_SECONDARY +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/default.cfg b/tests/sys/cddl/zfs/tests/clean_mirror/default.cfg new file mode 100644 index 00000000000..6684532b1b1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/default.cfg @@ -0,0 +1,57 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)default.cfg 1.3 08/08/15 SMI" +# + +typeset -i NUMBER_OF_DISKS=0 +for i in $DISKS; do + [[ -n $MIRROR_PRIMARY ]] && MIRROR_SECONDARY=$i + [[ -z $MIRROR_PRIMARY ]] && MIRROR_PRIMARY=$i +done + +if [[ -z $MIRROR_SECONDARY ]]; then + # We need to repartition the single disk to two slices + SINGLE_DISK=$MIRROR_PRIMARY + MIRROR_SECONDARY=$MIRROR_PRIMARY + SIDE_PRIMARY=${SINGLE_DISK}p1 + SIDE_SECONDARY=${SINGLE_DISK}p2 +else + SIDE_PRIMARY=${MIRROR_PRIMARY}p1 + SIDE_SECONDARY=${MIRROR_SECONDARY}p1 +fi + +export MIRROR_PRIMARY MIRROR_SECONDARY SINGLE_DISK SIDE_PRIMARY SIDE_SECONDARY + +export FILE_COUNT=10 +export BLOCKSZ=131072 +export WRITE_COUNT=8 +export FILE_SIZE=$(( BLOCKSZ * WRITE_COUNT )) +export MIRROR_SIZE=70 +export DD_BLOCK=$(( 64 * 1024 )) +export DD_COUNT=$(( MIRROR_SIZE * 1024 * 1024 / DD_BLOCK )) diff --git a/tests/sys/cddl/zfs/tests/clean_mirror/setup.ksh b/tests/sys/cddl/zfs/tests/clean_mirror/setup.ksh new file mode 100644 index 00000000000..f8ed2c5972b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/clean_mirror/setup.ksh @@ -0,0 +1,47 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.5 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if [[ -n $SINGLE_DISK ]]; then + log_note "Partitioning a single disk ($SINGLE_DISK)" +else + log_note "Partitioning disks ($MIRROR_PRIMARY $MIRROR_SECONDARY)" +fi +wipe_partition_table ${SINGLE_DISK} ${MIRROR_PRIMARY} ${MIRROR_SECONDARY} +log_must set_partition ${SIDE_PRIMARY##*p} "" ${MIRROR_SIZE}m $MIRROR_PRIMARY +log_must set_partition ${SIDE_SECONDARY##*p} "" ${MIRROR_SIZE}m $MIRROR_SECONDARY + +default_mirror_setup $SIDE_PRIMARY $SIDE_SECONDARY + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/Makefile b/tests/sys/cddl/zfs/tests/cli_root/Makefile new file mode 100644 index 00000000000..521564f855a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/Makefile @@ -0,0 +1,60 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= cli.cfg +${PACKAGE}FILES+= cli_common.kshlib +${PACKAGE}FILES+= setup.ksh + +TESTS_SUBDIRS+= zdb + +TESTS_SUBDIRS+= zfs +TESTS_SUBDIRS+= zfs_clone +TESTS_SUBDIRS+= zfs_copies +TESTS_SUBDIRS+= zfs_create +TESTS_SUBDIRS+= zfs_destroy +TESTS_SUBDIRS+= zfs_diff +TESTS_SUBDIRS+= zfs_get +TESTS_SUBDIRS+= zfs_inherit +TESTS_SUBDIRS+= zfs_mount +TESTS_SUBDIRS+= zfs_promote +TESTS_SUBDIRS+= zfs_property +TESTS_SUBDIRS+= zfs_receive +TESTS_SUBDIRS+= zfs_rename +TESTS_SUBDIRS+= zfs_reservation +TESTS_SUBDIRS+= zfs_rollback +TESTS_SUBDIRS+= zfs_send +TESTS_SUBDIRS+= zfs_set +TESTS_SUBDIRS+= zfs_share +TESTS_SUBDIRS+= zfs_snapshot +TESTS_SUBDIRS+= zfs_unshare +TESTS_SUBDIRS+= zfs_unmount +TESTS_SUBDIRS+= zfs_upgrade + +TESTS_SUBDIRS+= zpool +TESTS_SUBDIRS+= zpool_add +TESTS_SUBDIRS+= zpool_attach +TESTS_SUBDIRS+= zpool_clear +TESTS_SUBDIRS+= zpool_create +TESTS_SUBDIRS+= zpool_destroy +TESTS_SUBDIRS+= zpool_detach +TESTS_SUBDIRS+= zpool_expand +TESTS_SUBDIRS+= zpool_export +TESTS_SUBDIRS+= zpool_get +TESTS_SUBDIRS+= zpool_history +TESTS_SUBDIRS+= zpool_import +TESTS_SUBDIRS+= zpool_offline +TESTS_SUBDIRS+= zpool_online +TESTS_SUBDIRS+= zpool_remove +TESTS_SUBDIRS+= zpool_replace +TESTS_SUBDIRS+= zpool_set +TESTS_SUBDIRS+= zpool_scrub +TESTS_SUBDIRS+= zpool_status +TESTS_SUBDIRS+= zpool_upgrade + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/cli.cfg b/tests/sys/cddl/zfs/tests/cli_root/cli.cfg new file mode 100644 index 00000000000..35a8c00a131 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/cli.cfg @@ -0,0 +1,55 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cli.cfg 1.3 08/08/15 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +export ZFSROOT= + +export TESTSNAP=testsnap${TESTCASE_ID} +export TESTSNAP1=testsnap1${TESTCASE_ID} +export TESTSNAP2=testsnap2${TESTCASE_ID} +export TESTCLONE=testclone${TESTCASE_ID} +export TESTCLONE1=testclone1${TESTCASE_ID} +export TESTCLONE2=testclone2${TESTCASE_ID} +export TESTCLCT=testclct${TESTCASE_ID} +export TESTCTR1=testctr1${TESTCASE_ID} +export TESTCTR2=testctr2${TESTCASE_ID} +export TESTVOL=testvol${TESTCASE_ID} +export TESTVOL1=testvol1${TESTCASE_ID} +export TESTVOL2=testvol2${TESTCASE_ID} +export TESTFILE0=testfile0.${TESTCASE_ID} +export TESTFILE1=testfile1.${TESTCASE_ID} +export TESTFILE2=testfile2.${TESTCASE_ID} + +export LONGPNAME="poolname50charslong_012345678901234567890123456789" +export LONGFSNAME="fsysname50charslong_012345678901234567890123456789" + +export VOLSIZE=150m +export BIGVOLSIZE=1eb diff --git a/tests/sys/cddl/zfs/tests/cli_root/cli_common.kshlib b/tests/sys/cddl/zfs/tests/cli_root/cli_common.kshlib new file mode 100644 index 00000000000..636135ee581 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/cli_common.kshlib @@ -0,0 +1,91 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cli_common.kshlib 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Get the checksum and size of the file. +# +function get_cksum # +{ + return $($CKSUM $1 | $AWK '{print $1 $2}') +} + +# +# Compare the check sum of target files with the original file +# + +function compare_cksum # ... +{ + typeset orig_data=$1 + typeset orig_sum=$(get_cksum $orig_data) + typeset target_sum="" + typeset bad_data_list="" + typeset -i bad_count=0 + + shift + for data in $@; do + if [[ ! -e $data ]]; then + bad_data_list="$bad_data_list $data" + (( bad_count +=1 )) + continue + fi + + target_sum=$(get_cksum $data) + if [[ $target_sum != $orig_sum ]]; then + bad_data_list="$bad_data_list $data" + (( bad_count +=1 )) + fi + done + + [[ $bad_data_list != "" ]] && \ + log_fail "Data corruptions appear during send->receive." \ + "There are total $bad_count corruptions. They are:\n"\ + "$bad_data_list" +} + +# +# Check the received dataset exists or not +# +function receive_check #... +{ + typeset bad_rst_tgts="" + + for dataset in $@; do + ! datasetexists $dataset && \ + bad_rst_tgts="$bad_rst_tgts $dataset" + done + + if [[ $bad_rst_tgts != "" ]]; then + log_fail "Restoring fails. The specified datasets"\ + "$bad_rst_tgts are not being received." + fi +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zdb/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zdb/Makefile new file mode 100644 index 00000000000..091c707550a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zdb/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zdb +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zdb_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zdb_001_neg.ksh +${PACKAGE}FILES+= zdb.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zdb/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zdb/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zdb/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zdb/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zdb/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zdb/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb.cfg b/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb.cfg new file mode 100644 index 00000000000..3ddf3ca34ab --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zdb.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb_001_neg.ksh new file mode 100644 index 00000000000..4c9b7b87cad --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb_001_neg.ksh @@ -0,0 +1,86 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zdb_001_neg.ksh 1.4 08/02/27 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zdb_001_neg +# +# DESCRIPTION: +# A badly formed parameter passed to zdb(1) should +# return an error. +# +# STRATEGY: +# 1. Create an array containg bad zdb parameters. +# 2. For each element, execute the sub-command. +# 3. Verify it returns an error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-28) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A args "create" "add" "destroy" "import fakepool" \ + "export fakepool" "create fakepool" "add fakepool" \ + "create mirror" "create raidz" \ + "create mirror fakepool" "create raidz fakepool" \ + "create raidz1 fakepool" "create raidz2 fakepool" \ + "create fakepool mirror" "create fakepool raidz" \ + "create fakepool raidz1" "create fakepool raidz2" \ + "add fakepool mirror" "add fakepool raidz" \ + "add fakepool raidz1" "add fakepool raidz2" \ + "add mirror fakepool" "add raidz fakepool" \ + "add raidz1 fakepool" "add raidz2 fakepool" \ + "setvprop" "blah blah" "-%" "--?" "-*" "-=" \ + "-a" "-f" "-g" "-h" "-j" "-k" "-m" "-n" "-p" "-p /tmp" \ + "-r" "-t" "-w" "-x" "-y" "-z" \ + "-D" "-E" "-G" "-H" "-I" "-J" "-K" "-M" \ + "-N" "-Q" "-T" "-W" + +log_assert "Execute zdb using invalid parameters." + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZDB ${args[i]} + + ((i = i + 1)) +done + +log_pass "Badly formed zdb parameters fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb_test.sh new file mode 100755 index 00000000000..e75da9201b5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zdb/zdb_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zdb_001_neg cleanup +zdb_001_neg_head() +{ + atf_set "descr" "Execute zdb using invalid parameters." + atf_set "require.progs" zdb +} +zdb_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zdb.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zdb_001_neg.ksh || atf_fail "Testcase failed" +} +zdb_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zdb.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zdb_001_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs/Makefile new file mode 100644 index 00000000000..fc9ac73af68 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_malformed.cfg +${PACKAGE}FILES+= zfs_001_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_003_neg.ksh +${PACKAGE}FILES+= zfs_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_001_neg.ksh new file mode 100644 index 00000000000..21e95d7cfe6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_001_neg.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_001_neg.ksh 1.4 08/02/27 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_001_neg +# +# DESCRIPTION: +# Try each zfs(1) sub-command without parameters to make sure +# it returns an error. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute the sub-command +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A args "" "create" "create -s" "create -V" "create -s -V" \ + "destroy" "destroy -f" "destroy -r" "destroy -R" "destroy -rRf" \ + "snapshot" "snapshot -r" \ + "rollback" "rollback -r" "rollback -R" "rollback -f" "rollback -rRf" \ + "clone" "clone -p" "promote" "rename" "rename -p" "rename -r" "list blah" \ + "set" "get" "get -rHp" "get -o" "get -s" \ + "inherit" "inherit -r" "quota=" \ + "set reservation=" "set atime=" "set checksum=" "set compression=" \ + "set type=" "set creation=" "set used=" "set available=" "set referenced=" \ + "set compressratio=" "set mounted=" "set origin=" "set quota=" \ + "set reservation=" "set volsize=" " set volblocksize=" "set recordsize=" \ + "set mountpoint=" "set devices=" "set exec=" "set setuid=" "set readonly=" \ + "set zoned=" "set snapdir=" "set aclmode=" "set aclinherit=" \ + "set quota=blah" "set reservation=blah" "set atime=blah" "set checksum=blah" \ + "set compression=blah" \ + "upgrade blah" "mount blah" "mount -o" \ + "umount blah" "unmount" "unmount blah" "unmount -f" \ + "share" "unshare" "send" "send -i" "receive" "receive -d" "receive -vnF" \ + "recv" "recv -d" "recv -vnF" "allow" "unallow" \ + "blah blah" "-%" "--" "--?" "-*" "-=" + +log_assert "Badly-formed zfs sub-command should return an error." + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZFS ${args[i]} + ((i = i + 1)) +done + +log_pass "Badly formed zfs sub-commands fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_002_pos.ksh new file mode 100644 index 00000000000..d40ef6a75ff --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_002_pos.ksh @@ -0,0 +1,127 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_002_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_002_pos +# +# DESCRIPTION: +# With ZFS_ABORT set, all zfs commands should be able to abort and generate a core file. +# +# STRATEGY: +# 1. Create an array of zfs command +# 2. Execute each command in the array +# 3. Verify the command aborts and generate a core file +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + unset ZFS_ABORT + + if [[ -d $corepath ]]; then + $RM -rf $corepath + fi + for ds in $fs1 $fs $ctr; do + if datasetexists $ds; then + log_must $ZFS destroy -rRf $ds + fi + done +} + +log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a core file." +log_onexit cleanup + +#preparation work for testing +corepath=$TESTDIR/core +if [[ -d $corepath ]]; then + $RM -rf $corepath +fi +log_must $MKDIR $corepath + +ctr=$TESTPOOL/$TESTCTR +log_must $ZFS create $ctr + +fs=$ctr/$TESTFS +fs1=$ctr/$TESTFS1 +snap=$fs@$TESTSNAP +clone=$ctr/$TESTCLONE +streamf=$corepath/s.${TESTCASE_ID} + +set -A cmds "create $fs" "list $fs" "snapshot $snap" "set snapdir=hidden $fs" \ + "get snapdir $fs" "rollback $snap" "inherit snapdir $fs" \ + "rename $fs $fs-new" "rename $fs-new $fs" "unmount $fs" \ + "mount $fs" "share $fs" "unshare $fs" "send $snap \>$streamf" \ + "receive $fs1 \<$streamf" "clone $snap $clone" "promote $clone" \ + "promote $fs" "destroy -rRf $fs" + +set -A badparams "" "create" "destroy" "snapshot" "rollback" "clone" "promote" "rename" \ + "list -*" "set" "get -*" "inherit" "mount -A" "unmount" "share" \ + "unshare" "send" "receive" + +if ! is_userquota_supported; then + typeset -i i=${cmds[#]} + cmds[i]="allow everyone snapshot $fs" + cmds[((i+1))]="unallow everyone snapshot $fs" + + i=${badparams[#]} + badparams[i]="allow" + badparams[((i+1))]="unallow" +fi + + +log_must $COREADM -p ${corepath}/core.%f +log_must export ZFS_ABORT=yes + +for subcmd in "${cmds[@]}" "${badparams[@]}"; do + log_mustnot $ZFS $subcmd + corefile=${corepath}/core.zfs + if [[ ! -e $corefile ]]; then + log_fail "$ZFS $subcmd cannot generate core file with ZFS_ABORT set." + fi + log_must $RM -f $corefile +done + +log_pass "With ZFS_ABORT set, zfs command can abort and generate core file as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_003_neg.ksh new file mode 100644 index 00000000000..8fc2e452334 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_003_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_003_neg.ksh 1.1 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_003_neg +# +# DESCRIPTION: +# zfs command will failed with unexpected scenarios: +# (1) ZFS_DEV cannot be opened +# (2) MNTTAB cannot be opened +# +# STRATEGY: +# 1. Create an array of zfs command +# 2. Execute each command in the array +# 3. Verify the command aborts and generate a core file +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zfs fails with unexpected scenarios." + +#verify zfs failed if ZFS_DEV cannot be opened +ZFS_DEV=/dev/zfs +MNTTAB=/etc/mnttab + +for file in $ZFS_DEV $MNTTAB; do + if [[ -e $file ]]; then + $MV $file ${file}.bak + fi + for cmd in "" "list" "get all" "mount"; do + log_mustnot eval "$ZFS $cmd >/dev/null 2>&1" + done + $MV ${file}.bak $file +done + +log_pass "zfs fails with unexpected scenarios as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_malformed.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_malformed.cfg new file mode 100644 index 00000000000..5aeb09e7675 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_malformed.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_malformed.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_test.sh new file mode 100755 index 00000000000..3d2270e28af --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs/zfs_test.sh @@ -0,0 +1,108 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_001_neg cleanup +zfs_001_neg_head() +{ + atf_set "descr" "Badly-formed zfs sub-command should return an error." + atf_set "require.progs" zfs +} +zfs_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_malformed.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_malformed.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_002_pos cleanup +zfs_002_pos_head() +{ + atf_set "descr" "With ZFS_ABORT set, all zfs commands can abort and generate a core file." + atf_set "require.progs" zfs coreadm +} +zfs_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_malformed.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_malformed.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_003_neg cleanup +zfs_003_neg_head() +{ + atf_set "descr" "zfs fails with unexpected scenarios." + atf_set "require.progs" zfs +} +zfs_003_neg_body() +{ + atf_skip "FreeBSD does not allow /dev/zfs to be renamed" + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_malformed.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_003_neg.ksh || atf_fail "Testcase failed" +} +zfs_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_malformed.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_001_neg + atf_add_test_case zfs_002_pos + atf_add_test_case zfs_003_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/Makefile new file mode 100644 index 00000000000..6fcb871b2ca --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/Makefile @@ -0,0 +1,26 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_clone +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_clone_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_clone_005_pos.ksh +${PACKAGE}FILES+= zfs_clone_008_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_clone_004_pos.ksh +${PACKAGE}FILES+= zfs_clone_001_neg.ksh +${PACKAGE}FILES+= zfs_clone_009_neg.ksh +${PACKAGE}FILES+= zfs_clone_006_pos.ksh +${PACKAGE}FILES+= zfs_clone_002_pos.ksh +${PACKAGE}FILES+= zfs_clone.cfg +${PACKAGE}FILES+= zfs_clone_007_pos.ksh +${PACKAGE}FILES+= zfs_clone_003_pos.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/cleanup.ksh new file mode 100644 index 00000000000..a7b62a544f5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_container_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/setup.ksh new file mode 100644 index 00000000000..6b700be3a28 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_container_volume_setup ${DISK} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone.cfg new file mode 100644 index 00000000000..0d014d1c73c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone.cfg 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP" +export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_001_neg.ksh new file mode 100644 index 00000000000..cb9e5df8059 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_001_neg.ksh @@ -0,0 +1,143 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_001_neg.ksh 1.4 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_001_neg +# +# DESCRIPTION: +# 'zfs clone' should fail with inapplicable scenarios, including: +# * Null arguments +# * non-existant snapshots. +# * invalid characters in ZFS namesapec +# * Leading slash in the target clone name +# * The argument contains an empty component. +# * The pool specified in the target doesn't exist. +# * The parent dataset of the target doesn't exist. +# * The argument refer to a pool, not dataset. +# * The target clone already exists. +# * Null target clone argument. +# * Too many arguments. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute the sub-command +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset target1=$TESTPOOL/$TESTFS1 +typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1 +typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS" + +set -A args "" \ + "$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \ + "$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \ + "$SNAPFS $target1*" "$SNAPFS1 $target1*" \ + "$SNAPFS /$target1" "$SNAPFS1 /$target1" \ + "$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \ + "$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \ + "$SNAPFS" "$SNAPFS1" \ + "$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2" +typeset -i argsnum=${#args[*]} +typeset -i j=0 +while (( j < argsnum )); do + args[((argsnum+j))]="-p ${args[j]}" + ((j = j + 1)) +done + +set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \ + "$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \ + "$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \ + "$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS" + +set -A args ${args[*]} ${moreargs[*]} + +function setup_all +{ + log_note "Create snapshots and mount them..." + + for snap in $SNAPFS $SNAPFS1 ; do + if ! snapexists $snap ; then + log_must $ZFS snapshot $snap + fi + done + + return 0 +} + +function cleanup_all +{ + typeset -i i=0 + + for fs in $targets; do + + datasetexists $fs && \ + log_must $ZFS destroy -f $fs + + (( i = i + 1 )) + done + + for snap in $SNAPFS $SNAPFS1 ; do + snapexists $snap && \ + log_must $ZFS destroy -Rf $snap + done + + return 0 +} + +log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \ + "should return an error." +log_onexit cleanup_all + +setup_all + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZFS clone ${args[i]} + ((i = i + 1)) +done + +log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \ + "fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_002_pos.ksh new file mode 100644 index 00000000000..d83e663af6f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_002_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_002_pos.ksh 1.2 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_002_pos +# +# DESCRIPTION: +# 'zfs clone -p' should work as expected +# +# STRATEGY: +# 1. prepare snapshots +# 2. make sure without -p option, 'zfs clone' will fail +# 3. with -p option, the clone can be created +# 4. run 'zfs clone -p' again, the exit code should be zero +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-05) +# +# __stc_assertion_end +# +################################################################################ + +if ! $(check_opt_support "clone" "-p") ; then + log_unsupported "'zfs clone -p' is not supported yet." +fi + +verify_runnable "both" + +function setup_all +{ + log_note "Create snapshots and mount them..." + + for snap in $SNAPFS $SNAPFS1 ; do + if ! snapexists $snap ; then + log_must $ZFS snapshot $snap + fi + done + + return 0 +} + +function cleanup_all +{ + + if datasetexists $TESTPOOL/notexist ; then + log_must $ZFS destroy -rRf $TESTPOOL/notexist + fi + + for snap in $SNAPFS $SNAPFS1 ; do + if snapexists $snap ; then + log_must $ZFS destroy -Rf $snap + fi + done + + return 0 +} + +log_assert "clone -p should work as expected." +log_onexit cleanup_all + +setup_all + +log_must verify_opt_p_ops "clone" "fs" $SNAPFS \ + $TESTPOOL/notexist/new/clonefs${TESTCASE_ID} + +if is_global_zone ; then + log_must verify_opt_p_ops "clone" "vol" $SNAPFS1 \ + $TESTPOOL/notexist/new/clonevol${TESTCASE_ID} +fi + +log_pass "clone -p should work as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_003_pos.ksh new file mode 100644 index 00000000000..cd310273447 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_003_pos.ksh @@ -0,0 +1,99 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_003_pos.ksh 1.1 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_003_pos +# +# DESCRIPTION: +# 'zfs clone -o property=value filesystem' can successfully create a ZFS +# clone filesystem with correct property set. +# +# STRATEGY: +# 1. Create a ZFS clone filesystem in the storage pool with -o option +# 2. Verify the filesystem created successfully +# 3. Verify the property is correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists $SNAPFS ; then + log_must $ZFS destroy -Rf $SNAPFS + fi +} + +if ! $(check_opt_support "clone" "-o") ; then + log_unsupported "'zfs clone -o' unsupported." +fi + +log_onexit cleanup + + +log_assert "'zfs clone -o property=value filesystem' can successfully create" \ + "a ZFS clone filesystem with correct property set." + +log_must $ZFS snapshot $SNAPFS + +typeset -i i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + if [[ $WRAPPER == *"crypto"* ]] && \ + [[ ${RW_FS_PROP[$i]} == *"checksum"* ]]; then + (( i = i + 1 )) + continue + fi + log_must $ZFS clone -o ${RW_FS_PROP[$i]} $SNAPFS $TESTPOOL/$TESTCLONE + datasetexists $TESTPOOL/$TESTCLONE || \ + log_fail "zfs clone $TESTPOOL/$TESTCLONE fail." + propertycheck $TESTPOOL/$TESTCLONE ${RW_FS_PROP[i]} || \ + log_fail "${RW_FS_PROP[i]} is failed to set." + log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE + (( i = i + 1 )) +done + +log_pass "'zfs clone -o property=value filesystem' can successfully create" \ + "a ZFS clone filesystem with correct property set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_004_pos.ksh new file mode 100644 index 00000000000..e097fef8f78 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_004_pos.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_004_pos.ksh 1.1 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_004_pos +# +# DESCRIPTION: +# 'zfs clone -o property=value filesystem' can successfully create a ZFS +# clone filesystem with multiple properties set. +# +# STRATEGY: +# 1. Create a ZFS clone filesystem in the storage pool with multiple -o options +# 2. Verify the filesystem created successfully +# 3. Verify the properties are correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists $SNAPFS ; then + log_must $ZFS destroy -Rf $SNAPFS + fi +} + +if ! $(check_opt_support "clone" "-o") ; then + log_unsupported "'zfs clone -o' unsupported." +fi + +log_onexit cleanup + +log_assert "'zfs clone -o property=value filesystem' can successfully create" \ + "a ZFS clone filesystem with multiple properties set." + +typeset -i i=0 +typeset opts="" + +log_must $ZFS snapshot $SNAPFS + +while (( $i < ${#RW_FS_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then + opts="$opts -o ${RW_FS_PROP[$i]}" + fi + (( i = i + 1 )) +done + +log_must $ZFS clone $opts $SNAPFS $TESTPOOL/$TESTCLONE +datasetexists $TESTPOOL/$TESTCLONE || \ + log_fail "zfs create $TESTPOOL/$TESTCLONE fail." + +i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then + propertycheck $TESTPOOL/$TESTCLONE ${RW_FS_PROP[i]} || \ + log_fail "${RW_FS_PROP[i]} is failed to set." + fi + (( i = i + 1 )) +done + +log_pass "'zfs clone -o property=value filesystem' can successfully create" \ + "a ZFS clone filesystem with multiple properties set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_005_pos.ksh new file mode 100644 index 00000000000..5ba0c641b2e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_005_pos.ksh @@ -0,0 +1,99 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_005_pos.ksh 1.1 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_005_pos +# +# DESCRIPTION: +# 'zfs clone -o property=value -V size volume' can successfully create a ZFS +# clone volume with correct property set. +# +# STRATEGY: +# 1. Create a ZFS clone volume in the storage pool with -o option +# 2. Verify the volume created successfully +# 3. Verify the property is correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if snapexists $SNAPFS1 ; then + log_must $ZFS destroy -Rf $SNAPFS1 + fi +} + +if ! $(check_opt_support "clone" "-o") ; then + log_unsupported "'zfs clone -o' unsupported." +fi + +log_onexit cleanup + +log_assert "'zfs clone -o property=value -V size volume' can successfully" \ + "create a ZFS clone volume with correct property set." + +log_must $ZFS snapshot $SNAPFS1 +typeset -i i=0 +while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do + if [[ $WRAPPER == *"crypto"* ]] && \ + [[ ${RW_VOL_CLONE_PROP[$i]} == *"checksum"* ]]; then + (( i = i + 1 )) + continue + fi + + log_must $ZFS clone -o ${RW_VOL_CLONE_PROP[$i]} $SNAPFS1 $TESTPOOL/$TESTCLONE + datasetexists $TESTPOOL/$TESTCLONE || \ + log_fail "zfs clone $TESTPOOL/$TESTCLONE fail." + propertycheck $TESTPOOL/$TESTCLONE ${RW_VOL_CLONE_PROP[i]} || \ + log_fail "${RW_VOL_CLONE_PROP[i]} is failed to set." + log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE + + (( i = i + 1 )) +done + +log_pass "'zfs clone -o property=value volume' can successfully" \ + "create a ZFS clone volume with correct property set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_006_pos.ksh new file mode 100644 index 00000000000..6759ca33d6f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_006_pos.ksh @@ -0,0 +1,105 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_006_pos.ksh 1.1 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_006_pos +# +# DESCRIPTION: +# 'zfs clone -o property=value volume' can successfully create a ZFS +# clone volume with multiple properties set. +# +# STRATEGY: +# 1. Create a ZFS clone volume in the storage pool with -o option +# 2. Verify the volume created successfully +# 3. Verify the properties are correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if snapexists $SNAPFS1 ; then + log_must $ZFS destroy -Rf $SNAPFS1 + fi +} + +if ! $(check_opt_support "clone" "-o") ; then + log_unsupported "'zfs clone -o' unsupported." +fi + +log_onexit cleanup + +log_assert "'zfs clone -o property=value volume' can successfully" \ + "create a ZFS clone volume with multiple correct properties set." + +typeset -i i=0 +typeset opts="" + +log_must $ZFS snapshot $SNAPFS1 + +while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_VOL_CLONE_PROP[$i]} != *"checksum"* ]]; then + opts="$opts -o ${RW_VOL_CLONE_PROP[$i]}" + fi + (( i = i + 1 )) +done + +log_must $ZFS clone $opts $SNAPFS1 $TESTPOOL/$TESTCLONE + +i=0 +while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_VOL_CLONE_PROP[$i]} != *"checksum"* ]]; then + propertycheck $TESTPOOL/$TESTCLONE ${RW_VOL_CLONE_PROP[i]} || \ + log_fail "${RW_VOL_CLONE_PROP[i]} is failed to set." + fi + (( i = i + 1 )) +done + +log_pass "'zfs clone -o property=value volume' can successfully" \ + "create a ZFS clone volume with multiple correct properties set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_007_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_007_pos.ksh new file mode 100644 index 00000000000..2107270b901 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_007_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_007_pos.ksh 1.1 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_007_pos +# +# DESCRIPTION: +# 'zfs clone -o version=' could upgrade version, but downgrade is denied. +# +# STRATEGY: +# 1. Create clone with "-o version=" specified +# 2. Verify it succeed while upgrade, but fails while the version downgraded. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-16) +# +# __stc_assertion_end +# +################################################################################ + +if ! $(check_opt_support "upgrade") ; then + log_unsupported "'zfs upgrade' unsupported." +fi + +if ! $(check_opt_support "clone" "-o") ; then + log_unsupported "'zfs clone -o' unsupported." +fi + +ZFS_VERSION=$($ZFS upgrade | $HEAD -1 | $AWK '{print $NF}' \ + | $SED -e 's/\.//g') + +verify_runnable "both" + +function cleanup +{ + if snapexists $SNAPFS ; then + log_must $ZFS destroy -Rf $SNAPFS + fi +} + +log_onexit cleanup + +log_assert "'zfs clone -o version=' could upgrade version," \ + "but downgrade is denied." + +log_must $ZFS snapshot $SNAPFS + +typeset -i ver + +if (( ZFS_TEST_VERSION == 0 )) ; then + (( ZFS_TEST_VERSION = ZFS_VERSION )) +fi + +(( ver = ZFS_TEST_VERSION )) +while (( ver <= ZFS_VERSION )); do + log_must $ZFS clone -o version=$ver $SNAPFS $TESTPOOL/$TESTCLONE + cleanup + (( ver = ver + 1 )) +done + +(( ver = 0 )) +while (( ver < ZFS_TEST_VERSION )); do + log_mustnot $ZFS clone -o version=$ver \ + $SNAPFS $TESTPOOL/$TESTCLONE + log_mustnot datasetexists $TESTPOOL/$TESTCLONE + cleanup + (( ver = ver + 1 )) +done + +log_pass "'zfs clone -o version=' could upgrade version," \ + "but downgrade is denied." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_008_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_008_neg.ksh new file mode 100644 index 00000000000..db525b20992 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_008_neg.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_008_neg.ksh 1.1 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_008_neg +# +# DESCRIPTION: +# 'zfs clone -o ' fails with bad arguments, including: +# *Same property set multiple times via '-o property=value' +# *Volume's property set on filesystem +# +# STRATEGY: +# 1. Create an array of arguments +# 2. Execute 'zfs clone -o ' with each argument +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists $SNAPFS ; then + log_must $ZFS destroy -Rf $SNAPFS + fi +} + +if ! $(check_opt_support "clone" "-o") ; then + log_unsupported "'zfs clone -o' unsupported." +fi + +log_onexit cleanup + +log_assert "Verify 'zfs clone -o ' fails with bad argument." + +log_must $ZFS snapshot $SNAPFS + +typeset -i i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + log_mustnot $ZFS clone -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \ + $SNAPFS $TESTPOOL/$TESTCLONE + log_mustnot $ZFS clone -p -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \ + $SNAPFS $TESTPOOL/$TESTCLONE + ((i = i + 1)) +done + +i=0 +while (( $i < ${#VOL_ONLY_PROP[*]} )); do + log_mustnot $ZFS clone -o ${VOL_ONLY_PROP[i]} \ + $SNAPFS $TESTPOOL/$TESTCLONE + log_mustnot $ZFS clone -p -o ${VOL_ONLY_PROP[i]} \ + $SNAPFS $TESTPOOL/$TESTCLONE + ((i = i + 1)) +done + +log_pass "'zfs clone -o ' fails with bad argument." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_009_neg.ksh new file mode 100644 index 00000000000..fdfa158ebcf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_009_neg.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_009_neg.ksh 1.1 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_009_neg +# +# DESCRIPTION: +# 'zfs clone -o ' fails with badly formed arguments,including: +# *Same property set multiple times via '-o property=value' +# *Filesystems's property set on volume +# +# STRATEGY: +# 1. Create an array of badly formed arguments +# 2. For each argument, execute 'zfs clone -o ' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if snapexists $SNAPFS1 ; then + log_must $ZFS destroy -Rf $SNAPFS1 + fi +} + +if ! $(check_opt_support "clone" "-o") ; then + log_unsupported "'zfs clone -o' unsupported." +fi + +log_onexit cleanup + +log_assert "Verify 'zfs clone -o ' fails with bad argument." + +log_must $ZFS snapshot $SNAPFS1 + +typeset -i i=0 +while (( $i < ${#RW_VOL_PROP[*]} )); do + log_mustnot $ZFS clone -o ${RW_VOL_PROP[i]} -o ${RW_VOL_PROP[i]} \ + $SNAPFS1 $TESTPOOL/$TESTCLONE + log_mustnot $ZFS clone -p -o ${RW_VOL_PROP[i]} -o ${RW_VOL_PROP[i]} \ + $SNAPFS1 $TESTPOOL/$TESTCLONE + ((i = i + 1)) +done + +i=0 +while (( $i < ${#FS_ONLY_PROP[*]} )); do + log_mustnot $ZFS clone -o ${FS_ONLY_PROP[i]} \ + $SNAPFS1 $TESTPOOL/$TESTCLONE + log_mustnot $ZFS clone -p -o ${FS_ONLY_PROP[i]} \ + $SNAPFS1 $TESTPOOL/$TESTCLONE + ((i = i + 1)) +done + +log_pass "Verify 'zfs clone -o ' fails with bad argument." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_test.sh new file mode 100755 index 00000000000..5e82fd885ce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_clone/zfs_clone_test.sh @@ -0,0 +1,257 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_clone_001_neg cleanup +zfs_clone_001_neg_head() +{ + atf_set "descr" "Badly-formed 'zfs clone' with inapplicable scenariosshould return an error." + atf_set "require.progs" zfs +} +zfs_clone_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_clone_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_002_pos cleanup +zfs_clone_002_pos_head() +{ + atf_set "descr" "clone -p should work as expected." + atf_set "require.progs" zfs +} +zfs_clone_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_clone_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_003_pos cleanup +zfs_clone_003_pos_head() +{ + atf_set "descr" "'zfs clone -o property=value filesystem' can successfully createa ZFS clone filesystem with correct property set." + atf_set "require.progs" zfs +} +zfs_clone_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_clone_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_004_pos cleanup +zfs_clone_004_pos_head() +{ + atf_set "descr" "'zfs clone -o property=value filesystem' can successfully createa ZFS clone filesystem with multiple properties set." + atf_set "require.progs" zfs +} +zfs_clone_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_clone_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_005_pos cleanup +zfs_clone_005_pos_head() +{ + atf_set "descr" "'zfs clone -o property=value -V size volume' can successfullycreate a ZFS clone volume with correct property set." + atf_set "require.progs" zfs +} +zfs_clone_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_clone_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_006_pos cleanup +zfs_clone_006_pos_head() +{ + atf_set "descr" "'zfs clone -o property=value volume' can successfullycreate a ZFS clone volume with multiple correct properties set." + atf_set "require.progs" zfs +} +zfs_clone_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_clone_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_007_pos cleanup +zfs_clone_007_pos_head() +{ + atf_set "descr" "'zfs clone -o version=' could upgrade version,but downgrade is denied." + atf_set "require.progs" zfs +} +zfs_clone_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_007_pos.ksh || atf_fail "Testcase failed" +} +zfs_clone_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_008_neg cleanup +zfs_clone_008_neg_head() +{ + atf_set "descr" "Verify 'zfs clone -o ' fails with bad argument." + atf_set "require.progs" zfs +} +zfs_clone_008_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_008_neg.ksh || atf_fail "Testcase failed" +} +zfs_clone_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_009_neg cleanup +zfs_clone_009_neg_head() +{ + atf_set "descr" "Verify 'zfs clone -o ' fails with bad argument." + atf_set "require.progs" zfs +} +zfs_clone_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_009_neg.ksh || atf_fail "Testcase failed" +} +zfs_clone_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_clone.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_clone_001_neg + atf_add_test_case zfs_clone_002_pos + atf_add_test_case zfs_clone_003_pos + atf_add_test_case zfs_clone_004_pos + atf_add_test_case zfs_clone_005_pos + atf_add_test_case zfs_clone_006_pos + atf_add_test_case zfs_clone_007_pos + atf_add_test_case zfs_clone_008_neg + atf_add_test_case zfs_clone_009_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/Makefile new file mode 100644 index 00000000000..a951dc0b0cf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/Makefile @@ -0,0 +1,24 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_copies +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_copies_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_copies.cfg +${PACKAGE}FILES+= zfs_copies_001_pos.ksh +${PACKAGE}FILES+= zfs_copies_004_neg.ksh +${PACKAGE}FILES+= zfs_copies_005_neg.ksh +${PACKAGE}FILES+= zfs_copies.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_copies_006_pos.ksh +${PACKAGE}FILES+= zfs_copies_002_pos.ksh +${PACKAGE}FILES+= zfs_copies_003_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/cleanup.ksh new file mode 100644 index 00000000000..8441c267504 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/cleanup.ksh @@ -0,0 +1,48 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.4 08/11/03 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.kshlib +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.cfg + +if ! fs_prop_exist "copies" ; then + log_unsupported "copies is not supported by this release." +fi + +# +# umount the ufs fs if there is timedout in the ufs test +# + +if ismounted $UFS_MNTPOINT ufs ; then + log_must $UMOUNT -f $UFS_MNTPOINT + $RM -fr $UFS_MNTPOINT +fi + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/setup.ksh new file mode 100644 index 00000000000..fdb392b8293 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/setup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +if ! fs_prop_exist "copies" ; then + log_unsupported "copies is not supported by this release." +fi + +DISK=${DISKS%% *} +default_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies.cfg new file mode 100644 index 00000000000..7cefd082bce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies.cfg @@ -0,0 +1,40 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies.cfg 1.2 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export ZPOOL_VERSION_1_FILES="zfs-pool-v1.dat.Z" +export ZPOOL_VERSION_1_NAME="v1-pool" + +export FILESIZE=10m +export FILE=file.${TESTCASE_ID} +export SLEEPTIME=30 +export UFS_MNTPOINT=/testdir_nfs_mntpoint diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies.kshlib new file mode 100644 index 00000000000..3777c4950a4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies.kshlib @@ -0,0 +1,146 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies.kshlib 1.3 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Compare the value of copies property with specified value +# $1, the dataset name +# $2, the expected copies value +# +function cmp_prop +{ + typeset ds=$1 + typeset val_expect=$2 + typeset val_actual + + val_actual=$(get_prop copies $ds) + if [[ $val_actual != $val_expect ]]; then + log_fail "Expected value ($val_expect) != " \ + "actual value ($val_actual)" + fi +} + +# +# Get the value of property used via zfs list +# $1, the dataset name +# +function get_used_prop +{ + typeset ds=$1 + typeset used + + used=`$ZFS list -H -o used $ds` + used=${used%[m|M]} + if [[ $used == *K ]]; then + used=0 + fi + $ECHO $used +} + +# +# Check the used space is charged correctly +# $1, the number of used space +# $2, the expected common factor between the used space and the file space +# +function check_used +{ + typeset charged_spc=$1 + typeset -i used + typeset -i expected_cfactor=$2 + typeset -i cfactor + typeset -i fsize=${FILESIZE%[m|M]} + + (( used = ${charged_spc%[m|M]} )) + (( cfactor = used / fsize )) + if (( cfactor != expected_cfactor )); then + log_fail "The space is not charged correctly while setting"\ + "copies as $expected_cfactor." + fi +} + +# +# test ncopies on volume +# $1 test type zfs|ufs, default zfs +# $2 copies +# $3 mntp for ufs test +function do_vol_test +{ + typeset type=$1 + typeset copy=$2 + typeset mntp=$3 + + vol=$TESTPOOL/$TESTVOL1 + vol_b_path=/dev/zvol/$TESTPOOL/$TESTVOL1 + vol_r_path=/dev/zvol/$TESTPOOL/$TESTVOL1 + + log_must $ZFS create -V $VOLSIZE -o copies=$copy $vol + if fs_prop_exist "refreserv" ; then + log_must $ZFS set refreservation=none $vol + fi + if [[ $type == "ufs" ]]; then + log_must $ECHO y | $NEWFS $vol_r_path >/dev/null 2>&1 + log_must $MOUNT -F ufs -o rw $vol_b_path $mntp + else + log_must $ZPOOL create $TESTPOOL1 $vol_b_path + log_must $ZFS create $TESTPOOL1/$TESTFS1 + fi + + (( nfilesize = copy * ${FILESIZE%m} )) + pre_used=$(get_used_prop $vol) + (( target_size = pre_used + nfilesize )) + + if [[ $type == "ufs" ]]; then + log_must $MKFILE $FILESIZE $mntp/$FILE + else + log_must $MKFILE $FILESIZE /$TESTPOOL1/$TESTFS1/$FILE + fi + + post_used=$(get_used_prop $vol) + while (( post_used < target_size )) ; do + sleep 1 + post_used=$(get_used_prop $vol) + done + + (( used = post_used - pre_used )) + if (( used < nfilesize )); then + log_fail "The space is not charged correctly while setting"\ + "copies as $copy" + fi + + if [[ $type == "ufs" ]]; then + $UMOUNT $mntp + else + log_must $ZPOOL destroy $TESTPOOL1 + fi + + log_must $ZFS destroy $vol +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_001_pos.ksh new file mode 100644 index 00000000000..b11219dc043 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_001_pos.ksh @@ -0,0 +1,126 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies_001_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_copies_001_pos +# +# DESCRIPTION: +# Verify "copies" property can be correctly set as 1,2 and 3 and different +# filesystem can have different value of "copies" property within the same pool. +# +# STRATEGY: +# 1. Create different filesystems with copies set as 1,2,3; +# 2. Verify that the "copies" property has been set correctly +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset ds + + for ds in $fs1 $fs2 $vol1 $vol2; do + if datasetexists $ds; then + log_must $ZFS destroy $ds + fi + done +} + +log_assert "Verify 'copies' property with correct arguments works or not." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +fs1=$TESTPOOL/$TESTFS1 +fs2=$TESTPOOL/$TESTFS2 +vol=$TESTPOOL/$TESTVOL +vol1=$TESTPOOL/$TESTVOL1 +vol2=$TESTPOOL/$TESTVOL2 + +# +# Check the default value for copies property +# +for ds in $fs $vol; do + cmp_prop $ds 1 +done + +for val in 1 2 3; do + log_must $ZFS create -o copies=$val $fs1 + if is_global_zone; then + log_must $ZFS create -V $VOLSIZE -o copies=$val $vol1 + else + log_must $ZFS create -o copies=$val $vol1 + fi + for ds in $fs1 $vol1; do + cmp_prop $ds $val + done + + for val2 in 3 2 1; do + log_must $ZFS create -o copies=$val2 $fs2 + if is_global_zone; then + log_must $ZFS create -V $VOLSIZE -o copies=$val2 $vol2 + else + log_must $ZFS create -o copies=$val2 $vol2 + fi + for ds in $fs2 $vol2; do + cmp_prop $ds $val2 + log_must $ZFS destroy $ds + done + done + + for ds in $fs1 $vol1; do + log_must $ZFS destroy $ds + done + +done + +for val in 3 2 1; do + for ds in $fs $vol; do + log_must $ZFS set copies=$val $ds + cmp_prop $ds $val + done +done + +log_pass "'copies' property with correct arguments works as expected. " diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_002_pos.ksh new file mode 100644 index 00000000000..ac737d8c483 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_002_pos.ksh @@ -0,0 +1,117 @@ +#!/usr/local/bin/ksh93 +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies_002_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_copies_002_pos +# +# DESCRIPTION: +# Verify that the space used by multiple copies is charged correctly +# +# STRATEGY: +# 1. Create filesystems with copies set as 2,3 respectively; +# 2. Copy specified size data into each filesystem; +# 3. Verify that the space is charged as expected with zfs list, ls -s, df(1m), +# du(1) commands; +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset val + + for val in 1 2 3; do + if datasetexists $TESTPOOL/fs_$val; then + log_must $ZFS destroy $TESTPOOL/fs_$val + fi + done +} + +log_assert "Verify that the space used by multiple copies is charged correctly." +log_onexit cleanup + +for val in 1 2 3; do + log_must $ZFS create -o copies=$val $TESTPOOL/fs_$val + + log_must $MKFILE $FILESIZE /$TESTPOOL/fs_$val/$FILE +done + +# +# Sync up the filesystem +# +$SYNC + +# +# Verify 'zfs list' can correctly list the space charged +# +log_note "Verify 'zfs list' can correctly list the space charged." +fsize=${FILESIZE%[m|M]} +for val in 1 2 3; do + used=$(get_used_prop $TESTPOOL/fs_$val) + check_used $used $val +done + +log_note "Verify 'ls -s' can correctly list the space charged." +for val in 1 2 3; do + blks=`$LS -lsk /$TESTPOOL/fs_$val/$FILE | $AWK '{print $1}'` + (( used = blks / 1024 )) + check_used $used $val +done + +log_note "Verify df(1M) can corectly display the space charged." +for val in 1 2 3; do + used=`$DF -m /$TESTPOOL/fs_$val | $GREP $TESTPOOL/fs_$val \ + | $AWK -v fs=fs_$val '$4 ~ fs {print $3}'` + check_used $used $val +done + +log_note "Verify du(1) can correctly display the space charged." +for val in 1 2 3; do + used=`$DU -h /$TESTPOOL/fs_$val/$FILE | $AWK '{print $1}'` + check_used $used $val +done + +log_pass "The space used by multiple copies is charged correctly as expected. " diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_003_pos.ksh new file mode 100644 index 00000000000..f77acd8c541 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_003_pos.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies_003_pos.ksh 1.2 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_copies_003_pos +# +# DESCRIPTION: +# Verify that the volume space used by multiple copies is charged correctly +# +# STRATEGY: +# 1. Create volume; +# 2. Create ZFS filesystem based on the volume; +# 3. Set the copies property of volume to 1,2 or 3; +# 4. Copy specified size data into each filesystem; +# 5. Verify that the volume space is charged as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL1; then + destroy_pool $TESTPOOL1 + fi + + if datasetexists $vol; then + log_must $ZFS destroy $vol + fi +} + +log_assert "Verify that ZFS volume space used by multiple copies is charged correctly." +log_onexit cleanup +vol=$TESTPOOL/$TESTVOL1 + + +for val in 1 2 3; do + do_vol_test zfs $val +done + +log_pass "The volume space used by multiple copies is charged correctly as expected. " diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_004_neg.ksh new file mode 100644 index 00000000000..7104e6f1487 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_004_neg.ksh @@ -0,0 +1,71 @@ +#!/usr/local/bin/ksh93 +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies_004_neg.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_copies_004_neg +# +# DESCRIPTION: +# Verify that copies cannot be set to other value except for 1, 2 or 3 +# +# STRATEGY: +# 1. Create filesystems with copies set as any value other than 1, 2 or 3 +# 2. Verify that the create operations fail +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify that copies property cannot be set to any value other than 1,2 or 3" + +set -A badval 0 01 02 03 0 -1 -2 -3 10 20 30 4 5 6 ? * blah + +for val in ${badval[@]}; do + log_mustnot $ZFS create -o copies=$val $TESTPOOL/$TESTFS1 + log_mustnot $ZFS create -V $VOLSIZE -o copies=$val $TESTPOOL/$TESTVOL1 + log_mustnot $ZFS set copies=$val $TESTPOOL/$TESTFS + log_mustnot $ZFS set copies=$val $TESTPOOL/$TESTVOL +done + +log_pass "The copies property cannot be set to any value other than 1,2 or 3 as expected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_005_neg.ksh new file mode 100644 index 00000000000..0f2e2048b63 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_005_neg.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies_005_neg.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_copies_005_neg +# +# DESCRIPTION: +# Verify that copies cannot be set with pool version 1 +# +# STRATEGY: +# 1. Create filesystems with copies set in a pool with version 1 +# 2. Verify that the create operations fail +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if poolexists $ZPOOL_VERSION_1_NAME; then + destroy_pool $ZPOOL_VERSION_1_NAME + fi + + if [[ -f $TESTDIR/$ZPOOL_VERSION_1_FILES ]]; then + rm -f $TESTDIR/$ZPOOL_VERSION_1_FILES + fi +} + +log_assert "Verify that copies cannot be set with pool version 1" +log_onexit cleanup + +$CP $STF_SUITE/tests/cli_root/zpool_upgrade/blockfiles/$ZPOOL_VERSION_1_FILES $TESTDIR +$UNCOMPRESS $TESTDIR/$ZPOOL_VERSION_1_FILES +log_must $ZPOOL import -d $TESTDIR $ZPOOL_VERSION_1_NAME +log_must $ZFS create $ZPOOL_VERSION_1_NAME/$TESTFS +log_must $ZFS create -V 1m $ZPOOL_VERSION_1_NAME/$TESTVOL + +for val in 3 2 1; do + for ds in $ZPOOL_VERSION_1_NAME/$TESTFS $ZPOOL_VERSION_1_NAME/$TESTVOL; do + log_mustnot $ZFS set copies=$val $ds + done + for ds in $ZPOOL_VERSION_1_NAME/$TESTFS1 $ZPOOL_VERSION_1_NAME/$TESTVOL1; do + log_mustnot $ZFS create -o copies=$val $ds + done +done + +log_pass "Verification pass: copies cannot be set with pool version 1. " diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_006_pos.ksh new file mode 100644 index 00000000000..719f9b8eb55 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_006_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_copies_006_pos.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_copies/zfs_copies.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_copies_006_pos +# +# DESCRIPTION: +# Verify that the volume space used by multiple copies is charged correctly +# +# STRATEGY: +# 1. Create volume +# 2. Create UFS filesystem based on the volume +# 3. Set the copies property of volume to 1,2 or 3 +# 4. Copy specified size data into each filesystem +# 5. Verify that the volume space is charged as expected +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if ismounted $mntp ufs ; then + log_must $UMOUNT $mntp + fi + + if datasetexists $vol; then + log_must $ZFS destroy $vol + fi + + if [[ -d $mntp ]]; then + $RM -rf $mntp + fi +} + + +log_assert "Verify that ZFS volume space used by multiple copies is charged correctly." +log_onexit cleanup +mntp=$UFS_MNTPOINT +vol=$TESTPOOL/$TESTVOL1 + +if [[ ! -d $mntp ]]; then + $MKDIR -p $mntp +fi + +for val in 1 2 3; do + do_vol_test ufs $val $mntp +done + +log_pass "The volume space used by multiple copies is charged correctly as expected. " diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_test.sh new file mode 100755 index 00000000000..b480821c0c9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_copies/zfs_copies_test.sh @@ -0,0 +1,196 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_copies_001_pos cleanup +zfs_copies_001_pos_head() +{ + atf_set "descr" "Verify 'copies' property with correct arguments works or not." + atf_set "require.progs" zfs +} +zfs_copies_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_copies_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_copies_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_copies_002_pos cleanup +zfs_copies_002_pos_head() +{ + atf_set "descr" "Verify that the space used by multiple copies is charged correctly." + atf_set "require.progs" zfs +} +zfs_copies_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_copies_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_copies_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_copies_003_pos cleanup +zfs_copies_003_pos_head() +{ + atf_set "descr" "Verify that ZFS volume space used by multiple copies is charged correctly." + atf_set "require.progs" zfs +} +zfs_copies_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + verify_zvol_recursive + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_copies_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_copies_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_copies_004_neg cleanup +zfs_copies_004_neg_head() +{ + atf_set "descr" "Verify that copies property cannot be set to any value other than 1,2 or 3" + atf_set "require.progs" zfs +} +zfs_copies_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + verify_disk_count "$DISKS" 1 + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_copies_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_copies_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_copies_005_neg cleanup +zfs_copies_005_neg_head() +{ + atf_set "descr" "Verify that copies cannot be set with pool version 1" + atf_set "require.progs" zfs zpool +} +zfs_copies_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_copies_005_neg.ksh || atf_fail "Testcase failed" +} +zfs_copies_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_copies_006_pos cleanup +zfs_copies_006_pos_head() +{ + atf_set "descr" "Verify that ZFS volume space used by multiple copies is charged correctly." + atf_set "require.progs" zfs +} +zfs_copies_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + verify_disk_count "$DISKS" 1 + atf_skip "PR 225960 g_access leak when unmounting UFS on a zvol" + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_copies_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_copies_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_copies.kshlib + . $(atf_get_srcdir)/zfs_copies.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_copies_001_pos + atf_add_test_case zfs_copies_002_pos + atf_add_test_case zfs_copies_003_pos + atf_add_test_case zfs_copies_004_neg + atf_add_test_case zfs_copies_005_neg + atf_add_test_case zfs_copies_006_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/Makefile new file mode 100644 index 00000000000..080124a3ae6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/Makefile @@ -0,0 +1,32 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_create +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_create_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= properties.kshlib +${PACKAGE}FILES+= zfs_create_011_pos.ksh +${PACKAGE}FILES+= zfs_create_010_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_create_009_neg.ksh +${PACKAGE}FILES+= zfs_create_004_pos.ksh +${PACKAGE}FILES+= zfs_create_common.kshlib +${PACKAGE}FILES+= zfs_create_008_neg.ksh +${PACKAGE}FILES+= zfs_create_005_pos.ksh +${PACKAGE}FILES+= zfs_create_001_pos.ksh +${PACKAGE}FILES+= zfs_create_007_pos.ksh +${PACKAGE}FILES+= zfs_create_003_pos.ksh +${PACKAGE}FILES+= zfs_create_012_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_create_013_pos.ksh +${PACKAGE}FILES+= zfs_create.cfg +${PACKAGE}FILES+= zfs_create_006_pos.ksh +${PACKAGE}FILES+= zfs_create_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/properties.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/properties.kshlib new file mode 100644 index 00000000000..ec69e3d7162 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/properties.kshlib @@ -0,0 +1,83 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)properties.kshlib 1.6 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +set -A RW_FS_PROP "quota=512M" \ + "reservation=512M" \ + "recordsize=64K" \ + "mountpoint=/tmp/mnt${TESTCASE_ID}" \ + "checksum=fletcher2" \ + "compression=lzjb" \ + "atime=off" \ + "devices=off" \ + "exec=off" \ + "setuid=off" \ + "readonly=on" \ + "snapdir=visible" \ + "aclmode=discard" \ + "aclinherit=discard" \ + "canmount=off" \ + "local:department=123" + +is_global_zone && \ + set -A RW_FS_PROP ${RW_FS_PROP[*]} "sharenfs=on" + +set -A RW_VOL_PROP "volblocksize=16K" \ + "checksum=fletcher2" \ + "compression=lzjb" \ + "readonly=on" \ + "local:department=123" + +set -A RW_VOL_CLONE_PROP "checksum=fletcher2" \ + "compression=lzjb" \ + "readonly=on" \ + "local:department=123" + +set -A FS_ONLY_PROP "quota=512M" \ + "recordsize=64K" \ + "mountpoint=/tmp/mnt${TESTCASE_ID}" \ + "sharenfs=on" \ + "atime=off" \ + "devices=off" \ + "exec=off" \ + "setuid=off" \ + "snapdir=visible" \ + "aclmode=discard" \ + "aclinherit=discard" \ + "canmount=off" + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A FS_ONLY_PROP ${FS_ONLY_PROP[*]} "version=1" +fi + +set -A VOL_ONLY_PROP "volblocksize=16K" "volsize=512M" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create.cfg new file mode 100644 index 00000000000..8cbf80a79ed --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create.cfg @@ -0,0 +1,56 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create.cfg 1.3 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export BYND_MAX_NAME="byondmaxnamelength\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789" + +# There're 3 different prompt messages while create +# a volume that great than 1TB on 32-bit +# - volume size exceeds limit for this system. (happy gate) +# - max volume size is 1TB on 32-bit systems (s10u2) +# - value is too large (old) + +export VOL_LIMIT_KEYWORD1="1TB on 32-bit" +export VOL_LIMIT_KEYWORD2="value is too large" +export VOL_LIMIT_KEYWORD3="volume size exceeds limit" + +set -A size "8k" "8K" "1m" "1M" "1mb" "1mB" "1Mb" "1MB" "1g" "1G" \ + "1p" "1P" "1z" "1Z" "1gb" "1gB" "1Gb" "1GB" "1pb" "1pB" "1Pb" \ + "1PB" "1zb" "1zB" "1Zb" "1ZB" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_001_pos.ksh new file mode 100644 index 00000000000..1c06a14f6da --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_001_pos.ksh @@ -0,0 +1,84 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_001_pos +# +# DESCRIPTION: +# 'zfs create ' can create a ZFS filesystem in the namespace. +# +# STRATEGY: +# 1. Create a ZFS filesystem in the storage pool +# 2. Verify the filesystem created successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +function cleanup +{ + typeset -i i=0 + while (( $i < ${#datasets[*]} )); do + datasetexists ${datasets[$i]} && \ + log_must $ZFS destroy -f ${datasets[$i]} + ((i = i + 1)) + done +} + +log_onexit cleanup + +set -A datasets "$TESTPOOL/$TESTFS1" "$TESTPOOL/$LONGFSNAME" "$TESTPOOL/..." \ + "$TESTPOOL/_1234_" + +log_assert "'zfs create ' can create a ZFS filesystem in the namespace." + +typeset -i i=0 +while (( $i < ${#datasets[*]} )); do + log_must $ZFS create ${datasets[$i]} + datasetexists ${datasets[$i]} || \ + log_fail "zfs create ${datasets[$i]} fail." + ((i = i + 1)) +done + +log_pass "'zfs create ' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_002_pos.ksh new file mode 100644 index 00000000000..2ac46024215 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_002_pos.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_002_pos.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create.cfg + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_002_pos +# +# DESCRIPTION: +# 'zfs create -s -V ' can create various-size sparse volume. +# +# STRATEGY: +# 1. Create a volume in the storage pool. +# 2. Verify the volume is created correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset -i j=0 + while [[ $j -lt ${#size[*]} ]]; do + if datasetexists $TESTPOOL/${TESTVOL}${size[j]}; then + log_must $ZFS destroy $TESTPOOL/${TESTVOL}${size[j]} + fi + ((j = j + 1)) + done +} + +log_onexit cleanup + + +log_assert "'zfs create -s -V ' succeeds" + +typeset -i j=0 +while (( $j < ${#size[*]} )); do + typeset cmdline="$ZFS create -s -V ${size[j]} \ + $TESTPOOL/${TESTVOL}${size[j]}" + + str=$(eval $cmdline 2>&1) + if (( $? == 0 )); then + log_note "SUCCESS: $cmdline" + log_must datasetexists $TESTPOOL/${TESTVOL}${size[j]} + elif [[ $str == *${VOL_LIMIT_KEYWORD1}* || \ + $str == *${VOL_LIMIT_KEYWORD2}* || \ + $str == *${VOL_LIMIT_KEYWORD3}* ]] + then + log_note "UNSUPPORTED: $cmdline" + else + log_fail "$cmdline" + fi + + ((j = j + 1)) + +done +log_pass "'zfs create -s -V ' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_003_pos.ksh new file mode 100644 index 00000000000..b7193daf966 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_003_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_003_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_003_pos +# +# DESCRIPTION: +# 'zfs create [-b ] -V ' can create a volume +# with specified blocksize, which is power of 2 between 512 - 128k. +# +# STRATEGY: +# 1. Create a volume with blocksize in the storage pool +# 2. Verify the volume created successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-11-23) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $vol && \ + log_must $ZFS destroy -f $vol +} + +log_assert "Verify creating volume with specified blocksize works." +log_onexit cleanup + +set -A options "" "-b 1k" "-b 1K" "-b 1024" "-b 1024b" +vol=$TESTPOOL/$TESTVOL + +typeset -i i=0 +while (( i < ${#options[*]} )); do + log_must $ZFS create ${options[i]} -V $VOLSIZE $vol + datasetexists $vol || \ + log_fail "zfs create ${options[i]} -V $VOLSIZE $vol fail." + + log_must $ZFS destroy -f $vol + ((i = i + 1)) +done + +log_pass "'zfs create [-b ] -V ' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_004_pos.ksh new file mode 100644 index 00000000000..39b751102ac --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_004_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_004_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_004_pos +# +# DESCRIPTION: +# 'zfs create -o property=value filesystem' can successfully create a ZFS +# filesystem with correct property set. +# +# STRATEGY: +# 1. Create a ZFS filesystem in the storage pool with -o option +# 2. Verify the filesystem created successfully +# 3. Verify the property is correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTFS1 && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 +} + +log_onexit cleanup + + +log_assert "'zfs create -o property=value filesystem' can successfully create \ + a ZFS filesystem with correct property set." + +typeset -i i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + if [[ $WRAPPER == *"crypto"* ]] && \ + [[ ${RW_FS_PROP[$i]} == *"checksum"* ]]; then + (( i = i + 1 )) + continue + fi + log_must $ZFS create -o ${RW_FS_PROP[$i]} $TESTPOOL/$TESTFS1 + datasetexists $TESTPOOL/$TESTFS1 || \ + log_fail "zfs create $TESTPOOL/$TESTFS1 fail." + propertycheck $TESTPOOL/$TESTFS1 ${RW_FS_PROP[i]} || \ + log_fail "${RW_FS_PROP[i]} is failed to set." + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + (( i = i + 1 )) +done + +log_pass "'zfs create -o property=value filesystem' can successfully create \ + a ZFS filesystem with correct property set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_005_pos.ksh new file mode 100644 index 00000000000..6313b0b7daf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_005_pos.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_005_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_005_pos +# +# DESCRIPTION: +# 'zfs create -o property=value filesystem' can successfully create a ZFS +# filesystem with multiple properties set. +# +# STRATEGY: +# 1. Create a ZFS filesystem in the storage pool with multiple -o options +# 2. Verify the filesystem created successfully +# 3. Verify the properties are correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTFS1 && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 +} + +log_onexit cleanup + + +log_assert "'zfs create -o property=value filesystem' can successfully create \ + a ZFS filesystem with multiple properties set." + +typeset -i i=0 +typeset opts="" + +while (( $i < ${#RW_FS_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then + opts="$opts -o ${RW_FS_PROP[$i]}" + fi + (( i = i + 1 )) +done + +log_must $ZFS create $opts $TESTPOOL/$TESTFS1 +datasetexists $TESTPOOL/$TESTFS1 || \ + log_fail "zfs create $TESTPOOL/$TESTFS1 fail." + +i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then + propertycheck $TESTPOOL/$TESTFS1 ${RW_FS_PROP[i]} || \ + log_fail "${RW_FS_PROP[i]} is failed to set." + fi + (( i = i + 1 )) +done + +log_pass "'zfs create -o property=value filesystem' can successfully create \ + a ZFS filesystem with multiple properties set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_006_pos.ksh new file mode 100644 index 00000000000..01537d4dc39 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_006_pos.ksh @@ -0,0 +1,103 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_006_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_006_pos +# +# DESCRIPTION: +# 'zfs create -o property=value -V size volume' can successfully create a ZFS +# volume with correct property set. +# +# STRATEGY: +# 1. Create a ZFS volume in the storage pool with -o option +# 2. Verify the volume created successfully +# 3. Verify the property is correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL1 && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1 +} + +log_onexit cleanup + + +log_assert "'zfs create -o property=value -V size volume' can successfully \ + create a ZFS volume with correct property set." + +typeset -i i=0 +while (( $i < ${#RW_VOL_PROP[*]} )); do + if [[ $WRAPPER == *"crypto"* ]] && \ + [[ ${RW_VOL_PROP[$i]} == *"checksum"* ]]; then + (( i = i + 1 )) + continue + fi + + log_must $ZFS create -o ${RW_VOL_PROP[$i]} -V $VOLSIZE \ + $TESTPOOL/$TESTVOL1 + datasetexists $TESTPOOL/$TESTVOL1 || \ + log_fail "zfs create -V size $TESTPOOL/$TESTVOL1 fail." + propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \ + log_fail "${RW_VOL_PROP[i]} is failed to set." + log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1 + + log_must $ZFS create -s -o ${RW_VOL_PROP[$i]} -V $VOLSIZE \ + $TESTPOOL/$TESTVOL1 + datasetexists $TESTPOOL/$TESTVOL1 || \ + log_fail "zfs create -s -V $TESTPOOL/$TESTVOL1 fail." + propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \ + log_fail "${RW_VOL_PROP[i]} is failed to set." + log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1 + + (( i = i + 1 )) +done + +log_pass "'zfs create -o property=value -V size volume' can successfully \ + create a ZFS volume with correct property set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_007_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_007_pos.ksh new file mode 100644 index 00000000000..4678fa93073 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_007_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_007_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_007_pos +# +# DESCRIPTION: +# 'zfs create -o property=value -V size volume' can successfully create a ZFS +# volume with multiple properties set. +# +# STRATEGY: +# 1. Create a ZFS volume in the storage pool with -o option +# 2. Verify the volume created successfully +# 3. Verify the properties are correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL1 && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTVOL1 +} + +log_onexit cleanup + + +log_assert "'zfs create -o property=value -V size volume' can successfully \ + create a ZFS volume with correct property set." + +typeset -i i=0 +typeset opts="" + +while (( $i < ${#RW_VOL_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_VOL_PROP[$i]} != *"checksum"* ]]; then + opts="$opts -o ${RW_VOL_PROP[$i]}" + fi + (( i = i + 1 )) +done + +log_must $ZFS create $opts -V $VOLSIZE $TESTPOOL/$TESTVOL +datasetexists $TESTPOOL/$TESTVOL || \ + log_fail "zfs create $TESTPOOL/$TESTVOL fail." +log_must $ZFS create -s $opts -V $VOLSIZE $TESTPOOL/$TESTVOL1 +datasetexists $TESTPOOL/$TESTVOL1 || \ + log_fail "zfs create $TESTPOOL/$TESTVOL1 fail." + +i=0 +while (( $i < ${#RW_VOL_PROP[*]} )); do + if [[ $WRAPPER != *"crypto"* ]] || \ + [[ ${RW_VOL_PROP[$i]} != *"checksum"* ]]; then + propertycheck $TESTPOOL/$TESTVOL ${RW_VOL_PROP[i]} || \ + log_fail "${RW_VOL_PROP[i]} is failed to set." + propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \ + log_fail "${RW_VOL_PROP[i]} is failed to set." + fi + (( i = i + 1 )) +done + +log_pass "'zfs create -o property=value -V size volume' can successfully \ + create a ZFS volume with correct property set." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_008_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_008_neg.ksh new file mode 100644 index 00000000000..f369d2ae881 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_008_neg.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_008_neg.ksh 1.4 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_008_neg +# +# DESCRIPTION: +# 'zfs create' should return an error with badly formed parameters. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute 'zfs create' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1 ; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + fi +} + +log_onexit cleanup + +set -A args "ab" "-?" "-cV" "-Vc" "-c -V" "c" "V" "--c" "-e" "-s" \ + "-blah" "-cV 12k" "-s -cV 1P" "-sc" "-Vs 5g" "-o" "--o" "-O" "--O" \ + "-o QuOta=none" "-o quota=non" "-o quota=abcd" "-o quota=0" "-o quota=" \ + "-o ResErVaTi0n=none" "-o reserV=none" "-o reservation=abcd" "-o reserv=" \ + "-o recorDSize=64k" "-o recordsize=256K" "-o recordsize=256" \ + "-o recsize=" "-o recsize=zero" "-o recordsize=0" \ + "-o mountPoint=/tmp/tmpfile${TESTCASE_ID}" "-o mountpoint=non0" "-o mountpoint=" \ + "-o mountpoint=LEGACY" "-o mounpoint=none" \ + "-o sharenfs=ON" "-o ShareNFS=off" "-o sharenfs=sss" \ + "-o checkSUM=on" "-o checksum=SHA256" "-o chsum=off" "-o checksum=aaa" \ + "-o checkSUM=on -V $VOLSIZE" "-o checksum=SHA256 -V $VOLSIZE" \ + "-o chsum=off -V $VOLSIZE" "-o checksum=aaa -V $VOLSIZE" \ + "-o compression=of" "-o ComPression=lzjb" "-o compress=ON" "-o compress=a" \ + "-o compression=of -V $VOLSIZE" "-o ComPression=lzjb -V $VOLSIZE" \ + "-o compress=ON -V $VOLSIZE" "-o compress=a -V $VOLSIZE" \ + "-o atime=ON" "-o ATime=off" "-o atime=bbb" \ + "-o deviCes=on" "-o devices=OFF" "-o devices=aaa" \ + "-o exec=ON" "-o EXec=off" "-o exec=aaa" \ + "-o readonly=ON" "-o reADOnly=off" "-o rdonly=OFF" "-o rdonly=aaa" \ + "-o readonly=ON -V $VOLSIZE" "-o reADOnly=off -V $VOLSIZE" \ + "-o rdonly=OFF -V $VOLSIZE" "-o rdonly=aaa -V $VOLSIZE" \ + "-o zoned=ON" "-o ZoNed=off" "-o zoned=aaa" \ + "-o snapdIR=hidden" "-o snapdir=VISible" "-o snapdir=aaa" \ + "-o aclmode=DIScard" "-o aclmODE=groupmask" "-o aclmode=aaa" \ + "-o aclinherit=deny" "-o aclinHerit=secure" "-o aclinherit=aaa" \ + "-o type=volume" "-o type=snapshot" "-o type=filesystem" \ + "-o type=volume -V $VOLSIZE" "-o type=snapshot -V $VOLSIZE" \ + "-o type=filesystem -V $VOLSIZE" \ + "-o creation=aaa" "-o creation=aaa -V $VOLSIZE" \ + "-o used=10K" "-o used=10K -V $VOLSIZE" \ + "-o available=10K" "-o available=10K -V $VOLSIZE" \ + "-o referenced=10K" "-o referenced=10K -V $VOLSIZE" \ + "-o compressratio=1.00x" "-o compressratio=1.00x -V $VOLSIZE" \ + "-o version=0" "-o version=1.234" "-o version=10K" "-o version=-1" \ + "-o version=aaa" "-o version=999" + +log_assert "'zfs create' should return an error with badly-formed parameters." + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZFS create ${args[i]} $TESTPOOL/$TESTFS1 + log_mustnot $ZFS create -p ${args[i]} $TESTPOOL/$TESTFS1 + ((i = i + 1)) +done + +log_pass "'zfs create' with badly formed parameters failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_009_neg.ksh new file mode 100644 index 00000000000..5113ce3b38e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_009_neg.ksh @@ -0,0 +1,139 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_009_neg.ksh 1.4 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_009_neg +# +# DESCRIPTION: +# 'zfs create ' fails with bad arguments, including: +# *Invalid character against the ZFS namespace +# *Incomplete component +# *Too many arguments +# *Filesystem already exists +# *Beyond maximal name length. +# *Same property set multiple times via '-o property=value' +# *Volume's property set on filesystem +# +# STRATEGY: +# 1. Create an array of arguments +# 2. Execute 'zfs create ' with each argument +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset -i i + typeset found + + # + # check to see if there is any new fs created during the test + # if so destroy it. + # + for dset in $($ZFS list -H | \ + $AWK '{print $1}' | $GREP / ); do + found=false + i=0 + while (( $i < ${#existed_fs[*]} )); do + if [[ $dset == ${existed_fs[i]} ]]; then + found=true + break + fi + (( i = i + 1 )) + done + + # + # new fs created during the test, cleanup it + # + if [[ $found == "false" ]]; then + log_must $ZFS destroy -f $dset + fi + done +} + +log_onexit cleanup + +set -A args "$TESTPOOL/" "$TESTPOOL//blah" "$TESTPOOL/@blah" \ + "$TESTPOOL/blah@blah" "$TESTPOOL/blah^blah" "$TESTPOOL/blah%blah" \ + "$TESTPOOL/blah*blah" "$TESTPOOL/blah blah" \ + "-s $TESTPOOL/$TESTFS1" "-b 1092 $TESTPOOL/$TESTFS1" \ + "-b 64k $TESTPOOL/$TESTFS1" "-s -b 32k $TESTPOOL/$TESTFS1" \ + "$TESTPOOL/$BYND_MAX_NAME" + +log_assert "Verify 'zfs create ' fails with bad argument." + +datasetexists $TESTPOOL/$TESTFS || \ + log_must $ZFS create $TESTPOOL/$TESTFS + +set -A existed_fs $($ZFS list -H | $AWK '{print $1}' | $GREP / ) + +log_mustnot $ZFS create $TESTPOOL +log_mustnot $ZFS create $TESTPOOL/$TESTFS + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZFS create ${args[$i]} + log_mustnot $ZFS create -p ${args[$i]} + ((i = i + 1)) +done + +i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + log_mustnot $ZFS create -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \ + $TESTPOOL/$TESTFS1 + log_mustnot $ZFS create -p -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \ + $TESTPOOL/$TESTFS1 + ((i = i + 1)) +done + +i=0 +while (( $i < ${#VOL_ONLY_PROP[*]} )); do + log_mustnot $ZFS create -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1 + log_mustnot $ZFS create -p -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1 + ((i = i + 1)) +done + +log_pass "'zfs create ' fails as expected with bad argument." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_010_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_010_neg.ksh new file mode 100644 index 00000000000..e7fc2463def --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_010_neg.ksh @@ -0,0 +1,161 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_010_neg.ksh 1.4 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_010_neg +# +# DESCRIPTION: +# 'zfs create [-b ] -V ' fails with badly formed +# or arguments,including: +# *Invalid volume size and volume name +# *Invalid blocksize +# *Incomplete component in the dataset tree +# *The volume already exists +# *The volume name beyond the maximal name length - 256. +# *Same property set multiple times via '-o property=value' +# *Filesystems's property set on volume +# +# STRATEGY: +# 1. Create an array of badly formed arguments +# 2. For each argument, execute 'zfs create -V ' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset -i i + typeset found + + # + # check to see if there is any new fs created during the test + # if so destroy it. + # + for dset in $($ZFS list -H | \ + $AWK '{print $1}' | $GREP / ); do + found=false + i=0 + while (( $i < ${#existed_fs[*]} )); do + if [[ $dset == ${existed_fs[i]} ]]; then + found=true + break + fi + (( i = i + 1 )) + done + + # + # new fs created during the test, cleanup it + # + if [[ $found == "false" ]]; then + log_must $ZFS destroy -f $dset + fi + done +} + +log_onexit cleanup + +log_assert "Verify 'zfs create [-s] [-b ] -V ' fails with" \ + "badly-formed or arguments." + +set -A args "$VOLSIZE" "$TESTVOL1" \ + "$VOLSIZE $TESTVOL1" "0 $TESTPOOL/$TESTVOL1" \ + "-1gb $TESTPOOL/$TESTVOL1" "1g? $TESTPOOL/$TESTVOL1" \ + "1.01BB $TESTPOOL/$TESTVOL1" "1%g $TESTPOOL/$TESTVOL1" \ + "1g% $TESTPOOL/$TESTVOL1" "1g$ $TESTPOOL/$TESTVOL1" \ + "$m $TESTPOOL/$TESTVOL1" "1m$ $TESTPOOL/$TESTVOL1" \ + "1m! $TESTPOOL/$TESTVOL1" \ + "1gbb $TESTPOOL/blah" "1blah $TESTPOOL/blah" "blah $TESTPOOL/blah" \ + "$VOLSIZE $TESTPOOL" "$VOLSIZE $TESTPOOL/" "$VOLSIZE $TESTPOOL//blah"\ + "$VOLSIZE $TESTPOOL/blah@blah" "$VOLSIZE $TESTPOOL/blah^blah" \ + "$VOLSIZE $TESTPOOL/blah*blah" "$VOLSIZE $TESTPOOL/blah%blah" \ + "$VOLSIZE blah" "$VOLSIZE $TESTPOOL/$BYND_MAX_NAME" \ + "1m -b $TESTPOOL/$TESTVOL1" "1m -b 11k $TESTPOOL/$TESTVOL1" \ + "1m -b 511 $TESTPOOL/$TESTVOL1" "1m -b 256k $TESTPOOL/$TESTVOL1" + +set -A options "" "-s" + +datasetexists $TESTPOOL/$TESTVOL || \ + log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL + +set -A existed_fs $($ZFS list -H | $AWK '{print $1}' | $GREP / ) + +log_mustnot $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL +log_mustnot $ZFS create -s -V $VOLSIZE $TESTPOOL/$TESTVOL + +typeset -i i=0 +typeset -i j=0 +while (( i < ${#options[*]} )); do + + j=0 + while (( j < ${#args[*]} )); do + log_mustnot $ZFS create ${options[$i]} -V ${args[$j]} + log_mustnot $ZFS create -p ${options[$i]} -V ${args[$j]} + + ((j = j + 1)) + done + + j=0 + while (( $j < ${#RW_VOL_PROP[*]} )); do + log_mustnot $ZFS create ${options[$i]} -o ${RW_VOL_PROP[j]} \ + -o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1 + log_mustnot $ZFS create -p ${options[$i]} -o ${RW_VOL_PROP[j]} \ + -o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1 + ((j = j + 1)) + done + + j=0 + while (( $j < ${#FS_ONLY_PROP[*]} )); do + log_mustnot $ZFS create ${options[$i]} -o ${FS_ONLY_PROP[j]} \ + -V $VOLSIZE $TESTPOOL/$TESTVOL1 + log_mustnot $ZFS create -p ${options[$i]} -o ${FS_ONLY_PROP[j]} \ + -V $VOLSIZE $TESTPOOL/$TESTVOL1 + ((j = j + 1)) + done + + ((i = i + 1)) +done + +log_pass "'zfs create [-s][-b ] -V ' fails as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_011_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_011_pos.ksh new file mode 100644 index 00000000000..72487bc51e0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_011_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_011_pos.ksh 1.2 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_011_pos +# +# DESCRIPTION: +# 'zfs create -p' should work as expecteed +# +# STRATEGY: +# 1. To create $newdataset with -p option, first make sure the upper level +# of $newdataset does not exist +# 2. Make sure without -p option, 'zfs create' will fail +# 3. Create $newdataset with -p option, verify it is created +# 4. Run 'zfs create -p $newdataset' again, the exit code should be zero +# even $newdataset exists +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-05) +# +# __stc_assertion_end +# +################################################################################ + +if ! $(check_opt_support "create" "-p") ; then + log_unsupported "'zfs create -p' option is not supported yet." +fi + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1 ; then + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS1 + fi +} + +log_onexit cleanup + +typeset newdataset1="$TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1" +typeset newdataset2="$TESTPOOL/$TESTFS1/$TESTFS/$TESTVOL1" + +log_assert "'zfs create -p' works as expected." + +log_must verify_opt_p_ops "create" "fs" $newdataset1 + +# verify volume creation +if is_global_zone; then + log_must verify_opt_p_ops "create" "vol" $newdataset2 +fi + +log_pass "'zfs create -p' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_012_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_012_pos.ksh new file mode 100644 index 00000000000..85dc9cd393c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_012_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_012_pos.ksh 1.2 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_012_pos +# +# DESCRIPTION: +# 'zfs create -p -o version=1' should only cause the leaf filesystem to be version=1 +# +# STRATEGY: +# 1. Create $newdataset with -p option, verify it is created +# 2. Verify only the leaf filesystem to be version=1, others use the current version +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-08) +# +# __stc_assertion_end +# +################################################################################ + +if ! $(check_opt_support "create" "-p") ; then + log_unsupported "-p option is not supported yet." +fi + +if ! $(check_opt_support "upgrade"); then + log_unsupported "zfs upgrade not supported yet." +fi + +ZFS_VERSION=$($ZFS upgrade | $HEAD -1 | $AWK '{print $NF}' \ + | $SED -e 's/\.//g') + +verify_runnable "both" + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS1 ; then + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS1 + fi +} + +log_onexit cleanup + + +typeset newdataset1="$TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1" + +log_assert "'zfs create -p -o version=1' only cause the leaf filesystem to be version=1." + +log_must $ZFS create -p -o version=1 $newdataset1 +log_must datasetexists $newdataset1 + +log_must check_fs_version $TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1 1 +for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS ; do + log_must check_fs_version $fs $ZFS_VERSION +done + +log_pass "'zfs create -p -o version=1' only cause the leaf filesystem to be version=1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_013_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_013_pos.ksh new file mode 100644 index 00000000000..fe00580ae64 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_013_pos.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_013_pos.ksh 1.1 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create.cfg + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_013_pos +# +# DESCRIPTION: +# 'zfs create -s -V ' can create various-size sparse volume +# with long fs name +# +# STRATEGY: +# 1. Create a volume in the storage pool. +# 2. Verify the volume is created correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset -i j=0 + while [[ $j -lt ${#size[*]} ]]; do + datasetexists $TESTPOOL/${LONGFSNAME}${size[j]} && \ + log_must $ZFS destroy $TESTPOOL/${LONGFSNAME}${size[j]} + ((j = j + 1)) + done +} + +log_onexit cleanup + + +log_assert "'zfs create -s -V ' succeeds" + +typeset -i j=0 +while (( $j < ${#size[*]} )); do + typeset cmdline="$ZFS create -s -V ${size[j]} \ + $TESTPOOL/${LONGFSNAME}${size[j]}" + + str=$(eval $cmdline 2>&1) + if (( $? == 0 )); then + log_note "SUCCESS: $cmdline" + log_must datasetexists $TESTPOOL/${LONGFSNAME}${size[j]} + elif [[ $str == *${VOL_LIMIT_KEYWORD1}* || \ + $str == *${VOL_LIMIT_KEYWORD2}* || \ + $str == *${VOL_LIMIT_KEYWORD3}* ]] + then + log_note "UNSUPPORTED: $cmdline" + else + log_fail "$cmdline" + fi + + ((j = j + 1)) +done + +log_pass "'zfs create -s -V ' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_common.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_common.kshlib new file mode 100644 index 00000000000..d6b4f4abf79 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_common.kshlib @@ -0,0 +1,56 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +#!/bin/ksh -p +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_common.kshlib 1.3 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Check if the user property is identical to the expected value. +# +# $1 dataset +# $2 property string +# +function propertycheck +{ + typeset dtst=$1 + typeset propstr=$2 + + typeset prop=$($ECHO $propstr | $AWK -F= '{print $1}') + typeset expect_value=$($ECHO $propstr | $AWK -F= '{print $2}') + typeset value=$($ZFS get -H -o value $prop $dtst) + + + if [[ "$expect_value" == "$value" ]]; then + return 0 + else + return 1 + fi +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_test.sh new file mode 100755 index 00000000000..00185dbf4a0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_create/zfs_create_test.sh @@ -0,0 +1,410 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_create_001_pos cleanup +zfs_create_001_pos_head() +{ + atf_set "descr" "'zfs create ' can create a ZFS filesystem in the namespace." + atf_set "require.progs" zfs +} +zfs_create_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_002_pos cleanup +zfs_create_002_pos_head() +{ + atf_set "descr" "'zfs create -s -V ' succeeds" + atf_set "require.progs" zfs +} +zfs_create_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_003_pos cleanup +zfs_create_003_pos_head() +{ + atf_set "descr" "Verify creating volume with specified blocksize works." + atf_set "require.progs" zfs +} +zfs_create_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_004_pos cleanup +zfs_create_004_pos_head() +{ + atf_set "descr" "'zfs create -o property=value filesystem' can successfully createa ZFS filesystem with correct property set." + atf_set "require.progs" zfs +} +zfs_create_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_005_pos cleanup +zfs_create_005_pos_head() +{ + atf_set "descr" "'zfs create -o property=value filesystem' can successfully createa ZFS filesystem with multiple properties set." + atf_set "require.progs" zfs +} +zfs_create_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_006_pos cleanup +zfs_create_006_pos_head() +{ + atf_set "descr" "'zfs create -o property=value -V size volume' can successfullycreate a ZFS volume with correct property set." + atf_set "require.progs" zfs +} +zfs_create_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_007_pos cleanup +zfs_create_007_pos_head() +{ + atf_set "descr" "'zfs create -o property=value -V size volume' can successfullycreate a ZFS volume with correct property set." + atf_set "require.progs" zfs +} +zfs_create_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_007_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_008_neg cleanup +zfs_create_008_neg_head() +{ + atf_set "descr" "'zfs create' should return an error with badly-formed parameters." + atf_set "require.progs" zfs +} +zfs_create_008_neg_body() +{ + atf_expect_fail 'kern/221987 - ZFS does not validate the sharenfs parameter' + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_008_neg.ksh || atf_fail "Testcase failed" +} +zfs_create_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_009_neg cleanup +zfs_create_009_neg_head() +{ + atf_set "descr" "Verify 'zfs create ' fails with bad argument." + atf_set "require.progs" zfs +} +zfs_create_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_009_neg.ksh || atf_fail "Testcase failed" +} +zfs_create_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_010_neg cleanup +zfs_create_010_neg_head() +{ + atf_set "descr" "Verify 'zfs create [-s] [-b ] -V ' fails withbadly-formed or arguments." + atf_set "require.progs" zfs +} +zfs_create_010_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_010_neg.ksh || atf_fail "Testcase failed" +} +zfs_create_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_011_pos cleanup +zfs_create_011_pos_head() +{ + atf_set "descr" "'zfs create -p' works as expected." + atf_set "require.progs" zfs +} +zfs_create_011_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_011_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_012_pos cleanup +zfs_create_012_pos_head() +{ + atf_set "descr" "'zfs create -p -o version=1' only cause the leaf filesystem to be version=1." + atf_set "require.progs" zfs +} +zfs_create_012_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_012_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_012_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_013_pos cleanup +zfs_create_013_pos_head() +{ + atf_set "descr" "'zfs create -s -V ' succeeds" + atf_set "require.progs" zfs +} +zfs_create_013_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_013_pos.ksh || atf_fail "Testcase failed" +} +zfs_create_013_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_create_common.kshlib + . $(atf_get_srcdir)/properties.kshlib + . $(atf_get_srcdir)/zfs_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_create_001_pos + atf_add_test_case zfs_create_002_pos + atf_add_test_case zfs_create_003_pos + atf_add_test_case zfs_create_004_pos + atf_add_test_case zfs_create_005_pos + atf_add_test_case zfs_create_006_pos + atf_add_test_case zfs_create_007_pos + atf_add_test_case zfs_create_008_neg + atf_add_test_case zfs_create_009_neg + atf_add_test_case zfs_create_010_neg + atf_add_test_case zfs_create_011_pos + atf_add_test_case zfs_create_012_pos + atf_add_test_case zfs_create_013_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/Makefile new file mode 100644 index 00000000000..dacea20afe1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/Makefile @@ -0,0 +1,25 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_destroy +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_destroy_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_destroy_001_pos.ksh +${PACKAGE}FILES+= zfs_destroy.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_destroy_004_pos.ksh +${PACKAGE}FILES+= zfs_destroy_005_neg.ksh +${PACKAGE}FILES+= zfs_destroy_common.kshlib +${PACKAGE}FILES+= zfs_destroy_002_pos.ksh +${PACKAGE}FILES+= zfs_destroy_007_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_destroy_003_pos.ksh +${PACKAGE}FILES+= zfs_destroy_006_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/cleanup.ksh new file mode 100644 index 00000000000..7ac6c601f88 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib + +cleanup_testenv + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy.cfg new file mode 100644 index 00000000000..7804b6a016b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy.cfg @@ -0,0 +1,44 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export TESTFSCLONE=${TESTFS}clone +export TESTVOLCLONE=${TESTVOL}clone + +export CTR=$TESTPOOL/$TESTCTR +export FS=$CTR/$TESTFS +export VOL=$CTR/$TESTVOL +export FSSNAP=$FS@$TESTSNAP +export VOLSNAP=$VOL@$TESTSNAP +export FSCLONE=$TESTPOOL/$TESTFSCLONE +export VOLCLONE=$TESTPOOL/$TESTVOLCLONE +export STF_TIMEOUT=3600 diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh new file mode 100644 index 00000000000..4f0a9af1ea7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh @@ -0,0 +1,215 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_001_pos.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_destroy_001_pos +# +# DESCRIPTION: +# 'zfs destroy -r|-rf|-R|-Rf ' should recursively destroy +# all children and clones based on options. +# +# STRATEGY: +# 1. Create test environment according to options. There are three test +# models can be created. Only ctr, fs & vol; with snap; with clone. +# 2. According to option, make the dataset busy or not. +# 3. Run 'zfs destroy [-rRf] ' +# 4. According to dataset and option, check if get the expected results. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-22) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# +# According to parameters, 1st, create suitable testing environment. 2nd, +# run 'zfs destroy $opt '. 3rd, check the system status. +# +# $1 option of 'zfs destroy' +# $2 dataset will be destroied. +# +function test_n_check +{ + typeset opt=$1 + typeset dtst=$2 + + if ! is_global_zone ; then + if [[ $dtst == $VOL || $dtst == $VOLSNAP ]]; then + log_note "UNSUPPORTED: Volume are unavailable in LZ." + return + fi + fi + + # '-f' has no effect on non-filesystems + if [[ $opt == -f ]]; then + if [[ $dtst != $FS || $dtst != $CTR ]]; then + log_note "UNSUPPORTED: '-f ' is only available for FS." + return + fi + fi + + # Clean the test environment and make it clear. + if datasetexists $CTR; then + log_must $ZFS destroy -Rf $CTR + fi + + # According to option create test compatible environment. + case $opt in + -r|-rf) setup_testenv snap ;; + -R|-Rf) setup_testenv clone ;; + -f) setup_testenv ;; + *) log_fail "Incorrect option: '$opt'." ;; + esac + + # + # According to different dataset type, create busy condition when try to + # destroy this dataset. + # + typeset mpt_dir + case $dtst in + $CTR|$FS) + if [[ $opt == *f* ]]; then + mpt_dir=$(get_prop mountpoint $FS) + make_dir_busy $mpt_dir + log_mustnot $ZFS destroy -rR $dtst + make_dir_unbusy $mpt_dir + fi + ;; + $VOL) + if [[ $opt == *f* ]]; then + make_dir_busy $TESTDIR1 + log_mustnot $ZFS destroy -rR $dtst + make_dir_unbusy $TESTDIR1 + fi + ;; + $FSSNAP) + if [[ $opt == *f* ]]; then + mpt_dir=$(snapshot_mountpoint $dtst) + init_dir=$PWD + make_dir_busy $mpt_dir + log_must $ZFS destroy -rR $dtst + log_must $ZFS snapshot $dtst + make_dir_unbusy $mpt_dir + fi + ;; + $VOLSNAP) + if [[ $opt == *f* ]]; then + mpt_dir=$TESTDIR1 + init_dir=$PWD + make_dir_busy $mpt_dir + log_must $ZFS destroy -rR $dtst + log_must $ZFS snapshot $dtst + make_dir_unbusy $mpt_dir + fi + ;; + *) log_fail "Unsupported dataset: '$dtst'." + esac + + # Firstly, umount ufs filesystem which was created by zfs volume. + if is_global_zone; then + log_must $UMOUNT -f $TESTDIR1 + fi + # Invoke 'zfs destroy [-rRf] ' + log_must $ZFS destroy $opt $dtst + + case $dtst in + $CTR) check_dataset datasetnonexists \ + $CTR $FS $VOL $FSSNAP $VOLSNAP + if [[ $opt == *R* ]]; then + check_dataset datasetnonexists \ + $FSCLONE $VOLCLONE + fi + ;; + $FS) check_dataset datasetexists $CTR $VOL + check_dataset datasetnonexists $FS + if [[ $opt != -f ]]; then + check_dataset datasetexists $VOLSNAP + check_dataset datasetnonexists $FSSNAP + fi + if [[ $opt == *R* ]]; then + check_dataset datasetexists $VOLCLONE + check_dataset datasetnonexists $FSCLONE + fi + ;; + $VOL) check_dataset datasetexists $CTR $FS $FSSNAP + check_dataset datasetnonexists $VOL $VOLSNAP + if [[ $opt == *R* ]]; then + check_dataset datasetexists $FSCLONE + check_dataset datasetnonexists $VOLCLONE + fi + ;; + $FSSNAP) + check_dataset datasetexists $CTR $FS $VOL $VOLSNAP + check_dataset datasetnonexists $FSSNAP + if [[ $opt == *R* ]]; then + check_dataset datasetexists $VOLCLONE + check_dataset datasetnonexists $FSCLONE + fi + ;; + $VOLSNAP) + check_dataset datasetexists $CTR $FS $VOL $FSSNAP + check_dataset datasetnonexists $VOLSNAP + if [[ $opt == *R* ]]; then + check_dataset datasetexists $FSCLONE + check_dataset datasetnonexists $VOLCLONE + fi + ;; + esac + + log_note "'$ZFS destroy $opt $dtst' passed." +} + +log_assert "'zfs destroy -r|-R|-f|-rf|-Rf ' should " \ + "recursively destroy all children." +log_onexit cleanup_testenv + +typeset dtst="" +typeset opt="" +for dtst in $CTR $FS $VOL $FSSNAP $VOLSNAP; do + for opt in "-r" "-R" "-f" "-rf" "-Rf"; do + log_note "Starting test: $ZFS destroy $opt $dtst" + test_n_check $opt $dtst + done +done + +log_pass "'zfs destroy -r|-R|-f|-rf|-Rf ' passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh new file mode 100644 index 00000000000..a94f23347db --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_002_pos.ksh @@ -0,0 +1,114 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_002_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_destroy_002_pos +# +# DESCRIPTION: +# 'zfs destroy ' can successfully destroy +# the specified dataset which has no active dependents. +# +# STRATEGY: +# 1. Create a filesystem,volume and snapshot in the storage pool +# 2. Destroy the filesystem,volume and snapshot +# 3. Verify the datasets are destroyed successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset -i i=0 + while (( $i < ${#data_objs[*]} )); do + datasetexists "${data_objs[i]}" && \ + $ZFS destroy -rf ${data_objs[i]} + ((i = i + 1)) + done +} + +log_assert "Verify 'zfs destroy' can destroy the specified datasets without active" \ + "dependents." +log_onexit cleanup + +if is_global_zone ; then + set -A data_objs "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTFS1" \ + "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTVOL1" +else + set -A data_objs "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTFS1" +fi + +log_must $ZFS create $TESTPOOL/$TESTFS1 +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP + +if is_global_zone ; then + log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL + + # Max volume size is 1TB on 32-bit systems + [[ `$UNAME -p` == "i386" ]] && \ + BIGVOLSIZE=1Tb + [[ `$UNAME -p` == "arm" ]] && \ + BIGVOLSIZE=1Tb + [[ `$UNAME -p` == "mips" ]] && \ + BIGVOLSIZE=1Tb + [[ `$UNAME -p` == "powerpc" ]] && \ + BIGVOLSIZE=1Tb + log_must $ZFS create -sV $BIGVOLSIZE $TESTPOOL/$TESTVOL1 +fi + +typeset -i i=0 +while (( $i < ${#data_objs[*]} )); do + datasetexists ${data_objs[i]} || \ + log_fail "Create || fail." + ((i = i + 1)) +done + +i=0 +while (( $i < ${#data_objs[*]} )); do + log_must $ZFS destroy ${data_objs[i]} + datasetexists ${data_objs[i]} && \ + log_fail "'zfs destroy ||' fail." + ((i = i + 1)) +done + +log_pass "'zfs destroy ||' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh new file mode 100644 index 00000000000..29dec40605b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh @@ -0,0 +1,168 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_003_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion__start +# +# ID: zfs_destroy_003_pos +# +# DESCRIPTION: +# Verify 'zfs destroy [-rR]' succeeds as root. +# +# STRATEGY: +# 1. Create two datasets in the storage pool +# 2. Create fs,vol,ctr,snapshot and clones of snapshot in the two datasets +# 3. Create clone in the second dataset for the snapshot in the first dataset +# 4. Verify 'zfs destroy -r' fails to destroy dataset with clone outside it +# 5. Verify 'zfs destroy -R' succeeds to destroy dataset with clone outside it +# 6. Verify 'zfs destroy -r' succeeds to destroy dataset without clone outside it. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-02) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +function cleanup +{ + for obj in $ctr2 $ctr1 $ctr; do + datasetexists $obj && \ + log_must $ZFS destroy -Rf $obj + done + + for mntp in $TESTDIR1 $TESTDIR2; do + [[ -d $mntp ]] && \ + log_must $RM -rf $mntp + done +} + +log_assert "Verify that 'zfs destroy [-rR]' succeeds as root. " + +log_onexit cleanup + +# +# Preparations for testing +# +for dir in $TESTDIR1 $TESTDIR2; do + [[ ! -d $dir ]] && \ + log_must $MKDIR -p $dir +done + +ctr=$TESTPOOL/$TESTCTR +ctr1=$TESTPOOL/$TESTCTR1 +ctr2=$ctr/$TESTCTR2 +ctr3=$ctr1/$TESTCTR2 +child_fs=$ctr/$TESTFS1 +child_fs1=$ctr1/$TESTFS2 +child_fs_mntp=$TESTDIR1 +child_fs1_mntp=$TESTDIR2 +child_vol=$ctr/$TESTVOL +child_vol1=$ctr1/$TESTVOL +child_fs_snap=$child_fs@snap +child_fs1_snap=$child_fs1@snap +child_fs_snap_clone=$ctr/$TESTCLONE +child_fs_snap_clone1=$ctr1/${TESTCLONE}_across_ctr +child_fs_snap_clone2=$ctr2/$TESTCLONE2 +child_fs1_snap_clone=$ctr1/$TESTCLONE1 +child_fs1_snap_clone1=$ctr/${TESTCLONE1}_across_ctr + +# +# Create two datasets in the storage pool +# +log_must $ZFS create $ctr +log_must $ZFS create $ctr1 + +# +# Create children datasets fs,vol,snapshot in the datasets, and +# clones across two datasets +# +log_must $ZFS create $ctr2 + +for fs in $child_fs $child_fs1; do + log_must $ZFS create $fs +done + +log_must $ZFS set mountpoint=$child_fs_mntp $child_fs +log_must $ZFS set mountpoint=$child_fs1_mntp $child_fs1 + +for snap in $child_fs_snap $child_fs1_snap; do + log_must $ZFS snapshot $snap +done + +if is_global_zone ; then + for vol in $child_vol $child_vol1; do + log_must $ZFS create -V $VOLSIZE $vol + done +fi + +for clone in $child_fs_snap_clone $child_fs_snap_clone1; do + log_must $ZFS clone $child_fs_snap $clone +done + + +for clone in $child_fs1_snap_clone $child_fs1_snap_clone1; do + log_must $ZFS clone $child_fs1_snap $clone +done + +log_note "Verify that 'zfs destroy -r' fails to destroy dataset " \ + "with clone dependent outside it." + +for obj in $child_fs $child_fs1 $ctr $ctr1; do + log_mustnot $ZFS destroy -r $obj + datasetexists $obj || \ + log_fail "'zfs destroy -r' fails to keep clone " \ + "dependent outside the hirearchy." +done + + +log_note "Verify that 'zfs destroy -R' succeeds to destroy dataset " \ + "with clone dependent outside it." + +log_must $ZFS destroy -R $ctr1 +datasetexists $ctr1 && \ + log_fail "'zfs destroy -R' fails to destroy dataset with clone outside it." + +log_note "Verify that 'zfs destroy -r' succeeds to destroy dataset " \ + "without clone dependent outside it." + +log_must $ZFS destroy -r $ctr +datasetexists $ctr && \ + log_fail "'zfs destroy -r' fails to destroy dataset with clone outside it." + +log_pass "'zfs destroy [-rR] succeeds as root." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh new file mode 100644 index 00000000000..e545220331c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh @@ -0,0 +1,132 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_004_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_destroy_004_pos +# +# DESCRIPTION: +# Verify 'zfs destroy -f' succeeds as root. +# +# STRATEGY: +# 1. Create filesystem in the storage pool +# 2. Set mountpoint for the filesystem and make it busy +# 3. Verify that 'zfs destroy' fails to destroy the filesystem +# 4. Verify 'zfs destroy -f' succeeds to destroy the filesystem. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-02) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +function cleanup +{ + cd $olddir + + datasetexists $clone && \ + log_must $ZFS destroy -f $clone + + snapexists $snap && \ + log_must $ZFS destroy -f $snap + + for fs in $fs1 $fs2; do + datasetexists $fs && \ + log_must $ZFS destroy -f $fs + done + + for dir in $TESTDIR1 $TESTDIR2; do + [[ -d $dir ]] && \ + log_must $RM -rf $dir + done +} + +log_assert "Verify that 'zfs destroy -f' succeeds as root. " + +log_onexit cleanup + +# +# Preparations for testing +# +olddir=$PWD + +for dir in $TESTDIR1 $TESTDIR2; do + [[ ! -d $dir ]] && \ + log_must $MKDIR -p $dir +done + +fs1=$TESTPOOL/$TESTFS1 +mntp1=$TESTDIR1 +fs2=$TESTPOOL/$TESTFS2 +snap=$TESTPOOL/$TESTFS2@snap +clone=$TESTPOOL/$TESTCLONE +mntp2=$TESTDIR2 + +# +# Create filesystem and clone in the storage pool, mount them and +# make the mountpoint busy +# +for fs in $fs1 $fs2; do + log_must $ZFS create $fs +done + +log_must $ZFS snapshot $snap +log_must $ZFS clone $snap $clone + +log_must $ZFS set mountpoint=$mntp1 $fs1 +log_must $ZFS set mountpoint=$mntp2 $clone + +for arg in "$fs1 $mntp1" "$clone $mntp2"; do + fs=`$ECHO $arg | $AWK '{print $1}'` + mntp=`$ECHO $arg | $AWK '{print $2}'` + + log_note "Verify that 'zfs destroy' fails to" \ + "destroy filesystem when it is busy." + cd $mntp + log_mustnot $ZFS destroy $fs + + log_must $ZFS destroy -f $fs + datasetexists $fs && \ + log_fail "'zfs destroy -f' fails to destroy busy filesystem." + + cd $olddir +done + +log_pass "'zfs destroy -f' succeeds as root." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh new file mode 100644 index 00000000000..eeebb072bbb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_005_neg.ksh @@ -0,0 +1,197 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_005_neg.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_destroy_005_neg +# +# DESCRIPTION: +# Separately verify 'zfs destroy -f|-r|-rf|-R|-rR ' will fail in +# different conditions. +# +# STRATEGY: +# 1. Create pool, fs & vol. +# 2. Create snapshot for fs & vol. +# 3. Invoke 'zfs destroy ''|-f ', it should fail. +# 4. Create clone for fs & vol. +# 5. Invoke 'zfs destroy -r|-rf ', it should fail. +# 6. Write file to filesystem or enter snapshot mountpoint. +# 7. Invoke 'zfs destroy -R|-rR ', it should fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-03) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Separately verify 'zfs destroy -f|-r|-rf|-R|-rR ' will " \ + "fail in different conditions." +log_onexit cleanup_testenv + +# +# Run 'zfs destroy [-rRf] ', make sure it fail. +# +# $1 the collection of options +# $2 the collection of datasets +# +function negative_test +{ + typeset options=$1 + typeset datasets=$2 + + for dtst in $datasets; do + if ! is_global_zone; then + if [[ $dtst == $VOL || $dtst == $VOLSNAP || \ + $dtst == $VOLCLONE ]] + then + log_note "UNSUPPORTED: " \ + "Volume is unavailable in LZ." + continue + fi + fi + for opt in $options; do + log_mustnot $ZFS destroy $opt $dtst + done + done +} + +# This filesystem is created by setup.ksh, and conflicts with the filesystems +# created from within this file +$ZFS destroy -f $TESTPOOL/$TESTFS + +# +# Create snapshots for filesystem and volume, +# and verify 'zfs destroy' failed without '-r' or '-R'. +# +setup_testenv snap +negative_test "-f" "$CTR $FS $VOL" + +# +# Create clones for filesystem and volume, +# and verify 'zfs destroy' failed without '-R'. +# +setup_testenv clone +negative_test "-r -rf" "$CTR $FS $VOL" + +# +# Get $FS mountpoint and make it busy, then verify 'zfs destroy $CTR' +# failed without '-f'. +# +# Then verify the datasets are expected existed or non-existed. +# +typeset mtpt_dir=$(get_prop mountpoint $FS) +make_dir_busy $mtpt_dir +negative_test "-R -rR" $CTR +check_dataset datasetexists $CTR $FS $VOL $VOLSNAP $VOLCLONE +log_must datasetnonexists $FSSNAP $FSCLONE + +# +# Create the clones for test environment, then verify 'zfs destroy $FS' +# failed without '-f'. +# +# Then verify the datasets are expected existed or non-existed. +# +setup_testenv clone +negative_test "-R -rR" $FS +check_dataset datasetexists $CTR $FS $VOL $VOLSNAP $VOLCLONE +log_must datasetnonexists $FSSNAP $FSCLONE + +make_dir_unbusy $mtpt_dir + +if is_global_zone; then + # + # Create the clones for test environment and make the volume busy. + # Then verify 'zfs destroy $CTR' failed without '-f'. + # + # Then verify the datasets are expected existed or non-existed. + # + setup_testenv clone + make_dir_busy $TESTDIR1 + negative_test "-R -rR" $CTR + log_must datasetexists $CTR $VOL + log_must datasetnonexists $FS $FSSNAP $FSCLONE $VOLSNAP $VOLCLONE + + # + # Create the clones for test environment and make the volume busy. + # Then verify 'zfs destroy $VOL' failed without '-f'. + # + # Then verify the datasets are expected existed or non-existed. + # + setup_testenv clone + negative_test "-R -rR" $VOL + log_must datasetexists $CTR $VOL $FS $FSSNAP $FSCLONE + log_must datasetnonexists $VOLSNAP $VOLCLONE + + make_dir_unbusy $TESTDIR1 +fi + +# +# Create the clones for test environment and make the snapshot busy. +# Then verify 'zfs destroy $snap' failed without '-f'. +# +# Then verify the datasets are expected existed or non-existed. +# +snaplist="$FSSNAP" + +setup_testenv clone +for snap in $snaplist; do + for option in -R -rR ; do + mtpt_dir=$(snapshot_mountpoint $snap) + (( $? != 0 )) && \ + log_fail "get mountpoint $snap failed." + + init_dir=$PWD + log_must cd $mtpt_dir + + log_must $ZFS destroy $option $snap + check_dataset datasetexists $CTR $FS $VOL + if [[ $snap == $FSSNAP ]]; then + log_must datasetnonexists $snap $FSCLONE + else + log_must datasetnonexists $snap $VOLCLONE + fi + setup_testenv clone + done +done + +cmds="zfs destroy -f|-r|-rf|-R|-rR " +log_pass "'$cmds' must fail in certain conditions." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh new file mode 100644 index 00000000000..58711c2f2a3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_006_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_006_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_destroy_006_neg +# +# DESCRIPTION: +# 'zfs destroy' should return an error with badly formed parameters, +# including null destroyed object parameter, invalid options excluding +# '-r' and '-f', non-existent datasets. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute 'zfs destroy' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A args "" "-r" "-f" "-rf" "-fr" "$TESTPOOL" "-f $TESTPOOL" \ + "-? $TESTPOOL/$TESTFS" "$TESTPOOL/blah"\ + "-r $TESTPOOL/blah" "-f $TESTPOOL/blah" "-rf $TESTPOOL/blah" \ + "-fr $TESTPOOL/blah" "-$ $TESTPOOL/$TESTFS" "-5 $TESTPOOL/$TESTFS" \ + "-rfgh $TESTPOOL/$TESTFS" "-rghf $TESTPOOL/$TESTFS" \ + "$TESTPOOL/$TESTFS@blah" "/$TESTPOOL/$TESTFS" "-f /$TESTPOOL/$TESTFS" \ + "-rf /$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS" \ + "-rRf $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS" + +log_assert "'zfs destroy' should return an error with badly-formed parameters." + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZFS destroy ${args[i]} + ((i = i + 1)) +done + +log_pass "'zfs destroy' badly formed parameters fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh new file mode 100644 index 00000000000..8a07303f8b6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh @@ -0,0 +1,86 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_007_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_destroy_007_neg +# +# DESCRIPTION: +# 'zpool destroy' failed if this filesystem is namespace-parent +# of origin. +# +# STRATEGY: +# 1. Create pool, fs and snapshot. +# 2. Create a namespace-parent of origin clone. +# 3. Promote this clone +# 4. Verify the original fs can not be destroyed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $clonesnap; then + log_must $ZFS promote $fs + fi + datasetexists $clone && log_must $ZFS destroy $clone + datasetexists $fssnap && log_must $ZFS destroy $fssnap +} + +log_assert "Destroy dataset which is namespace-parent of origin should failed." +log_onexit cleanup + +# Define variable $fssnap & and namespace-parent of origin clone. +fs=$TESTPOOL/$TESTFS +fssnap=$fs@snap +clone=$fs/clone +clonesnap=$fs/clone@snap + +log_must $ZFS snapshot $fssnap +log_must $ZFS clone $fssnap $clone +log_must $ZFS promote $clone +log_mustnot $ZFS destroy $fs +log_mustnot $ZFS destroy $clone + +log_pass "Destroy dataset which is namespace-parent of origin passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib new file mode 100644 index 00000000000..61b89d759ef --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_common.kshlib @@ -0,0 +1,173 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_common.kshlib 1.3 07/03/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Create or recover a set of test environment which include ctr, vol, fs, +# snap & clone. It looks like the following. +# +# pool +# |ctr +# | |fs +# | | |fssnap +# | |vol +# | |volsnap +# |fsclone +# |volclone +# +# $1 indicate which dependent dataset need be created. Such as 'snap', 'clone'. +# +function setup_testenv #[dtst] +{ + typeset dtst=$1 + + if ! datasetexists $CTR; then + log_must $ZFS create $CTR + fi + if ! datasetexists $FS; then + log_must $ZFS create $FS + fi + # Volume test is only availible on globle zone + if ! datasetexists $VOL && is_global_zone; then + log_must $ZFS create -V $VOLSIZE $VOL + log_must $NEWFS /dev/zvol/$VOL + + if [[ ! -d $TESTDIR1 ]]; then + log_must $MKDIR $TESTDIR1 + fi + log_must $MOUNT /dev/zvol/$VOL $TESTDIR1 + fi + + if [[ $dtst == snap || $dtst == clone ]]; then + if ! datasetexists $FSSNAP; then + log_must $ZFS snapshot $FSSNAP + fi + if ! datasetexists $VOLSNAP && is_global_zone; then + log_must $ZFS snapshot $VOLSNAP + fi + fi + + if [[ $dtst == clone ]]; then + if ! datasetexists $FSCLONE; then + log_must $ZFS clone $FSSNAP $FSCLONE + fi + if ! datasetexists $VOLCLONE && is_global_zone; then + log_must $ZFS clone $VOLSNAP $VOLCLONE + fi + fi +} + +function make_dir_busy +{ + typeset dir=$1 + typeset dirfiltered=$(echo $dir | sed -Ee 's,[/\.],_,g') + + OLDPWD=$(pwd) + cd $dir + # Sleep for long enough for the test to have run through. Note that + # even if the test itself changes directory, sleep will still be on it. + $SLEEP $STF_TIMEOUT & + eval SLEEP_PID_${dirfiltered}=$! + pid=$(eval echo \$SLEEP_PID_${dirfiltered}) + cd ${OLDPWD} + log_note "Sleeping while on ${dir} in pid $pid" +} + +function make_dir_unbusy +{ + typeset dir=$1 + typeset dirfiltered=$(echo $dir | sed -Ee 's,[/\.],_,g') + typeset pid=$(eval echo \$SLEEP_PID_${dirfiltered}) + + # Safeguard in case this is used incorrectly. + [[ -z "$pid" ]] && log_fail "make_dir_unbusy called without busy?" + $KILL -15 $pid + eval SLEEP_PID_${dirfiltered}="" + log_note "Unbusied ${dir}" +} + +# Clean up the testing environment +# +function cleanup_testenv +{ + if [[ $STF_EXITCODE -eq $STF_FAIL ]]; then + $ECHO "Testcase failed; dataset listing follows:" + $ZFS list -t all -r $TESTPOOL + fi + if (( ${#init_dir} != 0 )); then + cd $init_dir + init_dir="" + fi + if is_global_zone && ismounted "$TESTDIR1" "ufs" ; then + log_must $UMOUNT -f $TESTDIR1 + fi + if [[ -d $TESTDIR1 ]]; then + log_must $RM -rf $TESTDIR1 + fi + + [[ -n "$SLEEP_PID" ]] && $KILL -15 $SLEEP_PID + + if datasetexists $CTR; then + log_must $ZFS destroy -Rf $CTR + fi +} + +# +# Delete volume and related datasets from list, if the test cases was +# runing in local zone. Then check them are existed or non-exists. +# +# $1 function name +# $2-n datasets name +# +function check_dataset +{ + typeset funname=$1 + typeset newlist="" + typeset dtst + shift + + for dtst in "$@"; do + # Volume and related stuff are unvailable in local zone + if ! is_global_zone; then + if [[ $dtst == $VOL || $dtst == $VOLSNAP || \ + $dtst == $VOLCLONE ]] + then + continue + fi + fi + newlist="$newlist $dtst" + done + + if (( ${#newlist} != 0 )); then + log_must eval "$funname $newlist" + fi +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_test.sh new file mode 100755 index 00000000000..4faa2202e93 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_destroy/zfs_destroy_test.sh @@ -0,0 +1,228 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_destroy_001_pos cleanup +zfs_destroy_001_pos_head() +{ + atf_set "descr" "'zfs destroy -r|-R|-f|-rf|-Rf ' shouldrecursively destroy all children." + atf_set "require.progs" zfs + atf_set "timeout" 3600 +} +zfs_destroy_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_destroy_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_destroy_002_pos cleanup +zfs_destroy_002_pos_head() +{ + atf_set "descr" "Verify 'zfs destroy' can destroy the specified datasets without activedependents." + atf_set "require.progs" zfs + atf_set "timeout" 3600 +} +zfs_destroy_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_destroy_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_destroy_003_pos cleanup +zfs_destroy_003_pos_head() +{ + atf_set "descr" "Verify that 'zfs destroy [-rR]' succeeds as root." + atf_set "require.progs" zfs + atf_set "timeout" 3600 +} +zfs_destroy_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_destroy_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_destroy_004_pos cleanup +zfs_destroy_004_pos_head() +{ + atf_set "descr" "Verify that 'zfs destroy -f' succeeds as root." + atf_set "require.progs" zfs + atf_set "timeout" 3600 +} +zfs_destroy_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_destroy_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_destroy_005_neg cleanup +zfs_destroy_005_neg_head() +{ + atf_set "descr" "Separately verify 'zfs destroy -f|-r|-rf|-R|-rR ' willfail in different conditions." + atf_set "require.progs" zfs + atf_set "timeout" 3600 +} +zfs_destroy_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_005_neg.ksh || atf_fail "Testcase failed" +} +zfs_destroy_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_destroy_006_neg cleanup +zfs_destroy_006_neg_head() +{ + atf_set "descr" "'zfs destroy' should return an error with badly-formed parameters." + atf_set "require.progs" zfs + atf_set "timeout" 3600 +} +zfs_destroy_006_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_006_neg.ksh || atf_fail "Testcase failed" +} +zfs_destroy_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_destroy_007_neg cleanup +zfs_destroy_007_neg_head() +{ + atf_set "descr" "Destroy dataset which is namespace-parent of origin should failed." + atf_set "require.progs" zfs + atf_set "timeout" 3600 +} +zfs_destroy_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_destroy_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_destroy_common.kshlib + . $(atf_get_srcdir)/zfs_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_destroy_001_pos + atf_add_test_case zfs_destroy_002_pos + atf_add_test_case zfs_destroy_003_pos + atf_add_test_case zfs_destroy_004_pos + atf_add_test_case zfs_destroy_005_neg + atf_add_test_case zfs_destroy_006_neg + atf_add_test_case zfs_destroy_007_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/Makefile new file mode 100644 index 00000000000..d86ef8c35e9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE= tests + +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_diff +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_diff_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_diff_001_pos.ksh +${PACKAGE}FILES+= zfs_diff.cfg +${PACKAGE}FILES+= zfs_diff_001_pos.golden + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/cleanup.ksh new file mode 100644 index 00000000000..d1bd2b24498 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/cleanup.ksh @@ -0,0 +1,33 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/setup.ksh new file mode 100644 index 00000000000..de7b04fc538 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/setup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff.cfg new file mode 100644 index 00000000000..01224df0ca2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff.cfg @@ -0,0 +1,30 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_001_pos.golden b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_001_pos.golden new file mode 100644 index 00000000000..dffc9b67d68 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_001_pos.golden @@ -0,0 +1,13 @@ ++ /testdir1526/dirs/create ++ /testdir1526/files/create +- /testdir1526/dirs/delete +- /testdir1526/files/delete +M /testdir1526/dirs +M /testdir1526/dirs/modify +M /testdir1526/files +M /testdir1526/files/dstdir +M /testdir1526/files/modify +M /testdir1526/files/srcdir +R /testdir1526/dirs/rename -> /testdir1526/dirs/rename.new +R /testdir1526/files/rename -> /testdir1526/files/rename.new +R /testdir1526/files/srcdir/move -> /testdir1526/files/dstdir/move diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_001_pos.ksh new file mode 100644 index 00000000000..9de8beff18a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_001_pos.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +verify_runnable "both" + +log_assert "'zfs diff' output for typical operations" + +# First create a bunch of files and directories + +#log_must ${CD} $TESTDIR +log_must ${MKDIR} ${TESTDIR}/dirs +log_must ${MKDIR} ${TESTDIR}/dirs/leavealone +log_must ${MKDIR} ${TESTDIR}/dirs/modify +log_must ${MKDIR} ${TESTDIR}/dirs/rename +log_must ${MKDIR} ${TESTDIR}/dirs/delete +log_must ${MKDIR} ${TESTDIR}/files +log_must ${TOUCH} ${TESTDIR}/files/leavealone +log_must ${TOUCH} ${TESTDIR}/files/modify +log_must ${TOUCH} ${TESTDIR}/files/rename +log_must ${TOUCH} ${TESTDIR}/files/delete +log_must ${MKDIR} ${TESTDIR}/files/srcdir +log_must ${MKDIR} ${TESTDIR}/files/dstdir +log_must ${TOUCH} ${TESTDIR}/files/srcdir/move + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@1 + +# Now modify them in different ways +log_must ${TOUCH} ${TESTDIR}/dirs/modify +log_must ${MV} ${TESTDIR}/dirs/rename ${TESTDIR}/dirs/rename.new +log_must ${RMDIR} ${TESTDIR}/dirs/delete +log_must ${MKDIR} ${TESTDIR}/dirs/create +log_must ${DATE} >> ${TESTDIR}/files/modify +log_must ${MV} ${TESTDIR}/files/rename ${TESTDIR}/files/rename.new +log_must ${RM} ${TESTDIR}/files/delete +log_must ${MV} ${TESTDIR}/files/srcdir/move ${TESTDIR}/files/dstdir/move +log_must ${TOUCH} ${TESTDIR}/files/create + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@2 + +# "zfs diff"'s output order is unspecified, so we must sort it. The golden +# file is already sorted. +LC_ALL=C $ZFS diff $TESTPOOL/$TESTFS@1 $TESTPOOL/$TESTFS@2 | ${SORT} > $TESTDIR/zfs_diff_output.txt +if [ $? -ne 0 ]; then + log_fail "zfs diff failed" +fi + +# Finally, compare output to the golden output +log_must diff $STF_SUITE/tests/cli_root/zfs_diff/zfs_diff_001_pos.golden $TESTDIR/zfs_diff_output.txt + +log_pass "'zfs diff' gave the expected output" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_test.sh new file mode 100755 index 00000000000..a69da905a3d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_diff/zfs_diff_test.sh @@ -0,0 +1,56 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_diff_001_pos cleanup +zfs_diff_001_pos_head() +{ + atf_set "descr" "zfs diff output for typical operations" + atf_set "require.progs" zfs +} +zfs_diff_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_diff.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_diff_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_diff_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_diff.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_init_test_cases() +{ + + atf_add_test_case zfs_diff_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/Makefile new file mode 100644 index 00000000000..5801f1d21ac --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/Makefile @@ -0,0 +1,29 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_get +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_get_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_get_002_pos.ksh +${PACKAGE}FILES+= zfs_get_007_neg.ksh +${PACKAGE}FILES+= zfs_get_003_pos.ksh +${PACKAGE}FILES+= zfs_get_list_d.kshlib +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_get_006_neg.ksh +${PACKAGE}FILES+= zfs_get_009_pos.ksh +${PACKAGE}FILES+= zfs_get_001_pos.ksh +${PACKAGE}FILES+= zfs_get_010_neg.ksh +${PACKAGE}FILES+= zfs_get.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_get_004_pos.ksh +${PACKAGE}FILES+= zfs_get_008_pos.ksh +${PACKAGE}FILES+= zfs_get_common.kshlib +${PACKAGE}FILES+= zfs_get_005_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/setup.ksh new file mode 100644 index 00000000000..095cbfb1a7a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_container_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get.cfg new file mode 100644 index 00000000000..df1a2752396 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get.cfg @@ -0,0 +1,34 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export TESTSNAP=testsnap${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_001_pos.ksh new file mode 100644 index 00000000000..5e0789f386f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_001_pos.ksh @@ -0,0 +1,160 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_001_pos.ksh 1.6 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_get_001_pos +# +# DESCRIPTION: +# Setting the valid option and properties, 'zfs get' should return the +# correct property value. +# +# STRATEGY: +# 1. Create pool, filesystem, volume and snapshot. +# 2. Setting valid parameter, 'zfs get' should succeed. +# 3. Compare the output property name with the original input property. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A options "" "-p" "-r" "-H" +if zfs_get_list_d_supported ; then + typeset -i i=${#options[*]} + typeset -i j=0 + while (( j<${#depth_options[*]} )); + do + options[$i]=-"${depth_options[$j]}" + (( j+=1 )) + (( i+=1 )) + done +fi + +set -A zfs_props type used available creation volsize referenced \ + compressratio mounted origin recordsize quota reservation mountpoint \ + sharenfs checksum compression atime devices exec readonly setuid \ + snapdir aclmode aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots + + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A zfs_props ${zfs_props[*]} version +fi + +if is_userquota_supported; then + set -A userquota_props userquota@root groupquota@root \ + userused@root groupused@root +fi + +set -A all_props -- "${zfs_props[@]}" "${userquota_props[@]}" + +set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP + +# +# According to dataset and option, checking if 'zfs get' return correct +# property information. +# +# $1 dataset +# $2 properties which are expected to output into $TESTDIR/$TESTFILE0 +# $3 option +# +function check_return_value +{ + typeset dst=$1 + typeset props=$2 + typeset opt=$3 + typeset -i found=0 + typeset p + + for p in $props; do + found=0 + + while read line; do + typeset item + item=$($ECHO $line | $AWK '{print $2}' 2>&1) + + if [[ $item == $p ]]; then + (( found += 1 )) + break + fi + done < $TESTDIR/$TESTFILE0 + + if (( found == 0 )); then + log_fail "'zfs get $opt $props $dst' return " \ + "error message.'$p' haven't been found." + fi + done + + log_note "SUCCESS: '$ZFS get $opt $prop $dst'." +} + +log_assert "Setting the valid options and properties 'zfs get' should return " \ + "the correct property value." +log_onexit cleanup + +# Create filesystem and volume's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +typeset -i i=0 +while (( i < ${#dataset[@]} )); do + for opt in "${options[@]}"; do + for prop in ${all_props[@]}; do + eval "$ZFS get $opt $prop ${dataset[i]} > \ + $TESTDIR/$TESTFILE0" + ret=$? + if [[ $ret != 0 ]]; then + log_fail "$ZFS get returned: $ret" + fi + check_return_value ${dataset[i]} "$prop" "$opt" + done + done + (( i += 1 )) +done + +log_pass "Setting the valid options to dataset, it should succeed and return " \ + "valid value. 'zfs get' pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_002_pos.ksh new file mode 100644 index 00000000000..cb765ecdabe --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_002_pos.ksh @@ -0,0 +1,116 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_002_pos.ksh 1.6 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_get_002_pos +# +# DESCRIPTION: +# Setting the valid option and properties 'zfs get' return correct value. +# It should be successful. +# +# STRATEGY: +# 1. Create pool, filesystem, dataset, volume and snapshot. +# 2. Getting the options and properties random combination. +# 3. Using the combination as the parameters of 'zfs get' to check the +# command line return value. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A options " " p r H + +set -A zfs_props type used available creation volsize referenced compressratio \ + mounted origin recordsize quota reservation mountpoint sharenfs \ + checksum compression atime devices exec readonly setuid snapdir \ + aclmode aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots + + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A zfs_props ${zfs_props[*]} version +fi + +if is_userquota_supported; then + set -A userquota_props userquota@root groupquota@root \ + userused@root groupused@root +fi + +set -A props -- "${zfs_props[@]}" "${userquota_props[@]}" + +set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP + +log_assert "Setting the valid options and properties 'zfs get' return correct "\ + "value. It should be successful." +log_onexit cleanup + +# Create volume and filesystem's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +# +# Begin to test 'get [-prH] +# ' +# 'get [-prH] <-a|-d> " +# +typeset -i opt_numb=8 +typeset -i prop_numb=20 +for dst in ${dataset[@]}; do + # option can be empty, so "" is necessary. + for opt in "" $(gen_option_str "${options[*]}" "-" "" $opt_numb); do + for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb) + do + $ZFS get $opt $prop $dst > /dev/null 2>&1 + ret=$? + if [[ $ret != 0 ]]; then + log_fail "$ZFS get $opt $prop $dst (Code: $ret)" + fi + done + done +done + +log_pass "Setting the valid options to dataset, 'zfs get' pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_003_pos.ksh new file mode 100644 index 00000000000..f43ea75b85e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_003_pos.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_003_pos.ksh 1.3 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_get_003_pos +# +# DESCRIPTION: +# 'zfs get' should get consistent report with different options. +# +# STRATEGY: +# 1. Create pool and filesystem. +# 2. 'zfs mount -o update,noatime .' +# 3. Verify the value of 'zfs get atime' and 'zfs get all | grep atime' +# are identical. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS mount -o update,atime $TESTPOOL/$TESTFS +} + +log_assert "'zfs get' should get consistent report with different option." +log_onexit cleanup + +log_must $ZFS set atime=on $TESTPOOL/$TESTFS +log_must $ZFS mount -o update,noatime $TESTPOOL/$TESTFS + +value1=$($ZFS get -H atime $TESTPOOL/$TESTFS | $AWK '{print $3}') +value2=$($ZFS get -H all $TESTPOOL/$TESTFS | $AWK '{print $2 " " $3}' | \ + $GREP ^atime | $AWK '{print $2}') +if [[ $value1 != $value2 ]]; then + log_fail "value1($value1) != value2($value2)" +fi + +log_pass "'zfs get' get consistent report with different option passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_004_pos.ksh new file mode 100644 index 00000000000..8d1e67ca144 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_004_pos.ksh @@ -0,0 +1,246 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_004_pos.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_get_004_pos +# +# DESCRIPTION: +# Verify 'zfs get all' can get all properties for all datasets in the system +# +# STRATEGY: +# 1. Create datasets for testing +# 2. Issue 'zfs get all' command +# 3. Verify the command gets all available properties of all datasets +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +#check 'zfs get all' supportability with the installed OS version +$ZFS get all >/dev/null 2>&1 +(( $? != 0 )) && log_unsupported "ZFS get all option is unsupported." + + +function cleanup +{ + [[ -e $propfile ]] && $RM -f $propfile + + datasetexists $clone && \ + log_must $ZFS destroy $clone + for snap in $fssnap $volsnap ; do + snapexists $snap && \ + log_must $ZFS destroy $snap + done + + if [[ -n $globalzone ]] ; then + for pool in $TESTPOOL1 $TESTPOOL2 $TESTPOOL3; do + poolexists $pool && \ + log_must $ZPOOL destroy -f $pool + done + for file in `$LS $TESTDIR1/poolfile*`; do + $RM -f $file + done + else + for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3; do + datasetexists $fs && \ + log_must $ZFS destroy -rf $fs + done + fi +} + +log_assert "Verify the functions of 'zfs get all' work." +log_onexit cleanup + +typeset globalzone="" + +if is_global_zone ; then + globalzone="true" +fi + +set -A opts "" "-r" "-H" "-p" "-rHp" "-o name" \ + "-s local,default,temporary,inherited,none" \ + "-o name -s local,default,temporary,inherited,none" \ + "-rHp -o name -s local,default,temporary,inherited,none" +set -A usrprops "a:b=c" "d_1:1_e=0f" "123:456=789" + +fs=$TESTPOOL/$TESTFS +fssnap=$fs@$TESTSNAP +clone=$TESTPOOL/$TESTCLONE +volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP + +#set user defined properties for $TESTPOOL +for usrprop in ${usrprops[@]}; do + log_must $ZFS set $usrprop $TESTPOOL +done +# create snapshot and clone in $TESTPOOL +log_must $ZFS snapshot $fssnap +log_must $ZFS clone $fssnap $clone +log_must $ZFS snapshot $volsnap + +# collect datasets which can be set user defined properties +usrpropds="$clone $fs" + +# collect all datasets which we are creating +allds="$fs $clone $fssnap $volsnap" + +#create pool and datasets to guarantee testing under multiple pools and datasets. +file=$TESTDIR1/poolfile +typeset -i FILESIZE=104857600 #100M +(( DFILESIZE = FILESIZE * 2 )) # double of FILESIZE +typeset -i VOLSIZE=10485760 #10M +availspace=$(get_prop available $TESTPOOL) +typeset -i i=0 + +# make sure 'availspace' is larger then twice of FILESIZE to create a new pool. +# If any, we only totally create 3 pools for multple datasets testing to limit +# testing time +while (( availspace > DFILESIZE )) && (( i < 3 )) ; do + (( i += 1 )) + + if [[ -n $globalzone ]] ; then + log_must create_vdevs ${file}$i + eval pool=\$TESTPOOL$i + log_must $ZPOOL create $pool ${file}$i + else + eval pool=$TESTPOOL/\$TESTFS$i + log_must $ZFS create $pool + fi + + #set user defined properties for testing + for usrprop in ${usrprops[@]}; do + log_must $ZFS set $usrprop $pool + done + + #create datasets in pool + log_must $ZFS create $pool/$TESTFS + log_must $ZFS snapshot $pool/$TESTFS@$TESTSNAP + log_must $ZFS clone $pool/$TESTFS@$TESTSNAP $pool/$TESTCLONE + + if [[ -n $globalzone ]] ; then + log_must $ZFS create -V $VOLSIZE $pool/$TESTVOL + else + log_must $ZFS create $pool/$TESTVOL + fi + + ds=`$ZFS list -H -r -o name -t filesystem,volume $pool` + usrpropds="$usrpropds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL" + allds="$allds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL \ + $pool/$TESTFS@$TESTSNAP" + + availspace=$(get_prop available $TESTPOOL) +done + +#the expected number of property for each type of dataset in this testing +typeset -i fspropnum=27 +typeset -i snappropnum=8 +typeset -i volpropnum=15 +propfile=$TMPDIR/allpropfile.${TESTCASE_ID} + +typeset -i i=0 +typeset -i propnum=0 +typeset -i failflag=0 +while (( i < ${#opts[*]} )); do + [[ -e $propfile ]] && $RM -f $propfile + log_must eval "$ZFS get ${opts[i]} all >$propfile" + + for ds in $allds; do + $GREP $ds $propfile >/dev/null 2>&1 + (( $? != 0 )) && \ + log_fail "There is no property for" \ + "dataset $ds in 'get all' output." + + propnum=`$CAT $propfile | $AWK '{print $1}' | \ + $GREP "${ds}$" | $WC -l` + ds_type=`$ZFS get -H -o value type $ds` + case $ds_type in + filesystem ) + (( propnum < fspropnum )) && \ + (( failflag += 1 )) + ;; + snapshot ) + (( propnum < snappropnum )) && \ + (( failflag += 1 )) + ;; + volume ) + (( propnum < volpropnum )) && \ + (( failflag += 1 )) + ;; + esac + + (( failflag != 0 )) && \ + log_fail " 'zfs get all' fails to get out " \ + "all properties for dataset $ds." + + (( propnum = 0 )) + (( failflag = 0 )) + done + + (( i += 1 )) +done + +log_note "'zfs get' can get particular property for all datasets with that property." + +function do_particular_prop_test # +{ + typeset props="$1" + typeset ds="$2" + + for prop in ${commprops[*]}; do + ds=`$ZFS get -H -o name $prop` + + [[ "$ds" != "$allds" ]] && \ + log_fail "The result datasets are $ds, but all suitable" \ + "datasets are $allds for the property $prop" + done +} + +# Here, we do a testing for user defined properties and the most common properties +# for all datasets. +commprop="type creation used referenced compressratio" +usrprop="a:b d_1:1_e 123:456" + +do_particular_prop_test "$commprop" "$allds" +do_particular_prop_test "$usrprop" "$usrpropds" + +log_pass "'zfs get all' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_005_neg.ksh new file mode 100644 index 00000000000..ec445ec290a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_005_neg.ksh @@ -0,0 +1,140 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_005_neg.ksh 1.5 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_get_005_neg +# +# DESCRIPTION: +# Setting the invalid option and properties, 'zfs get' should failed. +# +# STRATEGY: +# 1. Create pool, filesystem, volume and snapshot. +# 2. Getting incorrect combination by invalid parameters +# 3. Using the combination as the parameters of 'zfs get' to check the +# command line return value. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A val_opts p r H +set -A v_props type used available creation volsize referenced compressratio mounted \ + origin recordsize quota reservation mountpoint sharenfs checksum \ + compression atime devices exec readonly setuid zoned snapdir aclmode \ + aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A v_props ${v_props[*]} version +fi + +if is_userquota_supported; then + set -A userquota_props userquota@root groupquota@root \ + userused@root groupused@root +fi + +set -A val_pros -- "${v_props[@]}" "${userquota_props[@]}" + +set -f # Force shell does not parse '?' and '*' as the wildcard +set -A inval_opts P R h ? * +set -A inval_props Type 0 ? * -on --on readonl time USED RATIO MOUNTED + +set -A dataset $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP + +typeset -i opt_numb=6 +typeset -i prop_numb=12 + +val_opts_str=$(gen_option_str "${val_opts[*]}" "-" "" $opt_numb) +val_props_str=$(gen_option_str "${val_props[*]}" "" "," $prop_numb) +val_props_str="$val_props_str -a -d" + +inval_opts_str=$(gen_option_str "${inval_opts[*]}" "-" "" $opt_numb) +inval_props_str=$(gen_option_str "${inval_props[*]}" "" "," $prop_numb) + +# +# Test different options and properties combination. +# +# $1 options +# $2 properties +# +function test_options +{ + typeset opts=$1 + typeset props=$2 + + for dst in ${dataset[@]}; do + for opt in $opts; do + for prop in $props; do + $ZFS get $opt $prop $dst > /dev/null 2>&1 + ret=$? + if [[ $ret == 0 ]]; then + log_fail "$ZFS get \ + $opt $prop $dst unexpectedly succeeded." + fi + done + done + done +} + +log_assert "Setting the invalid option and properties, 'zfs get' should be \ + failed." +log_onexit cleanup + +# Create filesystem and volume's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +log_note "Valid options + invalid properties, 'zfs get' should fail." +test_options "$val_opts_str" "$inval_props_str" + +log_note "Invalid options + valid properties, 'zfs get' should fail." +test_options "$inval_opts_str" "$val_props_str" + +log_note "Invalid options + invalid properties, 'zfs get' should fail." +test_options "$inval_opts_str" "$inval_props_str" + +log_pass "Setting the invalid options to dataset, 'zfs get' pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_006_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_006_neg.ksh new file mode 100644 index 00000000000..7989665b17c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_006_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_006_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_get_006_neg +# +# DESCRIPTION: +# Verify 'zfs get all' can deal with invalid scenarios +# +# STRATEGY: +# 1. Define invalid scenarios for 'zfs get all' +# 2. Run zfs get with those invalid scenarios +# 3. Verify that zfs get fails with invalid scenarios +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify 'zfs get all' fails with invalid combination scenarios." + +set -f # Force ksh ignore '?' and '*' +set -A bad_combine "ALL" "\-R all" "-P all" "-h all" "-rph all" "-RpH all" "-PrH all" \ + "-o all" "-s all" "-? all" "-* all" "-?* all" "all -r" "all -p" \ + "all -H" "all -rp" "all -rH" "all -ph" "all -rpH" "all -r $TESTPOOL" \ + "all -H $TESTPOOL" "all -p $TESTPOOL" "all -r -p -H $TESTPOOL" \ + "all -rph $TESTPOOL" "all,available,reservation $TESTPOOL" \ + "all $TESTPOOL?" "all $TESTPOOL*" "all nonexistpool" + +typeset -i i=0 +while (( i < ${#bad_combine[*]} )) +do + log_mustnot eval "$ZFS get ${bad_combine[i]} >/dev/null" + + (( i = i + 1 )) +done + +log_pass "'zfs get all' fails with invalid combinations scenarios as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_007_neg.ksh new file mode 100644 index 00000000000..b5bd599f702 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_007_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_007_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_get_007_neg +# +# DESCRIPTION: +# 'zfs get -o' should fail with invalid column names +# +# STRATEGY: +# 1. Run zfs get -o with invalid column name combinations +# 2. Verify that zfs get returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "'zfs get -o' fails with invalid options or column names" + +set -A badargs "o name,property,value,resource" "o name" \ + "-O name,property,value,source" "-oo name" "-o blah" \ + "-o name,property,blah,source" "-o name,name,name,name,name" \ + "-o name,property,value,," "-o *,*,*,*" "-o ?,?,?,?" \ + "-o" "-o ,,,,," "-o -o -o -o" "-o NAME,PROPERTY,VALUE,SOURCE" \ + "-o name,properTy,value,source" "-o name, property, value,source" \ + "-o name:property:value:source" "-o name,property:value,source" \ + "-o name;property;value;source" + +typeset -i i=0 +while (( i < ${#badargs[*]} )) +do + log_mustnot eval "$ZFS get \"${badargs[i]}\" >/dev/null 2>&1" + + (( i = i + 1 )) +done + +log_pass "'zfs get -o' fails with invalid options or column name as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_008_pos.ksh new file mode 100644 index 00000000000..0c415999eed --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_008_pos.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_008_pos.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_get_008_pos +# +# DESCRIPTION: +# Verify "-d " can work with other options +# +# STRATEGY: +# 1. Create pool, filesystem, dataset, volume and snapshot. +# 2. Getting an -d option, other options and properties random combination. +# 3. Using the combination as the parameters of 'zfs get' to check the +# command line return value. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-05-22) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! zfs_get_list_d_supported ; then + log_unsupported "'zfs get -d' is not supported." +fi + +set -A options " " "-r" "-H" "-p" "-rHp" "-o name" \ + "-s local,default,temporary,inherited,none" \ + "-o name -s local,default,temporary,inherited,none" \ + "-rHp -o name -s local,default,temporary,inherited,none" + +set -A props type used available creation volsize referenced compressratio \ + mounted origin recordsize quota reservation mountpoint sharenfs \ + checksum compression atime devices exec readonly setuid snapdir \ + aclmode aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ + userquota@root groupquota@root userused@root groupused@root + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A all_props ${all_props[*]} version +fi + +set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP + +log_assert "Verify '-d ' can work with other options" +log_onexit cleanup + +# Create volume and filesystem's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +typeset -i opt_numb=16 +typeset -i prop_numb=16 +typeset -i i=0 +typeset -i item=0 +typeset -i depth_item=0 + +for dst in ${dataset[@]}; do + (( i=0 )) + while (( i < opt_numb )); do + (( item = $RANDOM % ${#options[@]} )) + (( depth_item = $RANDOM % ${#depth_options[@]} )) + for prop in $(gen_option_str "${props[*]}" "" "," $prop_numb) + do + log_must eval "$ZFS get -${depth_options[depth_item]} ${options[item]} $prop $dst > /dev/null 2>&1" + done + (( i += 1 )) + done +done + +log_pass "Verify '-d ' can work with other options" + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_009_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_009_pos.ksh new file mode 100644 index 00000000000..72e22eea9fe --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_009_pos.ksh @@ -0,0 +1,105 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_009_pos.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_get_009_pos +# +# DESCRIPTION: +# 'zfs get -d ' should get expected output. +# +# STRATEGY: +# 1. Create a multiple depth filesystem. +# 2. 'zfs get -d ' to get the output. +# 3. 'zfs get -r|egrep' to get the expected output. +# 4. Compare the two outputs, they shoud be same. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-05-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! zfs_get_list_d_supported ; then + log_unsupported "'zfs get -d' is not supported." +fi + +log_assert "'zfs get -d ' should get expected output." +log_onexit depth_fs_cleanup + +set -A all_props type used available creation volsize referenced \ + compressratio mounted origin recordsize quota reservation mountpoint \ + sharenfs checksum compression atime devices exec readonly setuid \ + snapdir aclmode aclinherit canmount primarycache secondarycache \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ + userquota@root groupquota@root userused@root groupused@root + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + set -A all_props ${all_props[*]} version +fi + +depth_fs_setup + +mntpnt=$(get_prop mountpoint $DEPTH_FS) +DEPTH_OUTPUT="$mntpnt/depth_output" +EXPECT_OUTPUT="$mntpnt/expect_output" +typeset -i prop_numb=16 +typeset -i old_val=0 +typeset -i j=0 +typeset eg_opt="$DEPTH_FS"$ +for dp in ${depth_array[@]}; do + (( j=old_val+1 )) + while (( j<=dp && j<=MAX_DEPTH )); do + eg_opt="$eg_opt""|d""$j"$ + (( j+=1 )) + done + for prop in $(gen_option_str "${all_props[*]}" "" "," $prop_numb); do + log_must eval "$ZFS get -H -d $dp -o name $prop $DEPTH_FS > $DEPTH_OUTPUT" + log_must eval "$ZFS get -rH -o name $prop $DEPTH_FS | $EGREP -e '$eg_opt' > $EXPECT_OUTPUT" + log_must $DIFF $DEPTH_OUTPUT $EXPECT_OUTPUT + done + (( old_val=dp )) +done + +log_pass "'zfs get -d ' should get expected output." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_010_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_010_neg.ksh new file mode 100644 index 00000000000..74fe132a75e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_010_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_010_neg.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_get_010_neg +# +# DESCRIPTION: +# A negative depth or a non numeric depth should fail in 'zfs get -d ' +# +# STRATEGY: +# 1. Run zfs get -d with negative depth or non numeric depth +# 2. Verify that zfs get returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-05-22) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! zfs_get_list_d_supported ; then + log_unsupported "'zfs get -d' is not supported." +fi + +log_assert "A negative depth or a non numeric depth should fail in 'zfs get -d '" + +set -A badargs "a" "AB" "aBc" "2A" "a2b" "aB2" "-1" "-32" "-999" + +typeset -i i=0 +while (( i < ${#badargs[*]} )) +do + log_mustnot eval "$ZFS get -d ${badargs[i]} $TESTPOOL/$TESTFS >/dev/null 2>&1" + (( i = i + 1 )) +done + +log_pass "A negative depth or a non numeric depth should fail in 'zfs get -d '" + + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_common.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_common.kshlib new file mode 100644 index 00000000000..d8c81742f76 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_common.kshlib @@ -0,0 +1,102 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_common.kshlib 1.3 07/03/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# According to $elements, $prefix and $separator, the function random produce +# the number of $counter combination. +# +# $1 elements which is used to get the combination. +# $2 prefix is appended to the combination +# $3 separator between the combination, such as ' ' or ',' +# $4 counter is the number of combination which you want to get. +# +function gen_option_str # $elements $prefix $separator $counter +{ + typeset elements="" + typeset prefix=${2} + typeset separator=${3} + typeset -i counter=${4:-0} + typeset -i i=0 + typeset comb_str="" + + for e in $1; do + elements[i]="$e" + (( i += 1 )) + done + (( ${#elements[@]} == 0 )) && log_fail "The elements can't be empty." + + typeset -i item=0 + typeset -i j=0 + typeset -i numb_item=0 + + # Loop and get the specified number combination strings. + i=0 + while (( i < counter )); do + j=0 + numb_item=0 + comb_str="" + + # Get random number items for each combinations. + (( numb_item = ($RANDOM % ${#elements[@]}) + 1 )) + + while (( j < numb_item )); do + # Random select elements from the array + (( item = $RANDOM % ${#elements[@]} )) + + if (( ${#comb_str} == 0 )); then + comb_str=${elements[item]} + else + comb_str=$comb_str$separator${elements[item]} + fi + (( j += 1 )) + done + + print "$prefix$comb_str" + + (( i += 1 )) + done +} + +# +# Cleanup the volume snapshot and filesystem snapshot were created for +# this test case. +# +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ + destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP + datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP + + [[ -e $TESTFILE0 ]] && log_must $RM $TESTFILE0 +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_list_d.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_list_d.kshlib new file mode 100644 index 00000000000..f441d9e0037 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_list_d.kshlib @@ -0,0 +1,94 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_list_d.kshlib 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DEPTH_FS=$TESTPOOL/depth_fs +MAX_DEPTH=3 +DS_COUNT=3 +set -A depth_options "d 0" "d 1" "d 2" "d 4" "d 32" +set -A depth_array 0 1 2 4 32 + +# +# 'zfs get -d or zfs list -d' is supported +# +function zfs_get_list_d_supported +{ + check_opt_support "get" "-d" + return $? +} + +# +# Setup multiple depths datasets, including fs, volume and snapshot. +# +function depth_fs_setup +{ + typeset -i i j k + typeset fslist + + log_must $ZFS create $DEPTH_FS + + (( i=1 )) + while (( i<=MAX_DEPTH )); do + if (( i==1 )); then + fslist=$DEPTH_FS + else + (( k=i-1 )) + fslist=$($ZFS list -rH -t filesystem -o name $DEPTH_FS|$GREP d"$k"$) + if (( $? != 0 )); then + zfs list -rH -t filesystem -o name $DEPTH_FS + log_fail "No d$k filesystem" + fi + fi + for fs in $fslist; do + (( j=1 )) + while (( j<=DS_COUNT )); do + log_must $ZFS create $fs/fs_"$j"_d"$i" + if is_global_zone ; then + log_must $ZFS create -V 8M $fs/v_"$j"_d"$i" + fi + log_must $ZFS snapshot $fs@s_"$j"_d"$i" + (( j=j+1 )) + done + done + (( i=i+1 )) + done +} + +# +# Cleanup multiple depths filesystem. +# +function depth_fs_cleanup +{ + log_must $ZFS destroy -rR $DEPTH_FS +} + + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_test.sh new file mode 100755 index 00000000000..633745657cc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_get/zfs_get_test.sh @@ -0,0 +1,323 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_get_001_pos cleanup +zfs_get_001_pos_head() +{ + atf_set "descr" "Setting the valid options and properties 'zfs get' should returnthe correct property value." + atf_set "require.progs" zfs +} +zfs_get_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_get_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_002_pos cleanup +zfs_get_002_pos_head() +{ + atf_set "descr" "Setting the valid options and properties 'zfs get' return correctvalue. It should be successful." + atf_set "require.progs" zfs +} +zfs_get_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_get_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_003_pos cleanup +zfs_get_003_pos_head() +{ + atf_set "descr" "'zfs get' should get consistent report with different option." + atf_set "require.progs" zfs +} +zfs_get_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_get_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_004_pos cleanup +zfs_get_004_pos_head() +{ + atf_set "descr" "Verify the functions of 'zfs get all' work." + atf_set "require.progs" zfs zpool +} +zfs_get_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_get_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_005_neg cleanup +zfs_get_005_neg_head() +{ + atf_set "descr" "Setting the invalid option and properties, 'zfs get' should befailed." + atf_set "require.progs" zfs +} +zfs_get_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_005_neg.ksh || atf_fail "Testcase failed" +} +zfs_get_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_006_neg cleanup +zfs_get_006_neg_head() +{ + atf_set "descr" "Verify 'zfs get all' fails with invalid combination scenarios." + atf_set "require.progs" zfs +} +zfs_get_006_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_006_neg.ksh || atf_fail "Testcase failed" +} +zfs_get_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_007_neg cleanup +zfs_get_007_neg_head() +{ + atf_set "descr" "'zfs get -o' fails with invalid options or column names" + atf_set "require.progs" zfs +} +zfs_get_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_get_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_008_pos cleanup +zfs_get_008_pos_head() +{ + atf_set "descr" "Verify '-d ' can work with other options" + atf_set "require.progs" zfs +} +zfs_get_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_008_pos.ksh || atf_fail "Testcase failed" +} +zfs_get_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_009_pos cleanup +zfs_get_009_pos_head() +{ + atf_set "descr" "'zfs get -d ' should get expected output." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +zfs_get_009_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_009_pos.ksh || atf_fail "Testcase failed" +} +zfs_get_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_010_neg cleanup +zfs_get_010_neg_head() +{ + atf_set "descr" "A negative depth or a non numeric depth should fail in 'zfs get -d '" + atf_set "require.progs" zfs +} +zfs_get_010_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_010_neg.ksh || atf_fail "Testcase failed" +} +zfs_get_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_get_list_d.kshlib + . $(atf_get_srcdir)/zfs_get_common.kshlib + . $(atf_get_srcdir)/zfs_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_get_001_pos + atf_add_test_case zfs_get_002_pos + atf_add_test_case zfs_get_003_pos + atf_add_test_case zfs_get_004_pos + atf_add_test_case zfs_get_005_neg + atf_add_test_case zfs_get_006_neg + atf_add_test_case zfs_get_007_neg + atf_add_test_case zfs_get_008_pos + atf_add_test_case zfs_get_009_pos + atf_add_test_case zfs_get_010_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/Makefile new file mode 100644 index 00000000000..7777549794e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_inherit +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_inherit_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_inherit_002_neg.ksh +${PACKAGE}FILES+= zfs_inherit_003_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_inherit_001_neg.ksh +${PACKAGE}FILES+= zfs_inherit.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/setup.ksh new file mode 100644 index 00000000000..095cbfb1a7a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_container_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit.cfg new file mode 100644 index 00000000000..d189b0ed611 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit.cfg @@ -0,0 +1,30 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh new file mode 100644 index 00000000000..3a2cc031719 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_001_neg.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_inherit_001_neg.ksh 1.4 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_inherit_001_neg +# +# DESCRIPTION: +# 'zfs inherit' should return an error when attempting to inherit +# properties which are not inheritable. +# +# STRATEGY: +# 1. Create an array of properties which cannot be inherited +# 2. For each property in the array, execute 'zfs inherit' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Define uninherited properties and their short name. +typeset props_str="type creation \ + compressratio ratio mounted origin quota reservation \ + reserv volsize volblocksize volblock" + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + props_str="$props_str version" +fi + +set -A prop $props_str canmount + + +log_assert "'zfs inherit' should return an error when attempting to inherit" \ + " un-inheritable properties." + +typeset -i i=0 +for obj in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do + i=0 + while [[ $i -lt ${#prop[*]} ]]; do + orig_val=$(get_prop ${prop[i]} $obj) + + log_mustnot $ZFS inherit ${prop[i]} $obj + + new_val=$(get_prop ${prop[i]} $obj) + + if [[ $new_val != $orig_val ]]; then + log_fail "${prop[i]} property changed from $orig_val " + " to $new_val" + fi + ((i = i + 1)) + done +done + +log_pass "'zfs inherit' failed as expected when attempting to inherit" \ + " un-inheritable properties." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh new file mode 100644 index 00000000000..0fb8409fd9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh @@ -0,0 +1,114 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_inherit_002_neg.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_inherit_002_neg +# +# DESCRIPTION: +# 'zfs inherit' should return an error with bad parameters in one command. +# +# STRATEGY: +# 1. Set an array of bad options and invlid properties to 'zfs inherit' +# 2. Execute 'zfs inherit' with bad options and passing invlid properties +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists $TESTPOOL/$TESTFS@$TESTSNAP; then + log_must $ZFS destroy $TESTPOOL/$TESTFS@$TESTSNAP + fi +} + +log_assert "'zfs inherit' should return an error with bad parameters in one command." +log_onexit cleanup + +set -A badopts "r" "R" "-R" "-rR" "-a" "-" "-?" "-1" "-2" "-v" "-n" +set -A props "recordsize" "mountpoint" "sharenfs" "checksum" "compression" \ + "atime" "devices" "exec" "setuid" "readonly" "zoned" "snapdir" "aclmode" \ + "aclinherit" "shareiscsi" "xattr" "copies" +set -A illprops "recordsiz" "mountpont" "sharen" "compres" "atme" "???" "***" "blah" + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP + +typeset -i i=0 +for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP; do + + #zfs inherit should fail with bad options + for opt in ${badopts[@]}; do + for prop in ${props[@]}; do + log_mustnot eval "$ZFS inherit $opt $prop $ds >/dev/null 2>&1" + done + done + + #zfs inherit should fail with invalid properties + for prop in ${illprops[@]}; do + log_mustnot eval "$ZFS inherit $prop $ds >/dev/null 2>&1" + log_mustnot eval "$ZFS inherit -r $prop $ds >/dev/null 2>&1" + done + + #zfs inherit should fail with too many arguments + (( i = 0 )) + while (( i < ${#props[*]} -1 )); do + log_mustnot eval "$ZFS inherit ${props[(( i ))]} \ + ${props[(( i + 1 ))]} $ds >/dev/null 2>&1" + log_mustnot eval "$ZFS inherit -r ${props[(( i ))]} \ + ${props[(( i + 1 ))]} $ds >/dev/null 2>&1" + + (( i = i + 2 )) + done + +done + +#zfs inherit should fail with missing datasets +for prop in ${props[@]}; do + log_mustnot eval "$ZFS inherit $prop >/dev/null 2>&1" + log_mustnot eval "$ZFS inherit -r $prop >/dev/null 2>&1" +done + +log_pass "'zfs inherit' failed as expected when passing illegal arguments." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh new file mode 100644 index 00000000000..746671d7f4b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_inherit_003_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_inherit_003_pos +# +# DESCRIPTION: +# 'zfs inherit' should return an error with bad parameters in one command. +# +# STRATEGY: +# 1. Set an array of bad options and invlid properties to 'zfs inherit' +# 2. Execute 'zfs inherit' with bad options and passing invlid properties +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do + if snapexists $ds@$TESTSNAP; then + log_must $ZFS destroy $ds@$TESTSNAP + fi + done + cleanup_user_prop $TESTPOOL +} + +log_assert "'zfs inherit' should inherit user property." +log_onexit cleanup + +for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do + typeset prop_name=$(valid_user_property 10) + typeset value=$(user_property_value 16) + + log_must eval "$ZFS set $prop_name='$value' $ds" + + log_must $ZFS snapshot $ds@$TESTSNAP + + typeset snapvalue=$(get_prop $prop_name $ds@$TESTSNAP) + + if [[ "$snapvalue" != "$value" ]] ; then + log_fail "The '$ds@$TESTSNAP '$prop_name' value '$snapvalue' " \ + "not equal to the expected value '$value'." + fi + + snapvalue=$(user_property_value 16) + log_must eval "$ZFS set $prop_name='$snapvalue' $ds@$TESTSNAP" + + log_must $ZFS inherit $prop_name $ds@$TESTSNAP + + snapvalue=$(get_prop $prop_name $ds@$TESTSNAP) + + if [[ "$snapvalue" != "$value" ]] ; then + log_fail "The '$ds@$TESTSNAP '$prop_name' value '$snapvalue' " \ + "not equal to the expected value '$value'." + fi + + +done + +log_pass "'zfs inherit' inherit user property." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_test.sh new file mode 100755 index 00000000000..1f110f52072 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_inherit/zfs_inherit_test.sh @@ -0,0 +1,107 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_inherit_001_neg cleanup +zfs_inherit_001_neg_head() +{ + atf_set "descr" "'zfs inherit' should return an error when attempting to inherit un-inheritable properties." + atf_set "require.progs" zfs +} +zfs_inherit_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_inherit.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_inherit_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_inherit_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_inherit.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_inherit_002_neg cleanup +zfs_inherit_002_neg_head() +{ + atf_set "descr" "'zfs inherit' should return an error with bad parameters in one command." + atf_set "require.progs" zfs +} +zfs_inherit_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_inherit.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_inherit_002_neg.ksh || atf_fail "Testcase failed" +} +zfs_inherit_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_inherit.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_inherit_003_pos cleanup +zfs_inherit_003_pos_head() +{ + atf_set "descr" "'zfs inherit' should inherit user property." + atf_set "require.progs" zfs +} +zfs_inherit_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_inherit.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_inherit_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_inherit_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_inherit.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_inherit_001_neg + atf_add_test_case zfs_inherit_002_neg + atf_add_test_case zfs_inherit_003_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/Makefile new file mode 100644 index 00000000000..9e38234a3f9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/Makefile @@ -0,0 +1,30 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_mount +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_mount_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_mount_004_pos.ksh +${PACKAGE}FILES+= zfs_mount_008_pos.ksh +${PACKAGE}FILES+= zfs_mount_009_neg.ksh +${PACKAGE}FILES+= zfs_mount_010_neg.ksh +${PACKAGE}FILES+= zfs_mount_011_neg.ksh +${PACKAGE}FILES+= zfs_mount_005_pos.ksh +${PACKAGE}FILES+= zfs_mount_001_pos.ksh +${PACKAGE}FILES+= zfs_mount.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_mount.kshlib +${PACKAGE}FILES+= zfs_mount_007_pos.ksh +${PACKAGE}FILES+= zfs_mount_003_pos.ksh +${PACKAGE}FILES+= zfs_mount_all_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_mount_006_pos.ksh +${PACKAGE}FILES+= zfs_mount_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/cleanup.ksh new file mode 100644 index 00000000000..26ce7c30a0b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/setup.ksh new file mode 100644 index 00000000000..167f749f724 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount.cfg new file mode 100644 index 00000000000..1c80531e773 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount.cfg @@ -0,0 +1,42 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export mountcmd=mount +export mountforce="$mountcmd -f" +export mountall="$mountcmd -a" + +export unmountcmd=unmount +export unmountforce="$unmountcmd -f" +export unmountall="$unmountcmd -a" + +export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount.kshlib new file mode 100644 index 00000000000..ddc097fa9bc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount.kshlib @@ -0,0 +1,135 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount.kshlib 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +function force_unmount #dev +{ + typeset dev=$1 + + ismounted $dev + if (( $? == 0 )); then + log_must $ZFS $unmountforce $dev + fi + return 0 +} + +# Create pool and ( fs | container | vol ) with the given parameters, +# it'll destroy prior exist one that has the same name. + +function setup_filesystem #disklist #pool #fs #mntpoint #type #vdev +{ + typeset disklist=$1 + typeset pool=$2 + typeset fs=${3##/} + typeset mntpoint=$4 + typeset type=$5 + typeset vdev=$6 + + if [[ -z $pool || -z $fs || -z $mntpoint ]]; then + log_note "Missing parameter: (\"$pool\", \"$fs\", \"$mntpoint\")" + return 1 + fi + + if is_global_zone && [[ -z $disklist ]] ; then + log_note "Missing disklist." + return 1 + fi + + if [[ $vdev != "" && \ + $vdev != "mirror" && \ + $vdev != "raidz" ]] ; then + + log_note "Wrong vdev: (\"$vdev\")" + return 1 + fi + + poolexists $pool || \ + create_pool $pool $vdev $disklist + + datasetexists $pool/$fs && \ + log_must cleanup_filesystem $pool $fs + + $RMDIR $mntpoint > /dev/null 2>&1 + if [[ ! -d $mntpoint ]]; then + log_must $MKDIR -p $mntpoint + fi + + case "$type" in + 'ctr') log_must $ZFS create $pool/$fs + log_must $ZFS set mountpoint=$mntpoint $pool/$fs + ;; + 'vol') log_must $ZFS create -V $VOLSIZE $pool/$fs + ;; + *) log_must $ZFS create $pool/$fs + log_must $ZFS set mountpoint=$mntpoint $pool/$fs + ;; + esac + + return 0 +} + +# Destroy ( fs | container | vol ) with the given parameters. +function cleanup_filesystem #pool #fs +{ + typeset pool=$1 + typeset fs=${2##/} + typeset mtpt="" + + if [[ -z $pool || -z $fs ]]; then + log_note "Missing parameter: (\"$pool\", \"$fs\")" + return 1 + fi + + if datasetexists "$pool/$fs" ; then + mtpt=$(get_prop mountpoint "$pool/$fs") + log_must $ZFS destroy -r $pool/$fs + + [[ -d $mtpt ]] && \ + log_must $RM -rf $mtpt + else + return 1 + fi + + return 0 +} + +# Make sure 'zfs mount' should display all ZFS filesystems currently mounted. +# The results of 'zfs mount' and 'df -F zfs' should be identical. +function verify_mount_display +{ + typeset fs + + for fs in $($ZFS $mountcmd | $AWK '{print $1}') ; do + log_must mounted $fs + done + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_001_pos.ksh new file mode 100644 index 00000000000..52f26fbb161 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_001_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_001_pos +# +# DESCRIPTION: +# Invoke "zfs mount " with a regular name of filesystem, +# will mount that filesystem successfully. +# +# STRATEGY: +# 1. Make sure that the ZFS filesystem is unmounted. +# 2. Invoke 'zfs mount '. +# 3. Verify that the filesystem is mounted. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must force_unmount $TESTPOOL/$TESTFS + return 0 +} + +log_assert "Verify that '$ZFS $mountcmd ' succeeds as root." + +log_onexit cleanup + +unmounted $TESTPOOL/$TESTFS || \ + log_must cleanup + +log_must $ZFS $mountcmd $TESTPOOL/$TESTFS + +log_note "Make sure the filesystem $TESTPOOL/$TESTFS is mounted" +mounted $TESTPOOL/$TESTFS || \ + log_fail Filesystem $TESTPOOL/$TESTFS is unmounted + +log_pass "'$ZFS $mountcmd ' succeeds as root." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_002_pos.ksh new file mode 100644 index 00000000000..941d151b73e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_002_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_002_pos +# +# DESCRIPTION: +# Invoking "zfs mount " with a filesystem whose name is not in +# "zfs list", will fail with a return code of 1. +# +# STRATEGY: +# 1. Make sure the NONEXISTFSNAME ZFS filesystem is not in 'zfs list'. +# 2. Invoke 'zfs mount '. +# 3. Verify that mount failed with return code of 1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset fs + for fs in $NONEXISTFSNAME $TESTFS ; do + log_must force_unmount $TESTPOOL/$fs + done +} + + +log_assert "Verify that '$ZFS $mountcmd' with a filesystem " \ + "whose name is not in 'zfs list' will fail with return code 1." + +log_onexit cleanup + +log_note "Make sure the filesystem $TESTPOOL/$NONEXISTFSNAME " \ + "is not in 'zfs list'" +log_mustnot $ZFS list $TESTPOOL/$NONEXISTFSNAME + +typeset -i ret=0 +$ZFS $mountcmd $TESTPOOL/$NONEXISTFSNAME +ret=$? +(( ret == 1 )) || \ + log_fail "'$ZFS $mountcmd $TESTPOOL/$NONEXISTFSNAME' " \ + "unexpected return code of $ret." + +log_note "Make sure the filesystem $TESTPOOL/$NONEXISTFSNAME is unmounted" +unmounted $TESTPOOL/$NONEXISTFSNAME || \ + log_fail Filesystem $TESTPOOL/$NONEXISTFSNAME is mounted + +log_pass "'$ZFS $mountcmd' with a filesystem " \ + "whose name is not in 'zfs list' failed with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_003_pos.ksh new file mode 100644 index 00000000000..6fc655bf91a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_003_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_003_pos +# +# DESCRIPTION: +# Invoke "zfs mount " with a filesystem whose mountpoint property +# is 'legacy' or 'none', +# it will fail with a return code of 1 and issue an error message. +# +# STRATEGY: +# 1. Make sure that the ZFS filesystem is unmounted. +# 2. Mount the filesystem using the various combinations +# - zfs set mountpoint=legacy +# - zfs set mountpoint=none +# 3. Verify that mount failed with return code of 1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + log_must force_unmount $TESTPOOL/$TESTFS + return 0 +} + +log_assert "Verify that '$ZFS $mountcmd' with a filesystem " \ + "whose mountpoint property is 'legacy' or 'none' " \ + "will fail with return code 1." + +log_onexit cleanup + +set -A mopt "legacy" "none" + +typeset -i ret=0 +typeset -i i=0 + +while (( i < ${#mopt[*]} )); do + unmounted $TESTPOOL/$TESTFS || \ + log_must cleanup + + log_must $ZFS set mountpoint=${mopt[i]} $TESTPOOL/$TESTFS + + $ZFS $mountcmd $TESTPOOL/$TESTFS + ret=$? + (( ret == 1)) || \ + log_fail "'$ZFS $mountcmd $TESTPOOL/$TESTFS' " \ + "unexpected return code of $ret." + + log_note "Make sure the filesystem $TESTPOOL/$TESTFS is unmounted" + unmounted $TESTPOOL/$TESTFS || \ + log_fail Filesystem $TESTPOOL/$TESTFS is mounted + + ((i = i + 1)) +done + +log_pass "Verify that '$ZFS $mountcmd' with a filesystem " \ + "whose mountpoint property is 'legacy' or 'none' " \ + "will fail with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_004_pos.ksh new file mode 100644 index 00000000000..cfc369932e8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_004_pos.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_004_pos +# +# DESCRIPTION: +# Invoke "zfs mount " with a filesystem +# which has been already mounted, +# it will fail with a return code of 1 +# +# STRATEGY: +# 1. Make sure that the ZFS filesystem is unmounted. +# 2. Invoke 'zfs mount '. +# 3. Verify that the filesystem is mounted. +# 4. Invoke 'zfs mount ' the second times. +# 5. Verify the last mount operation failed with return code of 1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must force_unmount $TESTPOOL/$TESTFS + return 0 +} + +typeset -i ret=0 + +log_assert "Verify that '$ZFS $mountcmd ' " \ + "with a mounted filesystem will fail with return code 1." + +log_onexit cleanup + +unmounted $TESTPOOL/$TESTFS || \ + log_must cleanup + +log_must $ZFS $mountcmd $TESTPOOL/$TESTFS + +mounted $TESTPOOL/$TESTFS || \ + log_unresolved "Filesystem $TESTPOOL/$TESTFS is unmounted" + +$ZFS $mountcmd $TESTPOOL/$TESTFS +ret=$? +(( ret == 1 )) || \ + log_fail "'$ZFS $mountcmd $TESTPOOL/$TESTFS' " \ + "unexpected return code of $ret." + +log_note "Make sure the filesystem $TESTPOOL/$TESTFS is mounted" +mounted $TESTPOOL/$TESTFS || \ + log_fail Filesystem $TESTPOOL/$TESTFS is unmounted + +log_pass "'$ZFS $mountcmd ' with a mounted filesystem " \ + "will fail with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_005_pos.ksh new file mode 100644 index 00000000000..dbdd398b769 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_005_pos.ksh @@ -0,0 +1,100 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_005_pos +# +# DESCRIPTION: +# Invoke "zfs mount " with a filesystem +# but its mountpoint is currently in use, +# it will fail with a return code of 1 +# and issue an error message. +# +# STRATEGY: +# 1. Make sure that the ZFS filesystem is unmounted. +# 2. Apply 'zfs set mountpoint=path '. +# 3. Change directory to that given mountpoint. +# 3. Invoke 'zfs mount '. +# 4. Verify that mount failed with return code of 1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + log_must force_unmount $TESTPOOL/$TESTFS + return 0 +} + +typeset -i ret=0 + +log_assert "Verify that '$ZFS $mountcmd' with a filesystem " \ + "whose mountpoint is currently in use will fail with return code 1." + +log_onexit cleanup + +unmounted $TESTPOOL/$TESTFS || \ + log_must cleanup + +[[ -d $TESTDIR ]] || \ + log_must $MKDIR -p $TESTDIR + +cd $TESTDIR || \ + log_unresolved "Unable change directory to $TESTDIR" + +$ZFS $mountcmd $TESTPOOL/$TESTFS +ret=$? +(( ret == 1 )) || \ + log_fail "'$ZFS $mountcmd $TESTPOOL/$TESTFS' " \ + "unexpected return code of $ret." + +log_note "Make sure the filesystem $TESTPOOL/$TESTFS is unmounted" +unmounted $TESTPOOL/$TESTFS || \ + log_fail Filesystem $TESTPOOL/$TESTFS is mounted + +log_pass "'$ZFS $mountcmd' with a filesystem " \ + "whose mountpoint is currently in use failed with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_006_pos.ksh new file mode 100644 index 00000000000..5e51a89c0ef --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_006_pos.ksh @@ -0,0 +1,138 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_006_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_006_pos +# +# DESCRIPTION: +# Invoke "zfs mount " with a filesystem +# which mountpoint be the identical or the top of an existing one, +# it will fail with a return code of 1 +# +# STRATEGY: +# 1. Prepare an existing mounted filesystem. +# 2. Setup a new filesystem and make sure that it is unmounted. +# 3. Mount the new filesystem using the various combinations +# - zfs set mountpoint= +# - zfs set mountpoint= +# 4. Verify that mount failed with return code of 1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must force_unmount $TESTPOOL/$TESTFS + + datasetexists $TESTPOOL/$TESTFS1 && \ + cleanup_filesystem $TESTPOOL $TESTFS1 + + [[ -d $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + log_must force_unmount $TESTPOOL/$TESTFS + + return 0 +} + +typeset -i ret=0 + +log_assert "Verify that '$ZFS $mountcmd ' " \ + "which mountpoint be the identical or the top of an existing one " \ + "will fail with return code 1." + +log_onexit cleanup + +unmounted $TESTPOOL/$TESTFS || \ + log_must force_unmount $TESTPOOL/$TESTFS + +[[ -d $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR + +typeset -i MAXDEPTH=3 +typeset -i depth=0 +typeset mtpt=$TESTDIR + +while (( depth < MAXDEPTH )); do + mtpt=$mtpt/$depth + (( depth = depth + 1)) +done + +log_must $ZFS set mountpoint=$mtpt $TESTPOOL/$TESTFS +log_must $ZFS $mountcmd $TESTPOOL/$TESTFS + +mounted $TESTPOOL/$TESTFS || \ + log_unresolved "Filesystem $TESTPOOL/$TESTFS is unmounted" + +log_must $ZFS create $TESTPOOL/$TESTFS1 + +unmounted $TESTPOOL/$TESTFS1 || \ + log_must force_unmount $TESTPOOL/$TESTFS1 + +while [[ -n $mtpt ]] ; do + (( depth == MAXDEPTH )) && \ + log_note "Verify that '$ZFS $mountcmd ' " \ + "which mountpoint be the identical of an existing one " \ + "will fail with return code 1." + + log_must $ZFS set mountpoint=$mtpt $TESTPOOL/$TESTFS1 + log_mustnot $ZFS $mountcmd $TESTPOOL/$TESTFS1 + + unmounted $TESTPOOL/$TESTFS1 || \ + log_fail "Filesystem $TESTPOOL/$TESTFS1 is mounted." + + mtpt=${mtpt%/*} + + (( depth == MAXDEPTH )) && \ + log_note "Verify that '$ZFS $mountcmd ' " \ + "which mountpoint be the top of an existing one " \ + "will fail with return code 1." + (( depth = depth - 1 )) +done + +log_pass "'$ZFS $mountcmd ' " \ + "which mountpoint be the identical or the top of an existing one " \ + "will fail with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_007_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_007_pos.ksh new file mode 100644 index 00000000000..98da3177d70 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_007_pos.ksh @@ -0,0 +1,152 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_007_pos.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_007_pos +# +# DESCRIPTION: +# The following options can be set on a temporary basis using the -o option +# without affecting the on-disk property. The original on-disk value will be +# restored when the file system is unmounted and mounted. +# +# PROPERTY MOUNT OPTION +# atime atime/noatime +# exec exec/noexec +# readonly ro/rw +# setuid setuid/nosetuid +# +# STRATEGY: +# 1. Create filesystem and get origianl property value. +# 2. Using 'zfs mount -o' to set filesystem property. +# 3. Verify the property was set temporarily. +# 4. Verify it will not affect the property that is stored on disk. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-02) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + if ! ismounted $TESTPOOL/$TESTFS; then + log_must $ZFS mount $TESTPOOL/$TESTFS + fi +} + +log_assert "Verify '-o' will set filesystem property temporarily, " \ + "without affecting the property that is stored on disk." +log_onexit cleanup + +set -A properties "atime" "exec" "readonly" "setuid" + +# +# Get the specified filesystem property reverse mount option. +# +# $1 filesystem +# $2 property +# +function get_reverse_option +{ + typeset fs=$1 + typeset prop=$2 + + # Define property value: "reverse if value=on" "reverse if value=off" + set -A values "noatime" "atime" \ + "noexec" "exec" \ + "rw" "ro" \ + "nosetuid" "setuid" + + typeset -i i=0 + while (( i < ${#properties[@]} )); do + if [[ $prop == ${properties[$i]} ]]; then + break + fi + + (( i += 1 )) + done + if (( i >= ${#properties[@]} )); then + log_fail "Incorrect option: $prop" + fi + + typeset val + typeset -i ind=0 + val=$(get_prop $prop $fs) || log_fail "get_prop $prop $fs" + if [[ $val == "on" ]]; then + (( ind = i * 2 )) + else + (( ind = i * 2 + 1 )) + fi + + $ECHO ${values[$ind]} +} + +fs=$TESTPOOL/$TESTFS +cleanup + +for property in ${properties[@]}; do + orig_val=$(get_prop $property $fs) + (($? != 0)) && log_fail "get_prop $property $fs" + + # Set filesystem property temporarily + reverse_opt=$(get_reverse_option $fs $property) + log_must $ZFS mount -o update,$reverse_opt $fs + + cur_val=$(get_prop $property $fs) + (($? != 0)) && log_fail "get_prop $property $fs" + + if [[ $orig_val == $cur_val ]]; then + log_fail "zfs mount -o update,$reverse_opt " \ + "doesn't change property." + fi + + # unmount & mount will revert property to the original value + log_must $ZFS unmount $fs + log_must $ZFS mount $fs + + cur_val=$(get_prop $property $fs) + (($? != 0)) && log_fail "get_prop $property $fs" + if [[ $orig_val != $cur_val ]]; then + log_fail "zfs mount -o update,$reverse_opt " \ + "change the property that is stored on disks" + fi +done + +log_pass "Verify '-o' set filesystem property temporarily passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_008_pos.ksh new file mode 100644 index 00000000000..facddbe7ba6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_008_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_008_pos.ksh 1.3 09/01/13 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_mount_008_pos +# +# DESCRIPTION: +# 'zfs mount -O' allow the file system to be mounted over an existing +# mount point, making the underlying file system inaccessible. +# +# STRATEGY: +# 1. Create two filesystem fs & fs1, and create two test files for them. +# 2. Unmount fs1 and set mountpoint property is identical to fs. +# 3. Verify 'zfs mount -O' will make the underlying filesystem fs +# inaccessible. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-02) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + ! ismounted $fs && log_must $ZFS mount $fs + + if datasetexists $fs1; then + log_must $ZFS destroy $fs1 + fi + + if [[ -f $testfile ]]; then + log_must $RM -f $testfile + fi +} + +log_assert "Verify 'zfs mount -O' will override existing mount point." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS; fs1=$TESTPOOL/$TESTFS1 + +cleanup + +# Get the original mountpoint of $fs and $fs1 +mntpnt=$(get_prop mountpoint $fs) +log_must $ZFS create $fs1 +mntpnt1=$(get_prop mountpoint $fs1) + +testfile=$mntpnt/$TESTFILE0; testfile1=$mntpnt1/$TESTFILE1 +log_must $MKFILE 1M $testfile $testfile1 + +log_must $ZFS unmount $fs1 +log_must $ZFS set mountpoint=$mntpnt $fs1 +log_must $ZFS mount $fs1 + +# Create new file in override mountpoint +log_must $MKFILE 1M $mntpnt/$TESTFILE2 + +# Verify the underlying file system inaccessible +log_mustnot $LS $testfile +log_must $LS $mntpnt/$TESTFILE1 $mntpnt/$TESTFILE2 + +# Verify $TESTFILE2 was created in $fs1, rather then $fs +log_must $ZFS unmount $fs1 +log_must $ZFS set mountpoint=$mntpnt1 $fs1 +log_must $ZFS mount $fs1 +log_must $LS $testfile1 $mntpnt1/$TESTFILE2 + +# Verify $TESTFILE2 was not created in $fs, and $fs is accessible again. +log_mustnot $LS $mntpnt/$TESTFILE2 +log_must $LS $testfile + +log_pass "Verify 'zfs mount -O' override mount point passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_009_neg.ksh new file mode 100644 index 00000000000..ac97249e101 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_009_neg.ksh @@ -0,0 +1,127 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_009_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_mount_009_neg +# +# DESCRIPTION: +# Try each 'zfs mount' with inapplicable scenarios to make sure +# it returns an error. include: +# * Multiple filesystems specified +# * '-a', but also with a specific filesystem. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute the sub-command +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +multifs="$TESTFS $TESTFS1" +datasets="" + +for fs in $multifs ; do + datasets="$datasets $TESTPOOL/$fs" +done + +set -A args "$mountall $TESTPOOL/$TESTFS" \ + "$mountcmd $datasets" + +function setup_all +{ + typeset fs + + for fs in $multifs ; do + setup_filesystem "$DISKS" "$TESTPOOL" \ + "$fs" \ + "${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID}/$TESTPOOL/$fs" + done + return 0 +} + +function cleanup_all +{ + typeset fs + + cleanup_filesystem "$TESTPOOL" "$TESTFS1" + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + [[ -d ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} ]] && \ + $RM -rf ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} + + + return 0 +} + +function verify_all +{ + typeset fs + + for fs in $multifs ; do + log_must unmounted $TESTPOOL/$fs + done + return 0 +} + +log_assert "Badly-formed 'zfs $mountcmd' with inapplicable scenarios " \ + "should return an error." + +log_onexit cleanup_all + +log_must setup_all + +log_must $ZFS $unmountall + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZFS ${args[i]} + ((i = i + 1)) +done + +log_must verify_all + +log_pass "Badly formed 'zfs $mountcmd' with inapplicable scenarios " \ + "fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_010_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_010_neg.ksh new file mode 100644 index 00000000000..515f2572109 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_010_neg.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_010_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_mount_010_neg +# +# DESCRIPTION: +# Verify that zfs mount should fail when mounting a mounted zfs filesystem or +# the mountpoint is busy +# +# STRATEGY: +# 1. Make a zfs filesystem mounted or mountpoint busy +# 2. Use zfs mount to mount the filesystem +# 3. Verify that zfs mount returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if ! ismounted $fs; then + log_must $ZFS mount $fs + fi +} + +log_assert "zfs mount fails with mounted filesystem or busy mountpoint" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +if ! ismounted $fs; then + log_must $ZFS mount $fs +fi + +log_mustnot $ZFS mount $fs + +mpt=$(get_prop mountpoint $fs) +log_must $ZFS umount $fs +curpath=`$DIRNAME $0` +cd $mpt +log_mustnot $ZFS mount $fs +cd $curpath + +log_pass "zfs mount fails with mounted filesystem or busy moutpoint as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_011_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_011_neg.ksh new file mode 100644 index 00000000000..5f3819d59b3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_011_neg.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_011_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_mount_011_neg +# +# DESCRIPTION: +# Verify that zfs mount should fail with bad parameters +# +# STRATEGY: +# 1. Make an array of bad parameters +# 2. Use zfs mount to mount the filesystem +# 3. Verify that zfs mount returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists $TESTPOOL/$TESTFS@$TESTSNAP; then + log_must $ZFS destroy $TESTPOOL/$TESTFS@$TESTSNAP + fi + + if is_global_zone && datasetexists $TESTPOOL/$TESTVOL; then + log_must $ZFS destroy $TESTPOOL/$TESTVOL + fi +} + +log_assert "zfs mount fails with bad parameters" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +set -A badargs "A" "-A" "-" "-x" "-?" "=" "-o *" "-a" + +for arg in "${badargs[@]}"; do + log_mustnot eval "$ZFS mount $arg $fs >/dev/null 2>&1" +done + +#verify that zfs mount fails with invalid dataset +for opt in "-o abc" "-O"; do + log_mustnot eval "$ZFS mount $opt /$fs >/dev/null 2>&1" +done + +#verify that zfs mount fails with volume and snapshot +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP +log_mustnot eval "$ZFS mount $TESTPOOL/$TESTFS@$TESTSNAP >/dev/null 2>&1" + +if is_global_zone; then + log_must $ZFS create -V 10m $TESTPOOL/$TESTVOL + log_mustnot eval "$ZFS mount $TESTPOOL/$TESTVOL >/dev/null 2>&1" +fi + +log_pass "zfs mount fails with bad parameters as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh new file mode 100644 index 00000000000..67a6c4711d7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_all_001_pos.ksh @@ -0,0 +1,197 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_all_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# __stc_assertion_start +# +# ID: zfs_mount_all_001_pos +# +# DESCRIPTION: +# Verify that 'zfs mount -a' succeeds as root. +# +# STRATEGY: +# 1. Create a group of pools with specified vdev. +# 2. Create zfs filesystems within the given pools. +# 3. Unmount all the filesystems. +# 4. Verify that 'zfs mount -a' command succeed, +# and all available ZFS filesystems are mounted. +# 5. Verify that 'zfs mount' is identical with 'df -F zfs' +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A fs "$TESTFS" "$TESTFS1" +set -A ctr "" "$TESTCTR" "$TESTCTR/$TESTCTR1" "$TESTCTR1" +set -A vol "$TESTVOL" "$TESTVOL1" + +function setup_all +{ + typeset -i i=0 + typeset -i j=0 + typeset path + + while (( i < ${#ctr[*]} )); do + + path=${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID}/$TESTPOOL + if [[ -n ${ctr[i]} ]]; then + path=$path/${ctr[i]} + + setup_filesystem "$DISKS" "$TESTPOOL" \ + "${ctr[i]}" "$path" \ + "ctr" + fi + + if is_global_zone ; then + j=0 + while (( j < ${#vol[*]} )); do + setup_filesystem "$DISKS" "$TESTPOOL" \ + "${ctr[i]}/${vol[j]}" \ + "$path/${vol[j]}" \ + "vol" + ((j = j + 1)) + done + fi + + j=0 + while (( j < ${#fs[*]} )); do + setup_filesystem "$DISKS" "$TESTPOOL" \ + "${ctr[i]}/${fs[j]}" \ + "$path/${fs[j]}" + ((j = j + 1)) + done + + ((i = i + 1)) + done + + return 0 +} + +function cleanup_all +{ + typeset -i i=0 + typeset -i j=0 + typeset path + + ((i = ${#ctr[*]} - 1)) + + while (( i >= 0 )); do + if is_global_zone ; then + j=0 + while (( j < ${#vol[*]} )); do + cleanup_filesystem "$TESTPOOL" \ + "${ctr[i]}/${vol[j]}" + ((j = j + 1)) + done + fi + + j=0 + while (( j < ${#fs[*]} )); do + cleanup_filesystem "$TESTPOOL" \ + "${ctr[i]}/${fs[j]}" + ((j = j + 1)) + done + + [[ -n ${ctr[i]} ]] && \ + cleanup_filesystem "$TESTPOOL" "${ctr[i]}" + + ((i = i - 1)) + done + + [[ -d ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} ]] && \ + $RM -rf ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} +} + +function verify_all +{ + typeset -i i=0 + typeset -i j=0 + typeset path + + while (( i < ${#ctr[*]} )); do + + path=$TESTPOOL + [[ -n ${ctr[i]} ]] && \ + path=$path/${ctr[i]} + + if is_global_zone ; then + j=0 + while (( j < ${#vol[*]} )); do + log_mustnot mounted "$path/${vol[j]}" + ((j = j + 1)) + done + fi + + j=0 + while (( j < ${#fs[*]} )); do + log_must mounted "$path/${fs[j]}" + ((j = j + 1)) + done + + log_must mounted "$path" + + ((i = i + 1)) + done + + return 0 +} + + +log_assert "Verify that 'zfs $mountall' succeeds as root, " \ + "and all available ZFS filesystems are mounted." + +log_onexit cleanup_all + +log_must setup_all + +log_must $ZFS $unmountall + +log_must $ZFS $mountall + +verify_all + +log_note "Verify that 'zfs $mountcmd' will display " \ + "all ZFS filesystems currently mounted." + +verify_mount_display + +log_pass "'zfs $mountall' succeeds as root, " \ + "and all available ZFS filesystems are mounted." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_test.sh new file mode 100755 index 00000000000..7ccbfc0aabd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_mount/zfs_mount_test.sh @@ -0,0 +1,372 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_mount_001_pos cleanup +zfs_mount_001_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $mountcmd ' succeeds as root." + atf_set "require.progs" zfs +} +zfs_mount_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_002_pos cleanup +zfs_mount_002_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $mountcmd' with a filesystemwhose name is not in 'zfs list' will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_mount_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_003_pos cleanup +zfs_mount_003_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $mountcmd' with a filesystemwhose mountpoint property is 'legacy' or 'none' \will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_mount_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_004_pos cleanup +zfs_mount_004_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $mountcmd 'with a mounted filesystem will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_mount_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_005_pos cleanup +zfs_mount_005_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $mountcmd' with a filesystemwhose mountpoint is currently in use will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_mount_005_pos_body() +{ + [[ `uname -s` = "FreeBSD" ]] && atf_skip "Unlike Illumos, FreeBSD allows the behavior the prohibition of which is tested by this testcase" + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_006_pos cleanup +zfs_mount_006_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $mountcmd 'which mountpoint be the identical or the top of an existing one \will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_mount_006_pos_body() +{ + [[ `uname -s` = "FreeBSD" ]] && atf_skip "Unlike Illumos, FreeBSD allows the behavior the prohibition of which is tested by this testcase" + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_007_pos cleanup +zfs_mount_007_pos_head() +{ + atf_set "descr" "Verify '-o' will set filesystem property temporarily,without affecting the property that is stored on disk." + atf_set "require.progs" zfs +} +zfs_mount_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + atf_expect_fail "PR 115361 zfs get setuid doesn't reflect setuid state as set by zfs mount" + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_007_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_008_pos cleanup +zfs_mount_008_pos_head() +{ + atf_set "descr" "Verify 'zfs mount -O' will override existing mount point." + atf_set "require.progs" zfs +} +zfs_mount_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_008_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_009_neg cleanup +zfs_mount_009_neg_head() +{ + atf_set "descr" "Badly-formed 'zfs $mountcmd' with inapplicable scenariosshould return an error." + atf_set "require.progs" zfs +} +zfs_mount_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_009_neg.ksh || atf_fail "Testcase failed" +} +zfs_mount_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_010_neg cleanup +zfs_mount_010_neg_head() +{ + atf_set "descr" "zfs mount fails with mounted filesystem or busy mountpoint" + atf_set "require.progs" zfs +} +zfs_mount_010_neg_body() +{ + [[ `uname -s` = "FreeBSD" ]] && atf_skip "Unlike Illumos, FreeBSD allows the behavior the prohibition of which is tested by this testcase" + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_010_neg.ksh || atf_fail "Testcase failed" +} +zfs_mount_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_011_neg cleanup +zfs_mount_011_neg_head() +{ + atf_set "descr" "zfs mount fails with bad parameters" + atf_set "require.progs" zfs +} +zfs_mount_011_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_011_neg.ksh || atf_fail "Testcase failed" +} +zfs_mount_011_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_all_001_pos cleanup +zfs_mount_all_001_pos_head() +{ + atf_set "descr" "Verify that 'zfs $mountall' succeeds as root,and all available ZFS filesystems are mounted." + atf_set "require.progs" zfs +} +zfs_mount_all_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_all_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_mount_all_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_mount.kshlib + . $(atf_get_srcdir)/zfs_mount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_mount_001_pos + atf_add_test_case zfs_mount_002_pos + atf_add_test_case zfs_mount_003_pos + atf_add_test_case zfs_mount_004_pos + atf_add_test_case zfs_mount_005_pos + atf_add_test_case zfs_mount_006_pos + atf_add_test_case zfs_mount_007_pos + atf_add_test_case zfs_mount_008_pos + atf_add_test_case zfs_mount_009_neg + atf_add_test_case zfs_mount_010_neg + atf_add_test_case zfs_mount_011_neg + atf_add_test_case zfs_mount_all_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/Makefile new file mode 100644 index 00000000000..3220cadfc36 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/Makefile @@ -0,0 +1,26 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_promote +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_promote_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_promote_006_neg.ksh +${PACKAGE}FILES+= zfs_promote_003_pos.ksh +${PACKAGE}FILES+= zfs_promote_common.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_promote_007_neg.ksh +${PACKAGE}FILES+= zfs_promote.cfg +${PACKAGE}FILES+= zfs_promote_002_pos.ksh +${PACKAGE}FILES+= zfs_promote_004_pos.ksh +${PACKAGE}FILES+= zfs_promote_008_pos.ksh +${PACKAGE}FILES+= zfs_promote_005_pos.ksh +${PACKAGE}FILES+= zfs_promote_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/setup.ksh new file mode 100644 index 00000000000..61f282cda9e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_volume_setup ${DISK} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote.cfg new file mode 100644 index 00000000000..c91fc779a70 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote.cfg @@ -0,0 +1,46 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export FILESIZE=1m + +export TESTSNAP3=testsnap3.${TESTCASE_ID} +export TESTSNAP4=testsnap4.${TESTCASE_ID} +export TESTSNAP5=testsnap5.${TESTCASE_ID} +export TESTFILE3=testfile3.${TESTCASE_ID} + +export CLONEFILE=clonefile.${TESTCASE_ID} +export CLONEFILE1=clonefile1.${TESTCASE_ID} +export CLONEFILE2=clonefile2.${TESTCASE_ID} +export CLONEFILE3=clonefile3.${TESTCASE_ID} + + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_001_pos.ksh new file mode 100644 index 00000000000..156a026cbf3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_001_pos.ksh @@ -0,0 +1,139 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_001_pos +# +# DESCRIPTION: +# 'zfs promote' can promote a clone filesystem to no longer be dependent +# on its "origin" snapshot. +# +# STRATEGY: +# 1. Create a snapshot and a clone of the snapshot +# 2. Promote the clone filesystem +# 3. Verify the promoted filesystem become independent +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists $csnap; then + log_must $ZFS promote $fs + fi + snapexists $snap && \ + log_must $ZFS destroy -rR $snap + + typeset data + for data in $file0 $file1; do + [[ -e $data ]] && $RM -f $data + done +} + +function testing_verify +{ + typeset ds=$1 + typeset ds_file=$2 + typeset snap_file=$3 + typeset c_ds=$4 + typeset c_file=$5 + typeset csnap_file=$6 + typeset origin_prop="" + + + snapexists $ds@$TESTSNAP && \ + log_fail "zfs promote cannot promote $ds@$TESTSNAP." + ! snapexists $c_ds@$TESTSNAP && \ + log_fail "The $c_ds@$TESTSNAP after zfs promote doesn't exist." + + origin_prop=$(get_prop origin $ds) + [[ "$origin_prop" != "$c_ds@$TESTSNAP" ]] && \ + log_fail "The dependency of $ds is not correct." + origin_prop=$(get_prop origin $c_ds) + [[ "$origin_prop" != "-" ]] && \ + log_fail "The dependency of $c_ds is not correct." + + if [[ -e $snap_file ]] || [[ ! -e $csnap_file ]]; then + log_fail "Data file $snap_file cannot be correctly promoted." + fi + if [[ ! -e $ds_file ]] || [[ ! -e $c_file ]]; then + log_fail "There exists data file losing after zfs promote." + fi + + log_mustnot $ZFS destroy -r $c_ds +} + +log_assert "'zfs promote' can promote a clone filesystem." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +file0=$TESTDIR/$TESTFILE0 +file1=$TESTDIR/$TESTFILE1 +snap=$fs@$TESTSNAP +snapfile=$TESTDIR/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0 +clone=$TESTPOOL/$TESTCLONE +cfile=/$clone/$CLONEFILE +csnap=$clone@$TESTSNAP +csnapfile=/$clone/$(get_snapdir_name)/$TESTSNAP/$TESTFILE0 + +# setup for promte testing +log_must $MKFILE $FILESIZE $file0 +log_must $ZFS snapshot $snap +log_must $MKFILE $FILESIZE $file1 +log_must $RM -f $file0 +log_must $ZFS clone $snap $clone +log_must $MKFILE $FILESIZE $cfile + +log_must $ZFS promote $clone +# verify the 'promote' operation +testing_verify $fs $file1 $snapfile $clone $cfile $csnapfile + +log_note "Verify 'zfs promote' can change back the dependency relationship." +log_must $ZFS promote $fs +#verify the result +testing_verify $clone $cfile $csnapfile $fs $file1 $snapfile + +log_pass "'zfs promote' reverses the clone parent-child dependency relationship"\ + "as expected." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_002_pos.ksh new file mode 100644 index 00000000000..32b033cd5f0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_002_pos.ksh @@ -0,0 +1,114 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_002_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_002_pos +# +# DESCRIPTION: +# 'zfs promote' can deal with multiple snapshots in the origin filesystem. +# +# STRATEGY: +# 1. Create multiple snapshots and a clone of the last snapshot +# 2. Promote the clone filesystem +# 3. Verify the promoted filesystem included all snapshots +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists $csnap1; then + log_must $ZFS promote $fs + fi + + typeset ds + typeset data + for ds in $snap $snap1; do + log_must $ZFS destroy -rR $ds + done + for file in $TESTDIR/$TESTFILE0 $TESTDIR/$TESTFILE1; do + [[ -e $file ]] && $RM -f $file + done +} + +log_assert "'zfs promote' can deal with multiple snapshots in a filesystem." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +snap=$fs@$TESTSNAP +snap1=$fs@$TESTSNAP1 +clone=$TESTPOOL/$TESTCLONE +csnap=$clone@$TESTSNAP +csnap1=$clone@$TESTSNAP1 + +# setup for promote testing +log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE0 +log_must $ZFS snapshot $snap +log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE1 +log_must $RM -f $testdir/$TESTFILE0 +log_must $ZFS snapshot $snap1 +log_must $ZFS clone $snap1 $clone +log_must $MKFILE $FILESIZE /$clone/$CLONEFILE + +log_must $ZFS promote $clone + +# verify the 'promote' operation +for ds in $csnap $csnap1; do + ! snapexists $ds && \ + log_fail "Snapshot $ds doesn't exist after zfs promote." +done +for ds in $snap $snap1; do + snapexists $ds && \ + log_fail "Snapshot $ds is still there after zfs promote." +done + +origin_prop=$(get_prop origin $fs) +[[ "$origin_prop" != "$csnap1" ]] && \ + log_fail "The dependency of $fs is not correct." +origin_prop=$(get_prop origin $clone) +[[ "$origin_prop" != "-" ]] && \ + log_fail "The dependency of $clone is not correct." + +log_pass "'zfs promote' deal with multiple snapshots as expected." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_003_pos.ksh new file mode 100644 index 00000000000..e23209893d3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_003_pos.ksh @@ -0,0 +1,146 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_003_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_003_pos +# +# DESCRIPTION: +# 'zfs promote' can deal with multi-point snapshots. +# +# STRATEGY: +# 1. Create multiple snapshots and a clone to a middle point snapshot +# 2. Promote the clone filesystem +# 3. Verify the origin filesystem and promoted filesystem include +# correct datasets separated by the clone point. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists ${csnap[2]}; then + log_must $ZFS promote $fs + fi + + typeset ds + typeset data + for ds in ${snap[*]}; do + snapexists $ds && \ + log_must $ZFS destroy -rR $ds + done + for data in ${file[*]}; do + [[ -e $data ]] && $RM -f $data + done + +} + +log_assert "'zfs promote' can deal with multi-point snapshots." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +clone=$TESTPOOL/$TESTCLONE + +# Define some arrays here to use loop to reduce code amount + +# Array which stores the origin snapshots created in the origin filesystem +set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3" +# Array which stores the snapshots existing in the clone after promote operation +set -A csnap "${clone}@$TESTSNAP" "${clone}@$TESTSNAP1" "${clone}@$TESTSNAP2" \ + "${clone}@$TESTSNAP3" +# The data will inject into the origin filesystem +set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \ + "$TESTDIR/$TESTFILE3" +snapdir=$TESTDIR/$(get_snapdir_name) +# The data which will exist in the snapshot after creation of snapshot +set -A snapfile "$snapdir/$TESTSNAP/$TESTFILE0" "$snapdir/$TESTSNAP1/$TESTFILE1" \ + "$snapdir/$TESTSNAP2/$TESTFILE2" "$snapdir/$TESTSNAP3/$TESTFILE3" +csnapdir=/$clone/$(get_snapdir_name) +# The data which will exist in the snapshot of clone filesystem after promote +set -A csnapfile "${csnapdir}/$TESTSNAP/$TESTFILE0" "${csnapdir}/$TESTSNAP1/$TESTFILE1" \ + "${csnapdir}/$TESTSNAP2/$TESTFILE2" + +# setup for promote testing +typeset -i i=0 +while (( i < 4 )); do + log_must $MKFILE $FILESIZE ${file[i]} + (( i>0 )) && log_must $RM -f ${file[((i-1))]} + log_must $ZFS snapshot ${snap[i]} + + (( i = i + 1 )) +done +log_must $ZFS clone ${snap[2]} $clone +log_must $MKFILE $FILESIZE /$clone/$CLONEFILE +log_must $RM -f /$clone/$TESTFILE2 +log_must $ZFS snapshot ${csnap[3]} + +log_must $ZFS promote $clone + +# verify the 'promote' operation +for ds in ${snap[3]} ${csnap[*]}; do + ! snapexists $ds && \ + log_fail "The snapshot $ds disappear after zfs promote." +done +for data in ${csnapfile[*]} $TESTDIR/$TESTFILE3 /$clone/$CLONEFILE; do + [[ ! -e $data ]] && \ + log_fail "The data file $data loses after zfs promote." +done + +for ds in ${snap[0]} ${snap[1]} ${snap[2]}; do + snapexists $ds && \ + log_fail "zfs promote cannot promote the snapshot $ds." +done +for data in ${snapfile[0]} ${snapfile[1]} ${snapfile[2]}; do + [[ -e $data ]] && \ + log_fail "zfs promote cannot promote the data $data." +done + +origin_prop=$(get_prop origin $fs) +[[ "$origin_prop" != "${csnap[2]}" ]] && \ + log_fail "The dependency is not correct for $fs after zfs promote." +origin_prop=$(get_prop origin $clone) +[[ "$origin_prop" != "-" ]] && \ + log_fail "The dependency is not correct for $clone after zfs promote." + +log_pass "'zfs promote' deal with multi-point snapshots as expected." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_004_pos.ksh new file mode 100644 index 00000000000..7407a6a29b2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_004_pos.ksh @@ -0,0 +1,152 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_004_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_004_pos +# +# DESCRIPTION: +# 'zfs promote' can deal with multi-level clones. +# +# STRATEGY: +# 1. Create multiple snapshots and multi-level clones +# 2. Promote a clone filesystem +# 3. Verify the dataset dependency relationships are correct after promotion. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if snapexists ${c1snap[1]}; then + log_must $ZFS promote $clone + fi + + typeset ds + typeset data + for ds in ${snap[*]}; do + snapexists $ds && \ + log_must $ZFS destroy -rR $ds + done + for data in ${file[*]}; do + [[ -e $data ]] && $RM -f $data + done +} + +log_assert "'zfs promote' can deal with multi-level clone." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +clone=$TESTPOOL/$TESTCLONE +clone1=$TESTPOOL/$TESTCLONE1 + +# Define some arrays here to use loop to reduce code amount + +# Array which stores the origin snapshots created in the origin filesystem +set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3" +# Array which stores the snapshots existing in the first clone +set -A csnap "${clone}@$TESTSNAP3" "${clone}@$TESTSNAP4" "${clone}@$TESTSNAP5" +# Array which stores the snapshots existing in the second clone after promote operation +set -A c1snap "${clone1}@$TESTSNAP3" "${clone1}@$TESTSNAP4" "${clone1}@$TESTSNAP5" +# The data will inject into the origin filesystem +set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \ + "$TESTDIR/$TESTFILE3" +cdir=/$TESTPOOL/$TESTCLONE +# The data will inject into the first clone +set -A cfile "${cdir}/$CLONEFILE" "${cdir}/$CLONEFILE1" "${cdir}/$CLONEFILE2" +c1snapdir=/$TESTPOOL/$TESTCLONE1/$(get_snapdir_name) +# The data which will exist in the snapshot of the second clone filesystem after promote +set -A c1snapfile "${c1snapdir}/$TESTSNAP3/$CLONEFILE" \ + "${c1snapdir}/$TESTSNAP4/$CLONEFILE1" \ + "${c1snapdir}/$TESTSNAP5/$CLONEFILE2" + +# setup for promote testing +typeset -i i=0 +while (( i < 4 )); do + log_must $MKFILE $FILESIZE ${file[i]} + (( i>0 )) && log_must $RM -f ${file[((i-1))]} + log_must $ZFS snapshot ${snap[i]} + + (( i = i + 1 )) +done +log_must $ZFS clone ${snap[2]} $clone + +log_must $RM -f /$clone/$TESTFILE2 +i=0 +while (( i < 3 )); do + log_must $MKFILE $FILESIZE ${cfile[i]} + (( i>0 )) && log_must $RM -f ${cfile[(( i-1 ))]} + log_must $ZFS snapshot ${csnap[i]} + + (( i = i + 1 )) +done + +log_must $ZFS clone ${csnap[1]} $clone1 +log_must $MKFILE $FILESIZE /$clone1/$CLONEFILE2 +log_must $RM -f /$clone1/$CLONEFILE1 +log_must $ZFS snapshot ${c1snap[2]} + +log_must $ZFS promote $clone1 + +# verify the 'promote' operation +for ds in ${snap[*]} ${csnap[2]} ${c1snap[*]}; do + ! snapexists $ds && \ + log_fail "The snapshot $ds disappear after zfs promote." +done +for data in ${c1snapfile[*]}; do + [[ ! -e $data ]] && \ + log_fail "The data file $data loses after zfs promote." +done + +origin_prop=$(get_prop origin $fs) +[[ "$origin_prop" != "-" ]] && \ + log_fail "The dependency is not correct for $fs after zfs promote." +origin_prop=$(get_prop origin $clone) +[[ "$origin_prop" != "${c1snap[1]}" ]] && \ + log_fail "The dependency is not correct for $clone after zfs promote." +origin_prop=$(get_prop origin $clone1) +[[ "$origin_prop" != "${snap[2]}" ]] && \ + log_fail "The dependency is not correct for $clone1 after zfs promote." + +log_pass "'zfs promote' deal with multi-level clones as expected." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_005_pos.ksh new file mode 100644 index 00000000000..dc7e09afa27 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_005_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_promote_005_pos +# +# DESCRIPTION: +# The original fs was unmounted, 'zfs promote' still should succeed. +# +# STRATEGY: +# 1. Create pool, fs and snapshot. +# 2. Create clone of fs. +# 3. Unmount fs, then verify 'zfs promote' clone still succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $fssnap ; then + datasetexists $clone && log_must $ZFS destroy $clone + log_must $ZFS destroy $fssnap + fi + if datasetexists $clone ; then + log_must $ZFS promote $fs + log_must $ZFS destroy $clone + log_must $ZFS destroy $fssnap + fi +} + +log_assert "The original fs was unmounted, 'zfs promote' still should succeed." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +clone=$TESTPOOL/$TESTCLONE +fssnap=$fs@fssnap + +log_must $ZFS snapshot $fssnap +log_must $ZFS clone $fssnap $clone +log_must $ZFS unmount $fs +log_must $ZFS promote $clone +log_must $ZFS unmount $clone +log_must $ZFS promote $fs + +log_pass "Unmount original fs, 'zfs promote' passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_006_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_006_neg.ksh new file mode 100644 index 00000000000..0559e64d72d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_006_neg.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_006_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_006_neg +# +# DESCRIPTION: +# 'zfs promote' will fail with invalid arguments: +# (1) NULL arguments +# (2) non-existent clone +# (3) non-clone datasets: +# pool, fs, snapshot,volume +# (4) too many arguments. +# (5) invalid options +# +# STRATEGY: +# 1. Create an array of invalid arguments +# 2. For each invalid argument in the array, 'zfs promote' should fail +# 3. Verify the return code from zfs promote +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +snap=$TESTPOOL/$TESTFS@$TESTSNAP +set -A args "" \ + "$TESTPOOL/blah" \ + "$TESTPOOL" "$TESTPOOL/$TESTFS" "$snap" \ + "$TESTPOOL/$TESTVOL" "$TESTPOL $TESTPOOL/$TESTFS" \ + "$clone $TESTPOOL/$TESTFS" "- $clone" "-? $clone" + +function cleanup +{ + if datasetexists $clone; then + log_must $ZFS destroy $clone + fi + + if snapexists $snap; then + destroy_snapshot $snap + fi +} + +log_assert "'zfs promote' will fail with invalid arguments. " +log_onexit cleanup + +snap=$TESTPOOL/$TESTFS@$TESTSNAP +clone=$TESTPOOL/$TESTCLONE +log_must $ZFS snapshot $snap +log_must $ZFS clone $snap $clone + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZFS promote ${args[i]} + + (( i = i + 1 )) +done + +log_pass "'zfs promote' fails with invalid argument as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_007_neg.ksh new file mode 100644 index 00000000000..306f316f7de --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_007_neg.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_007_neg.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_007_neg +# +# DESCRIPTION: +# 'zfs promote' can deal with conflicts in the namespaces. +# +# STRATEGY: +# 1. Create a snapshot and a clone of the snapshot +# 2. Create the same name snapshot for the clone +# 3. Promote the clone filesystem +# 4. Verify the promote operation fail due to the name conflicts. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-05-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + snapexists $snap && \ + log_must $ZFS destroy -rR $snap + + typeset data + for data in $TESTDIR/$TESTFILE0 $TESTDIR/$TESTFILE1; do + [[ -e $data ]] && $RM -f $data + done +} + +log_assert "'zfs promote' can deal with name conflicts." +log_onexit cleanup + +snap=$TESTPOOL/$TESTFS@$TESTSNAP +clone=$TESTPOOL/$TESTCLONE +clonesnap=$TESTPOOL/$TESTCLONE@$TESTSNAP + +# setup for promte testing +log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE0 +log_must $ZFS snapshot $snap +log_must $MKFILE $FILESIZE $TESTDIR/$TESTFILE1 +log_must $RM -f $TESTDIR/$TESTFILE0 +log_must $ZFS clone $snap $clone +log_must $MKFILE $FILESIZE /$clone/$CLONEFILE +log_must $ZFS snapshot $clonesnap + +log_mustnot $ZFS promote $clone + +log_pass "'zfs promote' deals with name conflicts as expected." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_008_pos.ksh new file mode 100644 index 00000000000..f20a29c2eb8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_008_pos.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_008_pos.ksh 1.1 07/05/25 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_008_pos +# +# DESCRIPTION: +# 'zfs promote' can successfully promote a volume clone. +# +# STRATEGY: +# 1. Create a volume clone +# 2. Promote the volume clone +# 3. Verify the dependency changed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-02-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if snapexists $csnap; then + log_must $ZFS promote $vol + fi + + log_must $ZFS destroy -rR $snap +} + +log_assert "'zfs promote' can promote a volume clone." +log_onexit cleanup + +vol=$TESTPOOL/$TESTVOL +snap=$vol@$TESTSNAP +clone=$TESTPOOL/volclone +csnap=$clone@$TESTSNAP + +if ! snapexists $snap ; then + log_must $ZFS snapshot $snap + log_must $ZFS clone $snap $clone +fi + +log_must $ZFS promote $clone + +# verify the 'promote' operation +! snapexists $csnap && \ + log_fail "Snapshot $csnap doesn't exist after zfs promote." +snapexists $snap && \ + log_fail "Snapshot $snap is still there after zfs promote." + +origin_prop=$(get_prop origin $vol) +[[ "$origin_prop" != "$csnap" ]] && \ + log_fail "The dependency of $vol is not correct." +origin_prop=$(get_prop origin $clone) +[[ "$origin_prop" != "-" ]] && \ + log_fail "The dependency of $clone is not correct." + +log_pass "'zfs promote' can promote volume clone as expected." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_common.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_common.kshlib new file mode 100644 index 00000000000..26b5e64d438 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_common.kshlib @@ -0,0 +1,48 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_common.kshlib 1.3 07/03/14 SMI" +# + +# +# Check whether the operating filesystem support 'zfs promote' or not +# +function unsupport_check +{ + typeset srch_str="unrecognized command" + typeset tmpout=$TMPDIR/tmpout.${TESTCASE_ID} + typeset -i ret + + $ZFS promote >$tmpout 2>&1 + $GREP "$srch_str" $tmpout >/dev/null 2>&1 + ret=$? + + $RM -f $tmpout + + return $ret +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_test.sh new file mode 100755 index 00000000000..bfea7b496ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_promote/zfs_promote_test.sh @@ -0,0 +1,248 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_promote_001_pos cleanup +zfs_promote_001_pos_head() +{ + atf_set "descr" "'zfs promote' can promote a clone filesystem." + atf_set "require.progs" zfs +} +zfs_promote_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_promote_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_002_pos cleanup +zfs_promote_002_pos_head() +{ + atf_set "descr" "'zfs promote' can deal with multiple snapshots in a filesystem." + atf_set "require.progs" zfs +} +zfs_promote_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_promote_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_003_pos cleanup +zfs_promote_003_pos_head() +{ + atf_set "descr" "'zfs promote' can deal with multi-point snapshots." + atf_set "require.progs" zfs +} +zfs_promote_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_promote_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_004_pos cleanup +zfs_promote_004_pos_head() +{ + atf_set "descr" "'zfs promote' can deal with multi-level clone." + atf_set "require.progs" zfs +} +zfs_promote_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_promote_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_005_pos cleanup +zfs_promote_005_pos_head() +{ + atf_set "descr" "The original fs was unmounted, 'zfs promote' still should succeed." + atf_set "require.progs" zfs +} +zfs_promote_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_promote_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_006_neg cleanup +zfs_promote_006_neg_head() +{ + atf_set "descr" "'zfs promote' will fail with invalid arguments." + atf_set "require.progs" zfs +} +zfs_promote_006_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_006_neg.ksh || atf_fail "Testcase failed" +} +zfs_promote_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_007_neg cleanup +zfs_promote_007_neg_head() +{ + atf_set "descr" "'zfs promote' can deal with name conflicts." + atf_set "require.progs" zfs +} +zfs_promote_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_promote_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_008_pos cleanup +zfs_promote_008_pos_head() +{ + atf_set "descr" "'zfs promote' can promote a volume clone." + atf_set "require.progs" zfs +} +zfs_promote_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_008_pos.ksh || atf_fail "Testcase failed" +} +zfs_promote_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_promote_common.kshlib + . $(atf_get_srcdir)/zfs_promote.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_promote_001_pos + atf_add_test_case zfs_promote_002_pos + atf_add_test_case zfs_promote_003_pos + atf_add_test_case zfs_promote_004_pos + atf_add_test_case zfs_promote_005_pos + atf_add_test_case zfs_promote_006_neg + atf_add_test_case zfs_promote_007_neg + atf_add_test_case zfs_promote_008_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_property/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/Makefile new file mode 100644 index 00000000000..5db427eb06b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_property +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_property_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_set_property_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_property.cfg +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_property/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_property/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_property.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_property.cfg new file mode 100644 index 00000000000..2a02aa1f2f1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_property.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_property.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_property_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_property_test.sh new file mode 100755 index 00000000000..6f01d23d496 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_property_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_set_property_001_pos cleanup +zfs_set_property_001_pos_head() +{ + atf_set "descr" "Verify each of the file system properties." + atf_set "require.progs" zfs +} +zfs_set_property_001_pos_body() +{ + atf_skip "Due to changing zfs ls output, test needs a re-write." + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_property.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_set_property_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_set_property_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_property.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_set_property_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_set_property_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_set_property_001_pos.ksh new file mode 100644 index 00000000000..0eb1257f7e8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_property/zfs_set_property_001_pos.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_set_property_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_set_property_001_pos +# +# DESCRIPTION: +# For each property verify that it accepts on/off/inherit. +# +# STRATEGY: +# 1. Create an array of properties. +# 2. Create an array of possible values. +# 3. For each property set to every possible value. +# 4. Verify success is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A options "on" "off" "inherit" +set -A args "compression" "checksum" "mutable" "atime" + +log_assert "Verify each of the file system properties." + +log_untested "Due to changing zfs ls output, test needs a re-write." + +typeset -i i=0 +typeset -i j=0 + +while [[ $i -lt ${#args[*]} ]]; do + j=0 + while [[ $j -lt ${#options[*]} ]]; do + log_must $ZFS ${args[i]}=${options[j]} $TESTPOOL/$TESTFS + + $ZFS ls -L | $GREP "${args[i]}" | $GREP "${options[j]}" + [[ $? -ne 0 ]] && \ + log_fail "Unable to verify ${args[i]}=${options[j]}" + + log_note "Verified ${args[i]}=${options[j]}" + + ((j = j + 1)) + done + + ((i = i + 1)) +done + +log_pass "zfs properties were set correctly." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/Makefile new file mode 100644 index 00000000000..b20acbe4700 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/Makefile @@ -0,0 +1,26 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_receive +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_receive_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_receive_004_neg.ksh +${PACKAGE}FILES+= zfs_receive_001_pos.ksh +${PACKAGE}FILES+= zfs_receive_009_neg.ksh +${PACKAGE}FILES+= zfs_receive_005_neg.ksh +${PACKAGE}FILES+= zfs_receive_008_pos.ksh +${PACKAGE}FILES+= zfs_receive.cfg +${PACKAGE}FILES+= zfs_receive_007_neg.ksh +${PACKAGE}FILES+= zfs_receive_002_pos.ksh +${PACKAGE}FILES+= zfs_receive_006_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_receive_003_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/cleanup.ksh new file mode 100644 index 00000000000..db372c2000f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +poolexists $TESTPOOL1 && \ + destroy_pool $TESTPOOL1 + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/setup.ksh new file mode 100644 index 00000000000..6d380766a3a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/setup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +if is_global_zone; then + default_volume_setup $DISK +else + default_setup $DISK +fi diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive.cfg new file mode 100644 index 00000000000..a32b4ed6765 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive.cfg @@ -0,0 +1,36 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export PARTSIZE=1g +export BLOCK_SIZE=512 +export WRITE_COUNT=8 diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_001_pos.ksh new file mode 100644 index 00000000000..aa816885dc4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_001_pos.ksh @@ -0,0 +1,188 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_001_pos.ksh 1.4 08/02/27 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_001_pos +# +# DESCRIPTION: +# Verifying 'zfs receive [] -d ' works. +# +# STRATEGY: +# 1. Fill in fs with some data +# 2. Create full and incremental send stream +# 3. Receive the send stream +# 4. Verify the restoring results. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset -i i=0 + + datasetexists $rst_root && \ + log_must $ZFS destroy -Rf $rst_root + while (( i < 2 )); do + snapexists ${orig_snap[$i]} && \ + log_must $ZFS destroy -f ${orig_snap[$i]} + log_must $RM -f ${bkup[$i]} + + (( i = i + 1 )) + done + + log_must $RM -rf $TESTDIR1 +} + +function recreate_root +{ + datasetexists $rst_root && \ + log_must $ZFS destroy -Rf $rst_root + if [[ -d $TESTDIR1 ]] ; then + log_must $RM -rf $TESTDIR1 + fi + log_must $ZFS create $rst_root + log_must $ZFS set mountpoint=$TESTDIR1 $rst_root +} + +log_assert "Verifying 'zfs receive [] -d ' works." +log_onexit cleanup + +typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" +set -A bkup "$TMPDIR/fullbkup" "$TMPDIR/incbkup" +orig_sum="" +rst_sum="" +rst_root=$TESTPOOL/rst_ctr +rst_fs=${rst_root}/$TESTFS + +for orig_fs in $datasets ; do + # + # Preparations for testing + # + recreate_root + + set -A orig_snap "${orig_fs}@init_snap" "${orig_fs}@inc_snap" + typeset mntpnt=$(get_prop mountpoint ${orig_fs}) + set -A orig_data "${mntpnt}/$TESTFILE1" "${mntpnt}/$TESTFILE2" + + typeset relative_path="" + if [[ ${orig_fs} == *"/"* ]]; then + relative_path=${orig_fs#*/} + fi + + typeset leaf_fs=${rst_root}/${relative_path} + leaf_fs=${leaf_fs%/} + rst_snap=${leaf_fs}@snap + + set -A rst_snap "$rst_root/$TESTFS@init_snap" "$rst_root/$TESTFS@inc_snap" + set -A rst_snap2 "${leaf_fs}@init_snap" "${leaf_fs}@inc_snap" + set -A rst_data "$TESTDIR1/$TESTFS/$TESTFILE1" "$TESTDIR1/$TESTFS/$TESTFILE2" + set -A rst_data2 "$TESTDIR1/${relative_path}/$TESTFILE1" "$TESTDIR1/${relative_path}/$TESTFILE2" + + typeset -i i=0 + while (( i < ${#orig_snap[*]} )); do + log_must $FILE_WRITE -o create -f ${orig_data[$i]} \ + -b $BLOCK_SIZE -c $WRITE_COUNT + log_must $ZFS snapshot ${orig_snap[$i]} + if (( i < 1 )); then + log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}" + else + log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \ + ${orig_snap[$i]} > ${bkup[$i]}" + fi + + (( i = i + 1 )) + done + + log_note "Verifying 'zfs receive ' works." + i=0 + while (( i < ${#bkup[*]} )); do + if (( i > 0 )); then + log_must $ZFS rollback ${rst_snap[0]} + fi + log_must eval "$ZFS receive $rst_fs < ${bkup[$i]}" + snapexists ${rst_snap[$i]} || \ + log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist" + compare_cksum ${orig_data[$i]} ${rst_data[$i]} + + (( i = i + 1 )) + done + + log_must $ZFS destroy -Rf $rst_fs + + log_note "Verifying 'zfs receive ' works." + i=0 + while (( i < ${#bkup[*]} )); do + if (( i > 0 )); then + log_must $ZFS rollback ${rst_snap[0]} + fi + log_must eval "$ZFS receive ${rst_snap[$i]} <${bkup[$i]}" + snapexists ${rst_snap[$i]} || \ + log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist" + compare_cksum ${orig_data[$i]} ${rst_data[$i]} + + (( i = i + 1 )) + done + + log_must $ZFS destroy -Rf $rst_fs + + log_note "Verfiying 'zfs receive -d ' works." + + i=0 + while (( i < ${#bkup[*]} )); do + if (( i > 0 )); then + log_must $ZFS rollback ${rst_snap2[0]} + fi + log_must eval "$ZFS receive -d -F $rst_root <${bkup[$i]}" + snapexists ${rst_snap2[$i]} || \ + log_fail "Restoring filesystem fails. ${rst_snap2[$i]} not exist" + compare_cksum ${orig_data[$i]} ${rst_data2[$i]} + + (( i = i + 1 )) + done + + cleanup +done + +log_pass "Verifying 'zfs receive [] -d ' succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_002_pos.ksh new file mode 100644 index 00000000000..53a3199985d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_002_pos.ksh @@ -0,0 +1,122 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_002_pos +# +# DESCRIPTION: +# Verifying 'zfs receive ' works. +# +# STRATEGY: +# 1. Fill in volume with some data +# 2. Create full and incremental send stream +# 3. Restore the send stream +# 4. Verify the restoring results. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset -i i=0 + typeset ds + + while (( i < ${#orig_snap[*]} )); do + snapexists ${rst_snap[$i]} && \ + log_must $ZFS destroy -f ${rst_snap[$i]} + snapexists ${orig_snap[$i]} && \ + log_must $ZFS destroy -f ${orig_snap[$i]} + [[ -e ${bkup[$i]} ]] && \ + log_must $RM -rf ${bkup[$i]} + + (( i = i + 1 )) + done + + for ds in $rst_vol $rst_root; do + datasetexists $ds && \ + log_must $ZFS destroy -Rf $ds + done +} + +log_assert "Verifying 'zfs receive ' works." +log_onexit cleanup + +set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap" +set -A bkup "$TMPDIR/fullbkup" "$TMPDIR/incbkup" +rst_root=$TESTPOOL/rst_ctr +rst_vol=$rst_root/$TESTVOL +set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap" + +# +# Preparations for testing +# +log_must $ZFS create $rst_root +[[ ! -d $TESTDIR1 ]] && \ + log_must $MKDIR -p $TESTDIR1 +log_must $ZFS set mountpoint=$TESTDIR1 $rst_root + +typeset -i i=0 +while (( i < ${#orig_snap[*]} )); do + log_must $ZFS snapshot ${orig_snap[$i]} + if (( i < 1 )); then + log_must eval "$ZFS send ${orig_snap[$i]} > ${bkup[$i]}" + else + log_must eval "$ZFS send -i ${orig_snap[(( i - 1 ))]} \ + ${orig_snap[$i]} > ${bkup[$i]}" + fi + + (( i = i + 1 )) +done + +i=0 +while (( i < ${#bkup[*]} )); do + log_must eval "$ZFS receive $rst_vol < ${bkup[$i]}" + ! datasetexists $rst_vol || ! snapexists ${rst_snap[$i]} && \ + log_fail "Restoring volume fails." + + (( i = i + 1 )) +done + +log_pass "Verifying 'zfs receive ' succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_003_pos.ksh new file mode 100644 index 00000000000..7bc33516d25 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_003_pos.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_003_pos +# +# DESCRIPTION: +# 'zfs recv -F' to force rollback. +# +# STRATEGY: +# 1. Create pool and fs. +# 2. Create some files in fs and take a snapshot1. +# 3. Create another files in fs and take snapshot2. +# 4. Create incremental stream from snapshot1 to snapshot2. +# 5. fs rollback to snapshot1 and modify fs. +# 6. Verify 'zfs recv -F' can force rollback. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for snap in $snap2 $snap1; do + datasetexists $snap && log_must $ZFS destroy -rf $snap + done + for file in $ibackup $mntpnt/file1 $mntpnt/file2; do + [[ -f $file ]] && log_must $RM -f $file + done +} + +log_assert "'zfs recv -F' to force rollback." +log_onexit cleanup + +ibackup=$TMPDIR/ibackup.${TESTCASE_ID} +fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2 + +mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs" +log_must $MKFILE 10m $mntpnt/file1 +log_must $ZFS snapshot $snap1 +log_must $MKFILE 10m $mntpnt/file2 +log_must $ZFS snapshot $snap2 + +log_must eval "$ZFS send -i $snap1 $snap2 > $ibackup" + +log_note "Verify 'zfs receive' succeed, if filesystem was not modified." +log_must $ZFS rollback -r $snap1 +log_must eval "$ZFS receive $fs < $ibackup" +if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then + log_fail "'$ZFS receive' failed." +fi + +log_note "Verify 'zfs receive' failed if filesystem was modified." +log_must $ZFS rollback -r $snap1 +log_must $RM -rf $mntpnt/file1 +log_mustnot eval "$ZFS receive $fs < $ibackup" + +# Verify 'zfs receive -F' to force rollback whatever filesystem was modified. +log_must $ZFS rollback -r $snap1 +log_must $RM -rf $mntpnt/file1 +log_must eval "$ZFS receive -F $fs < $ibackup" +if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then + log_fail "'$ZFS receive -F' failed." +fi + +log_pass "'zfs recv -F' to force rollback passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_004_neg.ksh new file mode 100644 index 00000000000..1dedd43c9e4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_004_neg.ksh @@ -0,0 +1,119 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_004_neg.ksh 1.4 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_004_neg +# +# DESCRIPTION: +# Verify 'zfs receive' fails with malformed parameters. +# +# STRATEGY: +# 1. Denfine malformed parameters array +# 2. Feed the malformed parameters to 'zfs receive' +# 3. Verify the command should be failed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset snap + typeset bkup + + for snap in $init_snap $inc_snap $init_topsnap $inc_topsnap ; do + snapexists $snap && \ + log_must $ZFS destroy -Rf $snap + done + + for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup; do + [[ -e $bkup ]] && \ + log_must $RM -f $bkup + done +} + +log_assert "Verify that invalid parameters to 'zfs receive' are caught." +log_onexit cleanup + +init_snap=$TESTPOOL/$TESTFS@initsnap +inc_snap=$TESTPOOL/$TESTFS@incsnap +full_bkup=$TMPDIR/full_bkup.${TESTCASE_ID} +inc_bkup=$TMPDIR/inc_bkup.${TESTCASE_ID} + +init_topsnap=$TESTPOOL@initsnap +inc_topsnap=$TESTPOOL@incsnap +full_topbkup=$TMPDIR/full_topbkup.${TESTCASE_ID} +inc_topbkup=$TMPDIR/inc_topbkup.${TESTCASE_ID} + +log_must $ZFS snapshot $init_topsnap +log_must eval "$ZFS send $init_topsnap > $full_topbkup" + +log_must $ZFS snapshot $inc_topsnap +log_must eval "$ZFS send -i $init_topsnap $inc_topsnap > $inc_topbkup" + +log_must $ZFS snapshot $init_snap +log_must eval "$ZFS send $init_snap > $full_bkup" + +log_must $ZFS snapshot $inc_snap +log_must eval "$ZFS send -i $init_snap $inc_snap > $inc_bkup" + +set -A badargs \ + "" "nonexistent-snap" "blah@blah" "$snap1" "$snap1 $snap2" \ + "-d" "-d nonexistent-dataset" \ + "$TESTPOOL/fs@" "$TESTPOOL/fs@@mysnap" "$TESTPOOL/fs@@" \ + "$TESTPOOL/fs/@mysnap" "$TESTPOOL/fs@/mysnap" \ + "$TESTPOOL/nonexistent-fs/nonexistent-fs" \ + "-d $TESTPOOL/nonexistent-fs" "-d $TESTPOOL/$TESTFS/nonexistent-fs" + +typeset -i i=0 +while (( i < ${#badargs[*]} )) +do + for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup ; do + log_mustnot eval "$ZFS receive ${badargs[i]} < $bkup" + done + + (( i = i + 1 )) +done + +log_pass "Invalid parameters to 'zfs receive' are caught as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_005_neg.ksh new file mode 100644 index 00000000000..c7cb20bb1fe --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_005_neg.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_005_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_005_neg +# +# DESCRIPTION: +# Verify 'zfs receive' fails with unsupported scenarios. +# including: +# (1) Invalid send streams; +# (2) The received incremental send doesn't match the filesystem +# latest status. +# +# STRATEGY: +# 1. Preparation for unsupported scenarios +# 2. Execute 'zfs receive' +# 3. Verify the results are failed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset snap + typeset bkup + + for snap in $init_snap $inc_snap; do + snapexists $snap && \ + log_must $ZFS destroy -f $snap + done + + datasetexists $rst_root && \ + log_must $ZFS destroy -Rf $rst_root + + for bkup in $full_bkup $inc_bkup; do + [[ -e $bkup ]] && \ + log_must $RM -f $bkup + done +} + +log_assert "Verify 'zfs receive' fails with unsupported scenarios." +log_onexit cleanup + +init_snap=$TESTPOOL/$TESTFS@initsnap +inc_snap=$TESTPOOL/$TESTFS@incsnap +rst_root=$TESTPOOL/rst_ctr +rst_init_snap=$rst_root/$TESTFS@init_snap +rst_inc_snap=$rst_root/$TESTFS@inc_snap +full_bkup=$TMPDIR/full_bkup.${TESTCASE_ID} +inc_bkup=$TMPDIR/inc_bkup.${TESTCASE_ID} + +log_must $ZFS create $rst_root +log_must $ZFS snapshot $init_snap +log_must eval "$ZFS send $init_snap > $full_bkup" + +log_note "'zfs receive' fails with invalid send streams." +log_mustnot eval "$ZFS receive $rst_init_snap < /dev/zero" +log_mustnot eval "$ZFS receive -d $rst_root $inc_bkup" +#make changes on the restoring filesystem +log_must $TOUCH $ZFSROOT/$rst_root/$TESTFS/tmpfile +log_mustnot eval "$ZFS receive $rst_inc_snap < $inc_bkup" +log_mustnot eval "$ZFS receive -d $rst_root < $inc_bkup" + +log_pass "Unsupported scenarios to 'zfs receive' fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_006_pos.ksh new file mode 100644 index 00000000000..b3512e129a1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_006_pos.ksh @@ -0,0 +1,122 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_006_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_006_pos +# +# DESCRIPTION: +# 'zfs recv -d ' should create ancestor filesystem if it does not +# exist and it should not fail if it exists +# +# STRATEGY: +# 1. Create pool and fs. +# 2. Create some files in fs and take snapshots. +# 3. Keep the stream and restore the stream to the pool +# 4. Verify receiving the stream succeeds, and the ancestor filesystem +# is created if it did not exist +# 5. Verify receiving the stream still succeeds when ancestor filesystem +# exists +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for snap in $snap2 $snap1; do + datasetexists $snap && log_must $ZFS destroy -rf $snap + done + for file in $fbackup1 $fbackup2 $mntpnt/file1 $mntpnt/file2; do + [[ -f $file ]] && log_must $RM -f $file + done + + if is_global_zone; then + datasetexists $TESTPOOL/$TESTFS/$TESTFS1 && \ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS/$TESTFS1 + else + datasetexists $TESTPOOL/${ZONE_CTR}0 && \ + log_must $ZFS destroy -rf $TESTPOOL/${ZONE_CTR}0 + fi + +} + +log_assert "'zfs recv -d ' should succeed no matter ancestor filesystem \ + exists." +log_onexit cleanup + +ancestor_fs=$TESTPOOL/$TESTFS +fs=$TESTPOOL/$TESTFS/$TESTFS1 +snap1=$fs@snap1 +snap2=$fs@snap2 +fbackup1=$TMPDIR/fbackup1.${TESTCASE_ID} +fbackup2=$TMPDIR/fbackup2.${TESTCASE_ID} + +datasetexists $ancestor_fs || \ + log_must $ZFS create $ancestor_fs +log_must $ZFS create $fs + +mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs" +log_must $MKFILE 10m $mntpnt/file1 +log_must $ZFS snapshot $snap1 +log_must $MKFILE 10m $mntpnt/file2 +log_must $ZFS snapshot $snap2 + +log_must eval "$ZFS send $snap1 > $fbackup1" +log_must eval "$ZFS send $snap2 > $fbackup2" + +log_note "Verify 'zfs receive -d' succeed and create ancestor filesystem \ + if it did not exist. " +log_must $ZFS destroy -rf $ancestor_fs +log_must eval "$ZFS receive -d $TESTPOOL < $fbackup1" +is_global_zone || ancestor_fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS +datasetexists $ancestor_fs || \ + log_fail "ancestor filesystem is not created" + +log_note "Verify 'zfs receive -d' still succeed if ancestor filesystem exists" +is_global_zone || fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS/$TESTFS1 +log_must $ZFS destroy -rf $fs +log_must eval "$ZFS receive -d $TESTPOOL < $fbackup2" + +log_pass "'zfs recv -d ' should succeed no matter ancestor filesystem \ + exists." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_007_neg.ksh new file mode 100644 index 00000000000..cb7ac0bcc52 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_007_neg.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_007_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_007_neg +# +# DESCRIPTION: +# 'zfs recv -F' should fail if the incremental stream does not match +# +# STRATEGY: +# 1. Create pool and fs. +# 2. Create some files in fs and take snapshots. +# 3. Keep the incremental stream and restore the stream to the pool +# 4. Verify receiving the stream fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for snap in $snap2 $snap1; do + datasetexists $snap && log_must $ZFS destroy -rf $snap + done + for file in $ibackup $mntpnt/file1 $mntpnt/file2; do + [[ -f $file ]] && log_must $RM -f $file + done +} + +log_assert "'zfs recv -F' should fail if the incremental stream does not match" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +snap1=$fs@snap1 +snap2=$fs@snap2 +ibackup=$TMPDIR/ibackup.${TESTCASE_ID} + +datasetexists $fs || log_must $ZFS create $fs + +mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs" +log_must $MKFILE 10m $mntpnt/file1 +log_must $ZFS snapshot $snap1 +log_must $MKFILE 10m $mntpnt/file2 +log_must $ZFS snapshot $snap2 + +log_must eval "$ZFS send -i $snap1 $snap2 > $ibackup" + +log_must $ZFS destroy $snap1 +log_must $ZFS destroy $snap2 +log_mustnot eval "$ZFS receive -F $fs < $ibackup" + +log_must $MKFILE 20m $mntpnt/file1 +log_must $RM -rf $mntpnt/file2 +log_must $ZFS snapshot $snap1 +log_mustnot eval "$ZFS receive -F $snap2 < $ibackup" + +log_pass "'zfs recv -F' should fail if the incremental stream does not match" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_008_pos.ksh new file mode 100644 index 00000000000..bd4865d9a94 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_008_pos.ksh @@ -0,0 +1,162 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_008_pos.ksh 1.3 08/02/27 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_008_pos +# +# DESCRIPTION: +# Verifying 'zfs receive -vn [] +# and zfs receive -vn -d ' +# +# STRATEGY: +# 1. Fill in fs with some data +# 2. Create full and incremental send stream +# 3. run zfs receive with -v option +# 3. Dryrun zfs receive with -vn option +# 3. Dryrun zfs receive with -vn -d option +# 4. Verify receive output and result +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-14) +# +# __stc_assertion_end +# +################################################################################ +function cleanup +{ + for dset in $rst_snap $rst_fs $orig_snap; do + if datasetexists $dset; then + log_must $ZFS destroy -fr $dset + fi + done + + for file in $fbackup $mnt_file $tmp_out; do + if [[ -f $file ]]; then + log_must $RM -f $file + fi + done + + if datasetexists $TESTPOOL/$TESTFS; then + log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + fi +} + +verify_runnable "both" +log_assert "Verifying 'zfs receive -vn [] " \ + "and zfs receive -vn -d '" + +log_onexit cleanup + +typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" +typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS +typeset fbackup=$TMPDIR/fbackup.${TESTCASE_ID} +typeset tmp_out=$TMPDIR/tmpout.${TESTCASE_ID} + +for orig_fs in $datasets ; do + typeset rst_snap=$rst_fs@snap + typeset orig_snap=$orig_fs@snap + typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}" + typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" + + if ! datasetexists $orig_fs; then + log_must $ZFS create $orig_fs + fi + + typeset mntpnt + mntpnt=$(get_prop mountpoint $orig_fs) + if [[ $? -ne 0 ]] ; then + log_fail "get_prop mountpoint $orig_fs failed" + fi + + typeset mnt_file=$mntpnt/file1 + + log_must $MKFILE 100m $mnt_file + log_must $ZFS snapshot $orig_snap + log_must eval "$ZFS send $orig_snap > $fbackup" + + for opt in "-v" "-vn"; do + if datasetexists $rst_fs; then + log_must $ZFS destroy -fr $rst_fs + fi + log_note "Check ZFS receive $opt []" + log_must eval "$ZFS receive $opt $rst_fs < $fbackup > $tmp_out 2>&1" + if [[ $opt == "-v" ]]; then + log_must eval "$GREP \"$verb_msg\" $tmp_out >/dev/null 2>&1" + if ! datasetexists $rst_snap; then + log_fail "dataset was not received, even though the"\ + " -v flag was used." + fi + else + log_must eval "$GREP \"$dryrun_msg\" $tmp_out >/dev/null 2>&1" + if datasetexists $rst_snap; then + log_fail "dataset was received, even though the -nv"\ + " flag was used." + fi + fi + done + + log_note "Check ZFS receive -vn -d " + if ! datasetexists $rst_fs; then + log_must $ZFS create $rst_fs + fi + log_must eval "$ZFS receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1" + typeset relative_path="" + if [[ ${orig_fs} == *"/"* ]]; then + relative_path=${orig_fs#*/} + fi + + typeset leaf_fs=${rst_fs}/${relative_path} + leaf_fs=${leaf_fs%/} + rst_snap=${leaf_fs}@snap + dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" + + log_must eval "$GREP \"$dryrun_msg\" $tmp_out > /dev/null 2>&1" + + if datasetexists $rst_snap; then + log_fail "dataset $rst_snap should not existed." + fi + log_must $ZFS destroy -Rf $rst_fs + + cleanup +done + +log_pass "zfs receive -vn [] and " \ + "zfs receive -vn -d ' succeed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_009_neg.ksh new file mode 100644 index 00000000000..df86deed267 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_009_neg.ksh @@ -0,0 +1,132 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_009_neg.ksh 1.2 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_receive_009_neg +# +# DESCRIPTION: +# Verify 'zfs receive' fails with bad options, missing argument or too many +# arguments. +# +# STRATEGY: +# 1. Set a array of illegal arguments +# 2. Execute 'zfs receive' with illegal arguments +# 3. Verify the command should be failed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset ds + + if snapexists $snap; then + log_must $ZFS destroy $snap + fi + for ds in $ctr1 $ctr2 $fs1; do + if datasetexists $ds; then + log_must $ZFS destroy -rf $ds + fi + done + if [[ -d $TESTDIR2 ]]; then + $RM -rf $TESTDIR2 + fi +} + +log_assert "Verify 'zfs receive' fails with bad option, missing or too many arguments" +log_onexit cleanup + +set -A badopts "v" "n" "F" "d" "-V" "-N" "-f" "-D" "-VNfD" "-vNFd" "-vnFD" "-dVnF" \ + "-vvvNfd" "-blah" "-12345" "-?" "-*" "-%" +set -A validopts "" "-v" "-n" "-F" "-vn" "-nF" "-vnF" "-vd" "-nd" "-Fd" "-vnFd" + +ctr1=$TESTPOOL/$TESTCTR1 +ctr2=$TESTPOOL/$TESTCTR2 +fs1=$TESTPOOL/$TESTFS1 +fs2=$TESTPOOL/$TESTFS2 +fs3=$TESTPOOL/$TESTFS3 +snap=$TESTPOOL/$TESTFS@$TESTSNAP +bkup=$TESTDIR2/bkup.${TESTCASE_ID} + +# Preparations for negative testing +for ctr in $ctr1 $ctr2; do + log_must $ZFS create $ctr +done +if [[ -d $TESTDIR2 ]]; then + $RM -rf $TESTDIR2 +fi +log_must $ZFS create -o mountpoint=$TESTDIR2 $fs1 +log_must $ZFS snapshot $snap +log_must eval "$ZFS send $snap > $bkup" + +#Testing zfs receive fails with input from terminal +log_mustnot eval "$ZFS recv $fs3 /dev/null 2>&1 + if (( $? != 0 )); then + log_mustnot eval "$ZFS recv ${validopts[i]} $fs2 $fs3 < $bkup" + else + log_mustnot eval "$ZFS recv ${validopts[i]} $ctr1 $ctr2 < $bkup" + fi + + (( i += 1 )) +done + +# Testing with bad options +i=0 +while (( i < ${#badopts[*]} )) +do + log_mustnot eval "$ZFS recv ${badopts[i]} $ctr1 < $bkup" + log_mustnot eval "$ZFS recv ${badopts[i]} $fs2 < $bkup" + + (( i = i + 1 )) +done + +log_pass "'zfs receive' as expected with bad options, missing or too many arguments." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_test.sh new file mode 100755 index 00000000000..6fe927fae82 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_receive/zfs_receive_test.sh @@ -0,0 +1,257 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_receive_001_pos cleanup +zfs_receive_001_pos_head() +{ + atf_set "descr" "Verifying 'zfs receive [] -d ' works." + atf_set "require.progs" zfs +} +zfs_receive_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_receive_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_002_pos cleanup +zfs_receive_002_pos_head() +{ + atf_set "descr" "Verifying 'zfs receive ' works." + atf_set "require.progs" zfs +} +zfs_receive_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_receive_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_003_pos cleanup +zfs_receive_003_pos_head() +{ + atf_set "descr" "'zfs recv -F' to force rollback." + atf_set "require.progs" zfs +} +zfs_receive_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_receive_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_004_neg cleanup +zfs_receive_004_neg_head() +{ + atf_set "descr" "Verify that invalid parameters to 'zfs receive' are caught." + atf_set "require.progs" zfs +} +zfs_receive_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_receive_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_005_neg cleanup +zfs_receive_005_neg_head() +{ + atf_set "descr" "Verify 'zfs receive' fails with unsupported scenarios." + atf_set "require.progs" zfs +} +zfs_receive_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_005_neg.ksh || atf_fail "Testcase failed" +} +zfs_receive_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_006_pos cleanup +zfs_receive_006_pos_head() +{ + atf_set "descr" "'zfs recv -d ' should succeed no matter ancestor filesystemexists." + atf_set "require.progs" zfs +} +zfs_receive_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_receive_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_007_neg cleanup +zfs_receive_007_neg_head() +{ + atf_set "descr" "'zfs recv -F' should fail if the incremental stream does not match" + atf_set "require.progs" zfs +} +zfs_receive_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_receive_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_008_pos cleanup +zfs_receive_008_pos_head() +{ + atf_set "descr" "Verifying 'zfs receive -vn []and zfs receive -vn -d '" + atf_set "require.progs" zfs +} +zfs_receive_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_008_pos.ksh || atf_fail "Testcase failed" +} +zfs_receive_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_009_neg cleanup +zfs_receive_009_neg_head() +{ + atf_set "descr" "Verify 'zfs receive' fails with bad option, missing or too many arguments" + atf_set "require.progs" zfs +} +zfs_receive_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_009_neg.ksh || atf_fail "Testcase failed" +} +zfs_receive_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_receive.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_receive_001_pos + atf_add_test_case zfs_receive_002_pos + atf_add_test_case zfs_receive_003_pos + atf_add_test_case zfs_receive_004_neg + atf_add_test_case zfs_receive_005_neg + atf_add_test_case zfs_receive_006_pos + atf_add_test_case zfs_receive_007_neg + atf_add_test_case zfs_receive_008_pos + atf_add_test_case zfs_receive_009_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/Makefile new file mode 100644 index 00000000000..8e78f0cf302 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/Makefile @@ -0,0 +1,31 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_rename +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_rename_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_rename_002_pos.ksh +${PACKAGE}FILES+= zfs_rename_006_pos.ksh +${PACKAGE}FILES+= zfs_rename_012_neg.ksh +${PACKAGE}FILES+= zfs_rename.cfg +${PACKAGE}FILES+= zfs_rename_013_pos.ksh +${PACKAGE}FILES+= zfs_rename_003_pos.ksh +${PACKAGE}FILES+= zfs_rename_007_pos.ksh +${PACKAGE}FILES+= zfs_rename_001_pos.ksh +${PACKAGE}FILES+= zfs_rename_004_neg.ksh +${PACKAGE}FILES+= zfs_rename_008_pos.ksh +${PACKAGE}FILES+= zfs_rename_009_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_rename_005_neg.ksh +${PACKAGE}FILES+= zfs_rename.kshlib +${PACKAGE}FILES+= zfs_rename_010_neg.ksh +${PACKAGE}FILES+= zfs_rename_011_pos.ksh +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/cleanup.ksh new file mode 100644 index 00000000000..d3878d0ed24 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/cleanup.ksh @@ -0,0 +1,43 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup_noexit + +if [[ -d $TESTDIR2 ]]; then + $RM -rf $TESTDIR2 + if (( $? != 0 )); then + log_unresolved Could not remove $TESTDIR2 + fi +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/setup.ksh new file mode 100644 index 00000000000..866b297b9bf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/setup.ksh @@ -0,0 +1,48 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup_noexit "$DISK" "true" "true" + +if [[ -d $TESTDIR2 ]]; then + $RM -rf $TESTDIR2 + if (( $? != 0 )); then + log_unresolved Could not remove $TESTDIR2 + fi +fi +log_must $ZFS create $TESTPOOL/$DATAFS +log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$DATAFS +log_must eval "$DD if=$IF of=$OF bs=$BS count=$CNT >/dev/null 2>&1" + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename.cfg new file mode 100644 index 00000000000..d8ce9ae98f4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename.cfg @@ -0,0 +1,41 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename.cfg 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export DATAFS=datafs${TESTCASE_ID} +export DATA=$TESTDIR2/data.${TESTCASE_ID} +export IF=/dev/urandom +export OF=$DATA +export BS=512 +export CNT=2048 +export VOL_R_PATH=/dev/zvol/$TESTPOOL/$TESTVOL +export VOLDATA=$TESTDIR2/voldata.${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename.kshlib new file mode 100644 index 00000000000..0d1dc6e7e0d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename.kshlib @@ -0,0 +1,117 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename.kshlib 1.5 07/10/09 SMI" +# + +function additional_setup +{ + # Create testfile + log_must $CP $DATA $TESTDIR/$TESTFILE0 + log_must $CP $DATA $TESTDIR1/$TESTFILE0 + + # Create snapshot + if ! snapexists $TESTPOOL/$TESTFS@snapshot; then + log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot + log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTFS-clone + fi + + # Create file system + datasetexists $TESTPOOL/$TESTFS1 || \ + log_must $ZFS create $TESTPOOL/$TESTFS1 + + # Create testfile + log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTFS1)/$TESTFILE0 + + # Create container + datasetexists $TESTPOOL/$TESTCTR1 || \ + log_must $ZFS create $TESTPOOL/$TESTCTR1 + log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTCTR1)/$TESTFILE0 + + # Create data in zvol + if is_global_zone; then + log_must eval "$DD if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT \ + >/dev/null 2>&1" + else + log_must $CP $DATA $(get_prop mountpoint $TESTPOOL/$TESTVOL)/$TESTFILE0 + fi + +} + +function rename_dataset # src dest +{ + typeset src=$1 + typeset dest=$2 + + log_must $ZFS rename $src $dest + + # + # Verify src name no longer in use + # + log_mustnot datasetexists $src + log_must datasetexists $dest +} + +function cleanup +{ + typeset -i i=0 + while ((i < ${#dataset[*]} )); do + if ! datasetexists ${dataset[i]}-new ; then + ((i = i + 1)) + continue + fi + + if [[ ${dataset[i]}-new != *@* ]] ; then + $ZFS rename ${dataset[i]}-new ${dataset[i]} + if [[ $? -ne 0 ]]; then + typeset newfs=${dataset[i]}-new + typeset oldfs=${dataset[i]} + typeset mntp=$(get_prop mountpoint $newfs) + log_must $ZFS destroy -f $newfs + log_must $ZFS create -p $oldfs + log_must $ZFS set mountpoint=$mntp $oldfs + fi + else + log_must $ZFS destroy -fR ${dataset[i]}-new + fi + + ((i = i + 1)) + done +} + +function cmp_data #<$1 src data, $2 tgt data> +{ + typeset src=$1 + typeset tgt=$2 + + $CMP $src $tgt >/dev/null 2>&1 + + return $? +} + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_001_pos.ksh new file mode 100644 index 00000000000..e51921a733f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_001_pos.ksh @@ -0,0 +1,121 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_001_pos.ksh 1.4 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rename_001_pos +# +# DESCRIPTION: +# 'zfs rename' should successfully rename valid datasets. +# As a sub-assertion we check to ensure the datasets that can +# be mounted are mounted. +# +# STRATEGY: +# 1. Given a file system, snapshot and volume. +# 2. Rename each dataset object to a new name. +# 3. Verify that only the new name is displayed by zfs list. +# 4. Verify mountable datasets are mounted. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-06-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +set -A dataset "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS1" \ + "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTCTR1" \ + "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS-clone" +set -A mountable "$TESTPOOL/$TESTFS1-new" "$TESTPOOL/$TESTFS@snapshot-new" \ + "$TESTPOOL/$TESTCTR/$TESTFS1-new" "$TESTPOOL/$TESTFS-clone-new" + +# +# cleanup defined in zfs_rename.kshlib +# +log_onexit cleanup + +log_assert "'zfs rename' should successfully rename valid datasets" + +additional_setup + +typeset -i i=0 +while (( i < ${#dataset[*]} )); do + rename_dataset ${dataset[i]} ${dataset[i]}-new + + ((i = i + 1)) +done + +log_note "Verify mountable datasets are mounted in their new namespace." +typeset mtpt +i=0 +while (( i < ${#mountable[*]} )); do + # Snapshot have no mountpoint + if [[ ${mountable[i]} != *@* ]]; then + log_must mounted ${mountable[i]} + mtpt=$(get_prop mountpoint ${mountable[i]}) + else + mtpt=$(snapshot_mountpoint ${mountable[i]}) + fi + + if ! cmp_data $DATA $mtpt/$TESTFILE0 ; then + log_fail "$mtpt/$TESTFILE0 gets corrupted after rename operation." + fi + + ((i = i + 1)) +done + +#verify the data integrity in zvol +if is_global_zone; then + log_must eval "$DD if=${VOL_R_PATH}-new of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1" + if ! cmp_data $VOLDATA $DATA ; then + log_fail "$VOLDATA gets corrupted after rename operation." + fi +fi + +# rename back fs +typeset -i i=0 +while ((i < ${#dataset[*]} )); do + if datasetexists ${dataset[i]}-new ; then + log_must $ZFS rename ${dataset[i]}-new ${dataset[i]} + fi + ((i = i + 1)) +done + +log_pass "'zfs rename' successfully renamed each dataset type." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_002_pos.ksh new file mode 100644 index 00000000000..893ecdba977 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_002_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_002_pos.ksh 1.3 07/07/31 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rename_002_pos +# +# DESCRIPTION: +# 'zfs rename' should successfully be capable of renaming +# valid datasets back and forth multiple times. +# +# STRATEGY: +# 1. Given a file system, snapshot and volume. +# 2. Rename each dataset object to a new name. +# 3. Rename each dataset back to its original name. +# 4. Repeat steps 2 and 3 multiple times. +# 5. Verify that the correct name is displayed by zfs list. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-06-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +set -A dataset "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS1" \ + "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTCTR1" \ + "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS-clone" + +# +# cleanup defined in zfs_rename.kshlib +# +log_onexit cleanup + +log_assert "'zfs rename' should successfully rename valid datasets" + +additional_setup + +typeset -i i=0 +typeset -i iters=10 + +while ((i < ${#dataset[*]} )); do + j=0 + while ((j < iters )); do + rename_dataset ${dataset[i]} ${dataset[i]}-new + rename_dataset ${dataset[i]}-new ${dataset[i]} + + ((j = j + 1)) + done + + if [[ ${dataset[i]} == *@* ]]; then + data=$(snapshot_mountpoint ${dataset[i]})/$TESTFILE0 + elif [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" ]] && is_global_zone; then + log_must eval "$DD if=$VOL_R_PATH of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1" + data=$VOLDATA + else + data=$(get_prop mountpoint ${dataset[i]})/$TESTFILE0 + fi + + if ! cmp_data $DATA $data; then + log_fail "$data gets corrupted after $iters times rename operations." + fi + + ((i = i + 1)) +done + +log_pass "'zfs rename' renamed each dataset type multiple times as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_003_pos.ksh new file mode 100644 index 00000000000..067394d85fb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_003_pos.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_003_pos.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rename_003_pos +# +# DESCRIPTION: +# 'zfs rename' can address the abbreviated snapshot name. +# +# STRATEGY: +# 1. Create pool, fs and snap. +# 2. Verify 'zfs rename' support the abbreviated snapshot name. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $snap && log_must $ZFS destroy $snap +} + +log_assert "'zfs rename' can address the abbreviated snapshot name." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS; snap=$fs@snap +set -A newname "$fs@new-snap" "@new-snap" "new-snap" + +log_must $ZFS snapshot $snap +log_must datasetexists $snap + +typeset -i i=0 +while ((i < ${#newname[*]} )); do + log_must $ZFS rename $snap ${newname[$i]} + log_must datasetexists ${snap%%@*}@${newname[$i]##*@} + log_must $ZFS rename ${snap%%@*}@${newname[$i]##*@} $snap + + ((i += 1)) +done + +log_pass "'zfs rename' address the abbreviated snapshot name passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_004_neg.ksh new file mode 100644 index 00000000000..ccd21d2b29f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_004_neg.ksh @@ -0,0 +1,125 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_004_neg.ksh 1.4 07/07/31 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rename_004_neg +# +# DESCRIPTION: +# 'zfs rename' should fail when this dataset was changed to an existed +# dataset name or datasets are of different types. +# For example, a filesystem cannot be renamed as a volume. +# +# STRATEGY: +# 1. Given a file system, snapshot and volume. +# 2. Rename each dataset object to a different type. +# 3. Verify that only the original name is displayed by zfs list. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-06-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +# +# This array is a list of pairs: +# item i: original type +# item i + 1: new type +# +set -A bad_dataset $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR1 \ + $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTCTR/$TESTFS1 \ + $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS1 \ + $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTFS1 \ + $TESTPOOL/$TESTCTR1 $TESTPOOL/$TESTCTR/$TESTFS1 \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS1 \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTCTR1 \ + $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR1 \ + $TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTVOL $TESTPOOL/$TESTFS1 \ + $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR/$TESTFS1 \ + $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR1 \ + $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS1 \ + $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTCTR/$TESTFS1 \ + $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%c \ + $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%d \ + $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%x \ + $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%p \ + $TESTPOOL/$TESTFS1 $TESTPOOL/${TESTFS1}%s \ + $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTFS@snapshot/fs + +# +# cleanup defined in zfs_rename.kshlib +# +log_onexit cleanup + +log_assert "'zfs rename' should fail when datasets are of a different type." + +additional_setup + +typeset -i i=0 +while ((i < ${#bad_dataset[*]} )); do + log_mustnot $ZFS rename ${bad_dataset[i]} ${bad_dataset[((i + 1))]} + log_must datasetexists ${bad_dataset[i]} + + log_mustnot $ZFS rename -p ${bad_dataset[i]} ${bad_dataset[((i + 1))]} + log_must datasetexists ${bad_dataset[i]} + + ((i = i + 2)) +done + +#verify 'rename -p' can not work with snapshots + +log_mustnot $ZFS rename -p $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTFS@snapshot2 +log_must datasetexists $TESTPOOL/$TESTFS@snapshot +log_mustnot $ZFS rename -p $TESTPOOL/$TESTFS@snapshot \ + $TESTPOOL/$TESTFS/$TESTFS@snapshot2 +log_must datasetexists $TESTPOOL/$TESTFS@snapshot + +log_pass "'zfs rename' fails as expected when given different dataset types." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_005_neg.ksh new file mode 100644 index 00000000000..9dc22ee0adb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_005_neg.ksh @@ -0,0 +1,105 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_005_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rename_005_neg +# +# DESCRIPTION: +# 'zfs rename' should fail when the dataset are not within the same pool +# +# STRATEGY: +# 1. Given a file system, snapshot and volume. +# 2. Rename each dataset object to a different pool. +# 3. Verify the operation fails, and only the original name +# is displayed by zfs list. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-13) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function my_cleanup +{ + poolexists $TESTPOOL1 && \ + destroy_pool $TESTPOOL1 + [[ -e $TESTDIR/$TESTFILE1 ]] && \ + log_must $RM -f $TESTDIR/$TESTFILE1 + cleanup +} + +set -A src_dataset \ + "$TESTPOOL/$TESTFS1" "$TESTPOOL/$TESTCTR1" \ + "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTVOL" \ + "$TESTPOOL/$TESTFS@snapshot" "$TESTPOOL/$TESTFS-clone" + +# +# cleanup defined in zfs_rename.kshlib +# +log_onexit my_cleanup + +log_assert "'zfs rename' should fail while datasets are within different pool." + +additional_setup + +typeset FILESIZE=64m +log_must $TRUNCATE -s $FILESIZE $TESTDIR/$TESTFILE1 +create_pool $TESTPOOL1 $TESTDIR/$TESTFILE1 + +for src in ${src_dataset[@]} ; do + dest=${src#$TESTPOOL/} + if [[ $dest == *"@"* ]]; then + dest=${dest#*@} + dest=${TESTPOOL1}@$dest + else + dest=${TESTPOOL1}/$dest + fi + log_mustnot $ZFS rename $src $dest + log_mustnot $ZFS rename -p $src $dest + + # + # Verify original dataset name still in use + # + log_must datasetexists $src +done + +log_pass "'zfs rename' fail while datasets are within different pool." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_006_pos.ksh new file mode 100644 index 00000000000..eaffb474450 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_006_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_006_pos.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rename_006_pos +# +# DESCRIPTION: +# 'zfs rename' can successfully rename a volume snapshot. +# +# STRATEGY: +# 1. Create a snapshot of volume. +# 2. Rename volume snapshot to a new one. +# 3. Rename volume to a new one. +# 5. Verify that the rename operations are successful and zfs list can +# list them. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-02-05) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +# +# cleanup defined in zfs_rename.kshlib +# +log_onexit cleanup + +log_assert "'zfs rename' can successfully rename a volume snapshot." + +vol=$TESTPOOL/$TESTVOL +snap=$TESTSNAP + +log_must eval "$DD if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT >/dev/null 2>&1" +if ! snapexists $vol@$snap; then + log_must $ZFS snapshot $vol@$snap +fi + +rename_dataset $vol@$snap $vol@${snap}-new +rename_dataset $vol ${vol}-new +rename_dataset ${vol}-new@${snap}-new ${vol}-new@$snap +rename_dataset ${vol}-new $vol + +#verify data integrity +for input in $VOL_R_PATH ${VOL_R_PATH}@$snap; do + log_must eval "$DD if=$input of=$VOLDATA bs=$BS count=$CNT >/dev/null 2>&1" + if ! cmp_data $VOLDATA $DATA ; then + log_fail "$input gets corrupted after rename operation." + fi +done + +log_must $ZFS destroy $vol@$snap + +log_pass "'zfs rename' can rename volume snapshot as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_007_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_007_pos.ksh new file mode 100644 index 00000000000..3279b4769fb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_007_pos.ksh @@ -0,0 +1,170 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_007_pos.ksh 1.2 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rename_007_pos +# +# DESCRIPTION: +# Rename dataset, verify that the data haven't changed. +# +# STRATEGY: +# 1. Create random data and copy to dataset. +# 2. Perform renaming commands. +# 3. Verify that the data haven't changed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Check if current system support recursive rename +$ZFS rename 2>&1 | grep "rename -r" >/dev/null 2>&1 +if (($? != 0)); then + log_unsupported +fi + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTFS ; then + log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS + fi + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + $RM -f $SRC_FILE $DST_FILE +} + +function target_obj +{ + typeset dtst=$1 + + typeset obj + typeset type=$(get_prop type $dtst) + if [[ $type == "filesystem" ]]; then + obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/} + elif [[ $type == "volume" ]]; then + obj=/dev/zvol/$dtst + fi + + print $obj +} + +log_assert "Rename dataset, verify that the data haven't changed." +log_onexit cleanup + +# Generate random data +# +BS=512 ; CNT=2048 +SRC_FILE=$TMPDIR/srcfile.${TESTCASE_ID} +DST_FILE=$TMPDIR/dstfile.${TESTCASE_ID} +log_must $DD if=/dev/random of=$SRC_FILE bs=$BS count=$CNT + +fs=$TESTPOOL/$TESTFS/fs.${TESTCASE_ID} +fsclone=$TESTPOOL/$TESTFS/fsclone.${TESTCASE_ID} +log_must $ZFS create $fs + +obj=$(target_obj $fs) +log_must $CP $SRC_FILE $obj + +snap=${fs}@snap.${TESTCASE_ID} +log_must $ZFS snapshot $snap +log_must $ZFS clone $snap $fsclone + +# Rename dataset & clone +# +log_must $ZFS rename $fs ${fs}-new +log_must $ZFS rename $fsclone ${fsclone}-new + +# Compare source file and target file +# +obj=$(target_obj ${fs}-new) +log_must $DIFF $SRC_FILE $obj +obj=$(target_obj ${fsclone}-new) +log_must $DIFF $SRC_FILE $obj + +# Rename snapshot and re-clone dataset +# +log_must $ZFS rename ${fs}-new $fs +log_must $ZFS rename $snap ${snap}-new +log_must $ZFS clone ${snap}-new $fsclone + +# Compare source file and target file +# +obj=$(target_obj $fsclone) +log_must $DIFF $SRC_FILE $obj + +if is_global_zone; then + vol=$TESTPOOL/$TESTFS/vol.${TESTCASE_ID} ; volclone=$TESTPOOL/$TESTFS/volclone.${TESTCASE_ID} + log_must $ZFS create -V 100M $vol + + obj=$(target_obj $vol) + log_must $DD if=$SRC_FILE of=$obj bs=$BS count=$CNT + + snap=${vol}@snap.${TESTCASE_ID} + log_must $ZFS snapshot $snap + log_must $ZFS clone $snap $volclone + + # Rename dataset & clone + log_must $ZFS rename $vol ${vol}-new + log_must $ZFS rename $volclone ${volclone}-new + + # Compare source file and target file + obj=$(target_obj ${vol}-new) + log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT + log_must $DIFF $SRC_FILE $DST_FILE + obj=$(target_obj ${volclone}-new) + log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT + log_must $DIFF $SRC_FILE $DST_FILE + + # Rename snapshot and re-clone dataset + log_must $ZFS rename ${vol}-new $vol + log_must $ZFS rename $snap ${snap}-new + log_must $ZFS clone ${snap}-new $volclone + + # Compare source file and target file + obj=$(target_obj $volclone) + log_must $DD if=$obj of=$DST_FILE bs=$BS count=$CNT + log_must $DIFF $SRC_FILE $DST_FILE +fi + +log_pass "Rename dataset, the data haven't changed passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_008_pos.ksh new file mode 100644 index 00000000000..3658edc2b59 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_008_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_008_pos.ksh 1.2 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rename_008_pos +# +# DESCRIPTION: +# zfs rename -r can rename snapshot recursively. +# +# STRATEGY: +# 1. Create snapshot recursively. +# 2. Rename snapshot recursively. +# 3. Verify rename -r snapshot correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Check if current system support recursive rename +$ZFS rename 2>&1 | grep "rename -r" > /dev/null 2>&1 +if (($? != 0)); then + log_unsupported +fi + +function cleanup +{ + typeset -i i=0 + while ((i < ${#datasets[@]})); do + if datasetexists ${datasets[$i]}@snap ; then + log_must $ZFS destroy ${datasets[$i]}@snap + fi + if datasetexists ${datasets[$i]}@snap-new ; then + log_must $ZFS destroy ${datasets[$i]}@snap-new + fi + + ((i += 1)) + done +} + +log_assert "zfs rename -r can rename snapshot recursively." +log_onexit cleanup + +set -A datasets $TESTPOOL $TESTPOOL/$TESTCTR \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS +if is_global_zone; then + datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL +fi + +log_must $ZFS snapshot -r ${TESTPOOL}@snap +typeset -i i=0 +while ((i < ${#datasets[@]})); do + log_must datasetexists ${datasets[$i]}@snap + + ((i += 1)) +done + +log_must $ZFS rename -r ${TESTPOOL}@snap ${TESTPOOL}@snap-new +i=0 +while ((i < ${#datasets[@]})); do + log_must datasetexists ${datasets[$i]}@snap-new + + ((i += 1)) +done + +log_must $ZFS destroy -rf ${TESTPOOL}@snap-new + +log_pass "Verify zfs rename -r passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_009_neg.ksh new file mode 100644 index 00000000000..54f58c63e0b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_009_neg.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_009_neg.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rename_009_neg +# +# DESCRIPTION: +# A snapshot already exists with the new name, then none of the +# snapshots is renamed. +# +# STRATEGY: +# 1. Create snapshot for a set of datasets. +# 2. Create a new snapshot for one of datasets. +# 3. Using rename -r command with exists snapshot name. +# 4. Verify none of the snapshots is renamed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Check if current system support recursive rename +$ZFS rename 2>&1 | grep "rename -r" >/dev/null 2>&1 +if (($? != 0)); then + log_unsupported +fi + +log_assert "zfs rename -r failed, when snapshot name is already existing." + +set -A datasets $TESTPOOL $TESTPOOL/$TESTCTR \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS +if is_global_zone; then + datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL +fi + +log_must $ZFS snapshot -r ${TESTPOOL}@snap +typeset -i i=0 +while ((i < ${#datasets[@]})); do + # Create one more snapshot + log_must $ZFS snapshot ${datasets[$i]}@snap2 + log_mustnot $ZFS rename -r ${TESTPOOL}@snap ${TESTPOOL}@snap2 + log_must $ZFS destroy ${datasets[$i]}@snap2 + + # Check datasets, make sure none of them was renamed. + typeset -i j=0 + while ((j < ${#datasets[@]})); do + if datasetexists ${datasets[$j]}@snap2 ; then + log_fail "${datasets[$j]}@snap2 should not exist." + fi + ((j += 1)) + done + + ((i += 1)) +done + +log_pass "zfs rename -r failed, when snapshot name is already existing passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_010_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_010_neg.ksh new file mode 100644 index 00000000000..7ddd41f41e1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_010_neg.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_010_neg.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rename_010_neg +# +# DESCRIPTION: +# The recursive flag -r can only be used for snapshots and not for +# volumes/filesystems. +# +# STRATEGY: +# 1. Loop pool, fs, container and volume. +# 2. Verify none of them can be rename by rename -r. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Check if current system support recursive rename +$ZFS rename 2>&1 | grep "rename -r" >/dev/null 2>&1 +if (($? != 0)); then + log_unsupported +fi + +log_assert "The recursive flag -r can only be used for snapshots." + +set -A datasets $TESTPOOL $TESTPOOL/$TESTCTR \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS +if is_global_zone; then + datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL +fi + +for opts in "-r" "-r -p"; do + typeset -i i=0 + while ((i < ${#datasets[@]})); do + log_mustnot $ZFS rename $opts ${datasets[$i]} \ + ${datasets[$i]}-new + + # Check datasets, make sure none of them was renamed. + typeset -i j=0 + while ((j < ${#datasets[@]})); do + if datasetexists ${datasets[$j]}-new ; then + log_fail "${datasets[$j]}-new should not exists." + fi + ((j += 1)) + done + + ((i += 1)) + done +done + +log_pass "The recursive flag -r can only be used for snapshots passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_011_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_011_pos.ksh new file mode 100644 index 00000000000..71bf65a0c3b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_011_pos.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_011_pos.ksh 1.2 09/01/13 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rename/zfs_rename.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rename_011_pos +# +# DESCRIPTION +# 'zfs rename -p' should work as expected +# +# STRATEGY: +# 1. Make sure the upper level of $newdataset does not exist +# 2. Make sure without -p option, 'zfs rename' will fail +# 3. With -p option, rename works +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-05) +# +# __stc_assertion_end +# +############################################################################### + +if ! $(check_opt_support "create" "-p") ; then + log_unsupported "-p option is not supported yet." +fi + +verify_runnable "both" + +function additional_cleanup +{ + if datasetexists $TESTPOOL/notexist ; then + log_must $ZFS destroy -Rf $TESTPOOL/notexist + fi + + if datasetexists $TESTPOOL/$TESTFS ; then + log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS + fi + log_must $ZFS create $TESTPOOL/$TESTFS + + if is_global_zone ; then + if datasetexists $TESTPOOL/$TESTVOL ; then + log_must $ZFS destroy -Rf $TESTPOOL/$TESTVOL + fi + log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL + fi +} + +log_onexit additional_cleanup + +log_assert "'zfs rename -p' should work as expected" + +log_must verify_opt_p_ops "rename" "fs" "$TESTPOOL/$TESTFS" \ + "$TESTPOOL/notexist/new/$TESTFS1" + +if is_global_zone; then + log_must verify_opt_p_ops "rename" "vol" "$TESTPOOL/$TESTVOL" \ + "$TESTPOOL/notexist/new/$TESTVOL1" +fi + +log_pass "'zfs rename -p' should work as expected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_012_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_012_neg.ksh new file mode 100644 index 00000000000..c1f68f0c173 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_012_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_012_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rename_012_neg +# +# DESCRIPTION: +# 'zfs rename' should be failed with bad option, null target dataset, +# too many datasets and long target dataset name. +# +# STRATEGY: +# 1. Create a set of ZFS datasets; +# 2. Try 'zfs rename' with various illegal scenarios; +# 3. Verify 'zfs rename' command should be failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "'zfs rename' should fail with bad option, null target dataset and" \ + "too long target dataset name." + +set -A badopts "r" "R" "-R" "-rR" "-Rr" "-P" "-pP" "-Pp" "-r*" "-p*" "-?" "-*" \ + "-" "-o" +set -A datasets "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS@$TESTSNAP" \ + "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" "$TESTPOOL/$TESTVOL" + +longname="$(gen_dataset_name 260 abcdefg)" + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP +for ds in ${datasets[@]}; do + for opt in ${badopts[@]}; do + log_mustnot $ZFS rename $opt $ds ${ds}-new + done + log_mustnot $ZFS rename $ds + log_mustnot $ZFS rename $ds ${ds}-new ${ds}-new1 + log_mustnot $ZFS rename $ds ${ds}.$longname +done + +log_pass "'zfs rename' fails with illegal scenarios as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_013_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_013_pos.ksh new file mode 100644 index 00000000000..befe912a098 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_013_pos.ksh @@ -0,0 +1,105 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_013_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rename_013_pos +# +# DESCRIPTION: +# zfs rename -r can rename snapshot when child datasets +# don't have a snapshot of the given name. +# +# STRATEGY: +# 1. Create snapshot. +# 2. Rename snapshot recursively. +# 3. Verify rename -r snapshot correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Check if current system support recursive rename +$ZFS rename 2>&1 | grep "rename -r" > /dev/null 2>&1 +if (($? != 0)); then + log_unsupported +fi + +function cleanup +{ + if datasetexists $TESTPOOL/$TESTCTR@snap-new ; then + log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap-new + fi + + if datasetexists $TESTPOOL/$TESTCTR@snap ; then + log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap + fi + + if datasetexists $TESTPOOL@snap-new ; then + log_must $ZFS destroy -f $TESTPOOL@snap-new + fi + + if datasetexists $TESTPOOL@snap ; then + log_must $ZFS destroy -f $TESTPOOL@snap + fi +} + +log_assert "zfs rename -r can rename snapshot when child datasets" \ + "don't have a snapshot of the given name." + +log_onexit cleanup + +log_must $ZFS snapshot $TESTPOOL/$TESTCTR@snap +log_must $ZFS rename -r $TESTPOOL/$TESTCTR@snap $TESTPOOL/$TESTCTR@snap-new +log_must datasetexists $TESTPOOL/$TESTCTR@snap-new + +log_must $ZFS snapshot $TESTPOOL@snap +log_must $ZFS rename -r $TESTPOOL@snap $TESTPOOL@snap-new +log_must datasetexists $TESTPOOL/$TESTCTR@snap-new +log_must datasetexists $TESTPOOL@snap-new + +log_must $ZFS destroy -f $TESTPOOL/$TESTCTR@snap-new +log_must $ZFS destroy -f $TESTPOOL@snap-new + +log_pass "Verify zfs rename -r passed when child datasets" \ + "don't have a snapshot of the given name." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_test.sh new file mode 100755 index 00000000000..9975e6cc888 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rename/zfs_rename_test.sh @@ -0,0 +1,383 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_rename_001_pos cleanup +zfs_rename_001_pos_head() +{ + atf_set "descr" "'zfs rename' should successfully rename valid datasets" + atf_set "require.progs" zfs +} +zfs_rename_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_002_pos cleanup +zfs_rename_002_pos_head() +{ + atf_set "descr" "'zfs rename' should successfully rename valid datasets" + atf_set "require.progs" zfs +} +zfs_rename_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_003_pos cleanup +zfs_rename_003_pos_head() +{ + atf_set "descr" "'zfs rename' can address the abbreviated snapshot name." + atf_set "require.progs" zfs +} +zfs_rename_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_004_neg cleanup +zfs_rename_004_neg_head() +{ + atf_set "descr" "'zfs rename' should fail when datasets are of a different type." + atf_set "require.progs" zfs +} +zfs_rename_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_rename_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_005_neg cleanup +zfs_rename_005_neg_head() +{ + atf_set "descr" "'zfs rename' should fail while datasets are within different pool." + atf_set "require.progs" zfs +} +zfs_rename_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_005_neg.ksh || atf_fail "Testcase failed" +} +zfs_rename_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_006_pos cleanup +zfs_rename_006_pos_head() +{ + atf_set "descr" "'zfs rename' can successfully rename a volume snapshot." + atf_set "require.progs" zfs +} +zfs_rename_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_007_pos cleanup +zfs_rename_007_pos_head() +{ + atf_set "descr" "Rename dataset, verify that the data haven't changed." + atf_set "require.progs" zfs +} +zfs_rename_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_007_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_008_pos cleanup +zfs_rename_008_pos_head() +{ + atf_set "descr" "zfs rename -r can rename snapshot recursively." + atf_set "require.progs" zfs +} +zfs_rename_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_008_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_009_neg cleanup +zfs_rename_009_neg_head() +{ + atf_set "descr" "zfs rename -r failed, when snapshot name is already existing." + atf_set "require.progs" zfs +} +zfs_rename_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_009_neg.ksh || atf_fail "Testcase failed" +} +zfs_rename_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_010_neg cleanup +zfs_rename_010_neg_head() +{ + atf_set "descr" "The recursive flag -r can only be used for snapshots." + atf_set "require.progs" zfs +} +zfs_rename_010_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_010_neg.ksh || atf_fail "Testcase failed" +} +zfs_rename_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_011_pos cleanup +zfs_rename_011_pos_head() +{ + atf_set "descr" "'zfs rename -p' should work as expected" + atf_set "require.progs" zfs +} +zfs_rename_011_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_011_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_012_neg cleanup +zfs_rename_012_neg_head() +{ + atf_set "descr" "'zfs rename' should fail with bad option, null target dataset andtoo long target dataset name." + atf_set "require.progs" zfs +} +zfs_rename_012_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_012_neg.ksh || atf_fail "Testcase failed" +} +zfs_rename_012_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_013_pos cleanup +zfs_rename_013_pos_head() +{ + atf_set "descr" "zfs rename -r can rename snapshot when child datasetsdon't have a snapshot of the given name." + atf_set "require.progs" zfs +} +zfs_rename_013_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_013_pos.ksh || atf_fail "Testcase failed" +} +zfs_rename_013_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rename.kshlib + . $(atf_get_srcdir)/zfs_rename.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_rename_001_pos + atf_add_test_case zfs_rename_002_pos + atf_add_test_case zfs_rename_003_pos + atf_add_test_case zfs_rename_004_neg + atf_add_test_case zfs_rename_005_neg + atf_add_test_case zfs_rename_006_pos + atf_add_test_case zfs_rename_007_pos + atf_add_test_case zfs_rename_008_pos + atf_add_test_case zfs_rename_009_neg + atf_add_test_case zfs_rename_010_neg + atf_add_test_case zfs_rename_011_pos + atf_add_test_case zfs_rename_012_neg + atf_add_test_case zfs_rename_013_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/Makefile new file mode 100644 index 00000000000..8ce768b174b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_reservation +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_reservation_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_reservation.cfg +${PACKAGE}FILES+= zfs_reservation_001_pos.ksh +${PACKAGE}FILES+= zfs_reservation_002_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation.cfg new file mode 100644 index 00000000000..25278ead688 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_reservation.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh new file mode 100644 index 00000000000..884eef3a77b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_001_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_reservation_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_reservation_001_pos +# +# DESCRIPTION: +# Exceed the maximum limit for a reservation and ensure it fails. +# +# STRATEGY: +# 1. Create a reservation file system. +# 2. Set the reservation to an absurd value. +# 3. Verify the return code is an error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +RESERVATION="reserve" + +function cleanup +{ + if datasetexists $TESTPOOL/$RESERVATION ; then + log_must $ZFS unmount $TESTPOOL/$RESERVATION + log_must $ZFS destroy $TESTPOOL/$RESERVATION + fi +} + +log_onexit cleanup + +log_assert "Verify that a reservation > 2^64 -1 fails." + +log_must $ZFS create $TESTPOOL/$RESERVATION + +log_mustnot $ZFS set reservation=18446744073709551615 $TESTPOOL/$RESERVATION + +log_pass "Unable to set a reservation > 2^64 - 1" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh new file mode 100644 index 00000000000..50e7f0e5ce7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_002_pos.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_reservation_002_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_reservation_002_pos +# +# DESCRIPTION: +# A reservation of 'none' (which is an alias for 0) should be allowed. This +# test verifies that is true. +# +# STRATEGY: +# 1. Create a new file system in the test pool. +# 2. Set the reservation to 'none'. +# 3. Verify the associated reservation is indeed 0. +# 4. Repeat with reservation set to 0. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Use a unique value so earlier test failures will not impact this test. +RESERVATION="reserve"-${TESTCASE_ID} +RESERVATION2="reserve2"-${TESTCASE_ID} + +function cleanup +{ + typeset FS + for FS in $TESTPOOL/$RESERVATION $TESTPOOL/$RESERVATION2 + do + if datasetexists $FS ; then + log_must $ZFS unmount $FS + log_must $ZFS destroy $FS + fi + done +} + +log_onexit cleanup + +log_assert "Ensure a reservation of 0 or 'none' is allowed." + +log_must $ZFS create $TESTPOOL/$RESERVATION +log_must $ZFS create $TESTPOOL/$RESERVATION2 + +log_must $ZFS set reservation=0 $TESTPOOL/$RESERVATION +log_must $ZFS set reservation=none $TESTPOOL/$RESERVATION2 + +for FS in $TESTPOOL/$RESERVATION $TESTPOOL/$RESERVATION2 +do + + reserve=`$ZFS get -pH reservation $FS | $AWK '{print $3}'` + if [[ $reserve -ne 0 ]]; then + log_fail "ZFS get -p reservation did not return 0" + fi + + reserve=`$ZFS get -H reservation $FS | $AWK '{print $3}'` + if [[ $reserve != "none" ]]; then + log_fail "ZFS get reservation did not return 'none'" + fi +done + +log_pass "Successfully set reservation to 0 and 'none'" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_test.sh new file mode 100755 index 00000000000..e14585cc42c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_reservation/zfs_reservation_test.sh @@ -0,0 +1,82 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_reservation_001_pos cleanup +zfs_reservation_001_pos_head() +{ + atf_set "descr" "Verify that a reservation > 2^64 -1 fails." + atf_set "require.progs" zfs +} +zfs_reservation_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_reservation_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_reservation_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_reservation_002_pos cleanup +zfs_reservation_002_pos_head() +{ + atf_set "descr" "Ensure a reservation of 0 or 'none' is allowed." + atf_set "require.progs" zfs +} +zfs_reservation_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_reservation_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_reservation_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_reservation_001_pos + atf_add_test_case zfs_reservation_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/Makefile new file mode 100644 index 00000000000..6cb54ca9599 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_rollback +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_rollback_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_rollback_003_neg.ksh +${PACKAGE}FILES+= zfs_rollback_002_pos.ksh +${PACKAGE}FILES+= zfs_rollback_common.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_rollback_004_neg.ksh +${PACKAGE}FILES+= zfs_rollback_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_rollback.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/cleanup.ksh new file mode 100644 index 00000000000..6179df35da6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/cleanup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +$MOUNT | grep -q "/dev/zvol/$VOL" > /dev/null 2>&1 +if (( $? == 0 )); then + log_must $UMOUNT -f $TESTDIR1 +fi + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/setup.ksh new file mode 100644 index 00000000000..2bc1412e1ee --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +default_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback.cfg new file mode 100644 index 00000000000..09b1bbbe484 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback.cfg @@ -0,0 +1,53 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rollback.cfg 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/cli.cfg + +export FS=$TESTPOOL/$TESTFS +export VOL=$TESTPOOL/$TESTVOL + +export FSSNAP0=$FS@$TESTSNAP +export FSSNAP1=$FS@$TESTSNAP1 +export FSSNAP2=$FS@$TESTSNAP2 + +export VOLSNAP0=$VOL@$TESTSNAP +export VOLSNAP1=$VOL@$TESTSNAP1 +export VOLSNAP2=$VOL@$TESTSNAP2 + +export FSCLONE0=$FS$TESTCLONE +export FSCLONE1=$FS$TESTCLONE1 +export FSCLONE2=$FS$TESTCLONE2 + +export VOLCLONE0=$VOL$TESTCLONE +export VOLCLONE1=$VOL$TESTCLONE1 +export VOLCLONE2=$VOL$TESTCLONE2 + +export STF_TIMEOUT=1800 diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh new file mode 100644 index 00000000000..f6ef41439e4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh @@ -0,0 +1,181 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rollback_001_pos.ksh 1.4 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rollback_001_pos +# +# DESCRIPTION: +# 'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any snapshots +# more recent than the one specified. +# +# STRATEGY: +# 1. Create pool, fs & volume. +# 2. Separately create three snapshots or clones for fs & volume +# 3. Roll back to the second snapshot and check the results. +# 4. Create the third snapshot or clones for fs & volume again. +# 5. Roll back to the first snapshot and check the results. +# 6. Separately create two snapshots for fs & volume. +# 7. Roll back to the first snapshot and check the results. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any " \ + "snapshots more recent than the one specified." +log_onexit cleanup_env + +# +# Create suitable test environment and run 'zfs rollback', then compare with +# expected value to check the system status. +# +# $1 option. +# $2 the number of snapshots or clones. +# $3 the number of snapshot point which we want to rollback. +# +function test_n_check #opt num_snap_clone num_rollback +{ + typeset opt=$1 + typeset -i cnt=$2 + typeset -i pointcnt=$3 + typeset dtst + + (( cnt > 3 || pointcnt > cnt )) && \ + log_fail "Unsupported testing condition." + + # Clean up the test environment + datasetexists $FS && log_must $ZFS destroy -Rf $FS + if datasetexists $VOL; then + $MOUNT | grep -q "/dev/zvol/$VOL" > /dev/null 2>&1 + (( $? == 0 )) && log_must $UMOUNT -f $TESTDIR1 + + log_must $ZFS destroy -Rf $VOL + fi + + # Create specified test environment + case $opt in + *r*) setup_snap_env $cnt ;; + *R*) setup_clone_env $cnt ;; + esac + + all_snap="$TESTSNAP $TESTSNAP1 $TESTSNAP2" + all_clone="$TESTCLONE $TESTCLONE1 $TESTCLONE2" + typeset snap_point + typeset exist_snap + typeset exist_clone + case $pointcnt in + 1) snap_point=$TESTSNAP + exist_snap=$TESTSNAP + [[ $opt == *R* ]] && exist_clone=$TESTCLONE + ;; + 2) snap_point=$TESTSNAP1 + exist_snap="$TESTSNAP $TESTSNAP1" + [[ $opt == *R* ]] && exist_clone="$TESTCLONE $TESTCLONE1" + ;; + esac + + typeset snap + for dtst in $FS $VOL; do + # Volume is not available in Local Zone. + if [[ $dtst == $VOL ]]; then + if ! is_global_zone; then + break + fi + fi + if [[ $opt == *f* ]]; then + # To write data to the mountpoint directory, + write_mountpoint_dir $dtst + opt=${opt%f} + fi + + if [[ $dtst == $VOL ]]; then + log_must $UMOUNT -f $TESTDIR1 + log_must $ZFS rollback $opt $dtst@$snap_point + log_must $MOUNT \ + /dev/zvol/$TESTPOOL/$TESTVOL $TESTDIR1 + else + log_must $ZFS rollback $opt $dtst@$snap_point + fi + + for snap in $all_snap; do + if [[ " $exist_snap " == *" $snap "* ]]; then + log_must datasetexists $dtst@$snap + else + log_must datasetnonexists $dtst@$snap + fi + done + for clone in $all_clone; do + if [[ " $exist_clone " == *" $clone "* ]]; then + log_must datasetexists $dtst$clone + else + log_must datasetnonexists $dtst$clone + fi + done + + check_files $dtst@$snap_point + done +} + +typeset opt +for opt in "-r" "-rf" "-R" "-Rf"; do + # + # Currently, the test case was limited to create and rollback + # in three snapshots + # + log_note "Create 3 snapshots, rollback to the 2nd snapshot " \ + "using $opt." + test_n_check "$opt" 3 2 + + log_note "Create 3 snapshots and rollback to the 1st snapshot " \ + "using $opt." + test_n_check "$opt" 3 1 + + log_note "Create 2 snapshots and rollback to the 1st snapshot " \ + "using $opt." + test_n_check "$opt" 2 1 +done + +log_pass "'zfs rollback -r|-rf|-R|-Rf' recursively destroy any snapshots more "\ + "recent than the one specified passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh new file mode 100644 index 00000000000..7f60df639f2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_002_pos.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rollback_002_pos.ksh 1.4 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rollback_002_pos +# +# DESCRIPTION: +# 'zfs rollback -f' will force unmount any filesystems. +# +# STRATEGY: +# 1. Create pool & fs. +# 2. Create the snapshot of this file system. +# 3. Write the mountpoint directory of this file system. +# 4. Make sure 'zfs rollback -f' succeeds. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "'zfs rollback -f' will force unmount any filesystems." +log_onexit cleanup_env + +# Create a snapshot of this file system: FSSNAP0 +setup_snap_env 1 + +# +# Write file and make the mountpoint directory busy when try to unmount +# the file system that was mounted on it. +# +write_mountpoint_dir ${FSSNAP0%%@*} + +log_must $ZFS rollback $FSSNAP0 +log_must $ZFS rollback -f $FSSNAP0 +log_must datasetexists $FSSNAP0 + +$PKILL ${DD##*/} + +check_files $FSSNAP0 + +log_pass "'zfs rollback -f' force unmount any filesystem passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh new file mode 100644 index 00000000000..e613b2d4533 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rollback_003_neg.ksh 1.5 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rollback_003_neg +# +# DESCRIPTION: +# Separately verify 'zfs rollback ''|-f|-r|-rf|-R|-rR will fail in +# different conditions. +# +# STRATEGY: +# 1. Create pool and file system +# 2. Create 'snap' and 'snap1' of this file system. +# 3. Run 'zfs rollback ""|-f ' and it should fail. +# 4. Create 'clone1' based on 'snap1'. +# 5. Run 'zfs rollback -r|-rf ' and it should fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $PKILL ${DD##*/} + for snap in $FSSNAP0 $FSSNAP1 $FSSNAP2; do + if snapexists $snap; then + log_must $ZFS destroy -Rf $snap + fi + done +} + +log_assert "Separately verify 'zfs rollback ''|-f|-r|-rf will fail in " \ + "different conditions." +log_onexit cleanup + +# Create snapshot1 and snapshot2 for this file system. +# +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1 + +# Run 'zfs rollback ""|-f ' and it should fail. +# +log_mustnot $ZFS rollback $TESTPOOL/$TESTFS@$TESTSNAP +log_mustnot $ZFS rollback -f $TESTPOOL/$TESTFS@$TESTSNAP + +# Create 'clone1' based on 'snap1'. +# +create_clone $TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE1 + +# Run 'zfs rollback -r|-rf ' and it should fail. +# +log_mustnot $ZFS rollback -r $TESTPOOL/$TESTFS@$TESTSNAP +log_mustnot $ZFS rollback -rf $TESTPOOL/$TESTFS@$TESTSNAP + +log_pass "zfs rollback ''|-f|-r|-rf will fail in different conditions " \ + "passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh new file mode 100644 index 00000000000..dcff3de5755 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh @@ -0,0 +1,100 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rollback_004_neg.ksh 1.2 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_rollback_004_neg +# +# DESCRIPTION: +# 'zfs rollback' should fail when passing invalid options, too many +# arguments,non-snapshot datasets or missing datasets +# +# STRATEGY: +# 1. Create an array of invalid options +# 2. Execute 'zfs rollback' with invalid options, too many arguments +# or missing datasets +# 3. Verify 'zfs rollback' return with errors +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset ds + + for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do + if snapexists ${ds}@$TESTSNAP; then + log_must $ZFS destroy ${ds}@$TESTSNAP + fi + done +} + +log_assert "'zfs rollback' should fail with bad options,too many arguments," \ + "non-snapshot datasets or missing datasets." +log_onexit cleanup + +set -A badopts "r" "R" "f" "-F" "-rF" "-RF" "-fF" "-?" "-*" "-blah" "-1" "-2" + +for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do + log_must $ZFS snapshot ${ds}@$TESTSNAP +done + +for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do + for opt in "" "-r" "-R" "-f" "-rR" "-rf" "-rRf"; do + log_mustnot eval "$ZFS rollback $opt $ds >/dev/null 2>&1" + log_mustnot eval "$ZFS rollback $opt ${ds}@$TESTSNAP \ + ${ds}@$TESTSNAP >/dev/null 2>&1" + log_mustnot eval "$ZFS rollback $opt >/dev/null 2>&1" + # zfs rollback should fail with non-existen snapshot + log_mustnot eval "$ZFS rollback $opt ${ds}@nosnap >/dev/null 2>&1" + done + + for badopt in ${badopts[@]}; do + log_mustnot eval "$ZFS rollback $badopt ${ds}@$TESTSNAP \ + >/dev/null 2>&1" + done +done + +log_pass "'zfs rollback' fails as expected with illegal arguments." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib new file mode 100644 index 00000000000..7ab7d14570f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib @@ -0,0 +1,305 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rollback_common.kshlib 1.6 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# Get file sum +# +# $1 full file name +function getsum #fname +{ + (( ${#1} == 0 )) && \ + log_fail "Need give file name." + return $($SUM $1 | $AWK '{print $1}') +} + +# Define global variable checksum, get the original file sum. +# +origsum=$(getsum /etc/passwd) + +# +# Setup or recover the test environment. Firstly, copy /etc/passwd to ZFS file +# system or volume, then make a snapshot or clone. Repeat up to three times. +# +# $1 number of snapshot. Note: Currently only support three snapshots. +# $2 indicate if it is necessary to create clone +# +function setup_snap_env +{ + typeset -i cnt=${1:-3} + typeset createclone=${2:-"false"} + + if datasetnonexists $FS; then + log_must $ZFS create $FS + log_must $ZFS set mountpoint=$TESTDIR $FS + fi + # Volume can't be created in Local Zone. + if datasetnonexists $VOL && is_global_zone; then + log_must $ZFS create -V $VOLSIZE $VOL + fi + + # Make sure $VOL is volume + typeset type=$(get_prop type $VOL) + if datasetexists $VOL && \ + [[ $type == 'volume' ]]; then + # + # At the first time, Make a UFS file system in volume and + # mount it. Otherwise, only check if this ufs file system + # was mounted. + # + log_must eval "$ECHO "y" | \ + $NEWFS /dev/zvol/$VOL > /dev/null 2>&1" + + [[ ! -d $TESTDIR1 ]] && log_must $MKDIR $TESTDIR1 + + # Make sure the ufs filesystem hasn't been mounted, + # then mount the new ufs filesystem. + $MOUNT | grep -q "/dev/zvol/$VOL" > /dev/null 2>&1 + if (( $? != 0 )); then + log_must $MOUNT \ + /dev/zvol/$TESTPOOL/$TESTVOL $TESTDIR1 + fi + fi + + # Separately Create three snapshots for file system & volume + typeset -i ind=0 + typeset dtst + for dtst in $FS $VOL; do + # Volume can be created in Local Zone. + if [[ $dtst == $VOL ]]; then + if ! is_global_zone; then + break + fi + fi + + ind=0 + while (( ind < cnt )); do + case $dtst in + $FS) + eval typeset snap=\$FSSNAP$ind + eval typeset clone=\$FSCLONE$ind + eval typeset fname=\$TESTDIR/\$TESTFILE$ind + ;; + $VOL) + eval typeset snap=\$VOLSNAP$ind + eval typeset clone=\$VOLCLONE$ind + eval typeset fname=\$TESTDIR1/\$TESTFILE$ind + ;; + esac + + if datasetnonexists $snap; then + log_must $CP /etc/passwd $fname + # + # Take the snapshot with the zvol unmounted so + # that its filesystem's state will be + # consistent. + # + mount -u -o ro /dev/zvol/$TESTPOOL/$TESTVOL + log_must $ZFS snapshot $snap + mount -u -o rw /dev/zvol/$TESTPOOL/$TESTVOL + fi + if [[ $createclone == "true" ]]; then + if datasetnonexists $clone; then + log_must $ZFS clone $snap $clone + fi + fi + (( ind += 1 )) + done + done +} + +function setup_clone_env +{ + setup_snap_env $1 "true" +} + +# +# Clean up the test environmnet +# +# $1 number of snapshot Note: Currently only support three snapshots. +# +function cleanup_env +{ + typeset -i cnt=${1:-3} + typeset -i ind=0 + typeset dtst + typeset snap + + $PKILL ${DD##*/} + + $MOUNT | grep -q "/dev/zvol/$VOL" > /dev/null 2>&1 + if (( $? == 0 )); then + log_must $UMOUNT -f $TESTDIR1 + fi + + [[ -d $TESTDIR ]] && log_must $RM -rf $TESTDIR/* + [[ -d $TESTDIR1 ]] && log_must $RM -rf $TESTDIR1/* + + for dtst in $FS $VOL; do + for snap in $TESTSNAP $TESTSNAP1 $TESTSNAP2; do + if snapexists $dtst@$snap; then + log_must $ZFS destroy -Rf $dtst@$snap + fi + done + done + + # Restore original test environment + if datasetnonexists $FS ; then + log_must $ZFS create $FS + fi + if datasetnonexists $VOL ; then + if is_global_zone ; then + log_must $ZFS create -V $VOLSIZE $VOL + else + log_must $ZFS create $VOL + fi + fi +} + +# +# check if the specified files have specified status. +# +# $1 expected status +# $2-n full file name +# If it is true return 0, else return 1 +# +function file_status +{ + (( $# == 0 )) && \ + log_fail "The file name is not defined." + + typeset opt + case $1 in + exist) opt="-e" ;; + nonexist) opt="! -e" ;; + *) log_fail "Unsupported file status." ;; + esac + + shift + while (( $# > 0 )); do + eval [[ $opt $1 ]] || return 1 + shift + done + + return 0 +} + +function files_exist +{ + file_status "exist" $@ +} + +function files_nonexist +{ + file_status "nonexist" $@ +} + +# +# According to snapshot check if the file system was recovered to the right +# point. +# +# $1 snapshot. fs@snap or vol@snap +# +function check_files +{ + typeset dtst=$1 + + if [[ $(get_prop type $dtst) != snapshot ]]; then + log_fail "Parameter must be a snapshot." + fi + + typeset fsvol=${dtst%%@*} + typeset snap=${dtst##*@} + if [[ $(get_prop type $fsvol) == "filesystem" ]]; then + ind="" + else + ind="1" + fi + + eval typeset file0=\$TESTDIR$ind/\$TESTFILE0 + eval typeset file1=\$TESTDIR$ind/\$TESTFILE1 + eval typeset file2=\$TESTDIR$ind/\$TESTFILE2 + + case $snap in + $TESTSNAP2) + log_must files_exist $file0 $file1 $file2 + + typeset sum0=$(getsum $file0) + typeset sum1=$(getsum $file1) + typeset sum2=$(getsum $file2) + if [[ $sum0 != $origsum || \ + $sum1 != $origsum || sum2 != $origsum ]] + then + log_fail "After rollback, file sum is changed." + fi + ;; + $TESTSNAP1) + log_must files_exist $file0 $file1 + log_must files_nonexist $file2 + + typeset sum0=$(getsum $file0) + typeset sum1=$(getsum $file1) + if [[ $sum0 != $origsum || $sum1 != $origsum ]] + then + log_fail "After rollback, file sum is changed." + fi + ;; + $TESTSNAP) + log_must files_exist $file0 + log_must files_nonexist $file1 $file2 + + typeset sum0=$(getsum $file0) + if [[ $sum0 != $origsum ]]; then + log_fail "After rollback, file sum is changed." + fi + ;; + esac +} + +# According to dataset type, write file to different directories. +# +# $1 dataset +# +function write_mountpoint_dir +{ + typeset dtst=$1 + typeset dir + + if [[ $dtst == $FS ]]; then + dir=$TESTDIR + log_must ismounted $dir + else + dir=$TESTDIR1 + log_must ismounted $dir "ufs" + fi + $DD if=/dev/urandom of=$dir/$TESTFILE1 & + log_must $SLEEP 3 +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_test.sh new file mode 100755 index 00000000000..14a566a074a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_rollback/zfs_rollback_test.sh @@ -0,0 +1,144 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_rollback_001_pos cleanup +zfs_rollback_001_pos_head() +{ + atf_set "descr" "'zfs rollback -r|-rf|-R|-Rf' will recursively destroy anysnapshots more recent than the one specified." + atf_set "require.progs" zfs + atf_set "timeout" 1800 +} +zfs_rollback_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rollback_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_rollback_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rollback_002_pos cleanup +zfs_rollback_002_pos_head() +{ + atf_set "descr" "'zfs rollback -f' will force unmount any filesystems." + atf_set "require.progs" zfs + atf_set "timeout" 1800 +} +zfs_rollback_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rollback_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_rollback_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rollback_003_neg cleanup +zfs_rollback_003_neg_head() +{ + atf_set "descr" "Separately verify 'zfs rollback ''|-f|-r|-rf will fail indifferent conditions." + atf_set "require.progs" zfs + atf_set "timeout" 1800 +} +zfs_rollback_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rollback_003_neg.ksh || atf_fail "Testcase failed" +} +zfs_rollback_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rollback_004_neg cleanup +zfs_rollback_004_neg_head() +{ + atf_set "descr" "'zfs rollback' should fail with bad options,too many arguments,non-snapshot datasets or missing datasets." + atf_set "require.progs" zfs + atf_set "timeout" 1800 +} +zfs_rollback_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rollback_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_rollback_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_rollback_common.kshlib + . $(atf_get_srcdir)/zfs_rollback.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_rollback_001_pos + atf_add_test_case zfs_rollback_002_pos + atf_add_test_case zfs_rollback_003_neg + atf_add_test_case zfs_rollback_004_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/Makefile new file mode 100644 index 00000000000..0824b7ad8bd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_send +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_send_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_send_003_pos.ksh +${PACKAGE}FILES+= zfs_send_002_pos.ksh +${PACKAGE}FILES+= zfs_send.cfg +${PACKAGE}FILES+= zfs_send_001_pos.ksh +${PACKAGE}FILES+= zfs_send_004_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/cleanup.ksh new file mode 100644 index 00000000000..db372c2000f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +poolexists $TESTPOOL1 && \ + destroy_pool $TESTPOOL1 + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send.cfg new file mode 100644 index 00000000000..865de67e8e5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send.cfg @@ -0,0 +1,36 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_send.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export PARTSIZE=1g +export BLOCK_SIZE=512 +export WRITE_COUNT=8 diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_001_pos.ksh new file mode 100644 index 00000000000..5ae36b0fb19 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_001_pos.ksh @@ -0,0 +1,140 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_send_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_send_001_pos +# +# DESCRIPTION: +# Verify 'zfs send' can create valid send streams as expected. +# +# STRATEGY: +# 1. Fill in fs with some data +# 2. Create a full send streams with the fs +# 3. Receive the send stream and verify the data integrity +# 4. Fill in fs with some new data +# 5. Create an incremental send stream with the fs +# 6. Receive the incremental send stream and verify the data integrity. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for snap in $init_snap $inc_snap $rst_snap $rst_inc_snap; do + snapexists $snap && \ + log_must $ZFS destroy -f $snap + done + + datasetexists $rst_root && \ + log_must $ZFS destroy -Rf $rst_root + + for file in $full_bkup $inc_bkup \ + $init_data $inc_data + do + [[ -e $file ]] && \ + log_must $RM -f $file + done + + [[ -d $TESTDIR1 ]] && \ + log_must $RM -rf $TESTDIR1 + +} + +log_assert "Verify 'zfs send' can create valid send streams as expected." +log_onexit cleanup + +init_snap=$TESTPOOL/$TESTFS@init_snap +inc_snap=$TESTPOOL/$TESTFS@inc_snap +full_bkup=$TMPDIR/fullbkup.${TESTCASE_ID} +inc_bkup=$TMPDIR/incbkup.${TESTCASE_ID} +init_data=$TESTDIR/$TESTFILE1 +inc_data=$TESTDIR/$TESTFILE2 +orig_sum="" +rst_sum="" +rst_root=$TESTPOOL/rst_ctr +rst_snap=$rst_root/$TESTFS@init_snap +rst_inc_snap=$rst_root/$TESTFS@inc_snap +rst_data=$TESTDIR1/$TESTFS/$TESTFILE1 +rst_inc_data=$TESTDIR1/$TESTFS/$TESTFILE2 + + +log_note "Verify 'zfs send' can create full send stream." + +#Pre-paration +log_must $ZFS create $rst_root +[[ ! -d $TESTDIR1 ]] && \ + log_must $MKDIR -p $TESTDIR1 +log_must $ZFS set mountpoint=$TESTDIR1 $rst_root + +log_must $FILE_WRITE -o create -f $init_data -b $BLOCK_SIZE -c $WRITE_COUNT + +log_must $ZFS snapshot $init_snap +$ZFS send $init_snap > $full_bkup +(( $? != 0 )) && \ + log_fail "'$ZFS send' fails to create full send" + +log_note "Verify the send stream is valid to receive." + +log_must $ZFS receive $rst_snap <$full_bkup +receive_check $rst_snap ${rst_snap%%@*} +compare_cksum $init_data $rst_data + +log_note "Verify 'zfs send -i' can create incremental send stream." + +log_must $FILE_WRITE -o create -f $inc_data -b $BLOCK_SIZE -c $WRITE_COUNT -d 0 + +log_must $ZFS snapshot $inc_snap +$ZFS send -i $init_snap $inc_snap > $inc_bkup +(( $? != 0 )) && \ + log_fail "'$ZFS send -i' fails to create incremental send" + +log_note "Verify the incremental send stream is valid to receive." + +log_must $ZFS rollback $rst_snap +log_must $ZFS receive $rst_inc_snap <$inc_bkup +receive_check $rst_inc_snap +compare_cksum $inc_data $rst_inc_data + +log_pass "Verifying 'zfs receive' succeed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_002_pos.ksh new file mode 100644 index 00000000000..81a0837512a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_002_pos.ksh @@ -0,0 +1,152 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_send_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_send_002_pos +# +# DESCRIPTION: +# Verify 'zfs send' can generate valid streams with a property setup. +# +# STRATEGY: +# 1. Setup property for filesystem +# 2. Fill in some data into filesystem +# 3. Create a full send streams +# 4. Receive the send stream +# 5. Verify the receive result +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + snapexists $snap && \ + log_must $ZFS destroy $snap + + datasetexists $ctr && \ + log_must $ZFS destroy -r $ctr + + [[ -e $origfile ]] && \ + log_must $RM -f $origfile + + [[ -e $stream ]] && \ + log_must $RM -f $stream +} + +function do_testing # +{ + typeset property=$1 + typeset prop_val=$2 + + log_must $ZFS set $property=$prop_val $fs + log_must $FILE_WRITE -o create -f $origfile -b $BLOCK_SIZE -c $WRITE_COUNT + log_must $ZFS snapshot $snap + $ZFS send $snap > $stream + (( $? != 0 )) && \ + log_fail "'$ZFS send' fails to create send streams." + $ZFS receive -d $ctr <$stream + (( $? != 0 )) && \ + log_fail "'$ZFS receive' fails to receive send streams." + + #verify receive result + ! datasetexists $rstfs && \ + log_fail "'$ZFS receive' fails to restore $rstfs" + ! snapexists $rstfssnap && \ + log_fail "'$ZFS receive' fails to restore $rstfssnap" + if [[ ! -e $rstfile ]] || [[ ! -e $rstsnapfile ]]; then + log_fail " Data lost after receiving stream" + fi + + compare_cksum $origfile $rstfile + compare_cksum $origsnapfile $rstsnapfile + + #Destroy datasets and stream for next testing + log_must $ZFS destroy $snap + if is_global_zone ; then + log_must $ZFS destroy -r $rstfs + else + log_must $ZFS destroy -r $ds_path + fi + log_must $RM -f $stream +} + +log_assert "Verify 'zfs send' generates valid streams with a property setup" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +snap=$fs@$TESTSNAP +ctr=$TESTPOOL/$TESTCTR +if is_global_zone; then + rstfs=$ctr/$TESTFS +else + ds_path=$ctr/${ZONE_CTR}0 + rstfs=$ds_path/$TESTFS +fi +rstfssnap=$rstfs@$TESTSNAP +snapdir="$(get_snapdir_name)/$TESTSNAP" +origfile=$TESTDIR/$TESTFILE1 +rstfile=/$rstfs/$TESTFILE1 +origsnapfile=$TESTDIR/$snapdir/$TESTFILE1 +rstsnapfile=/$rstfs/$snapdir/$TESTFILE1 +stream=$TMPDIR/streamfile.${TESTCASE_ID} + +set -A props "compression" "checksum" "recordsize" +set -A propval "on lzjb" "on fletcher2 fletcher4 sha256" \ + "512 1k 4k 8k 16k 32k 64k 128k" + +#Create a dataset to receive the send stream +log_must $ZFS create $ctr + +typeset -i i=0 +while (( i < ${#props[*]} )) +do + for value in ${propval[i]} + do + do_testing ${props[i]} $value + done + + (( i = i + 1 )) +done + +log_pass "'zfs send' generates streams with a property setup as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_003_pos.ksh new file mode 100644 index 00000000000..806a7d2b7bf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_003_pos.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_send_003_pos.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_send_003_pos +# +# DESCRIPTION: +# 'zfs send -i' can deal with abbreviated snapshot name. +# +# STRATEGY: +# 1. Create pool, fs and two snapshots. +# 2. Make sure 'zfs send -i' support abbreviated snapshot name. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $snap1 && log_must $ZFS destroy $snap1 + datasetexists $snap2 && log_must $ZFS destroy $snap2 +} + +log_assert "'zfs send -i' can deal with abbreviated snapshot name." +log_onexit cleanup + +snap1=$TESTPOOL/$TESTFS@snap1; snap2=$TESTPOOL/$TESTFS@snap2 + +set -A args "$snap1 $snap2" \ + "${snap1##*@} $snap2" "@${snap1##*@} $snap2" + +log_must $ZFS snapshot $snap1 +log_must $ZFS snapshot $snap2 + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_must eval "$ZFS send -i ${args[i]} > /dev/null" + + (( i += 1 )) +done + +log_pass "'zfs send -i' deal with abbreviated snapshot name passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_004_neg.ksh new file mode 100644 index 00000000000..3da25669913 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_004_neg.ksh @@ -0,0 +1,123 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_send_004_neg.ksh 1.5 08/02/27 SMI" +# + +. $STF_SUITE/tests/cli_root/cli_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_send_004_neg +# +# DESCRIPTION: +# Verify 'zfs send' fails with malformed parameters. +# +# STRATEGY: +# 1. Define malformed parameters in array +# 2. Feed the parameters to 'zfs send' +# 3. Verify the result +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset snap f + + for snap in $snap1 $snap2 $snap3; do + snapexists $snap && \ + log_must $ZFS destroy -f $snap + done + + for f in $tmpfile1 $tmpfile2; do + if [[ -e $f ]]; then + $RM -f $f + fi + done +} + +fs=$TESTPOOL/$TESTFS +snap1=$fs@snap1 +snap2=$fs@snap2 +snap3=$fs@snap3 + +set -A badargs \ + "" "$TESTPOOL" "$TESTFS" "$fs" "$fs@nonexisten_snap" "?" \ + "$snap1/blah" "$snap1@blah" "-i" "-x" "-i $fs" \ + "-x $snap1 $snap2" "-i $snap1" \ + "-i $snap2 $snap1" "$snap1 $snap2" "-i $snap1 $snap2 $snap3" \ + "-ii $snap1 $snap2" "-iii $snap1 $snap2" " -i $snap2 $snap1/blah" \ + "-i $snap2/blah $snap1" \ + "-i $snap2/blah $snap1/blah" \ + "-i $snap1 blah@blah" \ + "-i blah@blah $snap1" \ + "-i $snap1 ${snap2##*@}" "-i $snap1 @${snap2##*@}" \ + "-i ${snap1##*@} ${snap2##*@}" "-i @${snap1##*@} @${snap2##*@}" \ + "-i ${snap1##*@} $snap2/blah" "-i @${snap1##*@} $snap2/blah" \ + "-i @@${snap1##*@} $snap2" "-i $snap1 -i $snap1 $snap2" \ + "-i snap1 snap2" "-i $snap1 snap2" \ + "-i $snap1 $snap2 -i $snap1 $snap2" \ + "-i snap1 $snap2 -i snap1 $snap2" + +log_assert "Verify that invalid parameters to 'zfs send' are caught." +log_onexit cleanup + +log_must $ZFS snapshot $snap1 +tmpfile1=$TESTDIR/testfile1.${TESTCASE_ID} +log_must $TOUCH $tmpfile1 +log_must $ZFS snapshot $snap2 +tmpfile2=$TESTDIR/testfile2.${TESTCASE_ID} +log_must $TOUCH $tmpfile2 +log_must $ZFS snapshot $snap3 + +typeset -i i=0 +while (( i < ${#badargs[*]} )) +do + log_mustnot eval "$ZFS send ${badargs[i]} >/dev/null" + + (( i = i + 1 )) +done + +#Testing zfs send fails by send backup stream to terminal +for arg in "$snap1" "-i $snap1 $snap2"; do + log_mustnot eval "$ZFS send $arg >/dev/console" +done + +log_pass "Invalid parameters to 'zfs send' are caught as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_test.sh new file mode 100755 index 00000000000..0da9ed41bd2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_send/zfs_send_test.sh @@ -0,0 +1,132 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_send_001_pos cleanup +zfs_send_001_pos_head() +{ + atf_set "descr" "Verify 'zfs send' can create valid send streams as expected." + atf_set "require.progs" zfs +} +zfs_send_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_send_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_send_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_send_002_pos cleanup +zfs_send_002_pos_head() +{ + atf_set "descr" "Verify 'zfs send' generates valid streams with a property setup" + atf_set "require.progs" zfs +} +zfs_send_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_send_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_send_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_send_003_pos cleanup +zfs_send_003_pos_head() +{ + atf_set "descr" "'zfs send -i' can deal with abbreviated snapshot name." + atf_set "require.progs" zfs +} +zfs_send_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_send_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_send_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_send_004_neg cleanup +zfs_send_004_neg_head() +{ + atf_set "descr" "Verify that invalid parameters to 'zfs send' are caught." + atf_set "require.progs" zfs +} +zfs_send_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_send_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_send_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_send.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_send_001_pos + atf_add_test_case zfs_send_002_pos + atf_add_test_case zfs_send_003_pos + atf_add_test_case zfs_send_004_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/Makefile new file mode 100644 index 00000000000..faec06da391 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/Makefile @@ -0,0 +1,44 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_set +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_set_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_set_common.kshlib +${PACKAGE}FILES+= onoffs_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= mountpoint_001_pos.ksh +${PACKAGE}FILES+= share_mount_001_neg.ksh +${PACKAGE}FILES+= user_property_004_pos.ksh +${PACKAGE}FILES+= canmount_002_pos.ksh +${PACKAGE}FILES+= readonly_001_pos.ksh +${PACKAGE}FILES+= zfs_set_001_neg.ksh +${PACKAGE}FILES+= user_property_001_pos.ksh +${PACKAGE}FILES+= snapdir_001_pos.ksh +${PACKAGE}FILES+= canmount_003_pos.ksh +${PACKAGE}FILES+= reservation_001_neg.ksh +${PACKAGE}FILES+= compression_001_pos.ksh +${PACKAGE}FILES+= cache_001_pos.ksh +${PACKAGE}FILES+= zfs_set_003_neg.ksh +${PACKAGE}FILES+= canmount_001_pos.ksh +${PACKAGE}FILES+= property_alias_001_pos.ksh +${PACKAGE}FILES+= version_001_neg.ksh +${PACKAGE}FILES+= zfs_set.cfg +${PACKAGE}FILES+= cache_002_neg.ksh +${PACKAGE}FILES+= mountpoint_002_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= checksum_001_pos.ksh +${PACKAGE}FILES+= mountpoint_003_pos.ksh +${PACKAGE}FILES+= user_property_002_pos.ksh +${PACKAGE}FILES+= zfs_set_002_neg.ksh +${PACKAGE}FILES+= user_property_003_neg.ksh +${PACKAGE}FILES+= ro_props_001_pos.ksh +${PACKAGE}FILES+= canmount_004_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cache_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cache_001_pos.ksh new file mode 100644 index 00000000000..b5a5f304fef --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cache_001_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_001_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: cache_001_pos +# +# DESCRIPTION: +# Setting a valid primarycache and secondarycache on file system or volume. +# It should be successful. +# +# STRATEGY: +# 1. Create pool, then create filesystem & volume within it. +# 2. Setting valid cache value, it should be successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL" +set -A values "none" "all" "metadata" + +log_assert "Setting a valid {primary|secondary}cache on file system and volume, " \ + "It should be successful." + +typeset -i i=0 +typeset -i j=0 +for propname in "primarycache" "secondarycache" +do + while (( i < ${#dataset[@]} )); do + j=0 + while (( j < ${#values[@]} )); do + set_n_check_prop "${values[j]}" "$propname" "${dataset[i]}" + (( j += 1 )) + done + (( i += 1 )) + done +done + +log_pass "Setting a valid {primary|secondary}cache on file system or volume pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cache_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cache_002_neg.ksh new file mode 100644 index 00000000000..66dabac9c66 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cache_002_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cache_002_neg.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: cache_001_pos +# +# DESCRIPTION: +# Setting invalid primarycache and secondarycache on file system or volume. +# It should fail. +# +# STRATEGY: +# 1. Create pool, then create filesystem & volume within it. +# 2. Setting invalid {primary|secondary}cache value, it should fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL" +set -A values "12345" "null" "not_existed" "abcd1234" + +log_assert "Setting invalid {primary|secondary}cache on fs and volume, " \ + "It should fail." + +typeset -i i=0 +typeset -i j=0 +for propname in "primarycache" "secondarycache" +do + while (( i < ${#dataset[@]} )); do + j=0 + while (( j < ${#values[@]} )); do + log_mustnot $ZFS set $propname=${values[j]} ${dataset[i]} + (( j += 1 )) + done + (( i += 1 )) + done +done + +log_pass "Setting invalid {primary|secondary}cache on fs or volume fail as expeced." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_001_pos.ksh new file mode 100644 index 00000000000..53179e8a5a6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_001_pos.ksh @@ -0,0 +1,137 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)canmount_001_pos.ksh 1.5 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: canmount_001_pos +# +# DESCRIPTION: +# Setting valid canmount to filesystem, it is successful. +# Whatever is set to volume or snapshot, it is failed. +# 'zfs set canmount=on|off ' +# +# STRATEGY: +# 1. Setup a pool and create fs, volume, snapshot clone within it. +# 2. Loop all the valid mountpoint value. +# 3. Check the return value. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A dataset_pos \ + "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE" + +if is_global_zone ; then + set -A dataset_neg \ + "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \ + "$TESTPOOL/$TESTVOL@$TESTSNAP" "$TESTPOOL/$TESTCLONE1" +else + set -A dataset_neg \ + "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP" +fi + + +set -A values "on" "off" + +function cleanup +{ + if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then + log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP + fi + if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then + log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP + fi + + [[ -n $old_ctr_canmount ]] && \ + log_must $ZFS set canmount=$old_ctr_canmount $TESTPOOL/$TESTCTR + [[ -n $old_fs_canmount ]] && \ + log_must $ZFS set canmount=$old_fs_canmount $TESTPOOL/$TESTFS + + unmount_all_safe > /dev/null 2>&1 + log_must $ZFS mount -a +} + +log_assert "Setting a valid property of canmount to file system, it must be successful." +log_onexit cleanup + +typeset old_fs_canmount="" old_ctr_canmount="" + +old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS) +[[ $? != 0 ]] && \ + log_fail "Get the $TESTPOOL/$TESTFS canmount error." +old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR) +[[ $? != 0 ]] && \ + log_fail "Get the $TESTPOOL/$TESTCTR canmount error." + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP +log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP +log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE +log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 + +for dataset in "${dataset_pos[@]}" ; do + for value in "${values[@]}" ; do + set_n_check_prop "$value" "canmount" "$dataset" + if [[ $value == "off" ]]; then + log_mustnot ismounted $dataset + log_mustnot $ZFS mount $dataset + log_mustnot ismounted $dataset + else + if ! ismounted $dataset ; then + log_must $ZFS mount $dataset + fi + log_must ismounted $dataset + fi + done +done + +for dataset in "${dataset_neg[@]}" ; do + for value in "${values[@]}" ; do + set_n_check_prop "$value" "canmount" \ + "$dataset" "false" + log_mustnot ismounted $dataset + done +done + +log_pass "Setting canmount to filesystem pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_002_pos.ksh new file mode 100644 index 00000000000..bfb98d69ce6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_002_pos.ksh @@ -0,0 +1,170 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)canmount_002_pos.ksh 1.2 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: canmount_002_pos +# +# DESCRIPTION: +# Setting valid canmount to filesystem, it is successful. +# Whatever is set to volume or snapshot, it is failed. +# 'zfs set canmount=noauto ' +# +# STRATEGY: +# 1. Setup a pool and create fs, volume, snapshot clone within it. +# 2. Set canmount=noauto for each dataset and check the retuen value +# and check if it still can be mounted by mount -a. +# 3. mount each dataset(except volume) to see if it can be mounted. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# check if the testing box support noauto option or not. +$ZFS get 2>&1 | $GREP -w canmount | $GREP -w noauto >/dev/null 2>&1 +if (( $? != 0 )); then + log_unsupported "canmount=noauto is not supported." +fi + +set -A dataset_pos \ + "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE" + +if is_global_zone ; then + set -A dataset_neg \ + "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \ + "$TESTPOOL/$TESTVOL@$TESTSNAP" "$TESTPOOL/$TESTCLONE1" +else + set -A dataset_neg \ + "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP" +fi + +function cleanup +{ + i=0 + while (( i < ${#dataset_pos[*]} )); do + ds=${dataset_pos[i]} + if datasetexists $ds; then + log_must $ZFS set mountpoint=${old_mnt[i]} $ds + log_must $ZFS set canmount=${old_canmount[i]} $ds + fi + (( i = i + 1 )) + done + + ds=$TESTPOOL/$TESTCLONE + if datasetexists $ds; then + mntp=$(get_prop mountpoint $ds) + log_must $ZFS destroy $ds + if [[ -d $mntp ]]; then + $RM -fr $mntp + fi + fi + + if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then + log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP + fi + if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then + log_must $ZFS destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP + fi + + $ZFS unmount -a > /dev/null 2>&1 + log_must $ZFS mount -a + + if [[ -d $tmpmnt ]]; then + $RM -fr $tmpmnt + fi +} + +log_assert "Setting canmount=noauto to file system, it must be successful." +log_onexit cleanup + +set -A old_mnt +set -A old_canmount +typeset tmpmnt=/tmpmount${TESTCASE_ID} +typeset ds + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP +log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP +log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE +log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 + +typeset -i i=0 +while (( i < ${#dataset_pos[*]} )); do + ds=${dataset_pos[i]} + old_mnt[i]=$(get_prop mountpoint $ds) + old_canmount[i]=$(get_prop canmount $ds) + (( i = i + 1 )) +done + +i=0 +while (( i < ${#dataset_pos[*]} )) ; do + dataset=${dataset_pos[i]} + set_n_check_prop "noauto" "canmount" "$dataset" + log_must $ZFS set mountpoint=$tmpmnt $dataset + if ismounted $dataset; then + $ZFS unmount -a > /dev/null 2>&1 + log_must mounted $dataset + log_must $ZFS unmount $dataset + log_must unmounted $dataset + log_must $ZFS mount -a + log_must unmounted $dataset + else + log_must $ZFS mount -a + log_must unmounted $dataset + $ZFS unmount -a > /dev/null 2>&1 + log_must unmounted $dataset + fi + + log_must $ZFS mount $dataset + log_must mounted $dataset + log_must $ZFS set canmount="${old_canmount[i]}" $dataset + log_must $ZFS set mountpoint="${old_mnt[i]}" $dataset + (( i = i + 1 )) +done + +for dataset in "${dataset_neg[@]}" ; do + set_n_check_prop "noauto" "canmount" "$dataset" "false" + log_mustnot ismounted $dataset +done + +log_pass "Setting canmount=noauto to filesystem pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_003_pos.ksh new file mode 100644 index 00000000000..017ae5f750d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_003_pos.ksh @@ -0,0 +1,131 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)canmount_003_pos.ksh 1.2 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: canmount_003_pos +# +# DESCRIPTION: +# While canmount=noauto and the dataset is mounted, +# zfs must not attempt to unmount it. +# +# STRATEGY: +# 1. Setup a pool and create fs, volume, snapshot clone within it. +# 2. Set canmount=noauto for each dataset and check the return value +# and check if it still can not be unmounted when the dataset is mounted +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-09-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# check if the testing box support noauto option or not. +$ZFS get 2>&1 | $GREP -w canmount | $GREP -w noauto >/dev/null 2>&1 +if (( $? != 0 )); then + log_unsupported "canmount=noauto is not supported." +fi + +set -A dataset_pos "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCLONE" + +function cleanup +{ + i=0 + cd $pwd + while (( i < ${#dataset_pos[*]} )); do + ds=${dataset_pos[i]} + if datasetexists $ds; then + log_must $ZFS set mountpoint=${old_mnt[i]} $ds + log_must $ZFS set canmount=${old_canmount[i]} $ds + fi + (( i = i + 1 )) + done + + ds=$TESTPOOL/$TESTCLONE + if datasetexists $ds; then + mntp=$(get_prop mountpoint $ds) + log_must $ZFS destroy $ds + if [[ -d $mntp ]]; then + log_must $RM -fr $mntp + fi + fi + + if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then + log_must $ZFS destroy -R $TESTPOOL/$TESTFS@$TESTSNAP + fi + + unmount_all_safe > /dev/null 2>&1 + log_must $ZFS mount -a +} + +log_assert "While canmount=noauto and the dataset is mounted,"\ + " zfs must not attempt to unmount it" +log_onexit cleanup + +set -A old_mnt +set -A old_canmount +typeset ds +typeset pwd=$PWD + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP +log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE + +typeset -i i=0 +while (( i < ${#dataset_pos[*]} )); do + ds=${dataset_pos[i]} + old_mnt[i]=$(get_prop mountpoint $ds) + old_canmount[i]=$(get_prop canmount $ds) + (( i = i + 1 )) +done + +i=0 +while (( i < ${#dataset_pos[*]} )) ; do + dataset=${dataset_pos[i]} + if ismounted $dataset; then + log_must cd ${old_mnt[i]} + set_n_check_prop "noauto" "canmount" "$dataset" + log_must mounted $dataset + fi + (( i = i + 1 )) +done + +log_pass "Setting canmount=noauto to filesystem while dataset busy pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_004_pos.ksh new file mode 100644 index 00000000000..d341659fdb8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/canmount_004_pos.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)canmount_004_pos.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: canmount_sharenfs_001_pos +# +# DESCRIPTION: +# Verify canmount=noauto work fine when setting sharenfs or sharesmb. +# +# STRATEGY: +# 1. Create a fs canmount=noauto. +# 2. Set sharenfs or sharesmb. +# 3. Verify the fs is umounted. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-05-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +# properties +set -A sharenfs_prop "off" "on" "rw" +set -A sharesmb_prop "off" "on" +if check_version "5.11" ; then + set -A sharesmb_prop ${sharesmb_prop[*]} "name=anybody" +fi + +function cleanup +{ + log_must $ZFS destroy -rR $CS_FS +} + +function assert_unmounted +{ + mnted=$(get_prop mounted $CS_FS) + if [[ "$mnted" == "yes" ]]; then + canmnt=$(get_prop canmount $CS_FS) + shnfs=$(get_prop sharenfs $CS_FS) + shsmb=$(get_prop sharesmb $CS_FS) + mntpt=$(get_prop mountpoint $CS_FS) + log_fail "$CS_FS should be unmounted" \ + "[canmount=$canmnt,sharenfs=$shnfs,sharesmb=$shsmb,mountpoint=$mntpt]." + fi +} + +log_assert "Verify canmount=noauto work fine when setting sharenfs or sharesmb." +log_onexit cleanup + +CS_FS=$TESTPOOL/$TESTFS/cs_fs.${TESTCASE_ID} +oldmpt=$TESTDIR/old_cs_fs.${TESTCASE_ID} +newmpt=$TESTDIR/new_cs_fs.${TESTCASE_ID} + +log_must $ZFS create -o canmount=noauto -o mountpoint=$oldmpt $CS_FS +assert_unmounted + +for n in ${sharenfs_prop[@]}; do + log_must $ZFS set sharenfs="$n" $CS_FS + assert_unmounted + for s in ${sharesmb_prop[@]}; do + log_must $ZFS set sharesmb="$s" $CS_FS + assert_unmounted + + mntpt=$(get_prop mountpoint $CS_FS) + if [[ "$mntpt" == "$oldmpt" ]]; then + log_must $ZFS set mountpoint="$newmpt" $CS_FS + else + log_must $ZFS set mountpoint="$oldmpt" $CS_FS + fi + assert_unmounted + done +done + +log_pass "Verify canmount=noauto work fine when setting sharenfs or sharesmb." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/checksum_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/checksum_001_pos.ksh new file mode 100644 index 00000000000..aa150e245ee --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/checksum_001_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)checksum_001_pos.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: checksum_001_pos +# +# DESCRIPTION: +# Setting a valid checksum on a pool, file system, volume, it should be +# successful. +# +# STRATEGY: +# 1. Create pool, then create filesystem and volume within it. +# 2. Setting different valid checksum to each dataset. +# 3. Check the return value and make sure it is 0. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +enc=$(get_prop encryption $TESTPOOL/$TESTFS) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + log_unsupported "checksum property can not be changed when \ +encryption is set to on." +fi + +set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL" +set -A values "on" "off" "fletcher2" "fletcher4" "sha256" + +log_assert "Setting a valid checksum on a file system, volume," \ + "it should be successful." + +typeset -i i=0 +typeset -i j=0 +while (( i < ${#dataset[@]} )); do + j=0 + while (( j < ${#values[@]} )); do + set_n_check_prop "${values[j]}" "checksum" "${dataset[i]}" + (( j += 1 )) + done + (( i += 1 )) +done + +log_pass "Setting a valid checksum on a file system, volume pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cleanup.ksh new file mode 100644 index 00000000000..250c5b635c5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_container_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/compression_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/compression_001_pos.ksh new file mode 100644 index 00000000000..45381dfcdc9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/compression_001_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)compression_001_pos.ksh 1.3 07/06/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: compression_001_pos +# +# DESCRIPTION: +# Setting a valid compression on file system or volume. +# It should be successful. +# +# STRATEGY: +# 1. Create pool, then create filesystem & volume within it. +# 2. Setting valid value, it should be successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL" +set -A values $(get_compress_opts zfs_set) + +log_assert "Setting a valid compression on file system and volume, " \ + "It should be successful." + +typeset -i i=0 +typeset -i j=0 +for propname in "compression" "compress" +do + while (( i < ${#dataset[@]} )); do + j=0 + while (( j < ${#values[@]} )); do + set_n_check_prop "${values[j]}" "$propname" "${dataset[i]}" + (( j += 1 )) + done + (( i += 1 )) + done +done + +log_pass "Setting a valid compression on file system or volume pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_001_pos.ksh new file mode 100644 index 00000000000..30001b0057d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_001_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mountpoint_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: mountpoint_001_pos +# +# DESCRIPTION: +# Setting valid mountpoint to filesystem, it is successful. +# Whatever is set to volume, it is failed. +# 'zfs set mountpoint=|legacy|none ' +# +# STRATEGY: +# 1. Setup a pool and create fs, ctr within it. +# 2. Loop all the valid mountpoint value. +# 3. Check the return value. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if is_global_zone ; then + set -A dataset \ + "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" +else + set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" +fi + +set -A values "$TESTDIR2" "legacy" "none" "$TESTDIR_NOTEXISTING" + +function cleanup +{ + log_must $ZFS set mountpoint=$old_ctr_mpt $TESTPOOL/$TESTCTR + log_must $ZFS set mountpoint=$old_fs_mpt $TESTPOOL/$TESTFS + [[ -d $TESTDIR2 ]] && log_must $RM -r $TESTDIR2 + [[ -d $TESTDIR_NOTEXISTING ]] && log_must $RM -r $TESTDIR_NOTEXISTING +} + +log_assert "Setting a valid mountpoint to file system, it must be successful." +log_onexit cleanup + +old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS) +[[ $? != 0 ]] && \ + log_fail "Get the $TESTPOOL/$TESTFS mountpoint error." +old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR) +[[ $? != 0 ]] && \ + log_fail "Get the $TESTPOOL/$TESTCTR mountpoint error." + +if [[ ! -d $TESTDIR2 ]]; then + log_must $MKDIR $TESTDIR2 +fi + +typeset -i i=0 +typeset -i j=0 +while (( i < ${#dataset[@]} )); do + j=0 + while (( j < ${#values[@]} )); do + if [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" ]]; then + set_n_check_prop "${values[j]}" "mountpoint" \ + "${dataset[i]}" "false" + else + set_n_check_prop "${values[j]}" "mountpoint" \ + "${dataset[i]}" + fi + (( j += 1 )) + done + cleanup + (( i += 1 )) +done + +log_pass "Setting mountpoint to filesystem pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_002_pos.ksh new file mode 100644 index 00000000000..0d6a3719cc7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_002_pos.ksh @@ -0,0 +1,110 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mountpoint_002_pos.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: mountpoint_002_pos +# +# DESCRIPTION: +# If ZFS is currently managing the file system but it is currently unmoutned, +# and the mountpoint property is changed, the file system remains unmounted. +# +# STRATEGY: +# 1. Setup a pool and create fs, ctr within it. +# 2. Unmount that dataset +# 2. Change the mountpoint to the valid mountpoint value. +# 3. Check the file system remains unmounted. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" + +set -A values "$TESTDIR2" "$TESTDIR_NOTEXISTING" + +function cleanup +{ + log_must $ZFS set mountpoint=$old_ctr_mpt $TESTPOOL/$TESTCTR + log_must $ZFS set mountpoint=$old_fs_mpt $TESTPOOL/$TESTFS + log_must $ZFS mount -a + [[ -d $TESTDIR2 ]] && log_must $RM -r $TESTDIR2 + [[ -d $TESTDIR_NOTEXISTING ]] && log_must $RM -r $TESTDIR_NOTEXISTING +} + +log_assert "Setting a valid mountpoint for an unmounted file system, \ + it remains unmounted." +log_onexit cleanup + +old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS) +[[ $? != 0 ]] && \ + log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTFS" +old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR) +[[ $? != 0 ]] && \ + log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTCTR" + +if [[ ! -d $TESTDIR2 ]]; then + log_must $MKDIR $TESTDIR2 +fi + +typeset -i i=0 +typeset -i j=0 +while (( i < ${#dataset[@]} )); do + j=0 + if ismounted ${dataset[i]} ; then + log_must $ZFS unmount ${dataset[i]} + fi + log_mustnot ismounted ${dataset[i]} + while (( j < ${#values[@]} )); do + set_n_check_prop "${values[j]}" "mountpoint" \ + "${dataset[i]}" + log_mustnot ismounted ${dataset[i]} + (( j += 1 )) + done + cleanup + (( i += 1 )) +done + +log_pass "Setting a valid mountpoint for an unmounted file system, \ + it remains unmounted." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_003_pos.ksh new file mode 100644 index 00000000000..5a2dc548bbe --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/mountpoint_003_pos.ksh @@ -0,0 +1,116 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mountpoint_003_pos.ksh 1.5 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: mountpoint_003_pos +# +# DESCRIPTION: +# Verify FSType-specific option works well with legacy mount. +# +# STRATEGY: +# 1. Set up FSType-specific options and expected keywords array. +# 2. Create a test ZFS file system and set mountpoint=legacy. +# 3. Mount ZFS test filesystem with specific options. +# 4. Verify the filesystem was mounted with specific option. +# 5. Loop check all the options. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-01-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + ismounted $tmpmnt && log_must $UMOUNT $tmpmnt + [[ -d $tmpmnt ]] && log_must $RM -rf $tmpmnt + [[ -n $oldmpt ]] && log_must $ZFS set mountpoint=$oldmpt $testfs + ! ismounted $oldmpt && log_must $ZFS mount $testfs +} + +log_assert "With legacy mount, FSType-specific option works well." +log_onexit cleanup + +# +# /mnt on pool/fs read/write/setuid/devices/noexec/xattr/atime/dev=2d9009e +# +# FSType- FSType- +# specific Keyword specific Keyword +# option option +# +set -A args \ + "devices" "/devices/" "nodevices" "/nodevices/" \ + "exec" "/exec/" "noexec" "/noexec/" \ + "nbmand" "/nbmand/" "nonbmand" "/nonbmand/" \ + "ro" "read only" "rw" "read/write" \ + "setuid" "/setuid/" "nosetuid" "/nosetuid/" \ + "xattr" "/xattr/" "noxattr" "/noxattr/" \ + "atime" "/atime/" "noatime" "/noatime/" + +tmpmnt=/tmpmnt.${TESTCASE_ID} +[[ -d $tmpmnt ]] && $RM -rf $tmpmnt +testfs=$TESTPOOL/$TESTFS +log_must $MKDIR $tmpmnt +oldmpt=$(get_prop mountpoint $testfs) +log_must $ZFS set mountpoint=legacy $testfs + +typeset i=0 +while ((i < ${#args[@]})); do + log_must $MOUNT -t zfs -o ${args[$i]} $testfs $tmpmnt + msg=$($MOUNT | $GREP "^$tmpmnt ") + + # In LZ, a user with all zone privileges can never with "devices" + if ! is_global_zone && [[ ${args[$i]} == devices ]] ; then + args[((i+1))]="/nodevices/" + fi + + $ECHO $msg | $GREP "${args[((i+1))]}" > /dev/null 2>&1 + if (($? != 0)) ; then + log_fail "Expected option: ${args[((i+1))]} \n" \ + "Real option: $msg" + fi + + log_must $UMOUNT $tmpmnt + ((i += 2)) +done + +log_pass "With legacy mount, FSType-specific option works well passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/onoffs_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/onoffs_001_pos.ksh new file mode 100644 index 00000000000..2007e0871ad --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/onoffs_001_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)onoffs_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: onoffs_001_pos +# +# DESCRIPTION: +# Setting a valid value to atime, readonly, or setuid on file +# system or volume. It should be successful. +# +# STRATEGY: +# 1. Create pool and filesystem & volume within it. +# 2. Setting valid value, it should be successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS mount -a +} + +log_onexit cleanup + +set -A props "atime" "readonly" "setuid" +set -A values "on" "off" + +if is_global_zone ; then + set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" +else + set -A dataset "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" +fi + +log_assert "Setting a valid value to atime, readonly, or setuid on file" \ + "system or volume. It should be successful." + +typeset -i i=0 +typeset -i j=0 +typeset -i k=0 +while (( i < ${#dataset[@]} )); do + j=0 + while (( j < ${#props[@]} )); do + k=0 + while (( k < ${#values[@]} )); do + if [[ ${dataset[i]} == "$TESTPOOL/$TESTVOL" && \ + ${props[j]} != "readonly" ]] + then + set_n_check_prop "${values[k]}" "${props[j]}" \ + "${dataset[i]}" "false" + else + set_n_check_prop "${values[k]}" "${props[j]}" \ + "${dataset[i]}" + fi + + (( k += 1 )) + done + (( j += 1 )) + done + (( i += 1 )) +done + +log_pass "Setting a valid value to atime, readonly, or setuid on file" \ + "system or volume pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/property_alias_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/property_alias_001_pos.ksh new file mode 100644 index 00000000000..3b847d03f16 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/property_alias_001_pos.ksh @@ -0,0 +1,158 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)property_alias_001_pos.ksh 1.4 09/01/13 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: property_alias_001_pos +# +# DESCRIPTION: +# Verify the properties with aliases also work with those aliases +# +# STRATEGY: +# 1. Create pool, then create filesystem & volume within it. +# 2. Set or retrieve property via alias with datasets. +# 3. Verify the result should be successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function set_and_check # +{ + typeset ds=$1 + typeset setprop=$2 + typeset setval=$3 + typeset chkprop=$4 + typeset getval + + log_must $ZFS set $setprop=$setval $ds + if [[ $setval == "gzip-6" ]]; then + setval="gzip" + fi + getval=$(get_prop $chkprop $ds) + + case $setprop in + reservation|reserv ) + if [[ $setval == "none" ]]; then + [[ $getval != "0" ]] && \ + log_fail "Setting the property $setprop" \ + "with value $setval fails." + elif [[ $getval != $setval ]]; then + log_fail "Setting the property $setprop with" \ + "with $setval fails." + fi + ;; + * ) + [[ $getval != $setval ]] && \ + log_fail "Setting the property $setprop with value \ + $setval fails." + ;; + esac +} + +log_assert "Properties with aliases also work with those aliases." + +set -A ro_prop "available" "avail" "referenced" "refer" +set -A rw_prop "readonly" "rdonly" "compression" "compress" "reservation" "reserv" +set -A chk_prop "rdonly" "readonly" "compress" "compression" "reserv" "reservation" +set -A size "512" "1024" "2048" "4096" "8192" "16384" "32768" "65536" "131072" + +pool=$TESTPOOL +fs=$TESTPOOL/$TESTFS +vol=$TESTPOOL/$TESTVOL +typeset -l avail_space=$(get_prop avail $pool) +typeset -l reservsize +typeset -i i=0 + +for ds in $pool $fs $vol; do + for propname in ${ro_prop[*]}; do + $ZFS get -pH -o value $propname $ds >/dev/null 2>&1 + (( $? != 0 )) && \ + log_fail "Get the property $proname of $ds failed." + done + i=0 + while (( i < ${#rw_prop[*]} )); do + case ${rw_prop[i]} in + readonly|rdonly ) + for val in "on" "off"; do + set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]} + done + ;; + compression|compress ) + for val in $(get_compress_opts zfs_set); do + set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]} + done + ;; + reservation|reserv ) + (( reservsize = $avail_space % $RANDOM )) + for val in "0" "$reservsize" "none"; do + set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]} + done + ;; + esac + + (( i = i + 1 )) + done + if [[ $ds == $vol ]]; then + for propname in "volblocksize" "volblock" ; do + $ZFS get -pH -o value $propname $ds >/dev/null 2>&1 + (( $? != 0 )) && \ + log_fail "Get the property $propname of $ds failed." + done + fi +done + +for ds in $pool $fs; do + for propname in "recordsize" "recsize"; do + for val in ${size[*]}; do + if [[ $propname == "recordsize" ]]; then + set_and_check $ds $propname $val "recsize" + else + set_and_check $ds $propname $val "recordsize" + fi + done + done +done + +log_pass "The alias of a property works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/readonly_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/readonly_001_pos.ksh new file mode 100644 index 00000000000..f123addc5fa --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/readonly_001_pos.ksh @@ -0,0 +1,172 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)readonly_001_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: readonly_001_pos +# +# DESCRIPTION: +# Setting readonly on a dataset, it should keep the dataset as readonly. +# +# STRATEGY: +# 1. Create pool, then create filesystem and volume within it. +# 2. Setting readonly to each dataset. +# 3. Check the return value and make sure it is 0. +# 4. Verify the stuff under mountpoint is readonly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do + snapexists ${dataset}@$TESTSNAP && \ + log_must $ZFS destroy -R ${dataset}@$TESTSNAP + done +} + +function initial_dataset # $1 dataset +{ + typeset dataset=$1 + + typeset fstype=$(get_prop type $dataset) + + if [[ $fstype == "filesystem" ]] ; then + typeset mtpt=$(get_prop mountpoint $dataset) + log_must $TOUCH $mtpt/$TESTFILE0 + log_must $MKDIR -p $mtpt/$TESTDIR0 + fi +} + + +function cleanup_dataset # $1 dataset +{ + typeset dataset=$1 + + typeset fstype=$(get_prop type $dataset) + + if [[ $fstype == "filesystem" ]] ; then + typeset mtpt=$(get_prop mountpoint $dataset) + log_must $RM -f $mtpt/$TESTFILE0 + log_must $RM -rf $mtpt/$TESTDIR0 + fi +} + +function verify_readonly # $1 dataset, $2 on|off +{ + typeset dataset=$1 + typeset value=$2 + + if datasetnonexists $dataset ; then + log_note "$dataset not exist!" + return 1 + fi + + typeset fstype=$(get_prop type $dataset) + + expect="log_must" + + if [[ $2 == "on" ]] ; then + expect="log_mustnot" + fi + + case $fstype in + filesystem) + typeset mtpt=$(get_prop mountpoint $dataset) + $expect $TOUCH $mtpt/$TESTFILE1 + $expect $MKDIR -p $mtpt/$TESTDIR1 + $expect $ECHO 'y' | $RM $mtpt/$TESTFILE0 + $expect $RMDIR $mtpt/$TESTDIR0 + + if [[ $expect == "log_must" ]] ; then + log_must $ECHO 'y' | $RM $mtpt/$TESTFILE1 + log_must $RMDIR $mtpt/$TESTDIR1 + log_must $TOUCH $mtpt/$TESTFILE0 + log_must $MKDIR -p $mtpt/$TESTDIR0 + fi + ;; + volume) + $expect eval "$ECHO 'y' | $NEWFS /dev/zvol/$dataset > /dev/null 2>&1" + ;; + *) + ;; + esac + + return 0 +} + +log_onexit cleanup + +log_assert "Setting a valid readonly property on a dataset succeeds." + +typeset all_datasets + +log_must $ZFS mount -a + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP +log_must $ZFS clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE + +if is_global_zone ; then + log_must $ZFS snapshot $TESTPOOL/$TESTVOL@$TESTSNAP + log_must $ZFS clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 + all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCLONE $TESTPOOL/$TESTCLONE1" +else + all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE" +fi + + +for dataset in $all_datasets; do + for value in on off; do + set_n_check_prop "off" "readonly" "$dataset" + initial_dataset $dataset + + set_n_check_prop "$value" "readonly" "$dataset" + verify_readonly $dataset $value + + set_n_check_prop "off" "readonly" "$dataset" + cleanup_dataset $dataset + done +done + +log_pass "Setting a valid readonly property on a dataset succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/reservation_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/reservation_001_neg.ksh new file mode 100644 index 00000000000..1e5345059cd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/reservation_001_neg.ksh @@ -0,0 +1,116 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_001_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_001_neg +# +# DESCRIPTION: +# Valid reservation values should be positive integers only. +# +# STRATEGY: +# 1) Form an array of invalid reservation values (negative and +# incorrectly formed) +# 2) Attempt to set each invalid reservation value in turn on a +# filesystem and volume. +# 3) Verify that attempt fails and the reservation value remains +# unchanged +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify invalid reservation values are rejected" + +set -A suffix "b" "k" "m" "t" "p" "e" "K" "M" "G" "T" "P" "E" "kb" "Mb" "Gb" \ + "Tb" "Pb" "Eb" "KB" "MB" "GB" "TB" "PB" "EB" + +set -A values '' '-1' '-1.0' '-1.8' '-9999999999999999' '0x1' '0b' '1b' '1.1b' + +# +# Function to loop through a series of bad reservation +# values, checking they are when we attempt to set them +# on a dataset. +# +function set_n_check # data-set +{ + typeset obj=$1 + typeset -i i=0 + typeset -i j=0 + + orig_resv_val=$(get_prop reservation $obj) + + while (( $i < ${#values[*]} )); do + j=0 + while (( $j < ${#suffix[*]} )); do + + $ZFS set \ + reservation=${values[$i]}${suffix[$j]} $obj \ + > /dev/null 2>&1 + if [ $? -eq 0 ] + then + log_note "$ZFS set \ + reservation=${values[$i]}${suffix[$j]} $obj" + log_fail "The above reservation set returned 0!" + fi + + new_resv_val=$(get_prop reservation $obj) + + if [[ $new_resv_val != $orig_resv_val ]]; then + log_fail "$obj : reservation values changed " \ + "($orig_resv_val : $new_resv_val)" + fi + (( j = j + 1 )) + done + + (( i = i + 1 )) + done +} + +for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL +do + set_n_check $dataset +done + +log_pass "Invalid reservation values correctly rejected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/ro_props_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/ro_props_001_pos.ksh new file mode 100644 index 00000000000..d7422339c74 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/ro_props_001_pos.ksh @@ -0,0 +1,163 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)ro_props_001_pos.ksh 1.4 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: ro_props_001_pos +# +# DESCRIPTION: +# Verify that read-only properties are immutable. +# +# STRATEGY: +# 1. Create pool, fs, vol, fs@snap & vol@snap. +# 2. Get the original property value and set value to those properties. +# 3. Check return value. +# 4. Compare the current property value with the original one. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A values filesystem volume snapshot -3 0 1 50K 10G 80G \ + 2005/06/17 30K 20x yes no \ + on off default pool/fs@snap $TESTDIR +set -A dataset $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@$TESTSNAP \ + $TESTPOOL/$TESTVOL@$TESTSNAP + +typeset ro_props="type" +ro_props="$ro_props creation" +ro_props="$ro_props compressratio" +ro_props="$ro_props mounted" +ro_props="$ro_props origin" +# Uncomment these once the test ensures they can't be changed. +#ro_props="$ro_props used" +#ro_props="$ro_props available" +#ro_props="$ro_props avail" +#ro_props="$ro_props referenced" +#ro_props="$ro_props refer" + +typeset snap_ro_props="volsize" +snap_ro_props="$snap_ro_props recordsize" +snap_ro_props="$snap_ro_props recsize" +snap_ro_props="$snap_ro_props quota" +snap_ro_props="$snap_ro_props reservation" +snap_ro_props="$snap_ro_props reserv" +snap_ro_props="$snap_ro_props mountpoint" +snap_ro_props="$snap_ro_props sharenfs" +snap_ro_props="$snap_ro_props checksum" +snap_ro_props="$snap_ro_props compression" +snap_ro_props="$snap_ro_props compress" +snap_ro_props="$snap_ro_props atime" +snap_ro_props="$snap_ro_props devices" +snap_ro_props="$snap_ro_props exec" +snap_ro_props="$snap_ro_props readonly" +snap_ro_props="$snap_ro_props rdonly" +snap_ro_props="$snap_ro_props setuid" + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + snap_ro_props="$snap_ro_props version" +fi + +function cleanup +{ + poolexists $TESTPOOL && log_must $ZPOOL history $TESTPOOL + datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ + destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP + datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP +} + +log_assert "Verify that read-only properties are immutable." +log_onexit cleanup + +# Create filesystem and volume's snapshot +create_snapshot $TESTPOOL/$TESTFS $TESTSNAP +create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP + +# Make sure any history logs have been synced. They're asynchronously +# pushed to the syncing context, and could influence the value of some +# properties on $TESTPOOL, like 'used'. Fetching it here forces the sync, +# per spa_history.c:spa_history_get(). +log_must $ZPOOL history $TESTPOOL + +typeset -i i=0 +typeset -i j=0 +typeset cur_value="" +typeset props="" + +while (( i < ${#dataset[@]} )); do + props=$ro_props + + dst_type=$(get_prop type ${dataset[i]}) + if [[ $dst_type == 'snapshot' ]]; then + props="$ro_props $snap_ro_props" + fi + + for prop in $props; do + cur_value=$(get_prop $prop ${dataset[i]}) + + j=0 + while (( j < ${#values[@]} )); do + # + # If the current property value is equal to values[j], + # just expect it failed. Otherwise, set it to dataset, + # expecting it failed and the property value is not + # equal to values[j]. + # + if [[ $cur_value == ${values[j]} ]]; then + log_mustnot $ZFS set $prop=${values[j]} \ + ${dataset[i]} + else + set_n_check_prop ${values[j]} $prop \ + ${dataset[i]} false + fi + (( j += 1 )) + done + done + (( i += 1 )) +done + +log_pass "Setting uneditable properties fail, as required." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/setup.ksh new file mode 100644 index 00000000000..491e9e1fa03 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +default_container_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/share_mount_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/share_mount_001_neg.ksh new file mode 100644 index 00000000000..ace3d14c395 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/share_mount_001_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)share_mount_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: share_mount_001_neg +# +# DESCRIPTION: +# Verify that we cannot share or mount legacy filesystems. +# +# STRATEGY: +# 1. Set mountpoint as legacy or none +# 2. Use zfs share or zfs mount to share or mount the filesystem +# 3. Verify that the command returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS set mountpoint=$oldmpt $fs +} + +log_assert "Verify that we cannot share or mount legacy filesystems." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +oldmpt=$(get_prop mountpoint $fs) + +for propval in "legacy" "none"; do + log_must $ZFS set mountpoint=$propval $fs + + log_mustnot $ZFS mount $fs + log_mustnot $ZFS share $fs +done + +log_pass "We cannot share or mount legacy filesystems as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/snapdir_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/snapdir_001_pos.ksh new file mode 100644 index 00000000000..5fb2e63bef1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/snapdir_001_pos.ksh @@ -0,0 +1,128 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)snapdir_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: snapdir_001_pos +# +# DESCRIPTION: +# Setting a valid snapdir on a dataset, it should be successful. +# +# STRATEGY: +# 1. Create pool, then create filesystem and volume within it. +# 2. Create a snapshot for each dataset. +# 3. Setting different valid snapdir to each dataset. +# 4. Check the return value and make sure it is 0. +# 5. Verify .zfs directory is hidden|visible according to the snapdir setting. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-02-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for dataset in $all_datasets; do + snapexists ${dataset}@snap && \ + log_must $ZFS destroy ${dataset}@snap + done +} + +function verify_snapdir_visible # $1 dataset, $2 hidden|visible +{ + typeset dataset=$1 + typeset value=$2 + typeset mtpt=$(get_prop mountpoint $dataset) + typeset name + + CTLDIR=".zfs" + + for name in `$LS -a $mtpt`; do + if [[ $name == $CTLDIR ]]; then + if [[ $value == "visible" ]]; then + return 0 + else + return 1 + fi + fi + done + + if [[ $value == "visible" ]]; then + return 1 + else + return 0 + fi +} + + +typeset all_datasets + +if is_global_zone ; then + all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL" +else + all_datasets="$TESTPOOL $TESTPOOL/$TESTFS" +fi + +log_onexit cleanup + +for dataset in $all_datasets; do + log_must $ZFS snapshot ${dataset}@snap +done + +log_assert "Setting a valid snapdir property on a dataset succeeds." + +for dataset in $all_datasets; do + for value in hidden visible; do + if [[ $dataset == "$TESTPOOL/$TESTVOL" ]] ; then + set_n_check_prop "$value" "snapdir" \ + "$dataset" "false" + else + set_n_check_prop "$value" "snapdir" \ + "$dataset" + verify_snapdir_visible $dataset $value + [[ $? -eq 0 ]] || \ + log_fail "$dataset/.zfs is not $value as expect." + fi + done +done + +log_pass "Setting a valid snapdir property on a dataset succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_001_pos.ksh new file mode 100644 index 00000000000..fb3b73e41be --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_001_pos.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)user_property_001_pos.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: user_property_001_pos +# +# DESCRIPTION: +# ZFS can set any valid user defined property to the non-readonly dataset. +# +# STRATEGY: +# 1. Loop pool, fs and volume. +# 2. Combine all kind of valid characters into a valid user defined +# property name. +# 3. Random get a string as the value. +# 4. Verify all the valid user defined properties can be set to the +# dataset in #1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "ZFS can set any valid user defined property to the non-readonly " \ + "dataset." +log_onexit cleanup_user_prop $TESTPOOL + +typeset -i i=0 +while ((i < 10)); do + typeset -i len + ((len = RANDOM % 32)) + typeset user_prop=$(valid_user_property $len) + ((len = RANDOM % 512)) + typeset value=$(user_property_value $len) + + for dtst in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do + log_must eval "$ZFS set $user_prop='$value' $dtst" + log_must eval "check_user_prop $dtst $user_prop '$value'" + done + + ((i += 1)) +done + +log_pass "ZFS can set any valid user defined property passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_002_pos.ksh new file mode 100644 index 00000000000..085868d64ac --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_002_pos.ksh @@ -0,0 +1,136 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)user_property_002_pos.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: user_property_002_pos +# +# DESCRIPTION: +# User defined property are always inherited from its parent dataset +# directly. +# +# STRATEGY: +# 1. Create pool, fs, volume, fsclone & volclone. +# 2. Get random user property name and set to the pool +# 3. Verify all dataset user property inherit from pool. +# 4. Set intermediate dataset and verify its children will inherit user +# property from it directly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $new_vol && log_must $ZFS rename $new_vol $vol + + typeset dtst + for dtst in $new_fsclone $new_volclone $fsclone $volclone \ + $fssnap $volsnap; do + if datasetexists $dtst; then + log_must $ZFS destroy -f $dtst + fi + done + + cleanup_user_prop $pool +} + +# +# Verify options datasets (3-n) inherit from the inherited dataset $2. +# +# $1 user property +# $2 inherited dataset +# $3-n datasets +# +function inherit_check +{ + typeset prop=$1 + typeset inherited_dtst=$2 + shift 2 + [[ -z $@ ]] && return 1 + + typeset inherited_value=$(get_prop $prop $inherited_dtst) + for dtst in $@; do + typeset value=$(get_prop $prop $dtst) + typeset source=$(get_source $prop $dtst) + if [[ "$value" != "$inherited_value" || \ + "$source" != "inherited from $inherited_dtst" ]] + then + return 1 + fi + + shift + done + + return 0 +} + +log_assert "User defined property inherited from its parent." +log_onexit cleanup + +pool=$TESTPOOL; fs=$pool/$TESTFS; vol=$pool/$TESTVOL +fssnap=$fs@snap; volsnap=$vol@snap; +log_must $ZFS snapshot $fssnap +log_must $ZFS snapshot $volsnap +fsclone=$pool/fsclone; volclone=$pool/volclone +log_must $ZFS clone $fssnap $fsclone +log_must $ZFS clone $volsnap $volclone + +prop_name=$(valid_user_property 10) +value=$(user_property_value 16) +log_must eval "$ZFS set $prop_name='$value' $pool" +log_must eval "check_user_prop $pool $prop_name '$value'" +log_must inherit_check $prop_name $pool $fs $vol $fsclone $volclone + +new_fsclone=$fs/fsclone; new_volclone=$fs/volclone +log_must $ZFS rename $fsclone $new_fsclone +log_must $ZFS rename $volclone $new_volclone +log_must inherit_check $prop_name $pool $fs $new_fsclone $new_volclone + +log_note "Set intermediate dataset will change the inherited relationship." +new_value=$(user_property_value 16) +log_must eval "$ZFS set $prop_name='$new_value' $fs" +log_must eval "check_user_prop $fs $prop_name '$new_value'" +log_must inherit_check $prop_name $fs $new_fsclone $new_volclone + +log_pass "User defined property inherited from its parent passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_003_neg.ksh new file mode 100644 index 00000000000..36f71fb4a28 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_003_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)user_property_003_neg.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: user_property_003_neg +# +# DESCRIPTION: +# ZFS can handle any invalid user defined property. +# +# STRATEGY: +# 1. Loop pool, fs and volume. +# 2. Combine all kind of invalid user property names. +# 3. Random get a string as the value. +# 4. Verify all the invalid user defined properties can not be set to the +# dataset in #1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "ZFS can handle invalid user property." +log_onexit cleanup_user_prop $TESTPOOL + +typeset -i i=0 +while ((i < 10)); do + typeset -i len + ((len = RANDOM % 32)) + typeset user_prop=$(invalid_user_property $len) + ((len = RANDOM % 512)) + typeset value=$(user_property_value $len) + + for dtst in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do + log_mustnot $ZFS set $user_prop=$value $dtst + log_mustnot check_user_prop $dtst \"$user_prop\" \"$value\" + done + + ((i += 1)) +done + +log_pass "ZFS can handle invalid user property passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_004_pos.ksh new file mode 100644 index 00000000000..829820556ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/user_property_004_pos.ksh @@ -0,0 +1,115 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)user_property_004_pos.ksh 1.4 09/05/19 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: user_property_004_neg +# +# DESCRIPTION: +# User property has no effect to snapshot until 'Snapshot properties' supported. +# +# STRATEGY: +# 1. Verify user properties could be transformed by 'zfs snapshot' +# 2. Verify user properties could be set upon snapshot. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do + typeset fssnap=$fs@snap + if datasetexists $fssnap ; then + log_must $ZFS destroy -f $fssnap + fi + done + cleanup_user_prop $TESTPOOL +} + +function nonexist_user_prop +{ + typeset user_prop=$1 + typeset dtst=$2 + + typeset source=$(get_source $user_prop $dtst) + typeset value=$(get_prop $user_prop $dtst) + if [[ $source == '-' && $value == '-' ]]; then + return 0 + else + return 1 + fi +} + +log_assert "User property has no effect to snapshot until 'Snapshot properties' supported." +log_onexit cleanup + +typeset snap_property= + +$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1 +if (( $? == 0 )) ; then + snap_property="true" +fi + +for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do + typeset fssnap=$fs@snap + prop_name=$(valid_user_property 10) + value=$(user_property_value 16) + log_must eval "$ZFS set $prop_name='$value' $fs" + log_must eval "check_user_prop $fs $prop_name '$value'" + + log_must $ZFS snapshot $fssnap + + if [[ -n $snap_property ]] ; then + log_mustnot nonexist_user_prop $prop_name $fssnap + + log_must eval "$ZFS set $prop_name='$value' $fssnap" + log_mustnot nonexist_user_prop $prop_name $fssnap + else + log_must nonexist_user_prop $prop_name $fssnap + log_mustnot eval "$ZFS set $prop_name='$value' $fssnap" + log_must nonexist_user_prop $prop_name $fssnap + fi +done + +log_pass "User properties has effect upon snapshot." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/version_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/version_001_neg.ksh new file mode 100644 index 00000000000..4f4c08a5d65 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/version_001_neg.ksh @@ -0,0 +1,109 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)version_001_neg.ksh 1.2 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: version_001_neg +# +# DESCRIPTION: +# Valid version values should be positive integers only. +# +# STRATEGY: +# 1) Form an array of invalid reservation values (negative and +# incorrectly formed) +# 2) Attempt to set each invalid version value in turn on a +# filesystem and volume. +# 3) Verify that attempt fails and the version value remains +# unchanged +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! fs_prop_exist "version" ; then + log_unsupported "version is not supported by this release." +fi + +log_assert "Verify invalid version values are rejected" + +set -A values '' '-1' '-1.0' '-1.8' '-9999999999999999' \ + '0x1' '0b' '1b' '1.1b' '0' '0.000' '1.234' + +# +# Function to loop through a series of bad reservation +# values, checking they are when we attempt to set them +# on a dataset. +# +function set_n_check # data-set +{ + typeset obj=$1 + typeset -i i=0 + typeset -i j=0 + + orig_val=$(get_prop version $obj) + + while (( $i < ${#values[*]} )); do + $ZFS set version=${values[$i]} $obj > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + log_note "$ZFS set version=${values[$i]} $obj" + log_fail "The above version set returned 0!" + fi + + new_val=$(get_prop version $obj) + + if [[ $new_val != $orig_val ]]; then + log_fail "$obj : version values changed " \ + "($orig_val : $new_val)" + fi + + (( i = i + 1 )) + done +} + +for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL +do + set_n_check $dataset +done + +log_pass "Invalid version values correctly rejected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set.cfg new file mode 100644 index 00000000000..fe63d73a48a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_set.cfg 1.2 07/01/09 SMI" +# +. $STF_SUITE/tests/cli_root/cli.cfg + +export TESTDIR_NOTEXISTING=${TEST_BASE_DIR%%/}/testdir_notexisting${TESTCASE_ID} + +export STF_TIMEOUT=1200 #ro_prop_001_pos need more time diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_001_neg.ksh new file mode 100644 index 00000000000..746ac307ae3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_001_neg.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_set_001_neg.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_set_001_neg +# +# DESCRIPTION: +# Setting invalid value to mountpoint, checksum, atime, readonly, setuid, +# or canmount on a file system, volume. It should be failed. +# +# STRATEGY: +# 1. Create pool, then create file system & volume within it. +# 2. Setting invalid value, it should be failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A props "" "mountpoint" "checksum" "compression" "atime" "readonly" \ + "setuid" "canmount" + +set -A values "" "mountpoint" "checksum" "compression" "atime" "readonly" \ + "setuid" "0" "-?" "-on" "--on" "*" "?" "Legacy" "NONE" "oN" \ + "On" "ON" "ofF" "OFf" "oFF" "Off" "OfF" "OFF" "LzJb" "lZJb" "LZjB" \ + "blad" "default" "TESTPOOL" "$TESTPOOL/$TESTCTR" \ + "$TESTPOOL/$TESTCTR/$TESTFS" "$TESTPOOL/$TESTFS" +set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL" + +log_assert "Setting invalid value to mountpoint, checksum, compression, atime,"\ + "readonly, setuid, or canmount on a file system file system or volume." \ + "It should be failed." + +typeset -i i=0 +typeset -i j=0 +typeset -i k=0 +while (( i < ${#dataset[@]} )); do + j=0 + while (( j < ${#props[@]} )); do + k=0 + while (( k < ${#values[@]} )); do + set_n_check_prop "${values[k]}" "${props[j]}" \ + "${dataset[i]}" false + (( k += 1 )) + done + (( j += 1 )) + done + (( i += 1 )) +done + +log_pass "Setting invalid value to mountpoint, checksum, compression, atime, " \ + "readonly, setuid, or canmount on file system or volume pass." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_002_neg.ksh new file mode 100644 index 00000000000..30347134392 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_002_neg.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_set_002_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_set_002_neg +# +# DESCRIPTION: +# 'zfs set' should fail with invalid arguments +# +# STRATEGY: +# 1. Create an array of invalid arguments +# 1. Run zfs set with each invalid argument +# 2. Verify that zfs set returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "'zfs set' fails with invalid arguments" + +set -A editable_props "quota" "reservation" "reserv" "volsize" "recordsize" "recsize" \ + "mountpoint" "checksum" "compression" "compress" "atime" \ + "devices" "exec" "setuid" "readonly" "zoned" "snapdir" "aclmode" \ + "aclinherit" "canmount" "shareiscsi" "xattr" "copies" "version" + +for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ + $TESTPOOL/$TESTFS@$TESTSNAP; do + for badarg in "" "-" "-?"; do + for prop in ${editable_props[@]}; do + log_mustnot eval "$ZFS set $badarg $prop= $ds >/dev/null 2>&1" + done + done +done + +log_pass "'zfs set' fails with invalid arguments as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_003_neg.ksh new file mode 100644 index 00000000000..dd924552c5e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_003_neg.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_set_003_neg.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_set_003_neg +# +# DESCRIPTION: +# 'zfs set mountpoint/sharenfs' should fail when the mountpoint is invlid +# +# STRATEGY: +# 1. Create invalid scenarios +# 2. Run zfs set mountpoint/sharenfs with invalid value +# 3. Verify that zfs set returns expected errors +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if [ -e $badpath ]; then + $RM -f $badpath + fi + if datasetexists $TESTPOOL/foo; then + log_must $ZFS destroy $TESTPOOL/foo + fi +} + +log_assert "'zfs set mountpoint/sharenfs' fails with invalid scenarios" +log_onexit cleanup + +badpath=$TMPDIR/foo1.${TESTCASE_ID} +$TOUCH $badpath +longpath=$(gen_dataset_name 1030 "abcdefg") + +log_must $ZFS create -o mountpoint=legacy $TESTPOOL/foo + +# Do the negative testing about "property may be set but unable to remount filesystem" +log_mustnot eval "$ZFS set mountpoint=$badpath $TESTPOOL/foo >/dev/null 2>&1" + +# Do the negative testing about "property may be set but unable to reshare filesystem" +log_mustnot eval "$ZFS set sharenfs=on $TESTPOOL/foo >/dev/null 2>&1" + +# Do the negative testing about "sharenfs property can not be set to null" +log_mustnot eval "$ZFS set sharenfs= $TESTPOOL/foo >/dev/null 2>&1" + +# Do the too long pathname testing (>1024) +log_mustnot eval "$ZFS set mountpoint=/$longpath $TESTPOOL/foo >/dev/null 2>&1" + +log_pass "'zfs set mountpoint/sharenfs' fails with invalid scenarios as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_common.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_common.kshlib new file mode 100644 index 00000000000..f3b98d27170 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_common.kshlib @@ -0,0 +1,253 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_set_common.kshlib 1.7 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +set -A VALID_NAME_CHAR a b c d e f g h i j k l m n o p q r s t u v w x y z \ + 0 1 2 3 4 5 6 7 8 9 ':' '-' '.' '_' +set -A INVALID_NAME_CHAR A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \ + '`' '~' '!' '@' '#' '$' '%' '^' '&' '(' ')' '+' '=' \ + '|' '{' '[' ']' '}' ';' '"' '<' ',' '>' '?' '/' \ + ' ' +set -A ALL_CHAR ${VALID_NAME_CHAR[*]} ${INVALID_NAME_CHAR[*]} + +# +# Firstly, set the property value to dataset. Then checking if the property +# value is equal with the expected value, according to the expected result. +# +# $1 property value +# $2 property name +# $3 dataset +# $4 expected result +# +function set_n_check_prop +{ + typeset expect_value=$1 + typeset prop=$2 + typeset dataset=$3 + typeset expect_result=${4:-true} + typeset old_value="" + typeset cur_value="" + + [ -n "$prop" ] && old_value=$(get_prop $prop $dataset) + if [ "$expect_result" = "true" ]; then + log_must $ZFS set $prop=$expect_value $dataset + else + log_mustnot $ZFS set $prop=$expect_value $dataset + fi + [ -n "$prop" ] && cur_value=$(get_prop $prop $dataset) + + err="ERROR: Dataset '$dataset': '$prop' value '$cur_value'" + if [ "$expect_result" = "true" ]; then + [ "$expect_value" = "gzip-6" ] && expect_value="gzip" + case "$prop" in + reservation|reserv|quota) + if [ "$expect_value" = "none" -a "$cur_value" != "0" ]; then + err="$err should not be set!" + log_fail "$err" + return + fi + ;; + esac + if [ "$cur_value" != "$expect_value" ]; then + err="$err should have changed to '$expect_value'!" + log_fail "$err" + fi + else + if [ "$expect_value" != "" -a "$cur_value" != "$old_value" ]; then + err="$err should be unchanged at '$old_value'!" + log_fail "$err" + fi + fi +} + +# +# Cleanup all the user properties of the pool and the dataset reside it. +# +# $1 pool name +# +function cleanup_user_prop +{ + typeset pool=$1 + typeset dtst=$($ZFS list -H -r -o name -t filesystem,volume $pool) + + typeset user_prop + for dt in $dtst; do + user_prop=$($ZFS get -H -o property all $dtst | grep ":") + + typeset prop + for prop in $user_prop; do + $ZFS inherit $prop $dt + (($? != 0)) && log_must $ZFS inherit $prop $dt + done + done +} + +# +# Random select charactor from the specified charactor set and combine into a +# random string +# +# $1 character set name +# $2 String length +# +function random_string +{ + typeset char_set=${1:-VALID_NAME_CHAR} + typeset -i len=${2:-5} + + eval typeset -i count=\${#$char_set[@]} + + typeset str + typeset -i i=0 + while ((i < len)); do + typeset -i ind + ((ind = RANDOM % count)) + eval str=\${str}\${$char_set[\$ind]} + + ((i += 1)) + done + + $ECHO "$str" +} + +# +# Get vaild user defined property name +# +# $1 user defined property name length +# +function valid_user_property +{ + typeset -i sumlen=${1:-10} + ((sumlen < 2 )) && sumlen=2 + typeset -i len + ((len = RANDOM % sumlen)) + typeset part1 part2 + + while true; do + part1="$(random_string VALID_NAME_CHAR $len)" + if [[ "$part1" == "-"* ]]; then + continue + fi + break + done + ((len = sumlen - (len + 1))) + + while true; do + part2="$(random_string VALID_NAME_CHAR $len)" + if [[ -z $part1 && -z $part2 ]]; then + continue + fi + break + done + + $ECHO "${part1}:${part2}" +} + +# +# Get invaild user defined property name +# +# $1 user defined property name length +# +function invalid_user_property +{ + typeset -i sumlen=${1:-10} + ((sumlen == 0)) && sumlen=1 + typeset -i len + ((len = RANDOM % sumlen)) + + typeset part1 part2 + while true; do + part1="$(random_string VALID_NAME_CHAR $len)" + ((len = sumlen - len)) + part2="$(random_string INVALID_NAME_CHAR $len)" + + # Avoid $part1 is *:* and $part2 is "=*" + if [[ "$part1" == *":"* && "$part2" == "="* ]]; then + continue + fi + break + done + + $ECHO "${part1}${part2}" +} + +# +# Get user property value +# +# $1 user defined property name length +# +function user_property_value +{ + typeset -i len=${1:-100} + ((len < 1 )) && len=1 + + typeset value=$(random_string ALL_CHAR $len) + + $ECHO "$value" +} + +# +# Check if the user property is identical to the expected value. +# +# $1 dataset +# $2 user property +# $3 expected value +# +function check_user_prop +{ + typeset dtst=$1 + typeset user_prop="$2" + typeset expect_value="$3" + typeset value=$($ZFS get -p -H -o value "$user_prop" $dtst 2>&1) + + if [[ "$expect_value" == "$value" ]]; then + return 0 + else + return 1 + fi +} + +# +# Get source of the dataset +# +function get_source +{ + typeset prop=$1 + typeset dataset=$2 + typeset source + + source=$($ZFS get -H -o source $prop $dataset) + if (($? != 0)); then + log_fail "Unable to get $prop source for dataset $dataset" + fi + + $ECHO "$source" +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_test.sh new file mode 100755 index 00000000000..f106a150051 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_test.sh @@ -0,0 +1,765 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case cache_001_pos cleanup +cache_001_pos_head() +{ + atf_set "descr" "Setting a valid {primary|secondary}cache on file system and volume,It should be successful." + atf_set "timeout" 1200 +} +cache_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_001_pos.ksh || atf_fail "Testcase failed" +} +cache_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case cache_002_neg cleanup +cache_002_neg_head() +{ + atf_set "descr" "Setting invalid {primary|secondary}cache on fs and volume,It should fail." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +cache_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/cache_002_neg.ksh || atf_fail "Testcase failed" +} +cache_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case canmount_001_pos cleanup +canmount_001_pos_head() +{ + atf_set "descr" "Setting a valid property of canmount to file system, it must be successful." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +canmount_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/canmount_001_pos.ksh || atf_fail "Testcase failed" +} +canmount_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case canmount_002_pos cleanup +canmount_002_pos_head() +{ + atf_set "descr" "Setting canmount=noauto to file system, it must be successful." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +canmount_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/canmount_002_pos.ksh || atf_fail "Testcase failed" +} +canmount_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case canmount_003_pos cleanup +canmount_003_pos_head() +{ + atf_set "descr" "While canmount=noauto and the dataset is mounted, zfs must not attempt to unmount it" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +canmount_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/canmount_003_pos.ksh || atf_fail "Testcase failed" +} +canmount_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case canmount_004_pos cleanup +canmount_004_pos_head() +{ + atf_set "descr" "Verify canmount=noauto work fine when setting sharenfs or sharesmb." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +canmount_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/canmount_004_pos.ksh || atf_fail "Testcase failed" +} +canmount_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case checksum_001_pos cleanup +checksum_001_pos_head() +{ + atf_set "descr" "Setting a valid checksum on a file system, volume,it should be successful." + atf_set "timeout" 1200 +} +checksum_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/checksum_001_pos.ksh || atf_fail "Testcase failed" +} +checksum_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case compression_001_pos cleanup +compression_001_pos_head() +{ + atf_set "descr" "Setting a valid compression on file system and volume,It should be successful." + atf_set "timeout" 1200 +} +compression_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/compression_001_pos.ksh || atf_fail "Testcase failed" +} +compression_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case mountpoint_001_pos cleanup +mountpoint_001_pos_head() +{ + atf_set "descr" "Setting a valid mountpoint to file system, it must be successful." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +mountpoint_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mountpoint_001_pos.ksh || atf_fail "Testcase failed" +} +mountpoint_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case mountpoint_002_pos cleanup +mountpoint_002_pos_head() +{ + atf_set "descr" "Setting a valid mountpoint for an unmounted file system,it remains unmounted." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +mountpoint_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mountpoint_002_pos.ksh || atf_fail "Testcase failed" +} +mountpoint_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case mountpoint_003_pos cleanup +mountpoint_003_pos_head() +{ + atf_set "descr" "With legacy mount, FSType-specific option works well." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +mountpoint_003_pos_body() +{ + atf_expect_fail "The devices property is not yet supported on FreeBSD" + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mountpoint_003_pos.ksh || atf_fail "Testcase failed" +} +mountpoint_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case onoffs_001_pos cleanup +onoffs_001_pos_head() +{ + atf_set "descr" "Setting a valid value to atime, readonly, setuid or zoned on filesystem or volume. It should be successful." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +onoffs_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/onoffs_001_pos.ksh || atf_fail "Testcase failed" +} +onoffs_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case property_alias_001_pos cleanup +property_alias_001_pos_head() +{ + atf_set "descr" "Properties with aliases also work with those aliases." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +property_alias_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/property_alias_001_pos.ksh || atf_fail "Testcase failed" +} +property_alias_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case readonly_001_pos cleanup +readonly_001_pos_head() +{ + atf_set "descr" "Setting a valid readonly property on a dataset succeeds." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +readonly_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/readonly_001_pos.ksh || atf_fail "Testcase failed" +} +readonly_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_001_neg cleanup +reservation_001_neg_head() +{ + atf_set "descr" "Verify invalid reservation values are rejected" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +reservation_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_001_neg.ksh || atf_fail "Testcase failed" +} +reservation_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case ro_props_001_pos cleanup +ro_props_001_pos_head() +{ + atf_set "descr" "Verify that read-only properties are immutable." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +ro_props_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/ro_props_001_pos.ksh || atf_fail "Testcase failed" +} +ro_props_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case share_mount_001_neg cleanup +share_mount_001_neg_head() +{ + atf_set "descr" "Verify that we cannot share or mount legacy filesystems." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +share_mount_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/share_mount_001_neg.ksh || atf_fail "Testcase failed" +} +share_mount_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapdir_001_pos cleanup +snapdir_001_pos_head() +{ + atf_set "descr" "Setting a valid snapdir property on a dataset succeeds." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +snapdir_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapdir_001_pos.ksh || atf_fail "Testcase failed" +} +snapdir_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case user_property_001_pos cleanup +user_property_001_pos_head() +{ + atf_set "descr" "ZFS can set any valid user defined property to the non-readonlydataset." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +user_property_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/user_property_001_pos.ksh || atf_fail "Testcase failed" +} +user_property_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case user_property_002_pos cleanup +user_property_002_pos_head() +{ + atf_set "descr" "User defined property inherited from its parent." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +user_property_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/user_property_002_pos.ksh || atf_fail "Testcase failed" +} +user_property_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case user_property_003_neg cleanup +user_property_003_neg_head() +{ + atf_set "descr" "ZFS can handle invalid user property." + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +user_property_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/user_property_003_neg.ksh || atf_fail "Testcase failed" +} +user_property_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case user_property_004_pos cleanup +user_property_004_pos_head() +{ + atf_set "descr" "User property has no effect to snapshot until 'Snapshot properties' supported." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1200 +} +user_property_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/user_property_004_pos.ksh || atf_fail "Testcase failed" +} +user_property_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case version_001_neg cleanup +version_001_neg_head() +{ + atf_set "descr" "Verify invalid version values are rejected" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +version_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/version_001_neg.ksh || atf_fail "Testcase failed" +} +version_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_set_001_neg cleanup +zfs_set_001_neg_head() +{ + atf_set "descr" "Setting invalid value to mountpoint, checksum, compression, atime,readonly, setuid, zoned or canmount on a file system file system or volume. \It should be failed." + atf_set "timeout" 1200 +} +zfs_set_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_set_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_set_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_set_002_neg cleanup +zfs_set_002_neg_head() +{ + atf_set "descr" "'zfs set' fails with invalid arguments" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +zfs_set_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_set_002_neg.ksh || atf_fail "Testcase failed" +} +zfs_set_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_set_003_neg cleanup +zfs_set_003_neg_head() +{ + atf_set "descr" "'zfs set mountpoint/sharenfs' fails with invalid scenarios" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +zfs_set_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_set_003_neg.ksh || atf_fail "Testcase failed" +} +zfs_set_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_set_common.kshlib + . $(atf_get_srcdir)/zfs_set.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case cache_001_pos + atf_add_test_case cache_002_neg + atf_add_test_case canmount_001_pos + atf_add_test_case canmount_002_pos + atf_add_test_case canmount_003_pos + atf_add_test_case canmount_004_pos + atf_add_test_case checksum_001_pos + atf_add_test_case compression_001_pos + atf_add_test_case mountpoint_001_pos + atf_add_test_case mountpoint_002_pos + atf_add_test_case mountpoint_003_pos + atf_add_test_case onoffs_001_pos + atf_add_test_case property_alias_001_pos + atf_add_test_case readonly_001_pos + atf_add_test_case reservation_001_neg + atf_add_test_case ro_props_001_pos + atf_add_test_case share_mount_001_neg + atf_add_test_case snapdir_001_pos + atf_add_test_case user_property_001_pos + atf_add_test_case user_property_002_pos + atf_add_test_case user_property_003_neg + atf_add_test_case user_property_004_pos + atf_add_test_case version_001_neg + atf_add_test_case zfs_set_001_neg + atf_add_test_case zfs_set_002_neg + atf_add_test_case zfs_set_003_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/Makefile new file mode 100644 index 00000000000..01f5efc52db --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/Makefile @@ -0,0 +1,28 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_share +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_share_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_share_003_pos.ksh +${PACKAGE}FILES+= zfs_share_006_pos.ksh +${PACKAGE}FILES+= zfs_share_002_pos.ksh +${PACKAGE}FILES+= zfs_share_007_neg.ksh +${PACKAGE}FILES+= zfs_share.cfg +${PACKAGE}FILES+= zfs_share_004_pos.ksh +${PACKAGE}FILES+= zfs_share_009_neg.ksh +${PACKAGE}FILES+= zfs_share_010_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_share_009_pos.ksh +${PACKAGE}FILES+= zfs_share_005_pos.ksh +${PACKAGE}FILES+= zfs_share_001_pos.ksh +${PACKAGE}FILES+= zfs_share_008_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/setup.ksh new file mode 100644 index 00000000000..3bc69250e30 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# Make sure NFS server is running before testing. +setup_nfs_server + +DISK=${DISKS%% *} +default_container_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share.cfg new file mode 100644 index 00000000000..8828c0134ab --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export SNAPROOT="$(get_snapdir_name)" +export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_001_pos.ksh new file mode 100644 index 00000000000..24c363b3886 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_001_pos.ksh @@ -0,0 +1,163 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_001_pos +# +# DESCRIPTION: +# Verify that 'zfs set sharenfs' and 'zfs share' shares a given dataset. +# +# STRATEGY: +# 1. Invoke 'zfs set sharenfs'. +# 2. Verify that the file system is shared. +# 3. Invoke 'zfs share'. +# 4. Verify that the file system is shared. +# 5. Verify that a shared filesystem cannot be shared again. +# 6. Verify that share -a succeeds. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A fs \ + "$TESTDIR" "$TESTPOOL/$TESTFS" \ + "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTDIR2" "$TESTPOOL/$TESTFS-clone" + +function cleanup +{ + typeset -i i=0 + while (( i < ${#fs[*]} )); do + log_must $ZFS set sharenfs=off ${fs[((i+1))]} + unshare_fs ${fs[i]} + + ((i = i + 2)) + done + + if mounted $TESTPOOL/$TESTFS-clone; then + log_must $ZFS unmount $TESTDIR2 + fi + + datasetexists $TESTPOOL/$TESTFS-clone && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTFS-clone + + if snapexists "$TESTPOOL/$TESTFS@snapshot"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS@snapshot + fi +} + + +# +# Main test routine. +# +# Given a mountpoint and file system this routine will attempt +# share the mountpoint and then verify it has been shared. +# +function test_share # mntp filesystem +{ + typeset mntp=$1 + typeset filesystem=$2 + + not_shared $mntp || \ + log_fail "File system $filesystem is already shared." + + log_must $ZFS set sharenfs=on $filesystem + is_shared $mntp || \ + log_fail "File system $filesystem is not shared (set sharenfs)." + + # + # Verify 'zfs share' works as well. + # + log_must $ZFS unshare $filesystem + is_shared $mntp && \ + log_fail "File system $filesystem is still shared." + + log_must $ZFS share $filesystem + is_shared $mntp || \ + log_fail "file system $filesystem is not shared (zfs share)." + + log_note "Sharing a shared file system fails." + log_mustnot $ZFS share $filesystem +} + +log_assert "Verify that 'zfs share' succeeds as root." +log_onexit cleanup + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot +log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS-clone +log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS-clone + +typeset -i i=0 +while (( i < ${#fs[*]} )); do + test_share ${fs[i]} ${fs[((i + 1))]} + + ((i = i + 2)) +done + +log_note "Verify 'zfs share -a' succeeds." + +# +# Unshare each of the file systems. +# +i=0 +while (( i < ${#fs[*]} )); do + unshare_fs ${fs[i]} + + ((i = i + 2)) +done + +# +# Try a zfs share -a and verify all file systems are shared. +# +log_must $ZFS share -a + +i=0 +while (( i < ${#fs[*]} )); do + is_shared ${fs[i]} || \ + log_fail "File system ${fs[i]} is not shared (share -a)" + + ((i = i + 2)) +done + +log_pass "'$ZFS share [ -a ] ' succeeds as root." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_002_pos.ksh new file mode 100644 index 00000000000..0bdcd7689e4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_002_pos.ksh @@ -0,0 +1,86 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_002_pos +# +# DESCRIPTION: +# Verify that "zfs share" with a non-existent file system fails. +# +# STRATEGY: +# 1. Make sure the NONEXISTFSNAME ZFS file system is not in 'zfs list'. +# 2. Invoke 'zfs share '. +# 3. Verify that share fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset fs + for fs in $NONEXISTFSNAME $TESTFS ; do + log_must unshare_fs $TESTPOOL/$fs + done +} + +typeset -i ret=0 + +log_assert "Verify that "zfs share" with a non-existent file system fails." + +log_onexit cleanup + +log_mustnot $ZFS list $TESTPOOL/$NONEXISTFSNAME + +$ZFS share $TESTPOOL/$NONEXISTFSNAME +ret=$? +(( ret == 1)) || \ + log_fail "'$ZFS share $TESTPOOL/$NONEXISTFSNAME' " \ + "failed with an unexpected return code of $ret." + +log_note "Make sure the file system $TESTPOOL/$NONEXISTFSNAME is unshared" +not_shared $TESTPOOL/$NONEXISTFSNAME || \ + log_fail "File system $TESTPOOL/$NONEXISTFSNAME is unexpectedly shared." + +log_pass "'$ZFS share' with a non-existent file system fails." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_003_pos.ksh new file mode 100644 index 00000000000..193ffd6f8d0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_003_pos.ksh @@ -0,0 +1,124 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_003_pos +# +# DESCRIPTION: +# Invoking "zfs share " with a file system +# whose sharenfs property is 'off' , will fail with a +# return code of 1 and issue an error message. +# +# STRATEGY: +# 1. Make sure that the ZFS file system is unshared. +# 2. Mount the file system using the various combinations +# - zfs set sharenfs=off +# - zfs set sharenfs=none +# 3. Verify that share failed with return code of 1. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A fs \ + "$TESTDIR" "$TESTPOOL/$TESTFS" \ + "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" + +function cleanup +{ + typeset -i i=0 + while (( i < ${#fs[*]} )); do + log_must $ZFS inherit -r sharenfs ${fs[((i + 1))]} + log_must unshare_fs ${fs[i]} + + ((i = i + 2)) + done +} + + +# +# Main test routine. +# +# Given a mountpoint and file system this routine will attempt +# to share a legacy mountpoint and then verify the share fails as +# expected. +# +function test_legacy_share # mntp filesystem +{ + typeset mntp=$1 + typeset filesystem=$2 + + not_shared $mntp || \ + log_fail "File system $filesystem is already shared." + + if is_global_zone ; then + log_must $ZFS set sharenfs=off $filesystem + not_shared $mntp || \ + log_fail "File system $filesystem is still shared (set sharenfs)." + fi + + $ZFS share $filesystem + ret=$? + (( ret == 1)) || \ + log_fail "'$ZFS share $filesystem' " \ + "unexpected return code of $ret." + + not_shared $mntp || \ + log_fail "file system $filesystem is shared (zfs share)." +} + +log_assert "Verify that '$ZFS share' with a file system " \ + "whose sharenfs property is 'off' " \ + "will fail with return code 1." +log_onexit cleanup + +typeset -i i=0 +while (( i < ${#fs[*]} )); do + test_legacy_share ${fs[i]} ${fs[((i + 1))]} + + ((i = i + 2)) +done + +log_pass "Verify that '$ZFS share' with a file system " \ + "whose sharenfs property is 'off' fails." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_004_pos.ksh new file mode 100644 index 00000000000..a58605a9d46 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_004_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_004_pos +# +# DESCRIPTION: +# Verify that a file system and its snapshot are shared. +# +# STRATEGY: +# 1. Create a file system +# 2. Set the sharenfs property on the file system +# 3. Create a snapshot +# 4. Verify that both are shared. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if snapexists $TESTPOOL/$TESTFS@snapshot; then + log_must $ZFS destroy $TESTPOOL/$TESTFS@snapshot + fi + + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS + log_must unshare_fs $TESTPOOL/$TESTFS +} + +# +# Main test routine. +# +# Given a mountpoint and file system this routine will attempt +# share the mountpoint and then verify a snapshot of the mounpoint +# is also shared. +# +function test_snap_share # mntp filesystem +{ + typeset mntp=$1 + typeset filesystem=$2 + + not_shared $mntp || \ + log_fail "File system $filesystem is already shared." + + log_must $ZFS set sharenfs=on $filesystem + is_shared $mntp || \ + log_fail "File system $filesystem is not shared (set sharenfs)." + + log_must $LS -l $mntp/$SNAPROOT/snapshot + # + # Verify 'zfs share' works as well. + # + log_must $ZFS unshare $filesystem + log_must $ZFS share $filesystem + + is_shared $mntp || \ + log_fail "file system $filesystem is not shared (zfs share)." + + log_must $LS -l $mntp/$SNAPROOT/snapshot +} + +log_assert "Verify that a file system and its snapshot are shared." +log_onexit cleanup + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot +test_snap_share $TESTDIR $TESTPOOL/$TESTFS + +log_pass "A file system and its snapshot are both shared as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_005_pos.ksh new file mode 100644 index 00000000000..c0d4d2e41f9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_005_pos.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_005_pos +# +# DESCRIPTION: +# Verify that NFS share options are propagated correctly. +# +# STRATEGY: +# 1. Create a ZFS file system. +# 2. For each option in the list, set the sharenfs property. +# 3. Verify through the share command that the options are propagated. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS + is_shared $TESTPOOL/$TESTFS && \ + log_must unshare_fs $TESTPOOL/$TESTFS +} + +set -A shareopts \ + "ro" "ro=machine1" "ro=machine1:machine2" \ + "rw" "rw=machine1" "rw=machine1:machine2" \ + "ro=machine1:machine2,rw" "anon=0" "anon=0,sec=sys,rw" \ + "nosuid" "root=machine1:machine2" "rw=.mydomain.mycompany.com" \ + "rw=-terra:engineering" "log" "public" + +log_assert "Verify that NFS share options are propagated correctly." +log_onexit cleanup + +cleanup + +typeset -i i=0 +while (( i < ${#shareopts[*]} )) +do + log_must $ZFS set sharenfs="${shareopts[i]}" $TESTPOOL/$TESTFS + + option=`get_prop sharenfs $TESTPOOL/$TESTFS` + if [[ $option != ${shareopts[i]} ]]; then + log_fail "get sharenfs failed. ($option != ${shareopts[i]})" + fi + + $SHARE | $GREP $option > /dev/null 2>&1 + if (( $? != 0 )); then + log_fail "The '$option' option was not found in share output." + fi + + ((i = i + 1)) +done + +log_pass "NFS options were propagated correctly." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_006_pos.ksh new file mode 100644 index 00000000000..4e8c4297680 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_006_pos.ksh @@ -0,0 +1,119 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_006_pos.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_006_pos +# +# DESCRIPTION: +# Verify that a dataset could not be shared but filesystems are shared. +# +# STRATEGY: +# 1. Create a dataset and file system +# 2. Set the sharenfs property on the dataset +# 3. Verify that the dataset is unable be shared. +# 4. Add a new file system to the dataset. +# 5. Verify that the newly added file system be shared. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTCTR + if mounted $TESTDIR2; then + log_must $ZFS unmount $TESTDIR2 + fi + + datasetexists $TESTPOOL/$TESTCTR/$TESTFS2 && \ + log_must $ZFS destroy $TESTPOOL/$TESTCTR/$TESTFS2 + + typeset fs="" + for fs in $mntp $TESTDIR1 $TESTDIR2 + do + log_must unshare_fs $fs + done +} + +# +# Main test routine. +# +# Given a mountpoint and a dataset, this routine will set the +# sharenfs property on the dataset and verify that dataset +# is unable to be shared but the existing contained file systems +# could be shared. +# +function test_ctr_share # mntp ctr +{ + typeset mntp=$1 + typeset ctr=$2 + + not_shared $mntp || \ + log_fail "Mountpoint: $mntp is already shared." + + log_must $ZFS set sharenfs=on $ctr + + not_shared $mntp || \ + log_fail "File system $mntp is shared (set sharenfs)." + + # + # Add a new file system to the dataset and verify it is shared. + # + typeset mntp2=$TESTDIR2 + log_must $ZFS create $ctr/$TESTFS2 + log_must $ZFS set mountpoint=$mntp2 $ctr/$TESTFS2 + + is_shared $mntp2 || \ + log_fail "File system $mntp2 was not shared (set sharenfs)." +} + +log_assert "Verify that a dataset could not be shared, " \ + "but its sub-filesystems could be shared." +log_onexit cleanup + +typeset mntp=$(get_prop mountpoint $TESTPOOL/$TESTCTR) +test_ctr_share $mntp $TESTPOOL/$TESTCTR + +log_pass "A dataset could not be shared, " \ + "but its sub-filesystems could be shared as expect." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_007_neg.ksh new file mode 100644 index 00000000000..fa4dd3db4b1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_007_neg.ksh @@ -0,0 +1,99 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_007_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_007_neg +# +# DESCRIPTION: +# Verify that invalid share parameters and options are caught. +# +# STRATEGY: +# 1. Create a ZFS file system. +# 2. For each option in the list, set the sharenfs property. +# 3. Verify that the error code and sharenfs property. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup { + if is_global_zone; then + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS + fi +} + +set -A badopts \ + "r0" "r0=machine1" "r0=machine1:machine2" \ + "-g" "-b" "-c" "-d" "--invalid" \ + "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL\$TESTCTR\$TESTFS1" + +log_assert "Verify that invalid share parameters and options are caught." +log_onexit cleanup + +typeset -i i=0 +while (( i < ${#badopts[*]} )) +do + log_note "Setting sharenfs=${badopts[i]} $i " + log_mustnot $ZFS set sharenfs="${badopts[i]}" $TESTPOOL/$TESTFS + + $SHARE | $GREP $option > /dev/null 2>&1 + if (( $? == 0 )); then + log_fail "An invalid setting '$option' was propagated." + fi + + # + # To global zone, sharenfs must be set 'off' before malformed testing. + # Otherwise, the malformed test return '0'. + # + # To non-global zone, sharenfs can be set even 'off' or 'on'. + # + if is_global_zone; then + log_note "Resetting sharenfs option" + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS + fi + + ((i = i + 1)) +done + +log_pass "Invalid share parameters and options we caught as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_008_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_008_neg.ksh new file mode 100644 index 00000000000..b0bb72b641c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_008_neg.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_008_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_008_neg +# +# DESCRIPTION: +# Verify that sharing a dataset other than filesystem fails. +# +# STRATEGY: +# 1. Create a ZFS file system. +# 2. For each dataset in the list, set the sharenfs property. +# 3. Verify that the invalid datasets are not shared. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +if is_global_zone ; then + set -A datasets \ + "$TESTPOOL/$TESTVOL" "$TESTDIR" +fi + +log_assert "Verify that sharing a dataset other than filesystem fails." + +typeset -i i=0 +while (( i < ${#datasets[*]} )) +do + log_mustnot $ZFS set sharenfs=on ${datasets[i]} + + option=`get_prop sharenfs ${datasets[i]}` + if [[ $option == ${datasets[i]} ]]; then + log_fail "set sharenfs failed. ($option == ${datasets[i]})" + fi + + not_shared ${datasets[i]} || \ + log_fail "An invalid setting '$option' was propagated." + + log_mustnot $ZFS share ${datasets[i]} + + not_shared ${datasets[i]} || \ + log_fail "An invalid dataset '${datasets[i]}' was shared." + + ((i = i + 1)) +done + +log_pass "Sharing datasets other than filesystems failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_009_neg.ksh new file mode 100644 index 00000000000..fb63dd38841 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_009_neg.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_009_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_share_009_neg +# +# DESCRIPTION: +# Verify that zfs share should fail when sharing a shared zfs filesystem +# +# STRATEGY: +# 1. Make a zfs filesystem shared +# 2. Use zfs share to share the filesystem +# 3. Verify that zfs share returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset val + + val=$(get_prop sharenfs $fs) + if [[ $val == on ]]; then + log_must $ZFS set sharenfs=off $fs + fi +} + +log_assert "zfs share fails with shared filesystem" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +sharenfs_val=$(get_prop sharenfs $fs) +mpt=$(get_prop mountpoint $fs) +if [[ $sharenfs_val == off ]]; then + log_must $ZFS set sharenfs=on $fs +fi + +$SHARE | $GREP $mpt >/dev/null 2>&1 +if (( $? != 0 )); then + log_must $ZFS share $fs +fi + +log_mustnot $ZFS share $fs + +log_pass "zfs share fails with shared filesystem as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_009_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_009_pos.ksh new file mode 100644 index 00000000000..4f2877117d6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_009_pos.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_009_pos.ksh 1.2 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_share_009_pos +# +# DESCRIPTION: +# Verify that umount/rollback/destroy fails does not unshare the shared +# file system +# +# STRATEGY: +# 1. Share the filesystem via 'zfs set sharenfs'. +# 2. Try umount failure, and verify that the file system is still shared. +# 3. Try rollback failure, and verify that the file system is still shared. +# 4. Try destroy failure, and verify that the file system is still shared. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-04-28) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + log_must cd $origdir + + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS + unshare_fs $TESTPOOL/$TESTFS + + if snapexists "$TESTPOOL/$TESTFS@snapshot"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS@snapshot + fi + + if datasetexists $TESTPOOL/$TESTFS/fs2 ; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS/fs2 + fi +} + +log_assert "Verify umount/rollback/destroy fails does not unshare the shared" \ + "file system" +log_onexit cleanup + +typeset origdir=$PWD + +# unmount fails will not unshare the shared filesystem +log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS +log_must is_shared $TESTDIR +if cd $TESTDIR ; then + log_mustnot $ZFS umount $TESTPOOL/$TESTFS +else + log_fail "cd $TESTDIR fails" +fi +log_must is_shared $TESTDIR + +# rollback fails will not unshare the shared filesystem +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot +if cd $TESTDIR ; then + log_mustnot $ZFS rollback $TESTPOOL/$TESTFS@snapshot +else + log_fail "cd $TESTDIR fails" +fi +log_must is_shared $TESTDIR + +# destroy fails will not unshare the shared filesystem +log_must $ZFS create $TESTPOOL/$TESTFS/fs2 +if cd $TESTDIR/fs2 ; then + log_mustnot $ZFS destroy $TESTPOOL/$TESTFS/fs2 +else + log_fail "cd $TESTDIR/fs2 fails" +fi +log_must is_shared $TESTDIR/fs2 + +log_pass "Verify umount/rollback/destroy fails does not unshare the shared" \ + "file system" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_010_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_010_neg.ksh new file mode 100644 index 00000000000..15a12c6dbed --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_010_neg.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_010_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_share_010_neg +# +# DESCRIPTION: +# Verify that zfs share should fail with bad parameters +# +# STRATEGY: +# 1. Make an array of bad parameters +# 2. Use zfs share to share the filesystem +# 3. Verify that zfs share returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs share fails with bad parameters" + +fs=$TESTPOOL/$TESTFS +set -A badargs "A" "-A" "-" "-x" "-?" "=" "-a *" "-a" + +for arg in "${badargs[@]}"; do + log_mustnot eval "$ZFS share $arg $fs >/dev/null 2>&1" +done + +#zfs share failed when missing arguments or invalid datasetname +for obj in "" "/$fs"; do + log_mustnot eval "$ZFS share $obj >/dev/null 2>&1" +done + +log_pass "zfs share fails with bad parameters as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_test.sh new file mode 100755 index 00000000000..d7abce6f938 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_share/zfs_share_test.sh @@ -0,0 +1,296 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_share_001_pos cleanup +zfs_share_001_pos_head() +{ + atf_set "descr" "Verify that 'zfs share' succeeds as root." + atf_set "require.progs" zfs svcs +} +zfs_share_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_share_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_002_pos cleanup +zfs_share_002_pos_head() +{ + atf_set "descr" "Verify that zfs share with a non-existent file system fails." + atf_set "require.progs" zfs svcs +} +zfs_share_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_share_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_003_pos cleanup +zfs_share_003_pos_head() +{ + atf_set "descr" "Verify that '$ZFS share' with a file systemwhose sharenfs property is 'off' \will fail with return code 1." + atf_set "require.progs" zfs svcs +} +zfs_share_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_share_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_004_pos cleanup +zfs_share_004_pos_head() +{ + atf_set "descr" "Verify that a file system and its snapshot are shared." + atf_set "require.progs" zfs svcs +} +zfs_share_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_share_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_005_pos cleanup +zfs_share_005_pos_head() +{ + atf_set "descr" "Verify that NFS share options are propagated correctly." + atf_set "require.progs" zfs share svcs +} +zfs_share_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_share_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_006_pos cleanup +zfs_share_006_pos_head() +{ + atf_set "descr" "Verify that a dataset could not be shared,but its sub-filesystems could be shared." + atf_set "require.progs" zfs svcs +} +zfs_share_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_share_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_007_neg cleanup +zfs_share_007_neg_head() +{ + atf_set "descr" "Verify that invalid share parameters and options are caught." + atf_set "require.progs" zfs share svcs +} +zfs_share_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_share_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_008_neg cleanup +zfs_share_008_neg_head() +{ + atf_set "descr" "Verify that sharing a dataset other than filesystem fails." + atf_set "require.progs" zfs svcs +} +zfs_share_008_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_008_neg.ksh || atf_fail "Testcase failed" +} +zfs_share_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_009_neg cleanup +zfs_share_009_neg_head() +{ + atf_set "descr" "zfs share fails with shared filesystem" + atf_set "require.progs" zfs share svcs +} +zfs_share_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_009_neg.ksh || atf_fail "Testcase failed" +} +zfs_share_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_009_pos cleanup +zfs_share_009_pos_head() +{ + atf_set "descr" "Verify umount/rollback/destroy fails does not unshare the sharedfile system" + atf_set "require.progs" zfs svcs +} +zfs_share_009_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_009_pos.ksh || atf_fail "Testcase failed" +} +zfs_share_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_010_neg cleanup +zfs_share_010_neg_head() +{ + atf_set "descr" "zfs share fails with bad parameters" + atf_set "require.progs" zfs svcs +} +zfs_share_010_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_010_neg.ksh || atf_fail "Testcase failed" +} +zfs_share_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_share.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_share_001_pos + atf_add_test_case zfs_share_002_pos + atf_add_test_case zfs_share_003_pos + atf_add_test_case zfs_share_004_pos + atf_add_test_case zfs_share_005_pos + atf_add_test_case zfs_share_006_pos + atf_add_test_case zfs_share_007_neg + atf_add_test_case zfs_share_008_neg + atf_add_test_case zfs_share_009_neg + atf_add_test_case zfs_share_009_pos + atf_add_test_case zfs_share_010_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/Makefile new file mode 100644 index 00000000000..dcfd64999ce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/Makefile @@ -0,0 +1,24 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_snapshot +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_snapshot_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_snapshot_005_neg.ksh +${PACKAGE}FILES+= zfs_snapshot_001_neg.ksh +${PACKAGE}FILES+= zfs_snapshot_004_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_snapshot_002_neg.ksh +${PACKAGE}FILES+= zfs_snapshot_006_pos.ksh +${PACKAGE}FILES+= zfs_snapshot_007_neg.ksh +${PACKAGE}FILES+= zfs_snapshot_003_neg.ksh +${PACKAGE}FILES+= zfs_snapshot.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/cleanup.ksh new file mode 100644 index 00000000000..e2ccfb86862 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_container_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/setup.ksh new file mode 100644 index 00000000000..eb1c316dfae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_container_volume_setup ${DISK} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot.cfg new file mode 100644 index 00000000000..1f99bb8ea5c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot.cfg @@ -0,0 +1,37 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot.cfg 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/cli.cfg + +export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP" +export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP" +export SNAPDIR="$TESTDIR@$TESTSNAP" +export SNAPDIR1="$ZFSROOT/$SNAPFS1" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh new file mode 100644 index 00000000000..1820b351cf8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh @@ -0,0 +1,132 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_001_neg.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_snapshot_001_neg +# +# DESCRIPTION: +# Try each 'zfs snapshot' with inapplicable scenarios to make sure +# it returns an error. include: +# * No arguments given. +# * The argument contains invalid characters for the ZFS namesapec +# * Leading slash in snapshot name +# * The argument contains an empty component. +# * Missing '@' delimiter. +# * Multiple '@' delimiters in snapshot name. +# * The snapshot already exist. +# * Create snapshot upon the pool. +# (Be removed since pool is treated as filesystem as well) +# * Create snapshot upon a non-existent filesystem. +# * Too many arguments. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute the sub-command +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A args "" \ + "$TESTPOOL/$TESTFS@blah*" "$TESTPOOL/$TESTFS@blah?" \ + "$TESTPOOL/$TESTVOL@blah*" "$TESTPOOL/$TESTVOL@blah?" \ + "/$TESTPOOL/$TESTFS@$TESTSNAP" "/$TESTPOOL/$TESTVOL@$TESTSNAP" \ + "@$TESTSNAP" "$TESTPOOL/$TESTFS@" "$TESTPOOL/$TESTVOL@" \ + "$TESTPOOL//$TESTFS@$TESTSNAP" "$TESTPOOL//$TESTVOL@$TESTSNAP" \ + "$TESTPOOL/$TESTFS/$TESTSNAP" "$TESTPOOL/$TESTVOL/$TESTSNAP" \ + "$TESTPOOL/$TESTFS@$TESTSNAP@$TESTSNAP1" \ + "$TESTPOOL/$TESTVOL@$TESTSNAP@$TESTSNAP1" \ + "$SNAPFS" "$SNAPFS1" \ + "blah/blah@$TESTSNAP" + +function setup_all +{ + log_note "Create snapshots and mount them..." + + for snap in $SNAPFS $SNAPFS1 ; do + if ! snapexists $snap ; then + log_must $ZFS snapshot $snap + fi + done + + return 0 +} + +function cleanup_all +{ + typeset -i i=0 + + while (( i < ${#args[*]} )); do + + for snap in ${args[i]}; do + snapexists $snap && \ + log_must $ZFS destroy -f $snap + + done + + (( i = i + 1 )) + done + + for mtpt in $SNAPDIR $SNAPDIR1 ; do + [[ -d $mtpt ]] && \ + log_must $RM -rf $mtpt + done + + return 0 +} + +log_assert "Badly-formed 'zfs snapshot' with inapplicable scenarios " \ + "should return an error." +log_onexit cleanup_all + +setup_all + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZFS snapshot ${args[i]} + ((i = i + 1)) +done + +log_pass "Badly formed 'zfs snapshot' with inapplicable scenarios " \ + "fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh new file mode 100644 index 00000000000..f26b5f45139 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh @@ -0,0 +1,111 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_002_neg.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_snapshot_002_neg +# +# DESCRIPTION: +# "zfs snapshot -r" fails with invalid arguments or scenarios. +# The invalid scenarios may include: +# (1) The child filesystem already has snapshot with the same name +# (2) The child volume already has snapshot with the same name +# +# STRATEGY: +# 1. Create an array of invalid arguments +# 2. Execute 'zfs snapshot -r' with each argument in the array, +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset snap + + for snap in $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP \ + $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP; + do + snapexists $snap && \ + log_must $ZFS destroy $snap + done + + datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \ + log_must $ZFS destroy -rf $TESTPOOL/$TESTCTR/$TESTVOL + +} + +log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. " +log_onexit cleanup + +set -A args "" \ + "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \ + "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \ + "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \ + "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP" + +# setup preparations +log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP + +# testing +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZFS snapshot -r ${args[i]} + + ((i = i + 1)) +done + +# Testing the invalid senario: the child volume already has an +# identical name snapshot, zfs snapshot -r should fail when +# creating snapshot with -r for the parent +log_must $ZFS destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP +if is_global_zone; then + log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL +else + log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTVOL +fi +log_must $ZFS snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP + +log_mustnot $ZFS snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP + +log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh new file mode 100644 index 00000000000..ffd94166433 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_003_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_003_neg.ksh 1.1 07/07/31 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_snapshot_003_neg +# +# DESCRIPTION: +# "zfs snapshot" fails with bad options,too many arguments or too long +# snapshot name +# +# STRATEGY: +# 1. Create an array of invalid arguments +# 2. Execute 'zfs snapshot' with each argument in the array, +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "'zfs snapshot' fails with bad options, or too many arguments. " + +set -A badopts "r" "R" "-R" "-x" "-rR" "-?" "-*" "-123" + +# set too long snapshot name (>256) +l_name="$(gen_dataset_name 260 abcdefg)" + +for ds in $TESTPOOL/$TESTFS $TESTPOOL/$TESTCTR $TESTPOOL/$TESTVOL; do + for opt in ${badopts[@]}; do + log_mustnot $ZFS snapshot $opt $ds@$TESTSNAP + done + + log_mustnot $ZFS snapshot $ds@snap $ds@snap1 + log_mustnot $ZFS snapshot -r $ds@snap $ds@snap1 + + log_mustnot $ZFS snapshot $ds@$l_name + log_mustnot $ZFS snapshot -r $ds@$l_name +done + +log_pass "'zfs snapshot' fails with bad options or too many arguments as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh new file mode 100644 index 00000000000..75d16ca9054 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh @@ -0,0 +1,111 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_004_neg.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_snapshot_004_neg +# +# DESCRIPTION: +# Verify recursive snapshotting could not break ZFS. +# +# STRATEGY: +# 1. Create deeply-nested filesystems until it is too long to create snap +# 2. Verify zfs snapshot -r pool@snap will not break ZFS +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-08) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $initfs ; then + log_must $ZFS destroy -rf $initfs + fi +} + +log_assert "Verify recursive snapshotting could not break ZFS." +log_onexit cleanup + +initfs=$TESTPOOL/$TESTFS/$TESTFS +basefs=$initfs +typeset -i ret=0 len snaplen +while ((ret == 0)); do + $ZFS create $basefs + $ZFS snapshot $basefs@snap1 + ret=$? + + len=$($ECHO $basefs| $WC -c) + if ((ret != 0)); then + log_note "The deeply-nested filesystem len: $len" + # + # Make sure there are at lease 2 characters left + # for snapshot name space, otherwise snapshot name + # is incorrect + # + if ((len >= 255)); then + if datasetexists $basefs; then + log_must $ZFS destroy -r $basefs + fi + basefs=${basefs%/*} + len=$($ECHO $basefs| $WC -c) + fi + break + else + log_note "ZFS snapshot suceeded. len: $len" + fi + + basefs=$basefs/$TESTFS +done + +# Make snapshot name is longer than the max length +((snaplen = 256 - len + 10)) +snap=$(gen_dataset_name $snaplen "s") +log_mustnot $ZFS snapshot -r $TESTPOOL@$snap + +log_must datasetnonexists $TESTPOOL@$snap +while [[ $basefs != $TESTPOOL ]]; do + log_must datasetnonexists $basefs@$snap + basefs=${basefs%/*} +done + +log_pass "Verify recursive snapshotting could not break ZFS." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh new file mode 100644 index 00000000000..1f5acf4c93e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_005_neg.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_snapshot_005_neg +# +# DESCRIPTION: +# Long name filesystem with snapshot should not break ZFS. +# +# STRATEGY: +# 1. Create filesystem and snapshot. +# 2. When the snapshot length is 256, rename the filesystem. +# 3. Verify it does not break ZFS +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-09) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify long name filesystem with snapshot should not break ZFS." + +initfs=$TESTPOOL/$TESTFS/$TESTFS +basefs=$initfs +typeset -i ret=0 len snaplen +while ((ret == 0)); do + $ZFS create $basefs + $ZFS snapshot $basefs@snap1 + ret=$? + + if ((ret != 0)); then + len=$($ECHO $basefs | $WC -c) + log_note "The deeply-nested filesystem len: $len" + + # + # Make sure there are at lease 2 characters left + # for snapshot name space, otherwise snapshot name + # is incorrect + # + if ((len >= 255)); then + if datasetexists $basefs; then + log_must $ZFS destroy -r $basefs + fi + basefs=${basefs%/*} + len=$($ECHO $basefs| $WC -c) + fi + break + fi + + basefs=$basefs/$TESTFS +done + +# Make snapshot name length match the longest one +((snaplen = 256 - len - 1)) # 1: @ +snap=$(gen_dataset_name $snaplen "s") +log_must $ZFS snapshot $basefs@$snap + +log_mustnot $ZFS rename $basefs ${basefs}a +log_mustnot $ZFS rename $basefs ${basefs}-new +log_mustnot $ZFS rename $initfs ${initfs}-new +log_mustnot $ZFS rename $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS-new + +log_pass "Verify long name filesystem with snapshot should not break ZFS." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh new file mode 100644 index 00000000000..a57b05d4f4f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh @@ -0,0 +1,143 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_006_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_snapshot_006_pos +# +# DESCRIPTION: +# User property could be set via creation time by 'zfs snapshot -o' +# +# STRATEGY: +# 1. Create snapshot and give '-o property=value' +# 2. Verify the snapshot be created and user property have been set. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do + typeset fssnap=$fs@snap + if datasetexists $fssnap ; then + log_must $ZFS destroy -rf $fssnap + fi + done + cleanup_user_prop $TESTPOOL +} + +function nonexist_user_prop +{ + typeset user_prop=$1 + typeset dtst=$2 + + typeset source=$(get_source $user_prop $dtst) + typeset value=$(get_prop $user_prop $dtst) + if [[ $source == '-' && $value == '-' ]]; then + return 0 + else + return 1 + fi +} + +log_assert "User property could be set upon snapshot via 'zfs snapshot -o'." +log_onexit cleanup + +typeset snap_property= + +$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1 +if (( $? != 0 )) ; then + log_unsupported "Snapshot properties not supported on current system." +fi + +for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do + typeset fssnap=$fs@snap + prop_name=$(valid_user_property 10) + value=$(user_property_value 16) + + log_must eval "$ZFS snapshot -o $prop_name='$value' $fssnap" + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap + + log_must $ZFS destroy -f $fssnap + + prop_name2=$(valid_user_property 10) + value2=$(user_property_value 16) + + log_must eval "$ZFS snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap" + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap + log_mustnot nonexist_user_prop $prop_name2 $fssnap +done + +cleanup + +prop_name=$(valid_user_property 10) +value=$(user_property_value 16) + +log_must eval "$ZFS snapshot -r -o $prop_name='$value' $TESTPOOL@snap" +for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do + typeset fssnap=$fs@snap + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap + + log_must $ZFS destroy -rf $fssnap +done + +cleanup + +prop_name2=$(valid_user_property 10) +value2=$(user_property_value 16) + +log_must eval "$ZFS snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap" +for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do + typeset fssnap=$fs@snap + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap + log_mustnot nonexist_user_prop $prop_name2 $fssnap + + log_must $ZFS destroy -rf $fssnap +done + +log_pass "User property could be set upon snapshot via 'zfs snapshot -o'." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh new file mode 100644 index 00000000000..952940896ef --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh @@ -0,0 +1,146 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_007_neg.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_snapshot_007_pos +# +# DESCRIPTION: +# 'zfs snapshot -o' cannot set properties other than user property +# +# STRATEGY: +# 1. Create snapshot and give '-o property=value' with regular property. +# 2. Verify the snapshot creation failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do + typeset fssnap=$fs@snap + if datasetexists $fssnap ; then + log_must $ZFS destroy -rf $fssnap + fi + done + cleanup_user_prop $TESTPOOL +} + +function nonexist_user_prop +{ + typeset user_prop=$1 + typeset dtst=$2 + + typeset source=$(get_source $user_prop $dtst) + typeset value=$(get_prop $user_prop $dtst) + if [[ $source == '-' && $value == '-' ]]; then + return 0 + else + return 1 + fi +} + +log_assert "'zfs snapshot -o' cannot set properties other than user property." +log_onexit cleanup + +typeset ro_props="type used available avail creation referenced refer compressratio \ + mounted origin" +typeset snap_ro_props="volsize recordsize recsize quota reservation reserv mountpoint \ + sharenfs checksum compression compress atime devices exec readonly rdonly \ + setuid zoned" + +$ZFS upgrade -v > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + snap_ro_props="$snap_ro_props version" +fi + + +for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do + typeset fssnap=$fs@snap + prop_name=$(valid_user_property 10) + value=$(user_property_value 16) + + log_must eval "$ZFS snapshot -o $prop_name='$value' $fssnap" + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap + + log_must $ZFS destroy -f $fssnap + + prop_name2=$(valid_user_property 10) + value2=$(user_property_value 16) + + log_must eval "$ZFS snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap" + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap + log_mustnot nonexist_user_prop $prop_name2 $fssnap + + log_must $ZFS destroy -f $fssnap +done + +cleanup + +prop_name=$(valid_user_property 10) +value=$(user_property_value 16) + +log_must eval "$ZFS snapshot -r -o $prop_name='$value' $TESTPOOL@snap" +for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do + typeset fssnap=$fs@snap + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap +done + +cleanup + +prop_name2=$(valid_user_property 10) +value2=$(user_property_value 16) + +log_must eval "$ZFS snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap" +for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do + typeset fssnap=$fs@snap + log_must snapexists $fssnap + log_mustnot nonexist_user_prop $prop_name $fssnap + log_mustnot nonexist_user_prop $prop_name2 $fssnap +done + +log_pass "'zfs snapshot -o' cannot set properties other than user property." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_test.sh new file mode 100755 index 00000000000..7d654e922af --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_snapshot/zfs_snapshot_test.sh @@ -0,0 +1,207 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_snapshot_001_neg cleanup +zfs_snapshot_001_neg_head() +{ + atf_set "descr" "Badly-formed 'zfs snapshot' with inapplicable scenariosshould return an error." + atf_set "require.progs" zfs +} +zfs_snapshot_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_snapshot_002_neg cleanup +zfs_snapshot_002_neg_head() +{ + atf_set "descr" "'zfs snapshot -r' fails with invalid arguments or scenarios." + atf_set "require.progs" zfs +} +zfs_snapshot_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_002_neg.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_snapshot_003_neg cleanup +zfs_snapshot_003_neg_head() +{ + atf_set "descr" "'zfs snapshot' fails with bad options, or too many arguments." + atf_set "require.progs" zfs +} +zfs_snapshot_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_003_neg.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_snapshot_004_neg cleanup +zfs_snapshot_004_neg_head() +{ + atf_set "descr" "Verify recursive snapshotting could not break ZFS." + atf_set "require.progs" zfs +} +zfs_snapshot_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_snapshot_005_neg cleanup +zfs_snapshot_005_neg_head() +{ + atf_set "descr" "Verify long name filesystem with snapshot should not break ZFS." + atf_set "require.progs" zfs +} +zfs_snapshot_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_005_neg.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_snapshot_006_pos cleanup +zfs_snapshot_006_pos_head() +{ + atf_set "descr" "User property could be set upon snapshot via 'zfs snapshot -o'." + atf_set "require.progs" zfs zpool +} +zfs_snapshot_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_snapshot_007_neg cleanup +zfs_snapshot_007_neg_head() +{ + atf_set "descr" "'zfs snapshot -o' cannot set properties other than user property." + atf_set "require.progs" zfs +} +zfs_snapshot_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_snapshot_001_neg + atf_add_test_case zfs_snapshot_002_neg + atf_add_test_case zfs_snapshot_003_neg + atf_add_test_case zfs_snapshot_004_neg + atf_add_test_case zfs_snapshot_005_neg + atf_add_test_case zfs_snapshot_006_pos + atf_add_test_case zfs_snapshot_007_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/Makefile new file mode 100644 index 00000000000..68d6e21eb33 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/Makefile @@ -0,0 +1,28 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_unmount +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_unmount_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_unmount_003_pos.ksh +${PACKAGE}FILES+= zfs_unmount_all_001_pos.ksh +${PACKAGE}FILES+= zfs_unmount_006_pos.ksh +${PACKAGE}FILES+= zfs_unmount_002_pos.ksh +${PACKAGE}FILES+= zfs_unmount_007_neg.ksh +${PACKAGE}FILES+= zfs_unmount.cfg +${PACKAGE}FILES+= zfs_unmount_004_pos.ksh +${PACKAGE}FILES+= zfs_unmount_009_pos.ksh +${PACKAGE}FILES+= zfs_unmount_005_pos.ksh +${PACKAGE}FILES+= zfs_unmount_001_pos.ksh +${PACKAGE}FILES+= zfs_unmount_008_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_unmount.kshlib + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount.cfg new file mode 100644 index 00000000000..68142060678 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount.cfg @@ -0,0 +1,42 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export mountcmd=mount +export mountforce="$mountcmd -f" +export mountall="$mountcmd -a" + +export unmountcmd=unmount +export unmountforce="$unmountcmd -f" +export unmountall="$unmountcmd -a" + +export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount.kshlib new file mode 100644 index 00000000000..abae67ac8b0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount.kshlib @@ -0,0 +1,76 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount.kshlib 1.2 07/01/09 SMI" +# + +function do_unmount #cmd #opt #mnt #expect +{ + typeset cmd=$1 + typeset opt=$2 + typeset mnt=$3 + typeset -i expect=${4-0} + typeset -i ret + typeset -i wasmounted=1 + + mounted $mnt || wasmounted=0 + + if (( expect == 0 )) ; then + log_must $ZFS $cmd $opt $mnt + + log_must unmounted $mnt + + log_note "Successfully $ZFS $cmd $opt $mnt" + + else + log_note "$ZFS $cmd $opt $mnt" + + $ZFS $cmd $opt $mnt + ret=$? + if (( ret != expect)); then + log_fail "'$ZFS $cmd $opt $mnt' " \ + "unexpected return code of $ret." + fi + + if (( wasmounted == 1 )) ; then + log_must mounted $mnt + else + log_must unmounted $mnt + fi + log_note "Mount status of $mnt not changed." + fi +} + +function cleanup +{ + [[ -n $cwd ]] && cd $cwd + + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + mounted $TESTPOOL/$TESTFS || \ + log_must $ZFS $mountcmd $TESTPOOL/$TESTFS +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh new file mode 100644 index 00000000000..54ba2eec9eb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh @@ -0,0 +1,130 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_unmount_001_pos +# +# DESCRIPTION: +# Creates a file system and verifies that it can be unmounted +# using each of the various unmount options and sub-command +# variants. +# +# STRATEGY: +# 1. Create and mount a file system as necessary. +# 2. Umount the file system using the various combinations. +# - With force option. +# - Without force option. +# - Using the unmount sub-command. +# - Using the umount sub-command. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +function cleanup +{ + mounted $TESTDIR2 && \ + log_must $ZFS umount -f $TESTDIR2 + + datasetexists $TESTPOOL/$TESTFS2 && \ + log_must $ZFS destroy $TESTPOOL/$TESTFS2 + + [[ -d $TESTDIR2 ]] && \ + log_must $RM -rf $TESTDIR2 +} +function do_unmount +{ + typeset cmd=$1 + typeset opt=$2 + typeset mnt=$3 + + [[ ! -d $TESTDIR2 ]] && \ + log_must $MKDIR $TESTDIR2 + + if ! datasetexists $TESTPOOL/$TESTFS2 ; then + log_must $ZFS create $TESTPOOL/$TESTFS2 + log_must $ZFS set mountpoint=$TESTDIR2 \ + $TESTPOOL/$TESTFS2 + fi + + unmounted $TESTPOOL/$TESTFS2 && \ + log_must $ZFS mount $TESTPOOL/$TESTFS2 + + log_must $ZFS $cmd $options $mnt + + unmounted "$mnt" || \ + log_fail "Unable to unmount $options $mnt" + + log_note "Successfully unmounted $options $mnt" +} + +log_onexit cleanup + +set -A cmd "umount" "unmount" +set -A options "" "-f" +set -A dev "$TESTPOOL/$TESTFS2" "$TESTDIR2" + +log_assert "Verify the u[n]mount [-f] sub-command." + +typeset -i i=0 +typeset -i j=0 +typeset -i k=0 +while [[ $i -lt ${#cmd[*]} ]]; do + j=0 + while [[ $j -lt ${#options[*]} ]]; do + k=0 + while [[ $k -lt ${#dev[*]} ]]; do + do_unmount "${cmd[i]}" "${options[j]}" \ + "${dev[k]}" + + ((k = k + 1)) + done + + ((j = j + 1)) + done + + ((i = i + 1)) +done + +log_pass "zfs u[n]mount [-f] completed successfully." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh new file mode 100644 index 00000000000..b68b9ae38d6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_002_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_unmount/zfs_unmount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unmount_002_pos +# +# DESCRIPTION: +# If invoke "zfs unmount [-f]" with a filesystem|mountpoint +# whose name is not in "zfs list", +# it will fail with a return code of 1 +# and issue an error message. +# +# STRATEGY: +# 1. Make sure that the non-existent ZFS filesystem|mountpoint +# not in 'zfs list'. +# 2. Unmount the file system using the various combinations. +# - Without force option. (FAILED) +# - With force option. (FAILED) +# 3. Unmount the mountpoint using the various combinations. +# - Without force option. (FAILED) +# - With force option. (FAILED) +# 4. Verify the above expected results of the filesystem|mountpoint. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A cmd "umount" "unmount" +set -A options "" "-f" +set -A dev "$TESTPOOL/$NONEXISTFSNAME" "${TEST_BASE_DIR%%/}/$NONEXISTFSNAME" + +function do_unmount_multiple #options #expect +{ + typeset opt=$1 + typeset -i expect=${2-0} + + typeset -i i=0 + typeset -i j=0 + + while (( i < ${#cmd[*]} )); do + j=0 + while (( j < ${#dev[*]} )); do + log_note "Make sure ${dev[j]} is not in 'zfs list'" + log_mustnot $ZFS list ${dev[j]} + + do_unmount "${cmd[i]}" "$opt" \ + "${dev[j]}" $expect + + ((j = j + 1)) + done + + ((i = i + 1)) + done +} + +log_assert "Verify that '$ZFS $unmountcmd [-f] ' " \ + "whose name is not in 'zfs list' will fail with return code 1." + +log_onexit cleanup + +typeset -i i=0 + +while (( i < ${#options[*]} )); do + do_unmount_multiple "${options[i]}" 1 + ((i = i + 1)) +done + +log_pass "'$ZFS $unmountcmd [-f] ' " \ + "whose name is not in 'zfs list' failed with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh new file mode 100644 index 00000000000..7cb635c5532 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_003_pos.ksh @@ -0,0 +1,123 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_unmount/zfs_unmount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unmount_003_pos +# +# DESCRIPTION: +# If invoke "zfs unmount [-f]" with a filesystem|mountpoint +# whose mountpoint property is 'legacy' or 'none', +# it will fail with a return code of 1 +# and issue an error message. +# +# STRATEGY: +# 1. Make sure that the ZFS filesystem is mounted. +# 2. Apply 'zfs set mountpoint=legacy|none '. +# 3. Unmount the file system using the various combinations. +# - Without force option. (FAILED) +# - With force option. (FAILED) +# 4. Unmount the mountpoint using the various combinations. +# - Without force option. (FAILED) +# - With force option. (FAILED) +# 5. Verify the above expected results of the filesystem|mountpoint. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A cmd "umount" "unmount" +set -A options "" "-f" +set -A dev "$TESTPOOL/$TESTFS" "$TESTDIR" +set -A mopts "legacy" "none" + +function do_unmount_multiple #options #expect #mountpoint +{ + typeset opt=$1 + typeset -i expect=${2-0} + typeset mopt=$3 + + typeset -i i=0 + typeset -i j=0 + + while (( i < ${#cmd[*]} )); do + j=0 + while (( j < ${#dev[*]} )); do + [[ -n $mopt ]] && \ + log_must $ZFS set mountpoint=$mopt ${dev[0]} + + do_unmount "${cmd[i]}" "$opt" \ + "${dev[j]}" $expect + + cleanup + + ((j = j + 1)) + done + + ((i = i + 1)) + done +} + +log_assert "Verify that '$ZFS $unmountcmd [-f] ' " \ + "whose mountpoint property is 'legacy' or 'none' " \ + "will fail with return code 1." + +log_onexit cleanup + +typeset -i i=0 +typeset -i j=0 + +while (( i < ${#mopts[*]} )); do + j=0 + while (( j < ${#options[*]} )); do + do_unmount_multiple "${options[j]}" 1 "${mopts[i]}" + ((j = j + 1)) + done + ((i = i + 1)) +done + +log_pass "'$ZFS $unmountcmd [-f] ' " \ + "whose mountpoint property is 'legacy' or 'none' " \ + "will fail with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh new file mode 100644 index 00000000000..3777ca7f37f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_004_pos.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_unmount/zfs_unmount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unmount_004_pos +# +# DESCRIPTION: +# If invoke "zfs unmount [-f]" with a specific filesystem|mountpoint, +# which is not currently mounted, +# it will fail with a return code of 1 +# and issue an error message. +# +# STRATEGY: +# 1. Make sure that the ZFS filesystem is mounted. +# 2. Invoke 'zfs unmount '. +# 3. Verify that the filesystem is unmounted. +# 4. Unmount the file system using the various combinations. +# - Without force option. (FAILED) +# - With force option. (FAILED) +# 5. Unmount the mountpoint using the various combinations. +# - Without force option. (FAILED) +# - With force option. (FAILED) +# 6. Verify the above expected results of the filesystem|mountpoint. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A cmd "umount" "unmount" +set -A options "" "-f" +set -A dev "$TESTPOOL/$TESTFS" "$TESTDIR" + +function do_unmount_multiple #options #expect +{ + typeset opt=$1 + typeset -i expect=${2-0} + + typeset -i i=0 + typeset -i j=0 + + while (( i < ${#cmd[*]} )); do + j=0 + while (( j < ${#dev[*]} )); do + unmounted ${dev[j]} || \ + log_must $ZFS $unmountforce ${dev[j]} + + do_unmount "${cmd[i]}" "$opt" \ + "${dev[j]}" $expect + + ((j = j + 1)) + done + + ((i = i + 1)) + done +} + +log_assert "Verify that '$ZFS $unmountcmd [-f] ' " \ + "with an unmounted filesystem will fail with return code 1." + +log_onexit cleanup + +typeset -i i=0 + +while (( i < ${#options[*]} )); do + do_unmount_multiple "${options[i]}" 1 + ((i = i + 1)) +done + +log_pass "'$ZFS $unmountcmd [-f] ' " \ + "with an unmounted filesystem failed with return code 1." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh new file mode 100644 index 00000000000..43ed06e3fda --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_005_pos.ksh @@ -0,0 +1,127 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_unmount/zfs_unmount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unmount_005_pos +# +# DESCRIPTION: +# If invoke "zfs unmount" with a specific filesystem|mountpoint +# that have been mounted, but it's currently in use, +# it will fail with a return code of 1 +# and issue an error message. +# But unmount forcefully will bypass this restriction and +# unmount that given filesystem successfully. +# +# STRATEGY: +# 1. Make sure that the ZFS filesystem is mounted. +# 2. Change directory to that given mountpoint. +# 3. Unmount the file system using the various combinations. +# - Without force option. (FAILED) +# - With force option. (PASS) +# 4. Unmount the mountpoint using the various combinations. +# - Without force option. (FAILED) +# - With force option. (PASS) +# 5. Verify the above expected results of the filesystem|mountpoint. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A cmd "umount" "unmount" +set -A options "" "-f" +set -A dev "$TESTPOOL/$TESTFS" "$TESTDIR" + +function do_unmount_multiple #options #expect +{ + typeset opt=$1 + typeset -i expect=${2-0} + + typeset -i i=0 + typeset -i j=0 + + while (( i < ${#cmd[*]} )); do + j=0 + while (( j < ${#dev[*]} )); do + mounted ${dev[j]} || \ + log_must $ZFS $mountcmd ${dev[0]} + + cd $TESTDIR || \ + log_unresolved "Unable change dir to $TESTDIR" + + do_unmount "${cmd[i]}" "$opt" \ + "${dev[j]}" $expect + + cleanup + + ((j = j + 1)) + done + + ((i = i + 1)) + done +} + +log_assert "Verify that '$ZFS $unmountcmd ' " \ + "with a filesystem which mountpoint is currently in use " \ + "will fail with return code 1, and forcefully will succeeds as root." + +log_onexit cleanup + +cwd=$PWD + +typeset -i i=0 + +while (( i < ${#options[*]} )); do + if [[ ${options[i]} == "-f" ]]; then + do_unmount_multiple "${options[i]}" + else + do_unmount_multiple "${options[i]}" 1 + fi + ((i = i + 1)) +done + +log_pass "'$ZFS $unmountcmd ' " \ + "with a filesystem which mountpoint is currently in use " \ + "will fail with return code 1, and forcefully will succeeds as root." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh new file mode 100644 index 00000000000..df5a31f4f89 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_006_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_006_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unmount_006_pos +# +# DESCRIPTION: +# Re-creating zfs files, 'zfs unmount' still succeed. +# +# STRATEGY: +# 1. Create pool and filesystem. +# 2. Recreating the same file in this fs for a while, then breaking out. +# 3. Verify the filesystem can be unmount successfully. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if ! ismounted $TESTPOOL/$TESTFS ; then + log_must $ZFS mount $TESTPOOL/$TESTFS + fi +} + +log_assert "Re-creating zfs files, 'zfs unmount' still succeed." +log_onexit cleanup + +# Call cleanup to make sure the file system are mounted. +cleanup +mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS) +(($? != 0)) && log_fail "get_prop mountpoint $TESTPOOL/$TESTFS" + +typeset -i i=0 +while (( i < 10000 )); do + $CP $STF_SUITE/include/libtest.kshlib $mntpnt + + (( i += 1 )) +done +log_note "Recreating zfs files for 10000 times." + +log_must $ZFS unmount $TESTPOOL/$TESTFS + +log_pass "Re-creating zfs files, 'zfs unmount' passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh new file mode 100644 index 00000000000..1bcbcfb6761 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_007_neg.ksh @@ -0,0 +1,124 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_007_neg.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib +. $STF_SUITE/tests/cli_root/zfs_unmount/zfs_unmount.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_unmount_007_neg +# +# DESCRIPTION: +# Try each 'zfs unmount' with inapplicable scenarios to make sure +# it returns an error. include: +# * Multiple filesystem|mountpoint specified +# * '-a', but also with a specific filesystem|mountpoint. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute the sub-command +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +multifs="$TESTFS $TESTFS1" +datasets="" + +for fs in $multifs ; do + datasets="$datasets $TESTPOOL/$fs" +done + +set -A args "$unmountall $TESTPOOL/$TESTFS" \ + "$unmountcmd $datasets" + +function setup_all +{ + typeset fs + + for fs in $multifs ; do + setup_filesystem "$DISKS" "$TESTPOOL" \ + "$fs" \ + "${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID}/$TESTPOOL/$fs" + done + return 0 +} + +function cleanup_all +{ + typeset fs + + cleanup_filesystem "$TESTPOOL" "$TESTFS1" + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + [[ -d ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} ]] && \ + $RM -rf ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} + + return 0 +} + +function verify_all +{ + typeset fs + + for fs in $multifs ; do + log_must mounted $TESTPOOL/$fs + done + return 0 +} + +log_assert "Badly-formed 'zfs $unmountcmd' with inapplicable scenarios " \ + "should return an error." +log_onexit cleanup_all + +log_must setup_all + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZFS ${args[i]} + ((i = i + 1)) +done + +log_must verify_all + +log_pass "Badly formed 'zfs $unmountcmd' with inapplicable scenarios " \ + "fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh new file mode 100644 index 00000000000..ae0564b7c81 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh @@ -0,0 +1,157 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_008_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_unmount_008_neg +# +# DESCRIPTION: +# Verify that zfs unmount should fail with bad parameters or scenarios: +# 1. bad option; +# 2. too many arguments; +# 3. null arguments; +# 4. invalid datasets; +# 5. invalid mountpoint; +# 6. already unmounted zfs filesystem; +# 7. legacy mounted zfs filesystem +# +# STRATEGY: +# 1. Make an array of bad parameters +# 2. Use zfs unmount to unmount the filesystem +# 3. Verify that zfs unmount returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-9) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for ds in $vol $fs1; do + if datasetexists $ds; then + log_must $ZFS destroy -f $ds + fi + done + + if snapexists $snap; then + log_must $ZFS destroy $snap + fi + + if [[ -e $TMPDIR/$file ]]; then + $RM -f $TMPDIR/$file + fi + if [[ -d $TMPDIR/$dir ]]; then + $RM -rf $TMPDIR/$dir + fi + +} + +log_assert "zfs unmount fails with bad parameters or scenarios" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +vol=$TESTPOOL/vol.${TESTCASE_ID} +snap=$TESTPOOL/$TESTFS@snap.${TESTCASE_ID} +set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?" + +if ! ismounted $fs; then + log_must $ZFS mount $fs +fi + +log_must $ZFS snapshot $snap +if is_global_zone; then + log_must $ZFS create -V 10m $vol +else + vol="" +fi + +# Testing bad options +for arg in ${badargs[@]}; do + log_mustnot eval "$ZFS unmount $arg $fs >/dev/null 2>&1" +done + + +#Testing invalid datasets +for ds in $snap $vol "blah"; do + for opt in "" "-f"; do + log_mustnot eval "$ZFS unmount $opt $ds >/dev/null 2>&1" + done +done + +#Testing invalid mountpoint +dir=foodir.${TESTCASE_ID} +file=foo.${TESTCASE_ID} +fs1=$TESTPOOL/fs.${TESTCASE_ID} +$MKDIR $TMPDIR/$dir +$TOUCH $TMPDIR/$file +log_must $ZFS create -o mountpoint=$TMPDIR/$dir $fs1 +curpath=`$DIRNAME $0` +cd $TMPDIR +for mpt in "./$dir" "./$file"; do + for opt in "" "-f"; do + log_mustnot eval "$ZFS unmount $opt $mpt >/dev/null 2>&1" + done +done +cd $curpath + +#Testing null argument and too many arguments +for opt in "" "-f"; do + log_mustnot eval "$ZFS unmount $opt >/dev/null 2>&1" + log_mustnot eval "$ZFS unmount $opt $fs $fs1 >/dev/null 2>&1" +done + +#Testing already unmounted filesystem +log_must $ZFS unmount $fs1 +for opt in "" "-f"; do + log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1" + log_mustnot eval "$ZFS unmount $TMPDIR/$dir >/dev/null 2>&1" +done + +#Testing legacy mounted filesystem +log_must $ZFS set mountpoint=legacy $fs1 +log_must $MOUNT -t zfs $fs1 $TMPDIR/$dir +for opt in "" "-f"; do + log_mustnot eval "$ZFS unmount $opt $fs1 >/dev/null 2>&1" +done +$UMOUNT $TMPDIR/$dir + +log_pass "zfs unmount fails with bad parameters or scenarios as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh new file mode 100644 index 00000000000..0ba9a1f5623 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh @@ -0,0 +1,141 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_009_pos.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_unmount_009_pos +# +# DESCRIPTION: +# Verify that zfs unmount and destroy in a snapshot directory will not cause error. +# +# STRATEGY: +# 1. Create a file in a zfs filesystem, snapshot it and change directory to snapshot directory +# 2. Verify that 'zfs unmount -a' will fail and 'zfs unmount -fa' will succeed +# 3. Verify 'ls' and 'cd /' will succeed +# 4. 'zfs mount -a' and change directory to snapshot directory again +# 5. Verify that zfs destroy snapshot will succeed +# 6. Verify 'ls' and 'cd /' will succeed +# 7. Create zfs filesystem, create a file, snapshot it and change to snapshot directory +# 8. Verify that zpool destroy the pool will succeed +# 9. Verify 'ls' 'cd /' 'zpool list' and etc will succeed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-07-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + DISK=${DISKS%% *} + + for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do + typeset snap=$fs@$TESTSNAP + if snapexists $snap; then + log_must $ZFS destroy $snap + fi + done + + if ! poolexists $TESTPOOL && is_global_zone; then + log_must $ZPOOL create $TESTPOOL $DISK + fi + + if ! datasetexists $TESTPOOL/$TESTFS; then + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + fi +} + +function restore_dataset +{ + if ! datasetexists $TESTPOOL/$TESTFS ; then + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + log_must cd $TESTDIR + $ECHO hello > world + log_must $ZFS snapshot $TESTPOOL/$TESTFS@$TESTSNAP + log_must cd $(get_snapdir_name)/$TESTSNAP + fi +} + + +log_assert "zfs fource unmount and destroy in snapshot directory will not cause error." +log_onexit cleanup + +for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do + typeset snap=$fs@$TESTSNAP + typeset mtpt=$(get_prop mountpoint $fs) + + log_must cd $mtpt + $ECHO hello > world + log_must $ZFS snapshot $snap + log_must cd $(get_snapdir_name)/$TESTSNAP + + log_mustnot $ZFS unmount -a + log_must $ZFS unmount -fa + log_mustnot $LS + log_must cd / + + log_must $ZFS mount -a + log_must cd $mtpt + log_must cd $(get_snapdir_name)/$TESTSNAP + + if is_global_zone || [[ $fs != $TESTPOOL ]] ; then + log_must $ZFS destroy -rf $fs + log_mustnot $LS + log_must cd / + fi + + restore_dataset +done + +if is_global_zone ; then + log_must $ZPOOL destroy -f $TESTPOOL + log_mustnot $LS + log_must cd / +fi + +log_must eval $ZFS list > /dev/null 2>&1 +log_must eval $ZPOOL list > /dev/null 2>&1 +log_must eval $ZPOOL status > /dev/null 2>&1 +$ZPOOL iostat > /dev/null 2>&1 + +log_pass "zfs fource unmount and destroy in snapshot directory will not cause error." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh new file mode 100644 index 00000000000..f06a816c10d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_all_001_pos.ksh @@ -0,0 +1,209 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_all_001_pos.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib +. $STF_SUITE/tests/cli_root/zfs_unmount/zfs_unmount.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_unmount_all_001_pos +# +# DESCRIPTION: +# Verify that 'zfs unmount -a[f]' succeeds as root. +# +# STRATEGY: +# 1. Create a group of pools with specified vdev. +# 2. Create zfs filesystems within the given pools. +# 3. Mount all the filesystems. +# 4. Verify that 'zfs unmount -a[f]' command succeed, +# and all available ZFS filesystems are unmounted. +# 5. Verify that 'zfs mount' is identical with 'df -F zfs' +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A fs "$TESTFS" "$TESTFS1" +set -A ctr "" "$TESTCTR" "$TESTCTR1" "$TESTCTR/$TESTCTR1" +set -A vol "$TESTVOL" "$TESTVOL1" + +function setup_all +{ + typeset -i i=0 + typeset -i j=0 + typeset path + + while (( i < ${#ctr[*]} )); do + + path=${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID}/$TESTPOOL + if [[ -n ${ctr[i]} ]]; then + path=$path/${ctr[i]} + + setup_filesystem "$DISKS" "$TESTPOOL" \ + "${ctr[i]}" "$path" \ + "ctr" + fi + + if is_global_zone ; then + j=0 + while (( j < ${#vol[*]} )); do + setup_filesystem "$DISKS" "$TESTPOOL" \ + "${ctr[i]}/${vol[j]}" \ + "$path/${vol[j]}" \ + "vol" + ((j = j + 1)) + done + fi + j=0 + while (( j < ${#fs[*]} )); do + setup_filesystem "$DISKS" "$TESTPOOL" \ + "${ctr[i]}/${fs[j]}" \ + "$path/${fs[j]}" + ((j = j + 1)) + done + + ((i = i + 1)) + done + + return 0 +} + +function cleanup_all +{ + typeset -i i=0 + typeset -i j=0 + + ((i = ${#ctr[*]} - 1)) + + while (( i >= 0 )); do + if is_global_zone ; then + j=0 + while (( j < ${#vol[*]} )); do + cleanup_filesystem "$TESTPOOL" \ + "${ctr[i]}/${vol[j]}" + ((j = j + 1)) + done + fi + + j=0 + while (( j < ${#fs[*]} )); do + cleanup_filesystem "$TESTPOOL" \ + "${ctr[i]}/${fs[j]}" + ((j = j + 1)) + done + + [[ -n ${ctr[i]} ]] && \ + cleanup_filesystem "$TESTPOOL" "${ctr[i]}" + + ((i = i - 1)) + done + + [[ -d ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} ]] && \ + $RM -rf ${TEST_BASE_DIR%%/}/testroot${TESTCASE_ID} +} + +function verify_all +{ + typeset -i i=0 + typeset -i j=0 + typeset path + + while (( i < ${#ctr[*]} )); do + + path=$TESTPOOL + [[ -n ${ctr[i]} ]] && \ + path=$path/${ctr[i]} + + if is_global_zone ; then + j=0 + while (( j < ${#vol[*]} )); do + log_must unmounted "$path/${vol[j]}" + ((j = j + 1)) + done + fi + + j=0 + while (( j < ${#fs[*]} )); do + log_must unmounted "$path/${fs[j]}" + ((j = j + 1)) + done + + log_must unmounted "$path" + + ((i = i + 1)) + done + + return 0 +} + + +log_assert "Verify that 'zfs $unmountall' succeeds as root, " \ + "and all available ZFS filesystems are unmounted." + +log_onexit cleanup_all + +log_must setup_all + +typeset opt +for opt in "-a" "-fa"; do + log_must $ZFS $mountall + + if [[ $opt == "-fa" ]]; then + mntpnt=$(get_prop mountpoint ${TESTPOOL}/${TESTCTR}/${TESTFS}) + cd $mntpnt + log_mustnot $ZFS unmount -a + fi + + log_must $ZFS unmount $opt + + if [[ $opt == "-fa" ]]; then + cd /tmp + fi + + log_must verify_all + log_note "Verify that 'zfs $mountcmd' will display " \ + "all ZFS filesystems currently mounted." + log_must verify_mount_display + +done + +log_pass "'zfs mount -[f]a' succeeds as root, " \ + "and all available ZFS filesystems are unmounted." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_test.sh new file mode 100755 index 00000000000..ce2a85b8934 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unmount/zfs_unmount_test.sh @@ -0,0 +1,310 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_unmount_001_pos cleanup +zfs_unmount_001_pos_head() +{ + atf_set "descr" "Verify the u[n]mount [-f] sub-command." + atf_set "require.progs" zfs +} +zfs_unmount_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_002_pos cleanup +zfs_unmount_002_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $unmountcmd [-f] 'whose name is not in 'zfs list' will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_unmount_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_003_pos cleanup +zfs_unmount_003_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $unmountcmd [-f] 'whose mountpoint property is 'legacy' or 'none' \will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_unmount_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_004_pos cleanup +zfs_unmount_004_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $unmountcmd [-f] 'with an unmounted filesystem will fail with return code 1." + atf_set "require.progs" zfs +} +zfs_unmount_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_005_pos cleanup +zfs_unmount_005_pos_head() +{ + atf_set "descr" "Verify that '$ZFS $unmountcmd 'with a filesystem which mountpoint is currently in use \will fail with return code 1, and forcefully will succeeds as root." + atf_set "require.progs" zfs +} +zfs_unmount_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_006_pos cleanup +zfs_unmount_006_pos_head() +{ + atf_set "descr" "Re-creating zfs files, 'zfs unmount' still succeed." + atf_set "require.progs" zfs +} +zfs_unmount_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_007_neg cleanup +zfs_unmount_007_neg_head() +{ + atf_set "descr" "Badly-formed 'zfs $unmountcmd' with inapplicable scenariosshould return an error." + atf_set "require.progs" zfs +} +zfs_unmount_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_unmount_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_008_neg cleanup +zfs_unmount_008_neg_head() +{ + atf_set "descr" "zfs unmount fails with bad parameters or scenarios" + atf_set "require.progs" zfs +} +zfs_unmount_008_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_008_neg.ksh || atf_fail "Testcase failed" +} +zfs_unmount_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_009_pos cleanup +zfs_unmount_009_pos_head() +{ + atf_set "descr" "zfs fource unmount and destroy in snapshot directory will not cause error." + atf_set "require.progs" zfs zpool +} +zfs_unmount_009_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_009_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_all_001_pos cleanup +zfs_unmount_all_001_pos_head() +{ + atf_set "descr" "Verify that 'zfs $unmountall' succeeds as root,and all available ZFS filesystems are unmounted." + atf_set "require.progs" zfs +} +zfs_unmount_all_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_all_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_unmount_all_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unmount.kshlib + . $(atf_get_srcdir)/zfs_unmount.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_unmount_001_pos + atf_add_test_case zfs_unmount_002_pos + atf_add_test_case zfs_unmount_003_pos + atf_add_test_case zfs_unmount_004_pos + atf_add_test_case zfs_unmount_005_pos + atf_add_test_case zfs_unmount_006_pos + atf_add_test_case zfs_unmount_007_neg + atf_add_test_case zfs_unmount_008_neg + atf_add_test_case zfs_unmount_009_pos + atf_add_test_case zfs_unmount_all_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/Makefile new file mode 100644 index 00000000000..bd58561f438 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_unshare +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_unshare_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_unshare_003_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_unshare_002_pos.ksh +${PACKAGE}FILES+= zfs_unshare.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_unshare_005_neg.ksh +${PACKAGE}FILES+= zfs_unshare_001_pos.ksh +${PACKAGE}FILES+= zfs_unshare_004_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/setup.ksh new file mode 100644 index 00000000000..3bc69250e30 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# Make sure NFS server is running before testing. +setup_nfs_server + +DISK=${DISKS%% *} +default_container_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare.cfg new file mode 100644 index 00000000000..871d4a1592d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unshare.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export NONEXISTFSNAME="nonexistfs50charslong_0123456789012345678901234567" +export NONEXISTMOUNTPOINT="/nonexistmountpoint_0123456789" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh new file mode 100644 index 00000000000..2dc4f5a24c3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh @@ -0,0 +1,195 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unshare_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unshare_001_pos +# +# DESCRIPTION: +# Verify that 'zfs unshare ' unshares a given shared +# filesystem. +# +# STRATEGY: +# 1. Share filesystems +# 2. Invoke 'zfs unshare ' to unshare zfs file system +# 3. Verify that the file system is unshared +# 4. Verify that unsharing an unshared file system fails +# 5. Verify that "zfs unshare -a" succeeds to unshare all zfs file systems. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset -i i=0 + while (( i < ${#mntp_fs[*]} )); do + log_must $ZFS set sharenfs=off ${mntp_fs[((i+1))]} + + ((i = i + 2)) + done + + if mounted $TESTPOOL/$TESTCLONE; then + log_must $ZFS unmount $TESTDIR2 + fi + + [[ -d $TESTDIR2 ]] && \ + log_must $RM -rf $TESTDIR2 + + if datasetexists "$TESTPOOL/$TESTCLONE"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE + fi + + if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot + fi + + if datasetexists "$TESTPOOL/$TESTFS2"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS2 + fi +} + +# +# Main test routine. +# +# Given a mountpoint and file system this routine will attempt +# unshare the filesystem via argument +# and then verify it has been unshared. +# +function test_unshare # +{ + typeset mntp=$1 + typeset filesystem=$2 + typeset prop_value + + prop_value=$(get_prop "sharenfs" $filesystem) + + if [[ $prop_value == "off" ]]; then + not_shared $mntp || + log_must $UNSHARE -F nfs $mntp + log_must $ZFS set sharenfs=on $filesystem + is_shared $mntp || \ + log_fail "'$ZFS set sharenfs=on' fails to make" \ + "file system $filesystem shared." + fi + + is_shared $mntp || \ + log_must $ZFS share $filesystem + + # + # Verify 'zfs unshare ' works as well. + # + log_must $ZFS unshare $filesystem + not_shared $mntp || \ + log_fail "'zfs unshare ' fails" + + log_must $ZFS share $filesystem + + log_must $ZFS unshare $mntp + not_shared $mntp || \ + log_fail "'zfs unshare ' fails" + + log_note "Unsharing an unshared file system fails." + log_mustnot $ZFS unshare $filesystem + log_mustnot $ZFS unshare $mntp +} + + +set -A mntp_fs \ + "$TESTDIR" "$TESTPOOL/$TESTFS" \ + "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTDIR2" "$TESTPOOL/$TESTCLONE" + +log_assert "Verify that 'zfs unshare [-a] ' succeeds as root." +log_onexit cleanup + +log_must $ZFS create $TESTPOOL/$TESTFS2 +log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot +log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE +log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE + +# +# Invoke 'test_unshare' routine to test 'zfs unshare '. +# +typeset -i i=0 +while (( i < ${#mntp_fs[*]} )); do + test_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]} + + ((i = i + 2)) +done + +log_note "Verify '$ZFS unshare -a' succeds as root." + +i=0 +typeset sharenfs_val +while (( i < ${#mntp_fs[*]} )); do + sharenfs_val=$(get_prop "sharenfs" ${mntp_fs[((i+1))]}) + if [[ $sharenfs_val == "on" ]]; then + not_shared ${mntp_fs[i]} && \ + log_must $ZFS share ${mntp_fs[((i+1))]} + else + log_must $ZFS set sharenfs=on ${mntp_fs[((i+1))]} + is_shared ${mntp_fs[i]} || \ + log_fail "'$ZFS set sharenfs=on' fails to share filesystem." + fi + + ((i = i + 2)) +done + +# +# test 'zfs unshare -a ' +# +log_must $ZFS unshare -a + +# +# verify all shared filesystems become unshared +# +i=0 +while (( i < ${#mntp_fs[*]} )); do + not_shared ${mntp_fs[i]} || \ + log_fail "'$ZFS unshare -a' fails to unshare all shared zfs filesystems." + + ((i = i + 2)) +done + +log_pass "'$ZFS unshare [-a] ' succeeds as root." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh new file mode 100644 index 00000000000..b728595c636 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh @@ -0,0 +1,194 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unshare_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unshare_002_pos +# +# DESCRIPTION: +# Verify that 'zfs unshare [-a] ' is aware of legacy share. +# +# STRATEGY: +# 1. Set 'zfs set sharenfs=off' +# 2. Use 'share' to share given filesystem +# 3. Verify that 'zfs unshare ' is aware of legacy share +# 4. Verify that 'zfs unshare -a' is aware of legacy share. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-28) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset -i i=0 + while (( i < ${#mntp_fs[*]} )); do + is_shared ${mntp_fs[i]} && \ + log_must $UNSHARE -F nfs ${mntp_fs[i]} + + ((i = i + 2)) + done + + if mounted $TESTPOOL/$TESTCLONE; then + log_must $ZFS unmount $TESTDIR2 + fi + + [[ -d $TESTDIR2 ]] && \ + log_must $RM -rf $TESTDIR2 + + if datasetexists "$TESTPOOL/$TESTCLONE"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTCLONE + fi + + if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS2@snapshot + fi + + if datasetexists "$TESTPOOL/$TESTFS2"; then + log_must $ZFS destroy -f $TESTPOOL/$TESTFS2 + fi +} + +# +# Main test routine. +# +# Given a mountpoint and file system this routine will attempt +# to verify 'zfs unshare' is aware of legacy share. +# +function test_legacy_unshare # +{ + typeset mntp=$1 + typeset filesystem=$2 + + log_must $ZFS set sharenfs=off $filesystem + not_shared $mntp || \ + log_fail "'zfs set sharenfs=off' fails to make ZFS filesystem $filesystem unshared." + + log_must $SHARE -F nfs $mntp + is_shared $mntp || \ + log_fail "'share' command fails to share ZFS file system." + # + # Verify 'zfs unshare ' is aware of legacy share. + # + log_mustnot $ZFS unshare $filesystem + is_shared $mntp || \ + log_fail "'zfs unshare ' fails to be aware" \ + "of legacy share." + + # + # Verify 'zfs unshare ' is aware of legacy share. + # + log_mustnot $ZFS unshare $mntp + is_shared $mntp || \ + log_fail "'zfs unshare ' fails to be aware" \ + "of legacy share." +} + + +set -A mntp_fs \ + "$TESTDIR" "$TESTPOOL/$TESTFS" \ + "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTDIR2" "$TESTPOOL/$TESTCLONE" + +log_assert "Verify that 'zfs unshare [-a]' is aware of legacy share." +log_onexit cleanup + +log_must $ZFS create $TESTPOOL/$TESTFS2 +log_must $ZFS snapshot $TESTPOOL/$TESTFS2@snapshot +log_must $ZFS clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE +log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE + +# +# Invoke 'test_legacy_unshare' routine to verify. +# +typeset -i i=0 +while (( i < ${#mntp_fs[*]} )); do + test_legacy_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]} + + ((i = i + 2)) +done + + +log_note "Verify '$ZFS unshare -a' is aware of legacy share." + +# +# set the 'sharenfs' property to 'off' for each filesystem +# +i=0 +while (( i < ${#mntp_fs[*]} )); do + log_must $ZFS set sharenfs=off ${mntp_fs[((i + 1))]} + not_shared ${mntp_fs[i]} || \ + log_fail "'$ZFS set sharenfs=off' unshares file system failed." + + ((i = i + 2)) +done + +# +# Share each of the file systems via legacy share. +# +i=0 +while (( i < ${#mntp_fs[*]} )); do + $SHARE -F nfs ${mntp_fs[i]} + is_shared ${mntp_fs[i]} || \ + log_fail "'$SHARE' shares ZFS filesystem failed." + + ((i = i + 2)) +done + +# +# Verify that 'zfs unshare -a' is aware of legacy share +# +log_must $ZFS unshare -a + +# +# verify ZFS filesystems are still shared +# +i=0 +while (( i < ${#mntp_fs[*]} )); do + is_shared ${mntp_fs[i]} || \ + log_fail "'$ZFS unshare -a' fails to be aware of legacy share." + + ((i = i + 2)) +done + +log_pass "'$ZFS unshare [-a]' succeeds to be aware of legacy share." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh new file mode 100644 index 00000000000..a01e30a6f3d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unshare_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unshare_003_pos +# +# DESCRIPTION: +# Verify that a file system and its dependent are unshared when turn off sharenfs +# property. +# +# STRATEGY: +# 1. Create a file system +# 2. Set the sharenfs property on the file system +# 3. Create a snapshot +# 4. Verify that both are shared +# 5. Turn off the sharenfs property +# 6. Verify that both are unshared. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if snapexists $TESTPOOL/$TESTFS@snapshot; then + log_must $ZFS destroy $TESTPOOL/$TESTFS@snapshot + fi + + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS +} + +# +# Main test routine. +# +# Given a mountpoint and file system this routine will attempt +# unshare the mountpoint and then verify a snapshot of the mounpoint +# is also unshared. +# +function test_snap_unshare # +{ + typeset mntp=$1 + typeset filesystem=$2 + typeset prop_value + + prop_value=$(get_prop "sharenfs" $filesystem) + + if [[ $prop_value == "off" ]]; then + is_shared $mntp || \ + $UNSHARE -F nfs $mntp + log_must $ZFS set sharenfs=on $filesystem + fi + + log_must $ZFS set sharenfs=off $filesystem + + not_shared $mntp || \ + log_fail "File system $filesystem is shared (set sharenfs)." + + not_shared $mntp@snapshot || \ + log_fail "Snapshot $mntpt@snapshot is shared (set sharenfs)." +} + +log_assert "Verify that a file system and its dependent are unshared." +log_onexit cleanup + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot +test_snap_unshare $TESTDIR $TESTPOOL/$TESTFS + +log_pass "A file system and its dependent are both unshared as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh new file mode 100644 index 00000000000..3e39a8a976a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_004_neg.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unshare_004_neg.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unshare_004_neg +# +# DESCRIPTION: +# Verify that "zfs unshare" issue error message with badly formed parameter. +# +# STRATEGY: +# 1. Define badly formed parameters +# 2. Invoke 'zfs unshare' +# 3. Verify that unshare fails and issue error message. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A opts "" "$TESTPOOL/$NONEXISTFSNAME" "$NONEEXISTMOUNTPOINT" "-?" "-1" \ + "-a blah" "$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS1" \ + "-f $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS1" \ + "$TESTPOOL/$TESTFS $TESTDIR" "-f $TESTPOOL/$TESTFS $TESTDIR" \ + "${TESTDIR#/}" "-f ${TESTDIR#/}" + +log_assert "Verify that '$ZFS unshare' issue error message with badly formed parameter." + +shareval=$(get_prop sharenfs $TESTPOOL/$TESTFS) +if [[ $shareval == off ]]; then + log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS +fi + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZFS unshare ${args[i]} + + ((i = i + 1)) +done + +#Testing that unsharing unshared filesystem fails. +mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS) +log_must $ZFS unshare $TESTPOOL/$TESTFS +for opt in "" "-f"; do + log_mustnot eval "$ZFS unshare $opt $TESTPOOL/$TESTFS >/dev/null 2>&1" + log_mustnot eval "$ZFS unshare $opt $mpt >/dev/null 2>&1" +done + +#Testing zfs unshare fails with legacy share set +log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS +for opt in "" "-f"; do + log_mustnot eval "$ZFS unshare $opt $TESTPOOL/$TESTFS >/dev/null 2>&1" + log_mustnot eval "$ZFS unshare $opt $mpt >/dev/null 2>&1" +done + +log_pass "'$ZFS unshare' fails as expected with badly-formed parameters." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh new file mode 100644 index 00000000000..4f220b2ca56 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_005_neg.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unshare_005_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unshare_005_neg +# +# DESCRIPTION: +# Verify that unsharing a dataset and mountpoint other than filesystem fails. +# +# STRATEGY: +# 1. Create a volume, dataset other than a ZFS file system +# 2. Verify that the datasets other than file system are not support by 'zfs unshare'. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A datasets \ + "$TESTPOOL" "$ZFSROOT/$TESTPOOL" \ + "$TESTPOOL/$TESTCTR" "$ZFSROOT/$TESTPOOL/$TESTCTR" \ + "$TESTPOOL/$TESTVOL" "/dev/zvol/$TESTPOOL/$TESTVOL" + +log_assert "Verify that unsharing a dataset other than filesystem fails." + +typeset -i i=0 +while (( i < ${#datasets[*]} )) +do + log_mustnot $ZFS unshare ${datasets[i]} + + ((i = i + 1)) +done + +log_pass "Unsharing datasets other than filesystem failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_test.sh new file mode 100755 index 00000000000..1499b9e5382 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_unshare/zfs_unshare_test.sh @@ -0,0 +1,152 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_unshare_001_pos cleanup +zfs_unshare_001_pos_head() +{ + atf_set "descr" "Verify that 'zfs unshare [-a] ' succeeds as root." + atf_set "require.progs" zfs unshare svcs +} +zfs_unshare_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unshare_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_unshare_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unshare_002_pos cleanup +zfs_unshare_002_pos_head() +{ + atf_set "descr" "Verify that 'zfs unshare [-a]' is aware of legacy share." + atf_set "require.progs" zfs unshare share svcs +} +zfs_unshare_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unshare_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_unshare_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unshare_003_pos cleanup +zfs_unshare_003_pos_head() +{ + atf_set "descr" "Verify that a file system and its dependent are unshared." + atf_set "require.progs" zfs unshare svcs +} +zfs_unshare_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unshare_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_unshare_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unshare_004_neg cleanup +zfs_unshare_004_neg_head() +{ + atf_set "descr" "Verify that '$ZFS unshare' issue error message with badly formed parameter." + atf_set "require.progs" zfs svcs +} +zfs_unshare_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unshare_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_unshare_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unshare_005_neg cleanup +zfs_unshare_005_neg_head() +{ + atf_set "descr" "Verify that unsharing a dataset other than filesystem fails." + atf_set "require.progs" zfs svcs +} +zfs_unshare_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unshare_005_neg.ksh || atf_fail "Testcase failed" +} +zfs_unshare_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_unshare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_unshare_001_pos + atf_add_test_case zfs_unshare_002_pos + atf_add_test_case zfs_unshare_003_pos + atf_add_test_case zfs_unshare_004_neg + atf_add_test_case zfs_unshare_005_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/Makefile new file mode 100644 index 00000000000..e0ca28b6e1a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/Makefile @@ -0,0 +1,25 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zfs_upgrade +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_upgrade_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_upgrade.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zfs_upgrade_004_pos.ksh +${PACKAGE}FILES+= zfs_upgrade_001_pos.ksh +${PACKAGE}FILES+= zfs_upgrade_005_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_upgrade.kshlib +${PACKAGE}FILES+= zfs_upgrade_006_neg.ksh +${PACKAGE}FILES+= zfs_upgrade_003_pos.ksh +${PACKAGE}FILES+= zfs_upgrade_007_neg.ksh +${PACKAGE}FILES+= zfs_upgrade_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/cleanup.ksh new file mode 100644 index 00000000000..7789fef5acb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/10/09 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "both" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/setup.ksh new file mode 100644 index 00000000000..8eaae20b636 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/setup.ksh @@ -0,0 +1,46 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 07/10/09 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +# This should have been set by the .cfg script - verify it's set to something +# (we check that something later on) +if [ -z "$ZFS_VERSION" ] +then + log_unresolved "Unable to determine ZFS Filesystem version of this machine" +else + log_note "This machine is running ZFS Filesystem version $ZFS_VERSION" +fi + +default_setup "$DISK" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade.cfg b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade.cfg new file mode 100644 index 00000000000..1cc5d1a071e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib new file mode 100644 index 00000000000..b0c31a6fb2f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib @@ -0,0 +1,196 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade.kshlib 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# For zfs create. +# When pool version is 15, fs whose version is 4 can be created. +# +set -A zpl_create_versions 3 4 5 +set -A spa_create_versions 9 15 24 + +# +# For zfs upgrade +# +set -A zpl_upgrade_versions 3 4 5 +set -A spa_upgrade_versions 9 15 24 + +function get_pool_version #pool +{ + typeset pool=$1 + typeset vs=$(get_pool_prop version $pool) + if [ "$vs" = "-" ]; then + echo 5000 + else + echo "$vs" + fi +} + +function default_setup_datasets #rootfs +{ + typeset rootfs=$1 + typeset pool=${rootfs%%/*} + typeset -i vp=$(get_pool_version $pool) + typeset -i version + typeset -i m + typeset -i spa_version + typeset -i zpl_version + + for version in $ZFS_ALL_VERSIONS ; do + typeset verfs + eval verfs=\$ZFS_VERSION_$version + typeset current_fs=$rootfs/$verfs + typeset current_snap=${current_fs}@snap + typeset current_clone=$rootfs/clone$verfs + + (( m=0 )) + (( spa_version=0 )) + while (( m < ${#zpl_create_versions[@]} )); do + (( zpl_version=${zpl_create_versions[m]} )) + if (( version == zpl_version )); then + (( spa_version=${spa_create_versions[m]} )) + break + fi + (( m+=1 )) + done + if (( spa_version != 0 )) && (( vp < spa_version )); then + log_mustnot $ZFS create -o version=${version} ${current_fs} + continue + fi + log_must $ZFS create -o version=${version} ${current_fs} + log_must $ZFS snapshot ${current_snap} + log_must $ZFS clone ${current_snap} ${current_clone} + + for subversion in $ZFS_ALL_VERSIONS ; do + typeset subverfs + eval subverfs=\$ZFS_VERSION_$subversion + + (( m=0 )) + (( spa_version=0 )) + while (( m < ${#zpl_create_versions[@]} )); do + (( zpl_version=${zpl_create_versions[m]} )) + if (( subversion == zpl_version )); then + (( spa_version=${spa_create_versions[m]} )) + break + fi + (( m+=1 )) + done + if (( spa_version != 0 )) && (( vp < spa_version )); then + log_mustnot $ZFS create -o \ + version=${subversion} ${current_fs}/$subverfs + else + log_must $ZFS create -o \ + version=${subversion} ${current_fs}/$subverfs + fi + done + done +} + +function default_cleanup_datasets #rootfs +{ + typeset rootfs=$1 + + if datasetexists $rootfs ; then + log_must $ZFS destroy -Rf $rootfs + fi + + if datasetnonexists $rootfs ; then + log_must $ZFS create $rootfs + fi +} + +function default_check_zfs_upgrade #rootfs +{ + typeset rootfs=$1 + typeset pool=${rootfs%%/*} + typeset -i vp="$(get_pool_version $pool)" + typeset -i m + typeset -i spa_version + typeset -i zpl_version + typeset newv + typeset -i df_ret + + $DF -t zfs / > /dev/null 2>&1 + df_ret=$? + + for newv in "" $ZFS_VERSION; do + default_setup_datasets $rootfs + if [[ -n $newv ]]; then + opt="-V $newv" + else + newv=$ZFS_VERSION + fi + + (( m=0 )) + (( spa_version=0 )) + while (( m < ${#zpl_upgrade_versions[@]} )); do + (( zpl_version=${zpl_upgrade_versions[m]} )) + if (( newv == zpl_version )); then + (( spa_version=${spa_upgrade_versions[m]} )) + break + fi + (( m+=1 )) + done + + if (( df_ret != 0 )); then + if (( spa_version != 0 )) && (( vp < spa_version )); then + log_mustnot eval '$ZFS upgrade $opt -a > /dev/null 2>&1' + log_must eval '$ZPOOL upgrade $pool > /dev/null 2>&1' + vp="$(get_pool_version $pool)" + fi + + log_must eval '$ZFS upgrade $opt -a > /dev/null 2>&1' + + for fs in $($ZFS list -rH -t filesystem -o name $rootfs) ; do + log_must check_fs_version $fs $newv + done + fi + + default_cleanup_datasets $rootfs + done +} + +function check_fs_version #filesystem version +{ + typeset fs=$1 + typeset -i version=${2:-$ZFS_VERSION} + + if [[ -z $fs ]]; then + log_fail "No filesystem specified." + fi + + typeset -i curv=$(get_prop version $fs) + if (( curv != version )); then + return 1 + fi + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh new file mode 100644 index 00000000000..1763c784819 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh @@ -0,0 +1,154 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_001_pos.ksh 1.2 08/08/15 SMI" +# +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_upgrade_001_pos +# +# DESCRIPTION: +# Executing 'zfs upgrade' command succeeds, it should report +# the current system version and list all old-version filesystems. +# If no old-version filesystems be founded, it prints out +# "All filesystems are formatted with the current version." +# +# STRATEGY: +# 1. Prepare a set of datasets which contain old-version and current version. +# 2. Execute 'zfs upgrade', verify return 0, and it prints out +# the current system version and list all old-version filesystems. +# 3. Remove all old-version filesystems, then execute 'zfs upgrade' again, +# verify return 0, and get the expected message. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $rootfs ; then + log_must $ZFS destroy -Rf $rootfs + fi + log_must $ZFS create $rootfs + + for file in $output $oldoutput ; do + if [[ -f $file ]]; then + log_must $RM -f $file + fi + done +} + +log_assert "Executing 'zfs upgrade' command succeeds." +log_onexit cleanup + +rootfs=$TESTPOOL/$TESTFS +typeset output=$TMPDIR/zfs-versions.${TESTCASE_ID} +typeset oldoutput=$TMPDIR/zfs-versions-old.${TESTCASE_ID} +typeset expect_str1="This system is currently running ZFS filesystem version" +typeset expect_str2="All filesystems are formatted with the current version" +typeset expect_str3="The following filesystems are out of date, and can be upgraded" +typeset -i COUNT OLDCOUNT + +$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $oldoutput +OLDCOUNT=$( $WC -l $oldoutput | $AWK '{print $1}' ) + +old_datasets="" +for version in $ZFS_ALL_VERSIONS ; do + typeset verfs + eval verfs=\$ZFS_VERSION_$version + typeset current_fs=$rootfs/$verfs + typeset current_snap=${current_fs}@snap + typeset current_clone=$rootfs/clone$verfs + log_must $ZFS create -o version=${version} ${current_fs} + log_must $ZFS snapshot ${current_snap} + log_must $ZFS clone ${current_snap} ${current_clone} + + if (( version != $ZFS_VERSION )); then + old_datasets="$old_datasets ${current_fs} ${current_clone}" + fi +done + +if is_global_zone; then + log_must $ZFS create -V 100m $rootfs/$TESTVOL +fi + +log_must eval '$ZFS upgrade > $output 2>&1' + +# we also check that the usage message contains at least a description +# of the current ZFS version. +log_must eval '$GREP "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1' +$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $output +COUNT=$( $WC -l $output | $AWK '{print $1}' ) + +typeset -i i=0 +for fs in ${old_datasets}; do + log_must $GREP "^$fs$" $output + (( i = i + 1 )) +done + +if (( i != COUNT - OLDCOUNT )); then + $CAT $output + log_fail "More old-version filesystems print out than expect." +fi + +for fs in $old_datasets ; do + if datasetexists $fs ; then + log_must $ZFS destroy -Rf $fs + fi +done + +log_must eval '$ZFS upgrade > $output 2>&1' +log_must eval '$GREP "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1' +if (( OLDCOUNT == 0 )); then + log_must eval '$GREP "${expect_str2}" $output > /dev/null 2>&1' +else + log_must eval '$GREP "${expect_str3}" $output > /dev/null 2>&1' +fi +$ZFS upgrade | $NAWK '$1 ~ "^[0-9]+$" {print $2}'> $output +COUNT=$( $WC -l $output | $AWK '{print $1}' ) + +if (( COUNT != OLDCOUNT )); then + $CAT $output + log_fail "Unexpect old-version filesystems print out." +fi + +log_pass "Executing 'zfs upgrade' command succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh new file mode 100644 index 00000000000..ba9fb352412 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_002_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_002_pos.ksh 1.1 07/10/09 SMI" +# +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_upgrade_002_pos +# +# DESCRIPTION: +# Executing 'zfs upgrade -v ' command succeeds, it should +# show the info of available versions. +# +# STRATEGY: +# 1. Execute 'zfs upgrade -v', verify return value is 0. +# 2, Verify all the available versions info are printed out. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if [[ -f $output ]]; then + log_must $RM -f $output + fi +} + +log_assert "Executing 'zfs upgrade -v' command succeeds." +log_onexit cleanup + +typeset output=$TMPDIR/zfs-versions.${TESTCASE_ID} +typeset expect_str1="Initial ZFS filesystem version" +typeset expect_str2="Enhanced directory entries" + +log_must eval '$ZFS upgrade -v > /dev/null 2>&1' + +$ZFS upgrade -v | $NAWK '$1 ~ "^[0-9]+$" {print $0}'> $output +log_must eval '$GREP "${expect_str1}" $output > /dev/null 2>&1' +log_must eval '$GREP "${expect_str2}" $output > /dev/null 2>&1' + +log_pass "Executing 'zfs upgrade -v' command succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh new file mode 100644 index 00000000000..725293219bd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh @@ -0,0 +1,118 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_003_pos.ksh 1.2 09/06/22 SMI" +# +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_upgrade_003_pos +# +# DESCRIPTION: +# Executing 'zfs upgrade [-V version] filesystem' command succeeds, +# it could upgrade a filesystem to specific version or current version. +# +# STRATEGY: +# 1. Prepare a set of datasets which contain old-version and current version. +# 2. Execute 'zfs upgrade [-V version] filesystem', verify return 0, +# 3. Verify the filesystem be updated as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $rootfs ; then + log_must $ZFS destroy -Rf $rootfs + fi + log_must $ZFS create $rootfs +} + +function setup_datasets +{ + datasets="" + for version in $ZFS_ALL_VERSIONS ; do + typeset verfs + eval verfs=\$ZFS_VERSION_$version + typeset current_fs=$rootfs/$verfs + typeset current_snap=${current_fs}@snap + typeset current_clone=$rootfs/clone$verfs + log_must $ZFS create -o version=${version} ${current_fs} + log_must $ZFS snapshot ${current_snap} + log_must $ZFS clone ${current_snap} ${current_clone} + datasets="$datasets ${current_fs} ${current_clone}" + done +} + +log_assert "Executing 'zfs upgrade [-V version] filesystem' command succeeds." +log_onexit cleanup + +rootfs=$TESTPOOL/$TESTFS +typeset datasets + +typeset newv +for newv in "" "current" $ZFS_ALL_VERSIONS; do + setup_datasets + for fs in $datasets ; do + typeset -i oldv=$(get_prop version $fs) + + if [[ -n $newv ]]; then + opt="-V $newv" + if [[ $newv == current ]]; then + newv=$ZFS_VERSION + fi + else + newv=$ZFS_VERSION + fi + + if (( newv >= oldv )); then + log_must eval '$ZFS upgrade $opt $fs > /dev/null 2>&1' + log_must check_fs_version $fs $newv + else + log_mustnot eval '$ZFS upgrade $opt $fs > /dev/null 2>&1' + log_must check_fs_version $fs $oldv + fi + done + cleanup +done + +log_pass "Executing 'zfs upgrade [-V version] filesystem' command succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh new file mode 100644 index 00000000000..687adc2f6ef --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh @@ -0,0 +1,122 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_004_pos.ksh 1.2 09/06/22 SMI" +# +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_upgrade_004_pos +# +# DESCRIPTION: +# Executing 'zfs upgrade -r [-V version] filesystem' command succeeds, +# it upgrade filesystem recursively to specific or current version. +# +# STRATEGY: +# 1. Prepare a set of datasets which contain old-version and current version. +# 2. Execute 'zfs upgrade -r [-V version] filesystem', verify return 0, +# 3. Verify the filesystem be updated recursively as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $rootfs ; then + log_must $ZFS destroy -Rf $rootfs + fi + log_must $ZFS create $rootfs +} + +function setup_datasets +{ + datasets="" + for version in $ZFS_ALL_VERSIONS ; do + typeset verfs + eval verfs=\$ZFS_VERSION_$version + typeset current_fs=$rootfs/$verfs + typeset current_snap=${current_fs}@snap + typeset current_clone=$rootfs/clone$verfs + log_must $ZFS create -o version=${version} ${current_fs} + log_must $ZFS snapshot ${current_snap} + log_must $ZFS clone ${current_snap} ${current_clone} + + for subversion in $ZFS_ALL_VERSIONS ; do + typeset subverfs + eval subverfs=\$ZFS_VERSION_$subversion + log_must $ZFS create -o version=${subversion} \ + ${current_fs}/$subverfs + done + datasets="$datasets ${current_fs}" + done +} + +log_assert "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds." +log_onexit cleanup + +rootfs=$TESTPOOL/$TESTFS + +typeset datasets + +typeset newv +for newv in "" "current" $ZFS_VERSION; do + setup_datasets + for topfs in $datasets ; do + if [[ -n $newv ]]; then + opt="-V $newv" + if [[ $newv == current ]]; then + newv=$ZFS_VERSION + fi + else + newv=$ZFS_VERSION + fi + + log_must eval '$ZFS upgrade -r $opt $topfs > /dev/null 2>&1' + + for fs in $($ZFS list -rH -t filesystem -o name $topfs) ; do + log_must check_fs_version $fs $newv + done + done + cleanup +done + +log_pass "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh new file mode 100644 index 00000000000..7d50b9960d4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh @@ -0,0 +1,126 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_005_pos.ksh 1.3 09/06/22 SMI" +# +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_upgrade_005_pos +# +# DESCRIPTION: +# Executing 'zfs upgrade [-V version] -a' command succeeds, +# it upgrade all filesystems to specific or current version. +# +# STRATEGY: +# 1. Prepare a set of datasets which contain old-version and current version. +# 2. Execute 'zfs upgrade [-V version] -a', verify return 0, +# 3. Verify all the filesystems be updated as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $rootfs ; then + log_must $ZFS destroy -Rf $rootfs + fi + log_must $ZFS create $rootfs +} + +function setup_datasets +{ + datasets="" + for version in $ZFS_ALL_VERSIONS ; do + typeset verfs + eval verfs=\$ZFS_VERSION_$version + typeset current_fs=$rootfs/$verfs + typeset current_snap=${current_fs}@snap + typeset current_clone=$rootfs/clone$verfs + log_must $ZFS create -o version=${version} ${current_fs} + log_must $ZFS snapshot ${current_snap} + log_must $ZFS clone ${current_snap} ${current_clone} + + for subversion in $ZFS_ALL_VERSIONS ; do + typeset subverfs + eval subverfs=\$ZFS_VERSION_$subversion + log_must $ZFS create -o version=${subversion} \ + ${current_fs}/$subverfs + done + datasets="$datasets ${current_fs}" + done +} + +log_assert "Executing 'zfs upgrade [-V version] -a' command succeeds." + +$DF -t zfs / > /dev/null 2>&1 +if (( $? == 0 )) ; then + log_unsupported "This case should not run on ZFS root system" +fi + +log_onexit cleanup + +rootfs=$TESTPOOL/$TESTFS + +typeset datasets + +typeset newv +for newv in "" "current" $ZFS_VERSION; do + setup_datasets + if [[ -n $newv ]]; then + opt="-V $newv" + if [[ $newv == current ]]; then + newv=$ZFS_VERSION + fi + else + newv=$ZFS_VERSION + fi + + log_must eval '$ZFS upgrade $opt -a > /dev/null 2>&1' + + for fs in $($ZFS list -rH -t filesystem -o name $rootfs) ; do + log_must check_fs_version $fs $newv + done + cleanup +done + +log_pass "Executing 'zfs upgrade [-V version] -a' command succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh new file mode 100644 index 00000000000..6d6af1ec7a6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_006_neg.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_006_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_upgrade_006_neg +# +# DESCRIPTION: +# Verify that invalid upgrade parameters and options are caught. +# +# STRATEGY: +# 1. Create a ZFS file system. +# 2. For each option in the list, try 'zfs upgrade'. +# 3. Verify that the operation fails as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A args "" "-?" "-A" "-R" "-b" "-c" "-d" "--invalid" \ + "-V" "-V $TESTPOOL/$TESTFS" "-V $TESTPOOL $TESTPOOL/$TESTFS" + +log_assert "Badly-formed 'zfs upgrade' should return an error." + +typeset -i i=1 +while (( i < ${#args[*]} )); do + log_mustnot $ZFS upgrade ${args[i]} + ((i = i + 1)) +done + +log_pass "Badly-formed 'zfs upgrade' fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh new file mode 100644 index 00000000000..665138a21b7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_007_neg.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_007_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_upgrade_007_neg +# +# DESCRIPTION: +# Verify that version should only by '1' '2' or current version, +# non-digit input are invalid. +# +# STRATEGY: +# 1. For each invalid value of version in the list, try 'zfs upgrade -V version'. +# 2. Verify that the operation fails as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A args \ + "0" "0.000" "0.5" "-1.234" "-1" "1234b" "5678x" + +log_assert "Set invalid value or non-digit version should fail as expected." + +typeset -i i=0 +while (( i < ${#args[*]} )) +do + log_mustnot $ZFS upgrade -V ${args[i]} $TESTPOOL/$TESTFS + ((i = i + 1)) +done + +log_pass "Set invalid value or non-digit version fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_test.sh new file mode 100755 index 00000000000..e6c2f0c048f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zfs_upgrade/zfs_upgrade_test.sh @@ -0,0 +1,225 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_upgrade_001_pos cleanup +zfs_upgrade_001_pos_head() +{ + atf_set "descr" "Executing 'zfs upgrade' command succeeds." + atf_set "require.progs" zfs nawk +} +zfs_upgrade_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_upgrade_002_pos cleanup +zfs_upgrade_002_pos_head() +{ + atf_set "descr" "Executing 'zfs upgrade -v' command succeeds." + atf_set "require.progs" zfs nawk +} +zfs_upgrade_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_upgrade_003_pos cleanup +zfs_upgrade_003_pos_head() +{ + atf_set "descr" "Executing 'zfs upgrade [-V version] filesystem' command succeeds." + atf_set "require.progs" zfs +} +zfs_upgrade_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_upgrade_004_pos cleanup +zfs_upgrade_004_pos_head() +{ + atf_set "descr" "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds." + atf_set "require.progs" zfs +} +zfs_upgrade_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_upgrade_005_pos cleanup +zfs_upgrade_005_pos_head() +{ + atf_set "descr" "Executing 'zfs upgrade [-V version] -a' command succeeds." + atf_set "require.progs" zfs +} +zfs_upgrade_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_upgrade_006_neg cleanup +zfs_upgrade_006_neg_head() +{ + atf_set "descr" "Badly-formed 'zfs upgrade' should return an error." + atf_set "require.progs" zfs +} +zfs_upgrade_006_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_006_neg.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_upgrade_007_neg cleanup +zfs_upgrade_007_neg_head() +{ + atf_set "descr" "Set invalid value or non-digit version should fail as expected." + atf_set "require.progs" zfs +} +zfs_upgrade_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_upgrade.cfg + . $(atf_get_srcdir)/zfs_upgrade.kshlib + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_upgrade_001_pos + atf_add_test_case zfs_upgrade_002_pos + atf_add_test_case zfs_upgrade_003_pos + atf_add_test_case zfs_upgrade_004_pos + atf_add_test_case zfs_upgrade_005_pos + atf_add_test_case zfs_upgrade_006_neg + atf_add_test_case zfs_upgrade_007_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool/Makefile new file mode 100644 index 00000000000..1f7165d564f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_001_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool.cfg +${PACKAGE}FILES+= zpool_003_pos.ksh +${PACKAGE}FILES+= zpool_002_pos.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool.cfg new file mode 100644 index 00000000000..92c1a14a889 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_001_neg.ksh new file mode 100644 index 00000000000..ea9f52cfa4e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_001_neg.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_001_neg.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_001_neg +# +# DESCRIPTION: +# A badly formed sub-command passed to zpool(1) should +# return an error. +# +# STRATEGY: +# 1. Create an array containg each zpool sub-command name. +# 2. For each element, execute the sub-command. +# 3. Verify it returns an error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A args "" "create" "add" "destroy" "import fakepool" \ + "export fakepool" "create fakepool" "add fakepool" \ + "create mirror" "create raidz" "create raidz1" \ + "create mirror fakepool" "create raidz fakepool" \ + "create raidz1 fakepool" "create raidz2 fakepool" \ + "create fakepool mirror" "create fakepool raidz" \ + "create fakepool raidz1" "create fakepool raidz2" \ + "add fakepool mirror" "add fakepool raidz" \ + "add fakepool raidz1" "add fakepool raidz2" \ + "add mirror fakepool" "add raidz fakepool" \ + "add raidz1 fakepool" "add raidz2 fakepool" \ + "setvprop" "blah blah" "-%" "--" "--?" "-*" "-=" + +log_assert "Execute zpool sub-command without proper parameters." + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZPOOL ${args[i]} + + ((i = i + 1)) +done + +log_pass "Badly formed zpool sub-commands fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_002_pos.ksh new file mode 100644 index 00000000000..944eb8ffb17 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_002_pos.ksh @@ -0,0 +1,110 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_002_pos.ksh 1.2 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_002_pos +# +# DESCRIPTION: +# With ZFS_ABORT set, all zpool commands should be able to abort and generate a core file. +# +# STRATEGY: +# 1. Create an array of zpool command +# 2. Execute each command in the array +# 3. Verify the command aborts and generate a core file +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + unset ZFS_ABORT + + if [[ -d $corepath ]]; then + $RM -rf $corepath + fi + if poolexists $pool; then + log_must $ZPOOL destroy -f $pool + fi +} + +log_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file." +log_onexit cleanup + +#preparation work for testing +corepath=$TESTDIR/core +if [[ -d $corepath ]]; then + $RM -rf $corepath +fi +$MKDIR $corepath + +pool=pool.${TESTCASE_ID} +vdev1=$TESTDIR/file1 +vdev2=$TESTDIR/file2 +vdev3=$TESTDIR/file3 +log_must create_vdevs $vdev1 $vdev2 $vdev3 + +set -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \ + "status $pool" "upgrade $pool" "get delegation $pool" "set delegation=off $pool" \ + "export $pool" "import -d $TESTDIR $pool" "offline $pool $vdev1" \ + "online $pool $vdev1" "clear $pool" "detach $pool $vdev2" \ + "attach $pool $vdev1 $vdev2" "replace $pool $vdev2 $vdev3" \ + "scrub $pool" "destroy -f $pool" + +set -A badparams "" "create" "destroy" "add" "remove" "list *" "iostat" "status" \ + "online" "offline" "clear" "attach" "detach" "replace" "scrub" \ + "import" "export" "upgrade" "history -?" "get" "set" + +$COREADM -p ${corepath}/core.%f +export ZFS_ABORT=yes + +for subcmd in "${cmds[@]}" "${badparams[@]}"; do + $ZPOOL $subcmd >/dev/null 2>&1 + corefile=${corepath}/core.zpool + if [[ ! -e $corefile ]]; then + log_fail "$ZPOOL $subcmd cannot generate core file with ZFS_ABORT set." + fi + $RM -f $corefile +done + +log_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_003_pos.ksh new file mode 100644 index 00000000000..479b9c1d465 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_003_pos.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_003_pos.ksh 1.1 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_003_pos +# +# DESCRIPTION: +# Verify debugging features of zpool such as ABORT and freeze/unfreeze +# should run successfully. +# +# STRATEGY: +# 1. Create an array containg each zpool options. +# 2. For each element, execute the zpool command. +# 3. Verify it run successfully. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Debugging features of zpool should succeed." + +log_must $ZPOOL -? > /dev/null 2>&1 + +if is_global_zone ; then + log_must $ZPOOL freeze $TESTPOOL +else + log_mustnot $ZPOOL freeze $TESTPOOL + log_mustnot $ZPOOL freeze ${TESTPOOL%%/*} +fi + +log_mustnot $ZPOOL freeze fakepool + +ZFS_ABORT=1; export ZFS_ABORT +$ZPOOL > /dev/null 2>&1 +typeset ret=$? +unset ZFS_ABORT +# Note: "/bin/kill -l $ret" will not recognize the signal number. We must use +# ksh93's builtin kill command +if [ `kill -l $ret` != "ABRT" ]; then + log_fail "$ZPOOL not dump core by request." +fi + +log_pass "Debugging features of zpool succeed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_test.sh new file mode 100755 index 00000000000..b41c748cba5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool/zpool_test.sh @@ -0,0 +1,107 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_001_neg cleanup +zpool_001_neg_head() +{ + atf_set "descr" "Execute zpool sub-command without proper parameters." + atf_set "require.progs" zpool +} +zpool_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_002_pos cleanup +zpool_002_pos_head() +{ + atf_set "descr" "With ZFS_ABORT set, all zpool commands can abort and generate a core file." + atf_set "require.progs" zpool coreadm +} +zpool_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_003_pos cleanup +zpool_003_pos_head() +{ + atf_set "descr" "Debugging features of zpool should succeed." + atf_set "require.progs" zpool +} +zpool_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_001_neg + atf_add_test_case zpool_002_pos + atf_add_test_case zpool_003_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/Makefile new file mode 100644 index 00000000000..5825e0e593f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/Makefile @@ -0,0 +1,28 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_add +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_add_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_add.cfg +${PACKAGE}FILES+= zpool_add.kshlib +${PACKAGE}FILES+= zpool_add_001_pos.ksh +${PACKAGE}FILES+= zpool_add_002_pos.ksh +${PACKAGE}FILES+= zpool_add_003_pos.ksh +${PACKAGE}FILES+= zpool_add_004_pos.ksh +${PACKAGE}FILES+= zpool_add_005_pos.ksh +${PACKAGE}FILES+= zpool_add_006_pos.ksh +${PACKAGE}FILES+= zpool_add_007_neg.ksh +${PACKAGE}FILES+= zpool_add_008_neg.ksh +${PACKAGE}FILES+= zpool_add_009_neg.ksh +${PACKAGE}FILES+= zpool_add_010_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/cleanup.ksh new file mode 100644 index 00000000000..083ab9e34bd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +cleanup_devices $DISKS + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/setup.ksh new file mode 100644 index 00000000000..9b6adb17007 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/setup.ksh @@ -0,0 +1,52 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +verify_runnable "global" + +if [[ -n $DISK ]]; then + # + # Use 'zpool create' to clean up the infomation in + # in the given disk to avoid slice overlapping. + # + cleanup_devices $DISK + + partition_disk $SIZE $DISK 7 +else + for disk in `$ECHO $DISKSARRAY`; do + cleanup_devices $disk + partition_disk $SIZE $disk 7 + done +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.cfg new file mode 100644 index 00000000000..40e04d0a05e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.cfg @@ -0,0 +1,69 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add.cfg 1.3 08/08/15 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +. $STF_SUITE/include/libtest.kshlib + +export DISK_ARRAY_NUM=0 +export DISK_ARRAY_LIMIT=4 +export DISKSARRAY="" + +# +# Variables for zpool_add_006 +# +export STF_TIMEOUT=2400 +export VDEVS_NUM=300 +export FILE_SIZE=100 #100mb + +set_disks + +export FILESIZE="100m" +export FILESIZE1="150m" +export SIZE="150m" +export SIZE1="250m" + +export FILEDISK=filedisk${TESTCASE_ID} +export FILEDISK0=filedisk0${TESTCASE_ID} +export FILEDISK1=filedisk1${TESTCASE_ID} +export FILEDISK2=filedisk2${TESTCASE_ID} +export FILEDISK3=filedisk3${TESTCASE_ID} + +export VOLSIZE=64mb + +export BYND_MAX_NAME="byondmaxnamelength\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.kshlib new file mode 100644 index 00000000000..c3b657d2ddf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add.kshlib @@ -0,0 +1,154 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add.kshlib 1.3 07/03/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# check if the contains ... +# +# $1 pool +# $2..n ... +# +# Return 0 if are contained in the ; 1 if not used; 2 if pool +# name is missing +# +function iscontained +{ + typeset pool=$1 + typeset vdev + + if [[ -z $pool ]]; then + log_note "Missing pool name." + return 2 + fi + + shift + + for vdev in $@; do + +# remove /dev/dsk in vdev if there is + $ECHO $vdev | $GREP "^/dev/" >/dev/null 2>&1 + (( $? == 0 )) && \ + vdev=${vdev##*/} + + $ZPOOL status "$pool" | $AWK '$1 == vdevname {exit 1}' \ + vdevname=$vdev >/dev/null 2>&1 + (( $? != 1 )) && \ + return 1 + done + + return 0; + +} + +# +# Find the storage device in /etc/fstab +# +function find_vfstab_dev +{ + typeset vfstab="/etc/fstab" + typeset tmpfile="$TMPDIR/fstab.tmp" + typeset vfstabdev + typeset vfstabdevs="" + typeset line + + $CAT $vfstab | $GREP "^/dev/" >$tmpfile + while read -r line + do + vfstabdev=`$ECHO "$line" | $AWK '{print $1}'` + vfstabdev=${vfstabdev%%:} + vfstabdevs="$vfstabdev $vfstabdevs" + done <$tmpfile + + $RM -f $tmpfile + $ECHO $vfstabdevs +} + +# +# Find the storage device in /etc/mnttab +# +function find_mnttab_dev +{ + typeset mnttab="/etc/mnttab" + typeset tmpfile="$TMPDIR/mnttab.tmp" + typeset mnttabdev + typeset mnttabdevs="" + typeset line + + $MOUNT | $GREP "^/dev/" >$tmpfile + while read -r line + do + mnttabdev=`$ECHO "$line" | $AWK '{print $1}'` + mnttabdev=${mnttabdev%%:} + mnttabdevs="$mnttabdev $mnttabdevs" + done <$tmpfile + + $RM -f $tmpfile + $ECHO $mnttabdevs +} + +# +# Save the systme current dump device configuration +# +function save_dump_dev +{ + + typeset dumpdev + typeset swapdev + typeset swapdevs="" + typeset tmpfile="$TMPDIR/swapinfo.tmp" + + dumpdev=`readlink /dev/dumpdev` + swapinfo | $GREP "^/dev/" >$tmpfile + while read -r line + do + swapdev=`$ECHO "$line" | $AWK '{print $1}'` + swapdev=${swapdev%%:} + swapdevs="$swapdev $swapdevs" + done <$tmpfile + $ECHO "$dumpdev $swapdevs" +} + +# +# Common cleanup routine for partitions used in testing +# +function partition_cleanup +{ + log_note "Cleaning up partitions..." + if [[ -n $DISK ]]; then + partition_disk $SIZE $DISK 7 + else + typeset disk="" + for disk in $DISK0 $DISK1; do + partition_disk $SIZE $disk 7 + done + fi +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_001_pos.ksh new file mode 100644 index 00000000000..c27329d8156 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_001_pos.ksh @@ -0,0 +1,148 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_001_pos.ksh 1.4 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_001_pos +# +# DESCRIPTION: +# 'zpool add ...' can successfully add the specified +# devices to the given pool +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add spare devices to the pool +# 3. Verify the devices are added to the pool successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2005-09-27) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +log_assert "'zpool add ...' can add devices to the pool." + +log_onexit cleanup + +set -A keywords "" "mirror" "raidz" "raidz1" "spare" + +typeset diskname=${disk#/dev/} +typeset diskname0=${DISK0#/dev/} +typeset diskname1=${DISK1#/dev/} + +case $DISK_ARRAY_NUM in +0|1) + pooldevs="${diskname}p1 \ + /dev/${diskname}p1 \ + \"${diskname}p1 ${diskname}p2\"" + mirrordevs="\"/dev/${diskname}p1 ${diskname}p2\"" + raidzdevs="\"/dev/${diskname}p1 ${diskname}p2\"" + + ;; +2|*) + pooldevs="${diskname0}p1\ + \"/dev/${diskname0}p1 ${diskname1}p1\" \ + \"${diskname0}p1 ${diskname0}p2 ${diskname1}p2\"\ + \"${diskname0}p1 ${diskname1}p1 ${diskname0}p2\ + ${diskname1}p2\"" + mirrordevs="\"/dev/${diskname0}p1 ${diskname1}p1\"" + raidzdevs="\"/dev/${diskname0}p1 ${diskname1}p1\"" + + ;; +esac + +typeset -i i=0 +typeset vdev +eval set -A poolarray $pooldevs +eval set -A mirrorarray $mirrordevs +eval set -A raidzarray $raidzdevs + +while (( $i < ${#keywords[*]} )); do + case ${keywords[i]} in + ""|spare) + for vdev in "${poolarray[@]}"; do + create_pool "$TESTPOOL" "${diskname}p6" + log_must poolexists "$TESTPOOL" + log_must $ZPOOL add -f "$TESTPOOL" ${keywords[i]} \ + $vdev + log_must iscontained "$TESTPOOL" "$vdev" + destroy_pool "$TESTPOOL" + done + + ;; + mirror) + for vdev in "${mirrorarray[@]}"; do + create_pool "$TESTPOOL" "${keywords[i]}" \ + "${diskname}p4" "${diskname}p5" + log_must poolexists "$TESTPOOL" + log_must $ZPOOL add "$TESTPOOL" ${keywords[i]} \ + $vdev + log_must iscontained "$TESTPOOL" "$vdev" + destroy_pool "$TESTPOOL" + done + + ;; + raidz|raidz1) + for vdev in "${raidzarray[@]}"; do + create_pool "$TESTPOOL" "${keywords[i]}" \ + "${diskname}p4" "${diskname}p5" + log_must poolexists "$TESTPOOL" + log_must $ZPOOL add "$TESTPOOL" ${keywords[i]} \ + $vdev + log_must iscontained "$TESTPOOL" "$vdev" + destroy_pool "$TESTPOOL" + done + + ;; + esac + + (( i = i+1 )) +done + +log_pass "'zpool add ...' executes successfully" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_002_pos.ksh new file mode 100644 index 00000000000..0a1b2ae8a1c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_002_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_002_pos.ksh 1.5 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_002_pos +# +# DESCRIPTION: +# 'zpool add -f ...' can successfully add the specified +# devices to given pool in some cases. +# +# STRATEGY: +# 1. Create a mirrored pool +# 2. Without -f option to add 1-way device the mirrored pool will fail +# 3. Use -f to override the errors to add 1-way device to the mirrored +# pool +# 4. Verify the device is added successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +log_assert "'zpool add -f ...' can successfully add" \ + "devices to the pool in some cases." + +log_onexit cleanup + +create_pool "$TESTPOOL" mirror "${disk}p1" "${disk}p2" +log_must poolexists "$TESTPOOL" + +log_mustnot $ZPOOL add "$TESTPOOL" ${disk}p3 +log_mustnot iscontained "$TESTPOOL" "${disk}p3" + +log_must $ZPOOL add -f "$TESTPOOL" ${disk}p3 +log_must iscontained "$TESTPOOL" "${disk}p3" + +log_pass "'zpool add -f ...' executes successfully." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_003_pos.ksh new file mode 100644 index 00000000000..df2bd34da9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_003_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_003_pos.ksh 1.4 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_003_pos +# +# DESCRIPTION: +# 'zpool add -n ...' can display the configuration without +# adding the specified devices to given pool +# +# STRATEGY: +# 1. Create a storage pool +# 2. Use -n to add a device to the pool +# 3. Verify the device is not added actually +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup + + [[ -e $tmpfile ]] && \ + log_must $RM -f $tmpfile +} + +log_assert "'zpool add -n ...' can display the configuration" \ + "without actually adding devices to the pool." + +log_onexit cleanup + +tmpfile="$TMPDIR/zpool_add_003.tmp${TESTCASE_ID}" + +create_pool "$TESTPOOL" "${disk}p1" +log_must poolexists "$TESTPOOL" + +$ZPOOL add -n "$TESTPOOL" ${disk}p2 > $tmpfile + +log_mustnot iscontained "$TESTPOOL" "${disk}p2" + +str="would update '$TESTPOOL' to the following configuration:" +$CAT $tmpfile | $GREP "$str" >/dev/null 2>&1 +(( $? != 0 )) && \ + log_fail "'zpool add -n ...' is executed as unexpected" + +log_pass "'zpool add -n ...'executes successfully." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_004_pos.ksh new file mode 100644 index 00000000000..f3764575c62 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_004_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_004_pos.ksh 1.6 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_004_pos +# +# DESCRIPTION: +# 'zpool add ...' can successfully add a zfs volume +# to the given pool +# +# STRATEGY: +# 1. Create a storage pool and a zfs volume +# 2. Add the volume to the pool +# 3. Verify the devices are added to the pool successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool "$TESTPOOL" + + datasetexists $TESTPOOL1/$TESTVOL && \ + log_must $ZFS destroy -f $TESTPOOL1/$TESTVOL + poolexists $TESTPOOL1 && \ + destroy_pool "$TESTPOOL1" + + partition_cleanup + +} + +log_assert "'zpool add ...' can add zfs volume to the pool." + +log_onexit cleanup + +create_pool "$TESTPOOL" "${disk}p1" +log_must poolexists "$TESTPOOL" + +create_pool "$TESTPOOL1" "${disk}p2" +log_must poolexists "$TESTPOOL1" +log_must $ZFS create -V $VOLSIZE $TESTPOOL1/$TESTVOL + +log_must $ZPOOL add "$TESTPOOL" /dev/zvol/$TESTPOOL1/$TESTVOL + +log_must iscontained "$TESTPOOL" "/dev/zvol/$TESTPOOL1/$TESTVOL" + +log_pass "'zpool add ...' adds zfs volume to the pool successfully" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_005_pos.ksh new file mode 100644 index 00000000000..4f02d884ac3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_005_pos.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_005_pos.ksh 1.4 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_005_pos +# +# DESCRIPTION: +# 'zpool add' should return fail if +# 1. vdev is part of an active pool +# 2. vdev is currently mounted +# 3. vdev is in /etc/vfstab +# 3. vdev is specified as the dedicated dump device +# +# STRATEGY: +# 1. Create case scenarios +# 2. For each scenario, try to add the device to the pool +# 3. Verify the add operation get failed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists "$TESTPOOL" && \ + destroy_pool "$TESTPOOL" + poolexists "$TESTPOOL1" && \ + destroy_pool "$TESTPOOL1" + + if [[ -n $saved_dump_dev ]]; then + log_must eval "$DUMPADM -u -d $saved_dump_dev > /dev/null" + fi + + partition_cleanup +} + +log_assert "'zpool add' should fail with inapplicable scenarios." + +log_onexit cleanup + +mnttab_dev=$(find_mnttab_dev) +vfstab_dev=$(find_vfstab_dev) +saved_dump_dev=$(save_dump_dev) +dump_dev=${disk}p3 + +create_pool "$TESTPOOL" "${disk}p1" +log_must poolexists "$TESTPOOL" + +create_pool "$TESTPOOL1" "${disk}p2" +log_must poolexists "$TESTPOOL1" +log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}p2 + +log_mustnot $ZPOOL add -f "$TESTPOOL" $mnttab_dev + +log_mustnot $ZPOOL add -f "$TESTPOOL" $vfstab_dev + +log_must $ECHO "y" | $NEWFS /dev/$dump_dev > /dev/null 2>&1 +log_must $DUMPADM -u -d /dev/$dump_dev > /dev/null +log_mustnot $ZPOOL add -f "$TESTPOOL" $dump_dev + +log_pass "'zpool add' should fail with inapplicable scenarios." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_006_pos.ksh new file mode 100644 index 00000000000..decdc01af2c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_006_pos.ksh @@ -0,0 +1,161 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_006_pos.ksh 1.5 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_006_pos +# +# DESCRIPTION: +# 'zpool add [-f]' can add large numbers of file-in-zfs-filesystem-based vdevs +# to the specified pool without any errors. +# +# STRATEGY: +# 1. Create assigned number of files in ZFS filesystem as vdevs and use the first +# file to create a pool +# 2. Add other vdevs to the pool should get success +# 3 Fill in the filesystem and create a partially written file +# as vdev +# 4. Add the new file into the pool should be failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-09) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL1 && \ + destroy_pool $TESTPOOL1 + + datasetexists $TESTPOOL/$TESTFS && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTFS + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + if [[ -d $TESTDIR ]]; then + log_must $RM -rf $TESTDIR + fi + + partition_cleanup +} + + +# +# Create a pool and fs on the assigned disk, and dynamically create large +# numbers of files as vdevs.(the default value is ) +# the first file will be used to create a pool for other vdevs to be added into +# + +function setup_vdevs # +{ + typeset disk=$1 + typeset -i count=0 + typeset -i largest_num=0 + typeset -i slicesize=0 + typeset vdev="" + + fs_size=$(get_available_disk_size $disk) + + # 64M is the minimum size for the pool + (( largest_num = fs_size / (1024 * 1024 * 64) )) + if (( largest_num < $VDEVS_NUM )); then + # Minus $largest_num/20 to leave 5% space for metadata. + (( vdevs_num=largest_num - largest_num/20 )) + file_size=64 + vdev=$disk + else + vdevs_num=$VDEVS_NUM + (( file_size = fs_size / (1024 * 1024 * (vdevs_num + vdevs_num/20)) )) + if (( file_size > FILE_SIZE )); then + file_size=$FILE_SIZE + fi + # Plus $vdevs_num/20 to provide enough space for metadata. + (( slice_size = file_size * (vdevs_num + vdevs_num/20) )) + wipe_partition_table $disk + set_partition 0 "" ${slice_size}m $disk + vdev=${disk}p1 + fi + + create_pool $TESTPOOL $vdev + [[ -d $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR + log_must $MKDIR -p $TESTDIR + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +# Create a pool first using the first file, and make subsequent files ready +# as vdevs to add to the pool + + vdev=${TESTDIR}/file.$count + VDEV_SIZE=${file_size}m + log_must create_vdevs ${TESTDIR}/file.$count + create_pool "$TESTPOOL1" "${TESTDIR}/file.$count" + log_must poolexists "$TESTPOOL1" + + while (( count < vdevs_num )); do # minus 1 to avoid space non-enough + (( count = count + 1 )) + log_must create_vdevs ${TESTDIR}/file.$count + vdevs_list="$vdevs_list ${TESTDIR}/file.$count" + done + unset VDEV_SIZE +} + +log_assert " 'zpool add [-f]' can add large numbers of vdevs to the specified" \ + " pool without any errors." +log_onexit cleanup + +if [[ $DISK_ARRAY_NUM == 0 ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +vdevs_list="" +vdevs_num=$VDEVS_NUM +file_size=$FILE_SIZE + +setup_vdevs $disk +log_must $ZPOOL add -f "$TESTPOOL1" $vdevs_list +log_must iscontained "$TESTPOOL1" "$vdevs_list" + +log_pass "'zpool successfully add [-f]' can add large numbers of vdevs to the" \ + "specified pool without any errors." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_007_neg.ksh new file mode 100644 index 00000000000..ba2baddd7d9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_007_neg.ksh @@ -0,0 +1,84 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_007_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_007_neg +# +# DESCRIPTION: +# 'zpool add' should return an error with badly-formed parameters, +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute 'zpool add' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists "$TESTPOOL" && \ + destroy_pool "$TESTPOOL" + + partition_cleanup +} + +log_assert "'zpool add' should return an error with badly-formed parameters." + +log_onexit cleanup + +set -A args "" "-f" "-n" "-?" "-nf" "-fn" "-f -n" "--f" "-blah" \ + "-? $TESTPOOL ${disk}p2" + +create_pool "$TESTPOOL" "${disk}p1" +log_must poolexists "$TESTPOOL" + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZPOOL add ${args[i]} + ((i = i + 1)) +done + +log_pass "'zpool add' badly formed parameters fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_008_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_008_neg.ksh new file mode 100644 index 00000000000..39ebeeb665b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_008_neg.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_008_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_008_neg +# +# DESCRIPTION: +# 'zpool add' should return an error with nonexistent pools or vdevs +# +# STRATEGY: +# 1. Create an array of parameters which contains nonexistent pools/vdevs +# 2. For each parameter in the array, execute 'zpool add' +# 3. Verify an error is returned +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + + poolexists "$TESTPOOL" && \ + destroy_pool "$TESTPOOL" + + partition_cleanup +} + +log_assert "'zpool add' should return an error with nonexistent pools and vdevs" + +log_onexit cleanup + +set -A args "" "-f nonexistent_pool ${disk}p2" \ + "-f $TESTPOOL nonexistent_vdev" + +create_pool "$TESTPOOL" "${disk}p1" +log_must poolexists "$TESTPOOL" + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZPOOL add ${args[i]} + ((i = i + 1)) +done + +log_pass "'zpool add' with nonexistent pools and vdevs fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_009_neg.ksh new file mode 100644 index 00000000000..f0854ed7a41 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_009_neg.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_009_neg.ksh 1.4 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_009_neg +# +# DESCRIPTION: +# 'zpool add' should return fail if vdevs are the same or vdev is +# contained in the given pool +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add the two same devices to pool A +# 3. Add the device in pool A to pool A again +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + + poolexists "$TESTPOOL" && \ + destroy_pool "$TESTPOOL" + + partition_cleanup + +} + +log_assert "'zpool add' should fail if vdevs are the same or vdev is " \ + "contained in the given pool." + +log_onexit cleanup + +create_pool "$TESTPOOL" "${disk}p1" +log_must poolexists "$TESTPOOL" + +log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}p2 ${disk}p2 +log_mustnot $ZPOOL add -f "$TESTPOOL" ${disk}p1 + +log_pass "'zpool add' get fail as expected if vdevs are the same or vdev is " \ + "contained in the given pool." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_010_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_010_pos.ksh new file mode 100644 index 00000000000..3578340bfca --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_010_pos.ksh @@ -0,0 +1,56 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +log_assert "'zpool add' can add devices, even if a replacing vdev with a spare child is present" + +log_onexit cleanup + +create_pool $TESTPOOL mirror ${DISK0} ${DISK1} +# A replacing vdev will automatically detach the older member when resilvering +# is complete. We don't want that to happen during this test, so write some +# data just to slow down resilvering. +$TIMEOUT 60s $DD if=/dev/zero of=/$TESTPOOL/zerofile bs=128k +log_must $ZPOOL replace $TESTPOOL ${DISK0} ${DISK2} +log_must $ZPOOL add $TESTPOOL spare ${DISK3} +log_must $ZPOOL replace $TESTPOOL ${DISK0} ${DISK3} +log_must $ZPOOL add $TESTPOOL spare ${DISK4} + +log_pass "'zpool add ...' executes successfully, even when a replacing vdev with a spare child is present" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_test.sh new file mode 100755 index 00000000000..83c422047f4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_test.sh @@ -0,0 +1,313 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_add_001_pos cleanup +zpool_add_001_pos_head() +{ + atf_set "descr" "'zpool add ...' can add devices to the pool." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_add_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_002_pos cleanup +zpool_add_002_pos_head() +{ + atf_set "descr" "'zpool add -f ...' can successfully add devices to the pool in some cases." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_add_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_003_pos cleanup +zpool_add_003_pos_head() +{ + atf_set "descr" "'zpool add -n ...' can display the configuration without actually adding devices to the pool." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_add_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_004_pos cleanup +zpool_add_004_pos_head() +{ + atf_set "descr" "'zpool add ...' can add zfs volume to the pool." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2400 +} +zpool_add_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_zvol_recursive + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_005_pos cleanup +zpool_add_005_pos_head() +{ + atf_set "descr" "'zpool add' should fail with inapplicable scenarios." + atf_set "require.progs" dumpadm zpool + atf_set "timeout" 2400 +} +zpool_add_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 1 + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_005_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_006_pos cleanup +zpool_add_006_pos_head() +{ + atf_set "descr" "'zpool add [-f]' can add large numbers of vdevs to the specified pool without any errors." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2400 +} +zpool_add_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_006_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_007_neg cleanup +zpool_add_007_neg_head() +{ + atf_set "descr" "'zpool add' should return an error with badly-formed parameters." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_add_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_007_neg.ksh || atf_fail "Testcase failed" +} +zpool_add_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_008_neg cleanup +zpool_add_008_neg_head() +{ + atf_set "descr" "'zpool add' should return an error with nonexistent pools and vdevs" + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_add_008_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_008_neg.ksh || atf_fail "Testcase failed" +} +zpool_add_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_009_neg cleanup +zpool_add_009_neg_head() +{ + atf_set "descr" "'zpool add' should fail if vdevs are the same or vdev iscontained in the given pool." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_add_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_009_neg.ksh || atf_fail "Testcase failed" +} +zpool_add_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +# Regression test for PR 225546. "zpool add" asserts if the pool contains a +# replacing vdev with a spare child. +# Assertion failed: (nvlist_lookup_string(cnv, "path", &path) == 0), file /usr/home/alans/freebsd/head/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c, line 694. /usr/tests/sys/cddl/zfs/tests/cli_root/zpool_add/zpool_add_010_pos.ksh[54]: log_must[69]: log_pos: line 206: 27710: Abort(coredump) +atf_test_case zpool_add_010_pos cleanup +zpool_add_010_pos_head() +{ + atf_set "descr" "'zpool add' can add devices, even if a replacing vdev with a spare child is present" + atf_set "require.progs" zpool +} +zpool_add_010_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/zpool_add_010_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_add.kshlib + . $(atf_get_srcdir)/zpool_add.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_add_001_pos + atf_add_test_case zpool_add_002_pos + atf_add_test_case zpool_add_003_pos + atf_add_test_case zpool_add_004_pos + atf_add_test_case zpool_add_005_pos + atf_add_test_case zpool_add_006_pos + atf_add_test_case zpool_add_007_neg + atf_add_test_case zpool_add_008_neg + atf_add_test_case zpool_add_009_neg + atf_add_test_case zpool_add_010_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/Makefile new file mode 100644 index 00000000000..1e705543779 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_attach +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_attach_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_attach_001_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_attach.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/cleanup.ksh new file mode 100644 index 00000000000..b5a6a6c0f9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/setup.ksh new file mode 100644 index 00000000000..e4db7febd63 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +default_mirror_setup $DISKS diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach.cfg new file mode 100644 index 00000000000..e645431c4ab --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_attach.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach_001_neg.ksh new file mode 100644 index 00000000000..98cf10c7ea2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach_001_neg.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_attach_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_attach_001_neg +# +# DESCRIPTION: +# Executing 'zpool attach' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool attach' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +DISKLIST=$(get_disklist $TESTPOOL) + +set -A args "" "-f" "-?" "-z fakepool" "-f fakepool" "-ev fakepool" "fakepool" \ + "$TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \ + "$TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \ + "$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "$TESTPOOL/$TESTVOL $DISKLIST" \ + "$DISKLIST" \ + "fakepool fakedevice" "fakepool fakedevice fakenewdevice" \ + "$TESTPOOL fakedevice" "$TESTPOOL $DISKLIST" \ + "$TESTPOOL fakedevice fakenewdevice fakenewdevice" \ + "-f $TESTPOOL" "-f $TESTPOOL/$TESTFS" "-f $TESTPOOL/$TESTFS $DISKLIST" \ + "-f $TESTPOOL/$TESTCTR" "-f $TESTPOOL/$TESTCTR/$TESTFS1" \ + "-f $TESTPOOL/$TESTCTR $DISKLIST" "-f $TESTPOOL/$TESTVOL" \ + "-f $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "-f $TESTPOOL/$TESTVOL $DISKLIST" \ + "-f $DISKLIST" \ + "-f fakepool fakedevice" "-f fakepool fakedevice fakenewdevice" \ + "-f $TESTPOOL fakedevice fakenewdevice fakenewdevice" \ + "-f $TESTPOOL fakedevice" "-f $TESTPOOL $DISKLIST" + +log_assert "Executing 'zpool attach' with bad options fails" + +if [[ -z $DISKLIST ]]; then + log_fail "DISKLIST is empty." +fi + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL attach ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool attach' command with bad options failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach_test.sh new file mode 100755 index 00000000000..07181d679ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_attach/zpool_attach_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_attach_001_neg cleanup +zpool_attach_001_neg_head() +{ + atf_set "descr" "Executing 'zpool attach' with bad options fails" + atf_set "require.progs" zpool +} +zpool_attach_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_attach.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_attach_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_attach_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_attach.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_attach_001_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/Makefile new file mode 100644 index 00000000000..f9b16c4a296 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_clear +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_clear_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_clear_003_neg.ksh +${PACKAGE}FILES+= zpool_clear_002_neg.ksh +${PACKAGE}FILES+= zpool_clear.cfg +${PACKAGE}FILES+= zpool_clear_001_pos.ksh +${PACKAGE}FILES+= zpool_clear_004_pos.ksh +${PACKAGE}FILES+= zpool_clear_005_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear.cfg new file mode 100644 index 00000000000..e29c7282015 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear.cfg @@ -0,0 +1,37 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_clear.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export FILESIZE=100m +export STF_TIMEOUT=2100 +export BLOCKSZ=$(( 1024 * 1024 )) +export NUM_WRITES=40 diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_001_pos.ksh new file mode 100644 index 00000000000..8c054215c85 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_001_pos.ksh @@ -0,0 +1,110 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_clear_001_pos.ksh 1.3 07/02/06 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_clear_001_pos +# +# DESCRIPTION: +# Verify 'zpool clear' can clear pool errors. +# +# STRATEGY: +# 1. Create various configuration pools +# 2. Make errors to pool +# 3. Use zpool clear to clear errors +# 4. Verify the errors has been cleared. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-10) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + + for file in `$LS $TMPDIR/file.*`; do + log_must $RM -f $file + done +} + + +log_assert "Verify 'zpool clear' can clear errors of a storage pool." +log_onexit cleanup + +#make raw files to create various configuration pools +fbase=$TMPDIR/file +log_must create_vdevs $fbase.0 $fbase.1 $fbase.2 +set -A poolconf "mirror $fbase.0 $fbase.1 $fbase.2" \ + "raidz1 $fbase.0 $fbase.1 $fbase.2" \ + "raidz2 $fbase.0 $fbase.1 $fbase.2" + +function test_clear +{ + typeset type="$1" + typeset vdev_arg="" + + log_note "Testing ${type} clear type ..." + [ "$type" = "device" ] && vdev_arg="${fbase}.0" + + corrupt_file $TESTPOOL1 /$TESTPOOL1/f + log_must $ZPOOL scrub $TESTPOOL1 + wait_for 20 1 is_pool_scrubbed $TESTPOOL1 + log_must pool_has_errors $TESTPOOL1 + + # zpool clear races with things that set error counts; try several + # times in case that race is hit. + wait_for 10 1 pool_clear_succeeds $TESTPOOL1 $vdev_arg +} + +for devconf in "${poolconf[@]}"; do + # Create the pool and sync out a file to it. + log_must $ZPOOL create -f $TESTPOOL1 $devconf + log_must $FILE_WRITE -o create -f /$TESTPOOL1/f -b 131072 -c 32 + log_must $SYNC /$TESTPOOL1 + + test_clear "device" + test_clear "pool" + + log_must $ZPOOL destroy -f $TESTPOOL1 +done + +log_pass "'zpool clear' clears pool errors as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_002_neg.ksh new file mode 100644 index 00000000000..33919006bb6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_002_neg.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_clear_002_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_clear_002_neg +# +# DESCRIPTION: +# A badly formed parameter passed to 'zpool clear' should +# return an error. +# +# STRATEGY: +# 1. Create an array containing bad 'zpool clear' parameters. +# 2. For each element, execute the sub-command. +# 3. Verify it returns an error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL1 && \ + log_must $ZPOOL destroy -f $TESTPOOL1 + [[ -e $file ]] && \ + log_must $RM -f $file +} + +log_assert "Execute 'zpool clear' using invalid parameters." +log_onexit cleanup + +# Create another pool for negative testing, which clears pool error +# with vdev device not in the pool vdev devices. +file=$TMPDIR/file.${TESTCASE_ID} +log_must create_vdevs $file +log_must $ZPOOL create $TESTPOOL1 $file + +set -A args "" "-?" "--%" "-1234567" "0.0001" "0.7644" "-0.7644" \ + "blah" "blah $DISK" "$TESTPOOL c0txdx" "$TESTPOOL $file" \ + "$TESTPOOL c0txdx blah" "$TESTPOOL $file blah" + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZPOOL clear ${args[i]} + + ((i = i + 1)) +done + +log_pass "Invalid parameters to 'zpool clear' fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_003_neg.ksh new file mode 100644 index 00000000000..d22b659b9d1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_003_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_clear_003_neg.ksh 1.3 07/02/06 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_clear_003_neg +# +# DESCRIPTION: +# Verify 'zpool clear' cannot used on an available spare device. +# +# STRATEGY: +# 1. Create a spare pool. +# 2. Try to clear the spare device +# 3. Verify it returns an error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL1 && \ + log_must $ZPOOL destroy -f $TESTPOOL1 + + for file in `$LS $TMPDIR/file.*`; do + log_must $RM -f $file + done +} + + +log_assert "Verify 'zpool clear' cannot clear error for spare device." +log_onexit cleanup + +# make raw files to create a spare pool +fbase=$TMPDIR/file +log_must create_vdevs $fbase.1 $fbase.2 $fbase.3 $fbase.4 +log_must create_pool $TESTPOOL1 raidz $fbase.1 $fbase.2 $fbase.3 spare $fbase.4 +log_mustnot $ZPOOL clear $TESTPOOL1 $fbase.4 + +log_pass "'zpool clear' works on spare device failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_004_pos.ksh new file mode 100644 index 00000000000..7b7e4cb5561 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_004_pos.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_clear_004_pos +# +# DESCRIPTION: +# Verify 'zpool clear' can clear errors on spare devices. +# +# We don't need to check whether 'zpool clear' actually clears error counters. +# zpool_clear_001_pos will do that. We just need to check that it doesn't +# return an error when used on a spare vdev. This is really a test for whether +# zpool_find_vdev() from libzfs can work on a spare vdev. Note that we're +# talking about he mirror-like "spare-0" vdev, not the leaf hotspare vdev. +# +# STRATEGY: +# 1. Create a pool +# 2. Activate a spare +# 3. Verify that "zpool clear" on the spare returns no errors +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2013-06-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + + for file in `$LS $TMPDIR/file.*`; do + log_must $RM -f $file + done + + restart_zfsd +} + + +log_assert "Verify 'zpool clear' works on spare vdevs" +log_onexit cleanup + +# Stop ZFSD so it won't interfere with our spare device. +stop_zfsd + +#make raw files to create various configuration pools +fbase=$TMPDIR/file +log_must create_vdevs $fbase.0 $fbase.1 $fbase.2 +VDEV1=$fbase.0 +VDEV2=$fbase.1 +SDEV=$fbase.2 +typeset devlist="$VDEV1 $VDEV2 spare $SDEV" + +log_note "'zpool clear' clears leaf-device error." + + +log_must $ZPOOL create -f $TESTPOOL1 $devlist +log_must $ZPOOL replace $TESTPOOL1 $VDEV1 $SDEV +log_must $ZPOOL clear $TESTPOOL1 "spare-0" + +log_pass "'zpool clear' works on spare vdevs" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_005_pos.ksh new file mode 100644 index 00000000000..059c1c56b5c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_005_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2012-2018 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# Portions taken from: +# ident "@(#)replacement_001_pos.ksh 1.4 08/02/27 SMI" +# +# $Id$ +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/include/libgnop.kshlib + +function is_pool_unavail # pool +{ + is_pool_state "$1" "UNAVAIL" +} + +log_assert "A pool can come back online after all disks are failed and reactivated" + +set_disks +typeset ALLDISKS="${DISK0} ${DISK1} ${DISK2}" +typeset ALLNOPS=${ALLDISKS//~(E)([[:space:]]+|$)/.nop\1} + +log_must create_gnops $ALLDISKS +for type in "raidz" "mirror"; do + # Create a pool on the supplied disks + create_pool $TESTPOOL $type $ALLNOPS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + # Disable all vdevs. The pool should become UNAVAIL + log_must destroy_gnop $DISK0 + log_must destroy_gnop $DISK1 + log_must destroy_gnop $DISK2 + wait_for 5 1 is_pool_unavail $TESTPOOL + + # Renable all vdevs. The pool should become healthy again + log_must create_gnop $DISK0 + log_must create_gnop $DISK1 + log_must create_gnop $DISK2 + + # Manually online the pool + log_must $ZPOOL clear $TESTPOOL + + wait_for 5 1 is_pool_healthy $TESTPOOL + + destroy_pool $TESTPOOL + log_must $RM -rf /$TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_test.sh new file mode 100755 index 00000000000..467d6000a91 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_clear/zpool_clear_test.sh @@ -0,0 +1,151 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_clear_001_pos cleanup +zpool_clear_001_pos_head() +{ + atf_set "descr" "Verify 'zpool clear' can clear errors of a storage pool." + atf_set "require.progs" zpool zfs + atf_set "timeout" 2100 +} +zpool_clear_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/zpool_clear_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_clear_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_clear_002_neg cleanup +zpool_clear_002_neg_head() +{ + atf_set "descr" "Execute 'zpool clear' using invalid parameters." + atf_set "require.progs" zpool + atf_set "timeout" 2100 +} +zpool_clear_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/zpool_clear_002_neg.ksh || atf_fail "Testcase failed" +} +zpool_clear_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_clear_003_neg cleanup +zpool_clear_003_neg_head() +{ + atf_set "descr" "Verify 'zpool clear' cannot clear error for available spare devices." + atf_set "require.progs" zpool + atf_set "timeout" 2100 +} +zpool_clear_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/zpool_clear_003_neg.ksh || atf_fail "Testcase failed" +} +zpool_clear_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zpool_clear_004_pos cleanup +zpool_clear_004_pos_head() +{ + atf_set "descr" "Verify 'zpool clear' can work on spare vdevs" + atf_set "require.progs" zpool + atf_set "timeout" 2100 +} +zpool_clear_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/zpool_clear_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_clear_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zpool_clear_005_pos cleanup +zpool_clear_005_pos_head() +{ + atf_set "descr" "'zpool clear' can online an UNAVAIL pool after all vdevs have reappeared" + atf_set "require.progs" gnop zpool +} +zpool_clear_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + verify_disk_count "$DISKS" 3 + ksh93 $(atf_get_srcdir)/zpool_clear_005_pos.ksh || atf_fail "Testcase failed" +} +zpool_clear_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_clear.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_clear_001_pos + atf_add_test_case zpool_clear_002_neg + atf_add_test_case zpool_clear_003_neg + atf_add_test_case zpool_clear_004_pos + atf_add_test_case zpool_clear_005_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/Makefile new file mode 100644 index 00000000000..c6d23dae265 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/Makefile @@ -0,0 +1,41 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_create +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_create_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_create_003_pos.ksh +${PACKAGE}FILES+= zpool_create_020_pos.ksh +${PACKAGE}FILES+= zpool_create_017_neg.ksh +${PACKAGE}FILES+= zpool_create_013_neg.ksh +${PACKAGE}FILES+= zpool_create_016_pos.ksh +${PACKAGE}FILES+= zpool_create_012_neg.ksh +${PACKAGE}FILES+= zpool_create_006_pos.ksh +${PACKAGE}FILES+= zpool_create_002_pos.ksh +${PACKAGE}FILES+= zpool_create_021_pos.ksh +${PACKAGE}FILES+= zpool_create_007_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_create_014_neg.ksh +${PACKAGE}FILES+= zpool_create_010_neg.ksh +${PACKAGE}FILES+= zpool_create_019_pos.ksh +${PACKAGE}FILES+= zpool_create_008_pos.ksh +${PACKAGE}FILES+= zpool_create_004_pos.ksh +${PACKAGE}FILES+= zpool_create_009_neg.ksh +${PACKAGE}FILES+= zpool_create_022_pos.ksh +${PACKAGE}FILES+= zpool_create.cfg +${PACKAGE}FILES+= zpool_create_005_pos.ksh +${PACKAGE}FILES+= zpool_create_001_pos.ksh +${PACKAGE}FILES+= zpool_create_023_neg.ksh +${PACKAGE}FILES+= zpool_create.kshlib +${PACKAGE}FILES+= zpool_create_015_neg.ksh +${PACKAGE}FILES+= zpool_create_011_neg.ksh +${PACKAGE}FILES+= zpool_create_018_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/cleanup.ksh new file mode 100644 index 00000000000..0014ca9f237 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/cleanup.ksh @@ -0,0 +1,45 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +clean_blockfile "$TESTDIR $TESTDIR0 $TESTDIR1" + +for pool in $TESTPOOL2 $TESTPOOL1 $TESTPOOL; do + if poolexists $pool; then + destroy_pool $pool + fi +done + +cleanup_devices $DISKS + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/setup.ksh new file mode 100644 index 00000000000..8292e3d5829 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/setup.ksh @@ -0,0 +1,53 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +verify_runnable "global" + +if [[ -n $DISK ]]; then + # + # Use 'zpool create' to clean up the infomation in + # in the given disk to avoid slice overlapping. + # + cleanup_devices $DISK + + partition_disk $SIZE $DISK 7 +else + for disk in `$ECHO $DISKSARRAY`; do + cleanup_devices $disk + + partition_disk $SIZE $disk 7 + done +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create.cfg new file mode 100644 index 00000000000..4fe7496baaf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create.cfg @@ -0,0 +1,77 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create.cfg 1.5 08/08/15 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +. $STF_SUITE/include/libtest.kshlib + +export DISK_ARRAY_NUM=0 +export DISK_ARRAY_LIMIT=4 +export DISKSARRAY="" + +# +# Variables for zpool_create_005 +# +export STF_TIMEOUT=2400 +export VDEVS_NUM=300 +export FILE_SIZE=100 #100mb +export MD_OVERHEAD=10 # 10% +export POOL_MINSIZE=64 # the minimum size(64m) to create a storage pool + +set_disks + +export FILESIZE="100m" +export FILESIZE1="150m" +export SIZE="200m" +export SIZE1="250m" + +export FILEDISK=filedisk${TESTCASE_ID} +export FILEDISK0=filedisk0${TESTCASE_ID} +export FILEDISK1=filedisk1${TESTCASE_ID} +export FILEDISK2=filedisk2${TESTCASE_ID} +export FILEDISK3=filedisk3${TESTCASE_ID} + +export BYND_MAX_NAME="byondmaxnamelength\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789\ +012345678901234567890123456789" + +export TOOSMALL="toosmall" + +export TESTPOOL4=testpool4.${TESTCASE_ID} +export TESTPOOL5=testpool5.${TESTCASE_ID} +export TESTPOOL6=testpool6.${TESTCASE_ID} + +export CPATH="$TMPDIR/cachefile.${TESTCASE_ID}" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create.kshlib new file mode 100644 index 00000000000..864039b2c0f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create.kshlib @@ -0,0 +1,131 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create.kshlib 1.4 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Given a pool vdevs list, create the pool,verify the created pool, +# and destroy the pool +# $1, pool name +# $2, pool type, mirror, raidz, or none +# $3, vdevs list +# +function create_pool_test +{ + typeset pool=$1 + typeset keywd=$2 + typeset vdevs + eval set -A diskarray $3 + + for vdevs in "${diskarray[@]}";do + create_pool $pool $keywd $vdevs + log_must poolexists $pool + destroy_pool $pool + done +} + +# +# Create a ufs file system and make a vdev file on it +# +# $1, disk name to create ufs file system +# $2, file name +# +function create_blockfile +{ + typeset disk=$1 + typeset file=$2 + typeset dir=`$DIRNAME $file` + + if [[ -d $dir ]]; then + ismounted $dir ufs && log_must $UMOUNT -f $dir + else + log_must $MKDIR -p $dir + fi + + log_must $NEWFS $disk + log_must $MOUNT $disk $dir + log_must create_vdevs $file +} + +# +# Umount the ufs filesystem and remove the mountpoint +# $1, the mount point +# +function clean_blockfile +{ + typeset dirs=$1 + + for dir in $dirs; do + if [[ -d $dir ]]; then + if ismounted $dir ufs; then + log_must $UMOUNT -f $dir + fi + log_must $RM -rf $dir + fi + done +} + +# +# Find the storage device in /etc/vfstab +# +function find_vfstab_dev +{ + typeset vfstab="/etc/vfstab" + typeset tmpfile="$TMPDIR/vfstab.tmp" + typeset vfstabdev + typeset vfstabdevs="" + typeset line + + $CAT $vfstab | $GREP "^/dev" >$tmpfile + while read -r line + do + vfstabdev=`$ECHO "$line" | $AWK '{print $1}'` + vfstabdev=${vfstabdev%%:} + vfstabdevs="$vfstabdev $vfstabdevs" + done <$tmpfile + + $RM -f $tmpfile + $ECHO $vfstabdevs +} + +# +# Save the systme current dump device configuration +# +function save_dump_dev +{ + + typeset dumpdev + typeset fnd="Dump device" + + dumpdev=`$DUMPADM | $GREP "$fnd" | $CUT -f2 -d : | \ + $AWK '{print $1}'` + $ECHO $dumpdev +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_001_pos.ksh new file mode 100644 index 00000000000..543e5a01e58 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_001_pos.ksh @@ -0,0 +1,133 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_001_pos.ksh 1.4 09/05/19 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_001_pos +# +# DESCRIPTION: +# 'zpool create ...' can successfully create a +# new pool with a name in ZFS namespace. +# +# STRATEGY: +# 1. Create storage pools with a name in ZFS namespace with different +# vdev specs. +# 2. Verify the pool created successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + + clean_blockfile "$TESTDIR0 $TESTDIR1" +} + +log_assert "'zpool create ...' can successfully create" \ + "a new pool with a name in ZFS namespace." + +log_onexit cleanup + +set -A keywords "" "mirror" "raidz" "raidz1" + +typeset diskname0=${DISK0#/dev/} +typeset diskname1=${DISK1#/dev/} + +case $DISK_ARRAY_NUM in +0|1) + typeset disk="" + if (( $DISK_ARRAY_NUM == 0 )); then + disk=$DISK + else + disk=$DISK0 + fi + typeset diskname=${disk#/dev/} + create_blockfile ${disk}p5 $TESTDIR0/$FILEDISK0 + create_blockfile ${disk}p6 $TESTDIR1/$FILEDISK1 + + pooldevs="${diskname}p1 \ + /dev/${diskname}p1 \ + \"${diskname}p1 ${diskname}p2\" \ + $TESTDIR0/$FILEDISK0" + raidzdevs="\"/dev/${diskname}p1 ${diskname}p2\" \ + \"${diskname}p1 ${diskname}p2 ${diskname}p3\" \ + \"${diskname}p1 ${diskname}p2 ${diskname}p3 \ + ${diskname}p4\"\ + \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\"" + mirrordevs=$raidzdevs + ;; +2|*) + create_blockfile ${DISK0}p5 $TESTDIR0/$FILEDISK0 + create_blockfile ${DISK1}p5 $TESTDIR1/$FILEDISK1 + + pooldevs="${diskname0}p1\ + \"/dev/${diskname0}p1 ${diskname1}p1\" \ + \"${diskname0}p1 ${diskname0}p2 ${diskname1}p2\"\ + \"${diskname0}p1 ${diskname1}p1 ${diskname0}p2\ + ${diskname1}p2\" \ + \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\"" + raidzdevs="\"/dev/${diskname0}p1 ${diskname1}p1\" \ + \"${diskname0}p1 ${diskname0}p2 ${diskname1}p2\"\ + \"${diskname0}p1 ${diskname1}p1 ${diskname0}p2\ + ${diskname1}p2\" \ + \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\"" + mirrordevs=$raidzdevs + ;; +esac + +typeset -i i=0 +while (( $i < ${#keywords[*]} )); do + case ${keywords[i]} in + "") + create_pool_test "$TESTPOOL" "${keywords[i]}" "$pooldevs";; + mirror) + create_pool_test "$TESTPOOL" "${keywords[i]}" "$mirrordevs";; + raidz|raidz1) + create_pool_test "$TESTPOOL" "${keywords[i]}" "$raidzdevs" ;; + esac + (( i = i+1 )) +done + +log_pass "'zpool create ...' success." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_002_pos.ksh new file mode 100644 index 00000000000..98dbec79f1c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_002_pos.ksh @@ -0,0 +1,121 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_002_pos.ksh 1.5 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_002_pos +# +# DESCRIPTION: +# 'zpool create -f ...' can successfully create a +# new pool in some cases. +# +# STRATEGY: +# 1. Prepare the scenarios for '-f' option +# 2. Use -f to override the devices to create new pools +# 3. Verify the pool created successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + for pool in $TESTPOOL $TESTPOOL1 $TESTPOOL2 $TESTPOOL3 $TESTPOOL4 \ + $TESTPOOL5 $TESTPOOL6 + do + poolexists $pool && destroy_pool $pool + done + + clean_blockfile "$TESTDIR0 $TESTDIR1" + + for file in $TMPDIR/$FILEDISK0 $TMPDIR/$FILEDISK1 $TMPDIR/$FILEDISK2 + do + if [[ -e $file ]]; then + $RM -rf $file + fi + done +} + +log_onexit cleanup + +log_assert "'zpool create -f ...' can successfully create" \ + "a new pool in some cases." + +function create_fails_without_force +{ + log_mustnot $ZPOOL create $TESTPOOL $* + create_pool $TESTPOOL $* + destroy_pool $TESTPOOL +} + +[ -n "$DISK" ] && disk=$DISK || disk=$DISK0 + +create_pool "$TESTPOOL" "${disk}p1" +log_must $ZPOOL export $TESTPOOL +log_note "'zpool create' without '-f' will fail " \ + "while device is belong to an exported pool." +create_fails_without_force "${disk}p1" + +log_assert "'zpool create' mirror without '-f' will fail " \ + "when vdevs are different sizes." +VDEV_SIZE=84m +create_vdevs $TMPDIR/$FILEDISK0 +unset VDEV_SIZE +log_must create_vdevs $TMPDIR/$FILEDISK1 +create_fails_without_force mirror $TMPDIR/$FILEDISK0 $TMPDIR/$FILEDISK1 + +log_assert "'zpool create' mirror without '-f' will fail " \ + "when devices are different types." +create_vdevs $TMPDIR/$FILEDISK0 +log_mustnot $ZPOOL create "$TESTPOOL4" "mirror" $TMPDIR/$FILEDISK0 ${disk}p3 +create_fails_without_force mirror $TMPDIR/$FILEDISK0 ${disk}p3 + +log_assert "'zpool create' without '-f' will fail " \ + "while device is part of potentially active pool." +create_vdevs $TMPDIR/$FILEDISK1 $TMPDIR/$FILEDISK2 +create_pool "$TESTPOOL5" "mirror" $TMPDIR/$FILEDISK1 $TMPDIR/$FILEDISK2 +log_must $ZPOOL offline $TESTPOOL5 $TMPDIR/$FILEDISK2 +log_must $ZPOOL export $TESTPOOL5 +create_fails_without_force $TMPDIR/$FILEDISK2 + +log_pass "'zpool create -f ...' success." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_003_pos.ksh new file mode 100644 index 00000000000..962c045b3a5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_003_pos.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_003_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_003_pos +# +# DESCRIPTION: +# 'zpool create -n ...' can display the configuration without +# actually creating the pool. +# +# STRATEGY: +# 1. Create storage pool with -n option +# 2. Verify the pool has not been actually created +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + [[ -e $tmpfile ]] && \ + log_must $RM -f $tmpfile +} + +tmpfile="$TMPDIR/zpool_create_003.tmp${TESTCASE_ID}" + +log_assert "'zpool create -n ...' can display the configureation" \ + "without actually creating the pool." + +log_onexit cleanup + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +# +# Make sure disk is clean before we use it +# +create_pool $TESTPOOL ${disk}p1 > $tmpfile +destroy_pool $TESTPOOL + +$ZPOOL create -n $TESTPOOL ${disk}p1 > $tmpfile + +poolexists $TESTPOOL && \ + log_fail "'zpool create -n ...' fail." + +str="would create '$TESTPOOL' with the following layout:" +$CAT $tmpfile | $GREP "$str" >/dev/null 2>&1 +(( $? != 0 )) && \ + log_fail "'zpool create -n ...' is executed as unexpected." + +log_pass "'zpool create -n ...' success." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_004_pos.ksh new file mode 100644 index 00000000000..eea1feda631 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_004_pos.ksh @@ -0,0 +1,94 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_004_pos.ksh 1.4 08/11/03 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_004_pos +# +# DESCRIPTION: +# 'zpool create [-f]' can create a storage pool with large number of +# file-in-zfs-filesystem-based vdevs without any errors. +# +# STRATEGY: +# 1. Create assigned number of files in ZFS filesystem as vdevs +# 2. Creating a new pool based on the vdevs should get success +# 3. Fill in the filesystem and create a partially writen file as vdev +# 4. Add the new file into vdevs list and create a pool +# 5. Creating a storage pool with the new vdevs list should be failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +VDEVS_POOL=create_004_pool + +function cleanup +{ + destroy_pool $VDEVS_POOL + destroy_pool $TESTPOOL2 + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL + [ -d "$TESTDIR" ] && log_must $RM -rf $TESTDIR +} + +log_assert "'zpool create [-f]' can create a pool with $VDEVS_NUM vdevs " \ + "without any errors." +log_onexit cleanup + +log_note "Creating storage pool with $VDEVS_NUM file vdevs should succeed." +vdevs_list="" +file_size=$FILE_SIZE + +[ -n "$DISK" ] && disk=$DISK || disk=$DISK0 +create_pool $TESTPOOL $disk +$ZFS create -o mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +for (( i = 0; $i < $VDEVS_NUM; i++ )); do + log_must create_vdevs $TESTDIR/vdev.${i} + vdevs_list="$vdevs_list $TESTDIR/vdev.${i}" +done + +create_pool $TESTPOOL1 $vdevs_list +destroy_pool $TESTPOOL1 + +log_pass "'zpool create [-f]' with $VDEVS_NUM vdevs success." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_005_pos.ksh new file mode 100644 index 00000000000..b1b41e5731e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_005_pos.ksh @@ -0,0 +1,122 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_005_pos.ksh 1.3 08/02/27 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_005_pos +# +# DESCRIPTION: +# 'zpool create [-R root][-m mountpoint] ...' can create an +# alternate root pool or a new pool mounted at the specified mountpoint. +# +# STRATEGY: +# 1. Create a pool with '-m' option +# 2. Verify the pool is mounted at the specified mountpoint +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + log_must $ZPOOL destroy -f $TESTPOOL + + for dir in $TMPDIR/zpool_create_005_pos $TESTDIR1; do + [[ -d $dir ]] && $RM -rf $dir + done +} + +log_assert "'zpool create [-R root][-m mountpoint] ...' can create" \ + "an alternate pool or a new pool mounted at the specified mountpoint." +log_onexit cleanup + +set -A pooltype "" "mirror" "raidz" "raidz1" "raidz2" + +#prepare raw file for file disk +TDIR=$TMPDIR/zpool_create_005_pos +FBASE=$TDIR/file +log_must $MKDIR $TDIR +log_must create_vdevs $FBASE.0 $FBASE.1 $FBASE.2 $FBASE.3 +#Remove the directory with name as pool name if it exists +[[ -d /$TESTPOOL ]] && $RM -rf /$TESTPOOL + +for opt in "-R $TESTDIR1" "-m $TESTDIR1" \ + "-R $TESTDIR1 -m $TESTDIR1" "-m $TESTDIR1 -R $TESTDIR1" +do + i=0 + while (( i < ${#pooltype[*]} )); do + #Remove the testing pool and its mount directory + poolexists $TESTPOOL && \ + log_must $ZPOOL destroy -f $TESTPOOL + [[ -d $TESTDIR1 ]] && $RM -rf $TESTDIR1 + log_must $ZPOOL create $opt $TESTPOOL ${pooltype[i]} \ + $FBASE.1 $FBASE.2 $FBASE.3 + mpt=`$ZFS mount | $EGREP "^$TESTPOOL[^/]" | $AWK '{print $2}'` + (( ${#mpt} == 0 )) && \ + log_fail "$TESTPOOL created with $opt is not mounted." + mpt_val=$(get_prop "mountpoint" $TESTPOOL) + [[ "$mpt" != "$mpt_val" ]] && \ + log_fail "The value of mountpoint property is different\ + from the output of zfs mount" + if [[ "$opt" == "-R $TESTDIR1" ]]; then + expected_mpt=${TESTDIR1}/${TESTPOOL} + elif [[ "$opt" == "-m $TESTDIR1" ]]; then + expected_mpt=${TESTDIR1} + else + expected_mpt=${TESTDIR1}${TESTDIR1} + fi + [[ ! -d $expected_mpt ]] && \ + log_fail "$expected_mpt is not created auotmatically." + [[ "$mpt" != "$expected_mpt" ]] && \ + log_fail "$expected_mpt is mounted on ${mpt} instead of $expected_mpt." + + [[ -d /$TESTPOOL ]] && \ + log_fail "The default mountpoint /$TESTPOOL is created" \ + "while with $opt option." + + (( i = i + 1 )) + done +done + +log_pass "'zpool create [-R root][-m mountpoint] ...' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_006_pos.ksh new file mode 100644 index 00000000000..1045e7c832d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_006_pos.ksh @@ -0,0 +1,141 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_006_pos.ksh 1.6 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_create_006_pos +# +# DESCRIPTION: +# Verify zpool create succeed with multiple keywords combination. +# +# STRATEGY: +# 1. Create base filesystem to hold virtual disk files. +# 2. Create several files >= 64M. +# 3. Verify 'zpool create' succeed with valid keywords combination. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1 + datasetexists $TESTPOOL && destroy_pool $TESTPOOL +} + + +log_assert "Verify 'zpool create' succeed with keywords combination." +log_onexit cleanup + +create_pool $TESTPOOL $DISKS +mntpnt=$(get_prop mountpoint $TESTPOOL) + +typeset -i i=0 +while ((i < 10)); do + log_must create_vdevs $mntpnt/vdev$i + + eval vdev$i=$mntpnt/vdev$i + ((i += 1)) +done + +set -A valid_args \ + "mirror $vdev0 $vdev1 $vdev2 mirror $vdev3 $vdev4 $vdev5" \ + "mirror $vdev0 $vdev1 mirror $vdev2 $vdev3 mirror $vdev4 $vdev5" \ + "mirror $vdev0 $vdev1 $vdev2 mirror $vdev3 $vdev4 $vdev5 \ + spare $vdev6" \ + "mirror $vdev0 $vdev1 mirror $vdev2 $vdev3 mirror $vdev4 $vdev5 \ + spare $vdev6 $vdev7" \ + "mirror $vdev0 $vdev1 spare $vdev2 mirror $vdev3 $vdev4" \ + "raidz $vdev0 $vdev1 $vdev2 raidz1 $vdev3 $vdev4 $vdev5" \ + "raidz $vdev0 $vdev1 raidz1 $vdev2 $vdev3 raidz $vdev4 $vdev5" \ + "raidz $vdev0 $vdev1 $vdev2 raidz1 $vdev3 $vdev4 $vdev5 \ + spare $vdev6" \ + "raidz $vdev0 $vdev1 raidz1 $vdev2 $vdev3 raidz $vdev4 $vdev5 \ + spare $vdev6 $vdev7" \ + "raidz $vdev0 $vdev1 spare $vdev2 raidz $vdev3 $vdev4" \ + "raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5" \ + "raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5 \ + raidz2 $vdev6 $vdev7 $vdev8" \ + "raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5 \ + spare $vdev6" \ + "raidz2 $vdev0 $vdev1 $vdev2 raidz2 $vdev3 $vdev4 $vdev5 \ + raidz2 $vdev6 $vdev7 $vdev8 spare $vdev9" \ + "raidz2 $vdev0 $vdev1 $vdev2 spare $vdev3 raidz2 $vdev4 $vdev5 $vdev6" + +set -A forced_args \ + "$vdev0 raidz $vdev1 $vdev2 raidz1 $vdev3 $vdev4 $vdev5" \ + "$vdev0 raidz2 $vdev1 $vdev2 $vdev3 raidz2 $vdev4 $vdev5 $vdev6" \ + "$vdev0 mirror $vdev1 $vdev2 mirror $vdev3 $vdev4" \ + "$vdev0 mirror $vdev1 $vdev2 raidz $vdev3 $vdev4 \ + raidz2 $vdev5 $vdev6 $vdev7 spare $vdev8" \ + "$vdev0 mirror $vdev1 $vdev2 spare $vdev3 raidz $vdev4 $vdev5" \ + "raidz $vdev0 $vdev1 raidz2 $vdev2 $vdev3 $vdev4" \ + "raidz $vdev0 $vdev1 raidz2 $vdev2 $vdev3 $vdev4 spare $vdev5" \ + "raidz $vdev0 $vdev1 spare $vdev2 raidz2 $vdev3 $vdev4 $vdev5" \ + "mirror $vdev0 $vdev1 raidz $vdev2 $vdev3 raidz2 $vdev4 $vdev5 $vdev6" \ + "mirror $vdev0 $vdev1 raidz $vdev2 $vdev3 \ + raidz2 $vdev4 $vdev5 $vdev6 spare $vdev7" \ + "mirror $vdev0 $vdev1 raidz $vdev2 $vdev3 \ + spare $vdev4 raidz2 $vdev5 $vdev6 $vdev7" \ + "spare $vdev0 $vdev1 $vdev2 mirror $vdev3 $vdev4 raidz $vdev5 $vdev6" + +i=0 +while ((i < ${#valid_args[@]})); do + log_must $ZPOOL create $TESTPOOL1 ${valid_args[$i]} + $SYNC; $SYNC + log_must $ZPOOL destroy -f $TESTPOOL1 + + ((i += 1)) +done + +i=0 +while ((i < ${#forced_args[@]})); do + log_mustnot $ZPOOL create $TESTPOOL1 ${forced_args[$i]} + log_must $ZPOOL create -f $TESTPOOL1 ${forced_args[$i]} + $SYNC; $SYNC + log_must $ZPOOL destroy -f $TESTPOOL1 + + ((i += 1)) +done + +log_pass "'zpool create' succeed with keywords combination." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_007_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_007_neg.ksh new file mode 100644 index 00000000000..ae8dd4bb901 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_007_neg.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_007_neg.ksh 1.5 08/11/03 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_007_neg +# +# DESCRIPTION: +# 'zpool create' should return an error with badly formed parameters. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute 'zpool create' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +set -A args "" "-?" "-n" "-f" "-nf" "-fn" "-f -n" "--f" "-e" "-s" \ + "-m" "-R" "-m -R" "-Rm" "-mR" "-m $TESTDIR $TESTPOOL" \ + "-R $TESTDIR $TESTPOOL" "-m nodir $TESTPOOL $disk" \ + "-R nodir $TESTPOOL $disk" "-m nodir -R nodir $TESTPOOL $disk" \ + "-R nodir -m nodir $TESTPOOL $disk" "-R $TESTDIR -m nodir $TESTPOOL $disk" \ + "-R nodir -m $TESTDIR $TESTPOOL $disk" \ + "-blah" "$TESTPOOL" "$TESTPOOL blah" "$TESTPOOL c?t0d0" \ + "$TESTPOOL c0txd0" "$TESTPOOL c0t0dx" "$TESTPOOL cxtxdx" \ + "$TESTPOOL mirror" "$TESTPOOL raidz" "$TESTPOOL mirror raidz" \ + "$TESTPOOL raidz1" "$TESTPOOL mirror raidz1" \ + "$TESTPOOL mirror c?t?d?" "$TESTPOOL mirror $disk c0t1d?" \ + "$TESTPOOL RAIDZ ${disk}p1 ${disk}p2" \ + "$TESTPOOL ${disk}p1 log ${disk}p2 \ + log ${disk}p3" \ + "$TESTPOOL ${disk}p1 spare ${disk}p2 \ + spare ${disk}p3" \ + "$TESTPOOL RAIDZ1 ${disk}p1 ${disk}p2" \ + "$TESTPOOL MIRROR $disk" "$TESTPOOL raidz $disk" \ + "$TESTPOOL raidz1 $disk" \ + "1tank $disk" "1234 $disk" "?tank $disk" \ + "tan%k $disk" "ta@# $disk" "tan+k $disk" \ + "$BYND_MAX_NAME $disk" + +log_assert "'zpool create' should return an error with badly-formed parameters." +log_onexit default_cleanup_noexit + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZPOOL create ${args[i]} + ((i = i + 1)) +done + +log_pass "'zpool create' with badly formed parameters failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_008_pos.ksh new file mode 100644 index 00000000000..de98816e202 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_008_pos.ksh @@ -0,0 +1,158 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)zpool_create_008_pos.ksh 1.5 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_008_pos +# +# DESCRIPTION: +# 'zpool create' have to use '-f' scenarios +# +# STRATEGY: +# 1. Prepare the scenarios +# 2. Create pool without '-f' and verify it fails +# 3. Create pool with '-f' and verify it succeeds +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if [[ $exported_pool == true ]]; then + if [[ $force_pool == true ]]; then + log_must $ZPOOL create -f $TESTPOOL ${disk}p1 + else + log_must $ZPOOL import $TESTPOOL + fi + fi + + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + + if poolexists $TESTPOOL1 ; then + destroy_pool $TESTPOOL1 + fi + + # + # recover it back to EFI label + # + wipe_partition_table $disk +} + +# +# create overlap slice 0 and 1 on $disk +# +function create_overlap_slice +{ + typeset format_file=$TMPDIR/format_overlap.${TESTCASE_ID} + typeset disk=$1 + + $ECHO "partition" >$format_file + $ECHO "0" >> $format_file + $ECHO "" >> $format_file + $ECHO "" >> $format_file + $ECHO "0" >> $format_file + $ECHO "200m" >> $format_file + $ECHO "1" >> $format_file + $ECHO "" >> $format_file + $ECHO "" >> $format_file + $ECHO "0" >> $format_file + $ECHO "400m" >> $format_file + $ECHO "label" >> $format_file + $ECHO "" >> $format_file + $ECHO "q" >> $format_file + $ECHO "q" >> $format_file + + $FORMAT -e -s -d $disk -f $format_file + typeset -i ret=$? + $RM -fr $format_file + + if (( ret != 0 )); then + log_fail "unable to create overlap slice." + fi + + return 0 +} + +log_assert "'zpool create' have to use '-f' scenarios" +log_onexit cleanup + +typeset exported_pool=false +typeset force_pool=false + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +# overlapped slices as vdev need -f to create pool + +# Make the disk is EFI labeled first via pool creation +create_pool $TESTPOOL $disk +destroy_pool $TESTPOOL + +# Make the disk is VTOC labeled since only VTOC label supports overlap +log_must labelvtoc $disk +log_must create_overlap_slice $disk + +log_mustnot $ZPOOL create $TESTPOOL ${disk}p1 +log_must $ZPOOL create -f $TESTPOOL ${disk}p1 +destroy_pool $TESTPOOL + +# exported device to be as spare vdev need -f to create pool + +log_must $ZPOOL create -f $TESTPOOL $disk +destroy_pool $TESTPOOL +log_must partition_disk $SIZE $disk 6 +create_pool $TESTPOOL ${disk}p1 ${disk}p2 +log_must $ZPOOL export $TESTPOOL +exported_pool=true +log_mustnot $ZPOOL create $TESTPOOL1 ${disk}p3 spare ${disk}p2 +create_pool $TESTPOOL1 ${disk}p3 spare ${disk}p2 +force_pool=true +destroy_pool $TESTPOOL1 + +log_pass "'zpool create' have to use '-f' scenarios" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_009_neg.ksh new file mode 100644 index 00000000000..7b70cd6cf63 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_009_neg.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_009_neg.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_create_009_neg +# +# DESCRIPTION: +# Create a pool with same devices twice or create two pools with same +# devices, 'zpool create' should failed. +# +# STRATEGY: +# 1. Loop to create the following three kinds of pools. +# - Regular pool +# - Mirror +# - Raidz +# 2. Create two pools but using the same disks, expect failed. +# 3. Create one pool but using the same disks twice, expect failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dtst + typeset disk + + for dtst in $TESTPOOL $TESTPOOL1; do + poolexists $dtst && destroy_pool $dtst + done +} + +log_assert "Create a pool with same devices twice or create two pools with " \ + "same devices, 'zpool create' should fail." +log_onexit cleanup + +typeset opt +for opt in "" "mirror" "raidz" "raidz1"; do + typeset disk="$DISKS" + (( ${#opt} == 0 )) && disk=${DISKS%% *} + + typeset -i count=$(get_word_count "$disk") + if (( count < 2 && ${#opt} != 0 )) ; then + continue + fi + + # Create two pools but using the same disks. + create_pool $TESTPOOL $opt $disk + log_mustnot $ZPOOL create -f $TESTPOOL1 $opt $disk + destroy_pool $TESTPOOL + + # Create two pools and part of the devices were overlapped + create_pool $TESTPOOL $opt $disk + log_mustnot $ZPOOL create -f $TESTPOOL1 $opt ${DISKS% *} + destroy_pool $TESTPOOL + + # Create one pool but using the same disks twice. + log_mustnot $ZPOOL create -f $TESTPOOL $opt $disk $disk +done + +log_pass "Using overlapping or in-use disks to create a new pool fails as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_010_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_010_neg.ksh new file mode 100644 index 00000000000..3484d29b03e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_010_neg.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_010_neg.ksh 1.3 07/02/06 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_010_neg +# +# DESCRIPTION: +# 'zpool create' should return an error with VDEVsof size <64mb +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute 'zpool create' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-30) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "'zpool create' should return an error with VDEVs <64mb" + +verify_runnable "global" + +function cleanup +{ + poolexists $TOOSMALL && destroy_pool $TOOSMALL + poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 + + poolexists $TESTPOOL && destroy_pool $TESTPOOL + + [[ -d $TESTDIR ]] && $RM -rf $TESTDIR +} +log_onexit cleanup + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +create_pool $TESTPOOL $disk +log_must $ZFS create $TESTPOOL/$TESTFS +log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +VDEV_SIZE=63m +log_must create_vdevs $TESTDIR/file1 $TESTDIR/file2 +unset VDEV_SIZE + +set -A args \ + "$TOOSMALL $TESTDIR/file1" "$TESTPOOL1 $TESTDIR/file1 $TESTDIR/file2" \ + "$TOOSMALL mirror $TESTDIR/file1 $TESTDIR/file2" \ + "$TOOSMALL raidz $TESTDIR/file1 $TESTDIR/file2" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZPOOL create ${args[i]} + ((i = i + 1)) +done + +log_pass "'zpool create' with badly formed parameters failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_011_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_011_neg.ksh new file mode 100644 index 00000000000..214d9e74f18 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_011_neg.ksh @@ -0,0 +1,140 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)zpool_create_011_neg.ksh 1.5 08/11/03 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_011_neg +# +# DESCRIPTION: +# 'zpool create' will fail in the following cases: +# existent pool; device is part of an active pool; nested virtual devices; +# differently sized devices without -f option; device being currently +# mounted; devices in /etc/vfstab; specified as the dedicated dump device. +# +# STRATEGY: +# 1. Create case scenarios +# 2. For each scenario, try to create a new pool with the virtual devices +# 3. Verify the creation is failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + for pool in $TESTPOOL $TESTPOOL1 + do + destroy_pool $pool + done + + if [[ -n $saved_dump_dev ]]; then + log_must $DUMPADM -u -d $saved_dump_dev + fi +} + +log_assert "'zpool create' should be failed with inapplicable scenarios." +log_onexit cleanup + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi +pooldev1=${disk}p1 +pooldev2=${disk}p2 +mirror1="${disk}p2 ${disk}p3" +mirror2="${disk}p4 ${disk}p5" +raidz1=$mirror1 +raidz2=$mirror2 +diff_size_dev="${disk}p6 ${disk}p7" +vfstab_dev=$(find_vfstab_dev) +specified_dump_dev=${disk}p1 +saved_dump_dev=$(save_dump_dev) + +lba=$(get_partition_end $disk 6) +set_partition 7 "$lba" $SIZE1 $disk +create_pool "$TESTPOOL" "$pooldev1" + +# +# Set up the testing scenarios parameters +# +set -A arg "$TESTPOOL $pooldev2" \ + "$TESTPOOL1 $pooldev1" \ + "$TESTPOOL1 $TESTDIR0/$FILEDISK0" \ + "$TESTPOOL1 mirror mirror $mirror1 mirror $mirror2" \ + "$TESTPOOL1 raidz raidz $raidz1 raidz $raidz2" \ + "$TESTPOOL1 raidz1 raidz1 $raidz1 raidz1 $raidz2" \ + "$TESTPOOL1 mirror raidz $raidz1 raidz $raidz2" \ + "$TESTPOOL1 mirror raidz1 $raidz1 raidz1 $raidz2" \ + "$TESTPOOL1 raidz mirror $mirror1 mirror $mirror2" \ + "$TESTPOOL1 raidz1 mirror $mirror1 mirror $mirror2" \ + "$TESTPOOL1 mirror $diff_size_dev" \ + "$TESTPOOL1 raidz $diff_size_dev" \ + "$TESTPOOL1 raidz1 $diff_size_dev" \ + "$TESTPOOL1 mirror $mirror1 spare $mirror2 spare $diff_size_dev" \ + "$TESTPOOL1 $vfstab_dev" \ + "$TESTPOOL1 ${disk}s10" \ + "$TESTPOOL1 spare $pooldev2" + +typeset -i i=0 +while (( i < ${#arg[*]} )); do + log_mustnot $ZPOOL create ${arg[i]} + (( i = i+1 )) +done + +# now destroy the pool to be polite +log_must $ZPOOL destroy -f $TESTPOOL + +# create/destroy a pool as a simple way to set the partitioning +# back to something normal so we can use this $disk as a dump device +log_must $ZPOOL create -f $TESTPOOL3 $disk +log_must $ZPOOL destroy -f $TESTPOOL3 + +log_must $DUMPADM -d /dev/$specified_dump_dev +log_mustnot $ZPOOL create -f $TESTPOOL1 "$specified_dump_dev" + +# Also check to see that in-use checking prevents us from creating +# a zpool from just the first slice on the disk. +log_mustnot $ZPOOL create -f $TESTPOOL1 ${specified_dump_dev}s0 + +log_pass "'zpool create' is failed as expected with inapplicable scenarios." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_012_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_012_neg.ksh new file mode 100644 index 00000000000..345437ba3e2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_012_neg.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)zpool_create_012_neg.ksh 1.1 07/05/25 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_012_neg +# +# +# DESCRIPTION: +# 'zpool create' will fail with formal disk slice in swap +# +# +# STRATEGY: +# 1. Get all the disk devices in swap +# 2. For each device, try to create a new pool with this device +# 3. Verify the creation is failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-04-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL; then + destroy_pool $TESTPOOL + fi + +} +typeset swap_disks=`$SWAP -l | $GREP "c[0-9].*d[0-9].*s[0-9]" | \ + $AWK '{print $1}'` + +log_assert "'zpool create' should fail with disk slice in swap." +log_onexit cleanup + +for sdisk in $swap_disks; do + for opt in "-n" "" "-f"; do + log_mustnot $ZPOOL create $opt $TESTPOOL $sdisk + done +done + +log_pass "'zpool create' passed as expected with inapplicable scenario." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_013_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_013_neg.ksh new file mode 100644 index 00000000000..730a0213512 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_013_neg.ksh @@ -0,0 +1,116 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)zpool_create_013_neg.ksh 1.2 08/02/27 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_013_neg +# +# +# DESCRIPTION: +# 'zpool create' will fail with metadevice in swap +# +# STRATEGY: +# 1. Create a one way strip metadevice +# 2. Try to create a new pool with metadevice in swap +# 3. Verify the creation is failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-04-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + # cleanup SVM + $METASTAT $md_name > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + $SWAP -l | $GREP /dev/md/$md_name > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + $SWAP -d /dev/md/$md_name + fi + $METACLEAR $md_name + fi + + $METADB | $GREP $mddb_dev > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + $METADB -df /dev/$mddb_dev + fi + + if poolexists $TESTPOOL; then + destroy_pool $TESTPOOL + fi + +} + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +typeset mddb_dev=${disk}p1 +typeset md_dev=${disk}p2 +typeset md_name=d0 +typeset MD_DSK=/dev/md/d0 + +log_assert "'zpool create' should fail with metadevice in swap." +log_onexit cleanup + +# +# use metadevice in swap to create pool, which should fail. +# +$METADB | $GREP $mddb_dev > /dev/null 2>&1 +if [[ $? -ne 0 ]]; then + log_must $METADB -af $mddb_dev +fi + +$METASTAT $md_name > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + $METACLEAR $md_name +fi + +log_must $METAINIT $md_name 1 1 $md_dev +log_must $SWAP -a $MD_DSK +for opt in "-n" "" "-f"; do + log_mustnot $ZPOOL create $opt $TESTPOOL $MD_DSK +done + +log_pass "'zpool create' passed as expected with inapplicable scenario." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_014_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_014_neg.ksh new file mode 100644 index 00000000000..12d80285683 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_014_neg.ksh @@ -0,0 +1,103 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)zpool_create_014_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_014_neg +# +# +# DESCRIPTION: +# 'zpool create' will fail with ordinary file in swap +# +# STRATEGY: +# 1. Create a regular file on top of UFS-zvol filesystem +# 2. Try to create a new pool with regular file in swap +# 3. Verify the creation is failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-04-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if datasetexists $vol_name; then + $SWAP -l | $GREP $TMP_FILE > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + log_must $SWAP -d $TMP_FILE + fi + $RM -f $TMP_FILE + log_must $UMOUNT $mntp + $ZFS destroy $vol_name + fi + + if poolexists $TESTPOOL; then + destroy_pool $TESTPOOL + fi +} + +log_assert "'zpool create' should fail with regular file in swap." +log_onexit cleanup + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +typeset pool_dev=${disk}p1 +typeset vol_name=$TESTPOOL/$TESTVOL +typeset mntp=$TMPDIR +typeset TMP_FILE=$mntp/tmpfile.${TESTCASE_ID} + +create_pool $TESTPOOL $pool_dev +log_must $ZFS create -V 100m $vol_name +log_must $ECHO "y" | $NEWFS /dev/zvol/$vol_name > /dev/null 2>&1 +log_must $MOUNT /dev/zvol/$vol_name $mntp + +log_must $MKFILE 50m $TMP_FILE +log_must $SWAP -a $TMP_FILE + +for opt in "-n" "" "-f"; do + log_mustnot $ZPOOL create $opt $TESTPOOL $TMP_FILE +done + +log_pass "'zpool create' passed as expected with inapplicable scenario." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_015_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_015_neg.ksh new file mode 100644 index 00000000000..b463b381151 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_015_neg.ksh @@ -0,0 +1,103 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)zpool_create_015_neg.ksh 1.2 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_015_neg +# +# +# DESCRIPTION: +# 'zpool create' will fail with zfs vol device in swap +# +# +# STRATEGY: +# 1. Create a zpool +# 2. Create a zfs vol on zpool +# 3. Add this zfs vol device to swap +# 4. Try to create a new pool with devices in swap +# 5. Verify the creation is failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-04-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + # cleanup zfs pool and dataset + if datasetexists $vol_name; then + $SWAP -l | $GREP /dev/zvol/$vol_name > /dev/null 2>&1 + if [[ $? -eq 0 ]]; then + $SWAP -d /dev/zvol/${vol_name} + fi + fi + + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL +} + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +typeset pool_dev=${disk}p1 +typeset vol_name=$TESTPOOL/$TESTVOL + +log_assert "'zpool create' should fail with zfs vol device in swap." +log_onexit cleanup + +# +# use zfs vol device in swap to create pool which should fail. +# +create_pool $TESTPOOL $pool_dev +log_must $ZFS create -V 100m $vol_name +log_must $SWAP -a /dev/zvol/$vol_name +for opt in "-n" "" "-f"; do + log_mustnot $ZPOOL create $opt $TESTPOOL1 /dev/zvol/${vol_name} +done + +# cleanup +log_must $SWAP -d /dev/zvol/${vol_name} +log_must $ZFS destroy $vol_name + +log_pass "'zpool create' passed as expected with inapplicable scenario." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_016_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_016_pos.ksh new file mode 100644 index 00000000000..0f96a96f4c3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_016_pos.ksh @@ -0,0 +1,100 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_016_pos.ksh 1.2 08/08/15 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_016_pos +# +# +# DESCRIPTION: +# 'zpool create' will success with no device in swap +# +# +# STRATEGY: +# 1. delete all devices in the swap +# 2. create a zpool +# 3. Verify the creation is successed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-04-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL + + #recover swap devices + FSTAB=$TMPDIR/fstab_${TESTCASE_ID} + $RM -f $FSTAB + for sdisk in $swap_disks; do + $ECHO "$sdisk - - swap - no -" >> $FSTAB + done + if [ -e $FSTAB ] + then + log_must $SWAPADD $FSTAB + fi + $RM -f $FSTAB + if [ $dump_device != "none" ] + then + log_must $DUMPADM -u -d $dump_device + fi +} + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi +typeset pool_dev=${disk}p1 +typeset swap_disks=`$SWAP -l | $GREP -v "swapfile" | $AWK '{print $1}'` +typeset dump_device=`$DUMPADM | $GREP "Dump device" | $AWK '{print $3}'` + +log_assert "'zpool create' should success with no device in swap." +log_onexit cleanup + +for sdisk in $swap_disks; do + log_must $SWAP -d $sdisk +done + +log_must $ZPOOL create $TESTPOOL $pool_dev + +log_pass "'zpool create' passed as expected with applicable scenario." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_017_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_017_neg.ksh new file mode 100644 index 00000000000..3c2e238e925 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_017_neg.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)zpool_create_017_neg.ksh 1.1 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_017_neg +# +# +# DESCRIPTION: +# 'zpool create' will fail with mountpoint exists and is not empty. +# +# +# STRATEGY: +# 1. Prepare the mountpoint put some stuff into it. +# 2. Verify 'zpool create' over that mountpoint fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL; then + destroy_pool $TESTPOOL + fi + + if [[ -d $TESTDIR ]]; then + log_must $RM -rf $TESTDIR + fi +} + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +typeset pool_dev=${disk}p1 + +log_assert "'zpool create' should fail with mountpoint exists and not empty." +log_onexit cleanup + +if [[ ! -d $TESTDIR ]]; then + log_must $MKDIR -p $TESTDIR +fi + +typeset -i i=0 + +while (( i < 2 )); do + log_must $RM -rf $TESTDIR/* + if (( i == 0 )); then + log_must $MKDIR $TESTDIR/testdir + else + log_must $TOUCH $TESTDIR/testfile + fi + + log_mustnot $ZPOOL create -m $TESTDIR -f $TESTPOOL $pool_dev + log_mustnot poolexists $TESTPOOL + + (( i = i + 1 )) +done + +log_pass "'zpool create' fail as expected with mountpoint exists and not empty." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_018_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_018_pos.ksh new file mode 100644 index 00000000000..2f200ec9fa1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_018_pos.ksh @@ -0,0 +1,120 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_018_pos.ksh 1.4 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_018_pos +# +# DESCRIPTION: +# +# zpool create can create pools with specified properties +# +# STRATEGY: +# 1. Create a pool with all editable properties +# 2. Verify those properties are set +# 3. Create a pool with two properties set +# 4. Verify both properties are set correctly +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + destroy_pool $TESTPOOL + + if [[ -f $CPATH ]] ; then + log_must $RM $CPATH + fi +} + +log_onexit cleanup +log_assert "zpool create can create pools with specified properties" + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +# we don't include "root" property in this list, as it requires both "cachefile" +# and "root" to be set at the same time. A test for this is included in +# ../../root. +set -A props "autoreplace" "delegation" "cachefile" "version" +set -A vals "off" "off" "$CPATH" "3" + +if pool_prop_exist autoexpand ; then + set -A props ${props[*]} "autoexpand" + set -A vals ${vals[*]} "on" +fi + +typeset -i i=0; +while [ $i -lt "${#props[@]}" ] +do + log_must $ZPOOL create -o ${props[$i]}=${vals[$i]} $TESTPOOL $disk + RESULT=$(get_pool_prop ${props[$i]} $TESTPOOL) + if [[ $RESULT != ${vals[$i]} ]] + then + $ZPOOL get all $TESTPOOL + log_fail "Pool was created without setting the ${props[$i]} property" + fi + destroy_pool $TESTPOOL + (( i = i + 1 )) +done + +# pick two properties, and verify we can create with those as well +log_must $ZPOOL create -o delegation=off -o cachefile=$CPATH $TESTPOOL $disk +RESULT=$(get_pool_prop delegation $TESTPOOL) +if [[ $RESULT != off ]] +then + $ZPOOL get all $TESTPOOL + log_fail "Pool created without the delegation prop." +fi + +RESULT=$(get_pool_prop cachefile $TESTPOOL) +if [[ $RESULT != $CPATH ]] +then + $ZPOOL get all $TESTPOOL + log_fail "Pool created without the cachefile prop." +fi + +log_pass "zpool create can create pools with specified properties" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_019_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_019_pos.ksh new file mode 100644 index 00000000000..646669921fd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_019_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_019_pos.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_019_pos +# +# DESCRIPTION: +# +# zpool create cannot create pools specifying readonly properties +# +# STRATEGY: +# 1. Attempt to create a pool, specifying each readonly property in turn +# 2. Verify the pool was not created +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-24) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi +} + +log_onexit cleanup + +log_assert "zpool create cannot create pools specifying readonly properties" + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +set -A props "available" "capacity" "guid" "health" "size" "used" +set -A vals "100" "10" "12345" "HEALTHY" "10" "10" + +typeset -i i=0; +while [ $i -lt "${#props[@]}" ] +do + # try to set each property in the prop list with it's corresponding val + log_mustnot $ZPOOL create -o ${props[$i]}=${vals[$i]} $TESTPOOL $disk + if poolexists $TESTPOOL + then + log_fail "$TESTPOOL was created when setting ${props[$i]}!" + fi + i=$(( $i + 1)) +done + +log_pass "zpool create cannot create pools specifying readonly properties" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_020_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_020_pos.ksh new file mode 100644 index 00000000000..d9f7ed89f15 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_020_pos.ksh @@ -0,0 +1,123 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_020_pos.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_020_pos +# +# DESCRIPTION: +# +# zpool create -R works as expected +# +# STRATEGY: +# 1. Create a -R altroot pool +# 2. Verify the pool is mounted at the correct location +# 3. Verify that cachefile=none for the pool +# 4. Verify that root= for the pool +# 5. Verify that no reference to the pool is found in /etc/zfs/zpool.cache + +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + [[ -d ${TESTPOOL}.root ]] && log_must $RM -rf /${TESTPOOL}.root +} + +log_onexit cleanup + +log_assert "zpool create -R works as expected" + +if [[ -n $DISK ]]; then + disk=$DISK +else + disk=$DISK0 +fi + +$RM -rf /${TESTPOOL}.root +log_must $MKDIR /${TESTPOOL}.root +log_must $ZPOOL create -R /${TESTPOOL}.root $TESTPOOL $disk +if [ ! -d /${TESTPOOL}.root ] +then + log_fail "Mountpoint was not create when using zpool with -R flag!" +fi + +FS=$($ZFS list $TESTPOOL) +if [ -z "$FS" ] +then + log_fail "Mounted filesystem at /${TESTPOOL}.root isn't ZFS!" +fi + +log_must $ZPOOL get all $TESTPOOL +$ZPOOL get all $TESTPOOL > $TMPDIR/values.${TESTCASE_ID} + +# check for the cachefile property, verifying that it's set to 'none' +$GREP "$TESTPOOL[ ]*cachefile[ ]*none" $TMPDIR/values.${TESTCASE_ID} > /dev/null 2>&1 +if [ $? -ne 0 ] +then + log_fail "zpool property \'cachefile\' was not set to \'none\'." +fi + +# check that the root = /mountpoint property is set correctly +$GREP "$TESTPOOL[ ]*altroot[ ]*/${TESTPOOL}.root" $TMPDIR/values.${TESTCASE_ID} > /dev/null 2>&1 +if [ $? -ne 0 ] +then + log_fail "zpool property root was not found in pool output." +fi + +$RM $TMPDIR/values.${TESTCASE_ID} + +# finally, check that the pool has no reference in /etc/zfs/zpool.cache +if [[ -f /etc/zfs/zpool.cache ]] ; then + REF=$($STRINGS /etc/zfs/zpool.cache | $GREP ${TESTPOOL}) + if [ ! -z "$REF" ] + then + $STRINGS /etc/zfs/zpool.cache + log_fail "/etc/zfs/zpool.cache appears to have a reference to $TESTPOOL" + fi +fi + + +log_pass "zpool create -R works as expected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_021_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_021_pos.ksh new file mode 100644 index 00000000000..353bf71aa5f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_021_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_021_pos.ksh 1.2 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_021_pos +# +# DESCRIPTION: +# 'zpool create -O property=value pool' can successfully create a pool +# with correct filesystem property set. +# +# STRATEGY: +# 1. Create a storage pool with -O option +# 2. Verify the pool created successfully +# 3. Verify the filesystem property is correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-27) +# +# __stc_assertion_end +# +################################################################################ + +if ! $(check_zpool_opt_support "create" "-O") ; then + log_unsupported "-O option is not supported yet." +fi + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL +} + +log_onexit cleanup + +log_assert "'zpool create -O property=value pool' can successfully create a pool \ + with correct filesystem property set." + +set -A RW_FS_PROP "quota=512M" \ + "reservation=512M" \ + "recordsize=64K" \ + "mountpoint=/tmp/mnt${TESTCASE_ID}" \ + "checksum=fletcher2" \ + "compression=lzjb" \ + "atime=off" \ + "devices=off" \ + "exec=off" \ + "setuid=off" \ + "readonly=on" \ + "snapdir=visible" \ + "aclmode=discard" \ + "aclinherit=discard" \ + "canmount=off" \ + "sharenfs=on" + +typeset -i i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + log_must $ZPOOL create -O ${RW_FS_PROP[$i]} -f $TESTPOOL $DISKS + datasetexists $TESTPOOL || \ + log_fail "zpool create $TESTPOOL fail." + propertycheck $TESTPOOL ${RW_FS_PROP[i]} || \ + log_fail "${RW_FS_PROP[i]} is failed to set." + destroy_pool $TESTPOOL + (( i = i + 1 )) +done + +log_pass "'zpool create -O property=value pool' can successfully create a pool \ + with correct filesystem property set." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_022_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_022_pos.ksh new file mode 100644 index 00000000000..1713c8a610e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_022_pos.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_022_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_create/zfs_create_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_022_pos +# +# DESCRIPTION: +# 'zpool create -O property=value pool' can successfully create a pool +# with multiple filesystem properties set. +# +# STRATEGY: +# 1. Create a storage pool with multiple -O options +# 2. Verify the pool created successfully +# 3. Verify the properties are correctly set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-27) +# +# __stc_assertion_end +# +################################################################################ + +if ! $(check_zpool_opt_support "create" "-O") ; then + log_unsupported "-O option is not supported yet." +fi + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL +} + +log_onexit cleanup + +log_assert "'zpool create -O property=value pool' can successfully create a pool \ + with multiple filesystem properties set." + +set -A RW_FS_PROP "quota=512M" \ + "reservation=512M" \ + "recordsize=64K" \ + "mountpoint=/tmp/mnt${TESTCASE_ID}" \ + "checksum=fletcher2" \ + "compression=lzjb" \ + "atime=off" \ + "devices=off" \ + "exec=off" \ + "setuid=off" \ + "readonly=on" \ + "snapdir=visible" \ + "aclmode=discard" \ + "aclinherit=discard" \ + "canmount=off" \ + "sharenfs=on" + +typeset -i i=0 +typeset opts="" + +while (( $i < ${#RW_FS_PROP[*]} )); do + opts="$opts -O ${RW_FS_PROP[$i]}" + (( i = i + 1 )) +done + +log_must $ZPOOL create $opts -f $TESTPOOL $DISKS +datasetexists $TESTPOOL || log_fail "zpool create $TESTPOOL fail." + +i=0 +while (( $i < ${#RW_FS_PROP[*]} )); do + propertycheck $TESTPOOL ${RW_FS_PROP[i]} || \ + log_fail "${RW_FS_PROP[i]} is failed to set." + (( i = i + 1 )) +done + +log_pass "'zpool create -O property=value pool' can successfully create a pool \ + with multiple filesystem properties set." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_023_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_023_neg.ksh new file mode 100644 index 00000000000..889094e1616 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_023_neg.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_023_neg.ksh 1.1 09/05/19 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_023_neg +# +# DESCRIPTION: +# 'zpool create -O' should return an error with badly formed parameters. +# +# STRATEGY: +# 1. Create an array of parameters with '-O' +# 2. For each parameter in the array, execute 'zpool create -O' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-27) +# +# __stc_assertion_end +# +################################################################################ + +if ! $(check_zpool_opt_support "create" "-O") ; then + log_unsupported "-O option is not supported yet." +fi + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL +} + +log_onexit cleanup + +set -A args "QuOta=none" "quota=non" "quota=abcd" "quota=0" "quota=" \ + "ResErVaTi0n=none" "reserV=none" "reservation=abcd" "reserv=" \ + "recorDSize=64k" "recordsize=32M" "recordsize=256" \ + "recsize=" "recsize=zero" "recordsize=0" \ + "mountPoint=/tmp/tmpfile${TESTCASE_ID}" "mountpoint=non0" "mountpoint=" \ + "mountpoint=LEGACY" "mounpoint=none" \ + "sharenfs=ON" "ShareNFS=off" "sharenfs=sss" \ + "checkSUM=on" "checksum=SHA256" "chsum=off" "checksum=aaa" \ + "compression=of" "ComPression=lzjb" "compress=ON" "compress=a" \ + "atime=ON" "ATime=off" "atime=bbb" \ + "deviCes=on" "devices=OFF" "devices=aaa" \ + "exec=ON" "EXec=off" "exec=aaa" \ + "readonly=ON" "reADOnly=off" "rdonly=OFF" "rdonly=aaa" \ + "zoned=ON" "ZoNed=off" "zoned=aaa" \ + "snapdIR=hidden" "snapdir=VISible" "snapdir=aaa" \ + "aclmode=DIScard" "aclmODE=groupmask" "aclmode=aaa" \ + "aclinherit=deny" "aclinHerit=secure" "aclinherit=aaa" \ + "type=volume" "type=snapshot" "type=filesystem" \ + "creation=aaa" "used=10K" "available=10K" \ + "referenced=10K" "compressratio=1.00x" \ + "version=0" "version=1.234" "version=10K" "version=-1" \ + "version=aaa" "version=999" + +log_assert "'zpool create -O' should return an error with badly formed parameters." + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZPOOL create -O ${args[i]} -f $TESTPOOL $DISKS + ((i = i + 1)) +done + +log_pass "'zpool create -O' should return an error with badly formed parameters." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_test.sh new file mode 100755 index 00000000000..068942dc472 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_test.sh @@ -0,0 +1,677 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_create_001_pos cleanup +zpool_create_001_pos_head() +{ + atf_set "descr" "'zpool create ...' can successfully createa new pool with a name in ZFS namespace." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_002_pos cleanup +zpool_create_002_pos_head() +{ + atf_set "descr" "'zpool create -f ...' can successfully createa new pool in some cases." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_003_pos cleanup +zpool_create_003_pos_head() +{ + atf_set "descr" "'zpool create -n ...' can display the configureationwithout actually creating the pool." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_004_pos cleanup +zpool_create_004_pos_head() +{ + atf_set "descr" "'zpool create [-f]' can create a storage pool with large numbers of vdevswithout any errors." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2400 +} +zpool_create_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_005_pos cleanup +zpool_create_005_pos_head() +{ + atf_set "descr" "'zpool create [-R root][-m mountpoint] ...' can createan alternate pool or a new pool mounted at the specified mountpoint." + atf_set "require.progs" zpool zfs + atf_set "timeout" 2400 +} +zpool_create_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_005_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_006_pos cleanup +zpool_create_006_pos_head() +{ + atf_set "descr" "Verify 'zpool create' succeed with keywords combination." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_006_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_007_neg cleanup +zpool_create_007_neg_head() +{ + atf_set "descr" "'zpool create' should return an error with badly-formed parameters." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_007_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_007_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_008_pos cleanup +zpool_create_008_pos_head() +{ + atf_set "descr" "'zpool create' have to use '-f' scenarios" + atf_set "require.progs" zpool format + atf_set "timeout" 2400 +} +zpool_create_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_008_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_009_neg cleanup +zpool_create_009_neg_head() +{ + atf_set "descr" "Create a pool with same devices twice or create two pools withsame devices, 'zpool create' should fail." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_009_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_010_neg cleanup +zpool_create_010_neg_head() +{ + atf_set "descr" "'zpool create' should return an error with VDEVs <64mb" + atf_set "require.progs" zfs zpool + atf_set "timeout" 2400 +} +zpool_create_010_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_010_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_011_neg cleanup +zpool_create_011_neg_head() +{ + atf_set "descr" "'zpool create' should be failed with inapplicable scenarios." + atf_set "require.progs" dumpadm zpool + atf_set "timeout" 2400 +} +zpool_create_011_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_011_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_011_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_012_neg cleanup +zpool_create_012_neg_head() +{ + atf_set "descr" "'zpool create' should fail with disk slice in swap." + atf_set "require.progs" zpool swap + atf_set "timeout" 2400 +} +zpool_create_012_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_012_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_012_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_013_neg cleanup +zpool_create_013_neg_head() +{ + atf_set "descr" "'zpool create' should fail with metadevice in swap." + atf_set "require.progs" metadb metaclear metastat zpool metainit swap + atf_set "timeout" 2400 +} +zpool_create_013_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_013_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_013_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_014_neg cleanup +zpool_create_014_neg_head() +{ + atf_set "descr" "'zpool create' should fail with regular file in swap." + atf_set "require.progs" zfs swap zpool + atf_set "timeout" 2400 +} +zpool_create_014_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_014_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_014_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_015_neg cleanup +zpool_create_015_neg_head() +{ + atf_set "descr" "'zpool create' should fail with zfs vol device in swap." + atf_set "require.progs" zfs zpool swap + atf_set "timeout" 2400 +} +zpool_create_015_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_015_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_015_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_016_pos cleanup +zpool_create_016_pos_head() +{ + atf_set "descr" "'zpool create' should success with no device in swap." + atf_set "require.progs" dumpadm swapadd zpool swap + atf_set "timeout" 2400 +} +zpool_create_016_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_016_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_016_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_017_neg cleanup +zpool_create_017_neg_head() +{ + atf_set "descr" "'zpool create' should fail with mountpoint exists and not empty." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_017_neg_body() +{ + [ `uname -s` = "FreeBSD" ] && atf_skip "FreeBSD does not consider creating pools on non-empty mountpoints a bug" + + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_017_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_017_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_018_pos cleanup +zpool_create_018_pos_head() +{ + atf_set "descr" "zpool create can create pools with specified properties" + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_018_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_018_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_018_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_019_pos cleanup +zpool_create_019_pos_head() +{ + atf_set "descr" "zpool create cannot create pools specifying readonly properties" + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_019_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_019_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_019_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_020_pos cleanup +zpool_create_020_pos_head() +{ + atf_set "descr" "zpool create -R works as expected" + atf_set "require.progs" zfs zpool + atf_set "timeout" 2400 +} +zpool_create_020_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_020_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_020_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_021_pos cleanup +zpool_create_021_pos_head() +{ + atf_set "descr" "'zpool create -O property=value pool' can successfully create a poolwith correct filesystem property set." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_021_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_021_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_021_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_022_pos cleanup +zpool_create_022_pos_head() +{ + atf_set "descr" "'zpool create -O property=value pool' can successfully create a poolwith multiple filesystem properties set." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_022_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_022_pos.ksh || atf_fail "Testcase failed" +} +zpool_create_022_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_023_neg cleanup +zpool_create_023_neg_head() +{ + atf_set "descr" "'zpool create -O' should return an error with badly formed parameters." + atf_set "require.progs" zpool + atf_set "timeout" 2400 +} +zpool_create_023_neg_body() +{ + atf_expect_fail 'kern/221987 - ZFS does not validate the sharenfs parameter' + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_create_023_neg.ksh || atf_fail "Testcase failed" +} +zpool_create_023_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_create.kshlib + . $(atf_get_srcdir)/zpool_create.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_create_001_pos + atf_add_test_case zpool_create_002_pos + atf_add_test_case zpool_create_003_pos + atf_add_test_case zpool_create_004_pos + atf_add_test_case zpool_create_005_pos + atf_add_test_case zpool_create_006_pos + atf_add_test_case zpool_create_007_neg + atf_add_test_case zpool_create_008_pos + atf_add_test_case zpool_create_009_neg + atf_add_test_case zpool_create_010_neg + atf_add_test_case zpool_create_011_neg + atf_add_test_case zpool_create_012_neg + atf_add_test_case zpool_create_013_neg + atf_add_test_case zpool_create_014_neg + atf_add_test_case zpool_create_015_neg + atf_add_test_case zpool_create_016_pos + atf_add_test_case zpool_create_017_neg + atf_add_test_case zpool_create_018_pos + atf_add_test_case zpool_create_019_pos + atf_add_test_case zpool_create_020_pos + atf_add_test_case zpool_create_021_pos + atf_add_test_case zpool_create_022_pos + atf_add_test_case zpool_create_023_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/Makefile new file mode 100644 index 00000000000..05847ff4d95 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_destroy +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_destroy_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh + +${PACKAGE}FILES+= zpool_destroy.cfg +${PACKAGE}FILES+= zpool_destroy_001_pos.ksh +${PACKAGE}FILES+= zpool_destroy_002_pos.ksh +${PACKAGE}FILES+= zpool_destroy_003_neg.ksh +${PACKAGE}FILES+= zpool_destroy_004_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/cleanup.ksh new file mode 100644 index 00000000000..496e5fce294 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/cleanup.ksh @@ -0,0 +1,33 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy.cfg new file mode 100644 index 00000000000..a073a558a50 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_destroy.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export DISK=${DISKS%% *} +export PART_SIZE=500m diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh new file mode 100644 index 00000000000..b4b608a5d92 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_destroy_001_pos.ksh 1.7 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_destroy_001_pos +# +# DESCRIPTION: +# 'zpool destroy ' can successfully destroy the specified pool. +# +# STRATEGY: +# 1. Create a storage pool +# 2. Destroy the pool +# 3. Verify the is destroyed successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL2 + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL + wipe_partition_table $DISK +} + +set -A datasets "$TESTPOOL" "$TESTPOOL2" + +log_assert "'zpool destroy ' can destroy a specified pool." + +log_onexit cleanup + +partition_disk $PART_SIZE $DISK 2 + +create_pool "$TESTPOOL" "${DISK}p1" +create_pool "$TESTPOOL1" "${DISK}p2" +log_must $ZFS create -s -V $VOLSIZE $TESTPOOL1/$TESTVOL +create_pool "$TESTPOOL2" "/dev/zvol/$TESTPOOL1/$TESTVOL" + +typeset -i i=0 +while (( i < ${#datasets[*]} )); do + log_must poolexists "${datasets[i]}" + log_must $ZPOOL destroy "${datasets[i]}" + log_mustnot poolexists "${datasets[i]}" + ((i = i + 1)) +done + +log_pass "'zpool destroy ' executes successfully" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh new file mode 100644 index 00000000000..fd0d405bf76 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh @@ -0,0 +1,122 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_destroy_002_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_destroy_002_pos +# +# DESCRIPTION: +# 'zpool destroy -f ' can forcely destroy the specified pool. +# +# STRATEGY: +# 1. Create a storage pool +# 2. Create some datasets within the pool +# 3. Change directory to any mountpoint of these datasets, +# Verify 'zpool destroy' without '-f' will fail. +# 4. 'zpool destroy -f' the pool +# 5. Verify the pool is destroyed successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + [[ -n $cwd ]] && log_must cd $cwd + + if [[ -d $TESTDIR ]]; then + ismounted $TESTDIR + (( $? == 0 )) && \ + log_must $UNMOUNT $TESTDIR + log_must $RM -rf $TESTDIR + fi + + destroy_pool $TESTPOOL +} + +set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \ + +log_assert "'zpool destroy -f ' can forcely destroy the specified pool" + +log_onexit cleanup + +typeset cwd="" + +create_pool "$TESTPOOL" "$DISK" +log_must $ZFS create $TESTPOOL/$TESTFS +log_must $MKDIR -p $TESTDIR +log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +log_must $ZFS create $TESTPOOL/$TESTCTR +log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1 +log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL + +typeset -i i=0 +while (( $i < ${#datasets[*]} )); do + datasetexists "${datasets[i]}" || \ + log_fail "Create datasets fail." + ((i = i + 1)) +done + +cwd=$PWD +log_note "'zpool destroy' without '-f' will fail " \ + "while pool is busy." + +for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do + log_must cd $dir + log_mustnot $ZPOOL destroy $TESTPOOL + + # Need mount here, otherwise some dataset may be unmounted. + log_must $ZFS mount -a + + i=0 + while (( i < ${#datasets[*]} )); do + datasetexists "${datasets[i]}" || \ + log_fail "Dataset ${datasets[i]} removed unexpected." + ((i = i + 1)) + done +done + +destroy_pool $TESTPOOL +log_mustnot poolexists "$TESTPOOL" + +log_pass "'zpool destroy -f ' success." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh new file mode 100644 index 00000000000..92cf393cb2a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_003_neg.ksh @@ -0,0 +1,70 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_destroy_003_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_destroy_003_neg +# +# DESCRIPTION: +# 'zpool destroy' should return an error with badly formed parameters, +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute 'zpool destroy' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +set -A args "" "-f" "-? $TESTPOOL" "nonexistent_pool" \ + "$TESTPOOL abcd" "abcd $TESTPOOL" + +log_assert "'zpool destroy' should return an error with badly-formed parameters." + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZPOOL destroy ${args[i]} + ((i = i + 1)) +done + +log_pass "'zpool destroy' badly formed parameters fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_004_pos.ksh new file mode 100644 index 00000000000..17c1b90e12d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_004_pos.ksh @@ -0,0 +1,146 @@ +#!/usr/local/bin/ksh93 -p +# +# Copyright 2015 Spectra Logic Corporation. +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_destroy_004_pos +# +# DESCRIPTION: +# 'zpool destroy -f ' can forcibly destroy the specified pool, +# even if that pool has running zfs send or receive activity. +# +# STRATEGY: +# 1. Create a storage pool +# 2. For each sleep time in a set: +# 2a. For each destroy type (same pool, sender only, receiver only): +# - Create a dataset with some amount of data +# - Run zfs send | zfs receive in the background. +# - Sleep the amount of time specified for this run. +# - 'zpool destroy -f' the pool. +# - Wait for the send|receive to exit. It must not be killed in +# order to ensure that the destroy takes care of doing so. +# - Verify the pool destroyed successfully +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 +} + +function create_sender +{ + cleanup + create_pool "$TESTPOOL" "$DISK0" + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $MKDIR -p $TESTDIR + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + log_must dd if=/dev/zero of=$TESTDIR/f0 bs=1024k count=$datasz + log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap1 +} + +function create_sender_and_receiver +{ + create_sender + create_pool "$TESTPOOL1" "$DISK1" +} + +function send_recv_destroy +{ + sleeptime=$1 + recv=$2 + to_destroy=$3 + who_to_destroy="$4" + + # The pid of this pipe line is that of zfs receive + # + ( $ZFS send -RP $TESTPOOL/$TESTFS@snap1 | $ZFS receive -Fu $recv/d1 ) & + sndrcv_start=$(date '+%s') + rcvpid=$! + sndpid=$(pgrep -P $rcvpid) + + log_must sleep $sleeptime + log_note "post sleep: $(ps -p ${sndpid},${rcvpid} -o command)" + + destroy_start=$(date '+%s') + log_must $ZPOOL destroy -f $to_destroy + destroy_end=$(date '+%s') + dtime=$((destroy_end - destroy_start)) + log_note "Destroy of $who_to_destroy took ${dtime} seconds." + + log_note "post destroy: $(ps -p ${sndpid},${rcvpid} -o command)" + + # Wait for send and recv to exit. + # + wait $sndpid + snderr=$? + wait $rcvpid + rcverr=$? + wait_end=$(date '+%s') + wtime=$((wait_end - sndrcv_start)) + log_note "send|receive took ${wtime} seconds to finish." + + # KSH: "wait pid" exit status of 127 means that process never existed + # or already completed; ksh's wait only returns the status of the + # child process if the child was running when the wait was issued. + # Therefore, we can not imply much about the interruption of the + # send | recv by zpool destroy -f + # + # The real test of success is simply that the pool was destroyed. + # + log_note \ + "Destruction of ${who_to_destroy}: send ${snderr}, recv ${rcverr}" + + log_mustnot $ZPOOL list $to_destroy +} + +function run_tests +{ + log_note "TEST: send|receive to the same pool" + create_sender + send_recv_destroy $sleeptime $TESTPOOL $TESTPOOL SAME_POOL + + log_note "TEST: send|receive to different pools, destroy sender" + create_sender_and_receiver + send_recv_destroy $sleeptime $TESTPOOL1 $TESTPOOL SENDER + + log_note "TEST: send|receive to different pools, destroy receiver" + create_sender_and_receiver + send_recv_destroy $sleeptime $TESTPOOL1 $TESTPOOL1 RECEIVER +} + +log_assert "'zpool destroy -f ' can force destroy active pool" +log_onexit cleanup +set_disks + +# Faster tests using 1GB data size +datasz=1000 +log_note "Running fast tests with 1000MB of data" +for sleeptime in 0.1 0.3 0.5 0.75 1 2 3; do + run_tests +done + +# A longer test that simulates a more realistic send|receive that exceeds +# the size of arc memory by 1/3 and gets interrupted a decent amount of +# time after the start of the run. +arcmem=$(sysctl -n vfs.zfs.arc_max) +# ARC will use 2xdatasz memory since it caches both the src and dst copies +datasz=$((arcmem / 1048576 * 2 / 3)) +log_note "Running longer test with ${datasz}MB of data" +sleeptime=15 +run_tests + +log_pass "'zpool destroy -f ' successful with active pools." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_test.sh new file mode 100755 index 00000000000..d24c16e4a21 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_test.sh @@ -0,0 +1,129 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_destroy_001_pos cleanup +zpool_destroy_001_pos_head() +{ + atf_set "descr" "'zpool destroy ' can destroy a specified pool." + atf_set "require.progs" zfs zpool +} +zpool_destroy_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + verify_zvol_recursive + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/zpool_destroy_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_destroy_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_destroy_002_pos cleanup +zpool_destroy_002_pos_head() +{ + atf_set "descr" "'zpool destroy -f ' can forcely destroy the specified pool" + atf_set "require.progs" zfs zpool +} +zpool_destroy_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/zpool_destroy_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_destroy_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_destroy_003_neg cleanup +zpool_destroy_003_neg_head() +{ + atf_set "descr" "'zpool destroy' should return an error with badly-formed parameters." + atf_set "require.progs" zpool +} +zpool_destroy_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + ksh93 $(atf_get_srcdir)/zpool_destroy_003_neg.ksh || atf_fail "Testcase failed" +} +zpool_destroy_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_destroy_004_pos cleanup +zpool_destroy_004_pos_head() +{ + atf_set "descr" "'zpool destroy -f' should work on active pools." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2000 +} +zpool_destroy_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/zpool_destroy_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_destroy_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_destroy_001_pos + atf_add_test_case zpool_destroy_002_pos + atf_add_test_case zpool_destroy_003_neg + atf_add_test_case zpool_destroy_004_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/Makefile new file mode 100644 index 00000000000..087f0d6aa62 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_detach +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_detach_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_detach.cfg +${PACKAGE}FILES+= zpool_detach_001_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/cleanup.ksh new file mode 100644 index 00000000000..b5a6a6c0f9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/setup.ksh new file mode 100644 index 00000000000..e4db7febd63 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +default_mirror_setup $DISKS diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach.cfg new file mode 100644 index 00000000000..68a9c850205 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_detach.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach_001_neg.ksh new file mode 100644 index 00000000000..c8e9be414ff --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach_001_neg.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_detach_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_detach_001_neg +# +# DESCRIPTION: +# Executing 'zpool detach' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool detach' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +DISKLIST=$(get_disklist $TESTPOOL) + +set -A args "" "-?" "-t fakepool" "-f fakepool" "-ev fakepool" "fakepool" \ + "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $DISKLIST" \ + "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTPOOL/$TESTCTR $DISKLIST" "$TESTPOOL/$TESTVOL" \ + "$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" "$TESTPOOL/$TESTVOL $DISKLIST" \ + "$DISKLIST" + +log_assert "Executing 'zpool detach' with bad options fails" + +if [[ -z $DISKLIST ]]; then + log_fail "DISKLIST is empty." +fi + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL detach ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool detach' command with bad options failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach_test.sh new file mode 100755 index 00000000000..e33bf7f0e75 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_detach/zpool_detach_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_detach_001_neg cleanup +zpool_detach_001_neg_head() +{ + atf_set "descr" "Executing 'zpool detach' with bad options fails" + atf_set "require.progs" zpool +} +zpool_detach_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_detach.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_detach_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_detach_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_detach.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_detach_001_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/Makefile new file mode 100644 index 00000000000..d2f6f321446 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_expand +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_expand_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_expand_003_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_expand_002_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_expand.cfg +${PACKAGE}FILES+= zpool_expand_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/cleanup.ksh new file mode 100644 index 00000000000..dff86e31599 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/setup.ksh new file mode 100644 index 00000000000..3989fd70d79 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/setup.ksh @@ -0,0 +1,42 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if ! pool_prop_exist "autoexpand"; then + log_unsupported "zpool autoexpand is not support on testing machine" +fi + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand.cfg new file mode 100644 index 00000000000..1cf5a8114fb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand.cfg @@ -0,0 +1,47 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_expand.cfg 1.1 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +org_size=1g +exp_size=2g + +export org_size +export exp_size + +VFS=$TESTPOOL/$TESTFS +export VFS + +EX_1GB=1073741824 +EX_3GB=3221225472 + +export EX_1GB +export EX_3GB + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_001_pos.ksh new file mode 100644 index 00000000000..dd407aae371 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_001_pos.ksh @@ -0,0 +1,138 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_expand_001_pos.ksh 1.2 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zpool_expand_001_pos +# +# DESCRIPTION: +# Once zpool set autoexpand=on poolname, zpool can autoexpand by +# Dynamic LUN Expansion +# +# +# STRATEGY: +# 1) Create a pool +# 2) Create volume on top of the pool +# 3) Create pool by using the zvols and set autoexpand=on +# 4) Expand the vol size by 'zfs set volsize' +# 5) Check that the pool size was expanded +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + + for i in 1 2 3; do + if datasetexists $VFS/vol$i; then + log_must $ZFS destroy $VFS/vol$i + fi + done +} + +log_onexit cleanup + +log_assert "zpool can be autoexpanded after set autoexpand=on on LUN expansion" + +for i in 1 2 3; do + log_must $ZFS create -V $org_size $VFS/vol$i +done + +for type in " " mirror raidz raidz2; do + + log_must $ZPOOL create -o autoexpand=on $TESTPOOL1 $type \ + /dev/zvol/$VFS/vol1 \ + /dev/zvol/$VFS/vol2 \ + /dev/zvol/$VFS/vol3 + + typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) + if [[ $autoexp != "on" ]]; then + log_fail "zpool $TESTPOOL1 autoexpand should on but is $autoexp" + fi + + typeset prev_size=$(get_pool_prop size $TESTPOOL1) + + for i in 1 2 3; do + log_must $ZFS set volsize=$exp_size $VFS/vol$i + done + + $SYNC + $SLEEP 10 + $SYNC + + typeset expand_size=$(get_pool_prop size $TESTPOOL1) + + # check for zpool history for the pool size expansion + if [[ $type == "mirror" ]]; then + $ZPOOL history -il $TESTPOOL1 | \ + $GREP "pool '$TESTPOOL1' size:" | \ + $GREP "internal vdev online" | \ + $GREP "(+${EX_1GB})" >/dev/null 2>&1 + + if [[ $? -ne 0 ]] ; then + log_fail "pool $TESTPOOL1" \ + " is not autoexpand after LUN expansion" + fi + else + $ZPOOL history -il $TESTPOOL1 | \ + $GREP "pool '$TESTPOOL1' size:" | \ + $GREP "internal vdev online" | \ + $GREP "(+${EX_3GB})" >/dev/null 2>&1 + + if [[ $? -ne 0 ]] ; then + log_fail "pool $TESTPOOL1" \ + " is not autoexpand after LUN expansion" + fi + fi + + log_must $ZPOOL destroy $TESTPOOL1 + + for i in 1 2 3; do + log_must $ZFS set volsize=$org_size $VFS/vol$i + done + +done + +log_pass "zpool can be autoexpanded after set autoexpand=on on LUN expansion" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_002_pos.ksh new file mode 100644 index 00000000000..dabcbbe06a1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_002_pos.ksh @@ -0,0 +1,142 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_expand_002_pos.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zpool_expand_002_pos +# +# DESCRIPTION: +# After zpool online -e poolname zvol vdevs, zpool can autoexpand by +# Dynamic LUN Expansion +# +# +# STRATEGY: +# 1) Create a pool +# 2) Create volume on top of the pool +# 3) Create pool by using the zvols +# 4) Expand the vol size by zfs set volsize +# 5 Use zpool online -e to online the zvol vdevs +# 6) Check that the pool size was expaned +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + + for i in 1 2 3; do + if datasetexists $VFS/vol$i; then + log_must $ZFS destroy $VFS/vol$i + fi + done +} + +log_onexit cleanup + +log_assert "zpool can expand after zpool online -e zvol vdevs on LUN expansion" + +for i in 1 2 3; do + log_must $ZFS create -V $org_size $VFS/vol$i +done + +for type in " " mirror raidz raidz2; do + log_must $ZPOOL create $TESTPOOL1 $type \ + /dev/zvol/$VFS/vol1 \ + /dev/zvol/$VFS/vol2 \ + /dev/zvol/$VFS/vol3 + + typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) + if [[ $autoexp != "off" ]]; then + log_fail "zpool $TESTPOOL1 autoexpand should off but is $autoexp" + fi + + typeset prev_size=$(get_pool_prop size $TESTPOOL1) + + for i in 1 2 3; do + log_must $ZFS set volsize=$exp_size $VFS/vol$i + done + + for i in 1 2 3; do + log_must $ZPOOL online -e $TESTPOOL1 /dev/zvol/$VFS/vol$i + done + + $SYNC + $SLEEP 10 + $SYNC + + # check for zpool history for the pool size expansion + if [[ $type == " " || $type == "mirror" ]]; then + $ZPOOL history -il $TESTPOOL1 | \ + $GREP "pool '$TESTPOOL1' size:" | \ + $GREP "internal vdev online" | \ + $GREP "(+${EX_1GB})" >/dev/null 2>&1 + + if [[ $? -ne 0 ]]; then + log_fail "pool $TESTPOOL1" \ + " is not autoexpand after LUN expansion" + fi + else + $ZPOOL history -il $TESTPOOL1 | \ + $GREP "pool '$TESTPOOL1' size:" | \ + $GREP "internal vdev online" | \ + $GREP "(+${EX_3GB})" >/dev/null 2>&1 + + if [[ $? -ne 0 ]] ; then + log_fail "pool $TESTPOOL1" \ + " is not autoexpand after LUN expansion" + fi + fi + + typeset expand_size=$(get_pool_prop size $TESTPOOL1) + + log_must $ZPOOL destroy $TESTPOOL1 + + for i in 1 2 3; do + log_must $ZFS set volsize=$org_size $VFS/vol$i + done + +done + +log_pass "zpool can expand after zpool online -e zvol vdevs on LUN expansion" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_003_neg.ksh new file mode 100644 index 00000000000..5a7fa55a39d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_003_neg.ksh @@ -0,0 +1,128 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_expand_003_neg.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zpool_expand_003_neg +# +# Description: +# Once set zpool autoexpand=off, zpool can *NOT* autoexpand by +# Dynamic LUN Expansion +# +# +# STRATEGY: +# 1) Create a pool +# 2) Create volumes on top of the pool +# 3) Create pool by using the zvols and set autoexpand=off +# 4) Expand the vol size by zfs set volsize +# 5) Check that the pool size is not changed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + + for i in 1 2 3; do + if datasetexists $VFS/vol$i; then + log_must $ZFS destroy $VFS/vol$i + fi + done +} + +log_onexit cleanup + +log_assert "zpool can not expand if set autoexpand=off after LUN expansion" + +for i in 1 2 3; do + log_must $ZFS create -V $org_size $VFS/vol$i +done + +for type in "" mirror raidz raidz2; do + log_must $ZPOOL create $TESTPOOL1 $type \ + /dev/zvol/$VFS/vol1 \ + /dev/zvol/$VFS/vol2 \ + /dev/zvol/$VFS/vol3 + + typeset autoexp=$(get_pool_prop autoexpand $TESTPOOL1) + if [[ $autoexp != "off" ]]; then + log_fail "zpool $TESTPOOL1 autoexpand should off but is $autoexp" + fi + + typeset prev_size=$(get_pool_prop size $TESTPOOL1) + + for i in 1 2 3; do + log_must $ZFS set volsize=$exp_size $VFS/vol$i + done + + $SYNC + $SLEEP 10 + $SYNC + + # check for zpool history for the pool size expansion + $ZPOOL history -il $TESTPOOL1 | \ + $GREP "pool '$TESTPOOL1' size:" | \ + $GREP "internal vdev online" >/dev/null 2>&1 + + if [[ $? -eq 0 ]]; then + log_fail "pool $TESTPOOL1" \ + " is not autoexpand after LUN expansion" + fi + + typeset expand_size=$(get_pool_prop size $TESTPOOL1) + + if [[ "$prev_size" != "$expand_size" ]]; then + log_fail "pool $TESTPOOL1 size changed after LUN expansion" + fi + + log_must $ZPOOL destroy $TESTPOOL1 + + for i in 1 2 3; do + log_must $ZFS set volsize=$org_size $VFS/vol$i + done + +done + +log_pass "zpool can not expand if set autoexpand=off after LUN expansion" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_test.sh new file mode 100755 index 00000000000..042c0b07e29 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_expand/zpool_expand_test.sh @@ -0,0 +1,110 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_expand_001_pos cleanup +zpool_expand_001_pos_head() +{ + atf_set "descr" "zpool can be autoexpanded after set autoexpand=on on LUN expansion" + atf_set "require.progs" zfs zpool +} +zpool_expand_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_expand.cfg + + verify_zvol_recursive + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_expand_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_expand_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_expand.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_expand_002_pos cleanup +zpool_expand_002_pos_head() +{ + atf_set "descr" "zpool can expand after zpool online -e zvol vdevs on LUN expansion" + atf_set "require.progs" zfs zpool +} +zpool_expand_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_expand.cfg + + verify_zvol_recursive + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_expand_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_expand_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_expand.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_expand_003_neg cleanup +zpool_expand_003_neg_head() +{ + atf_set "descr" "zpool can not expand if set autoexpand=off after LUN expansion" + atf_set "require.progs" zfs zpool +} +zpool_expand_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_expand.cfg + + verify_zvol_recursive + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_expand_003_neg.ksh || atf_fail "Testcase failed" +} +zpool_expand_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_expand.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_expand_001_pos + atf_add_test_case zpool_expand_002_pos + atf_add_test_case zpool_expand_003_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/Makefile new file mode 100644 index 00000000000..ebbeb662a76 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_export +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_export_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_export.cfg +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_export_001_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_export_004_pos.ksh +${PACKAGE}FILES+= zpool_export_003_neg.ksh +${PACKAGE}FILES+= zpool_export_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export.cfg new file mode 100644 index 00000000000..baeafdc9778 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_export.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_001_pos.ksh new file mode 100644 index 00000000000..9f99c5cd356 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_001_pos.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_export_001_pos.ksh 1.3 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_export_001_pos +# +# DESCRIPTION: +# Exported pools should no longer be visible from 'zpool list'. +# Therefore, we export an existing pool and verify it cannot +# be accessed. +# +# STRATEGY: +# 1. Unmount the test directory. +# 2. Export the pool. +# 3. Verify the pool is no longer present in the list output. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dir=$(get_device_dir $DISKS) + + datasetexists "$TESTPOOL/$TESTFS" || \ + log_must $ZPOOL import -d $dir $TESTPOOL + + ismounted "$TESTPOOL/$TESTFS" + (( $? != 0 )) && \ + log_must $ZFS mount $TESTPOOL/$TESTFS +} + +log_onexit cleanup + +log_assert "Verify a pool can be exported." + +log_must $ZFS umount $TESTDIR +log_must $ZPOOL export $TESTPOOL + +poolexists $TESTPOOL && \ + log_fail "$TESTPOOL unexpectedly found in 'zpool list' output." + +log_pass "Successfully exported a ZPOOL." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_002_pos.ksh new file mode 100644 index 00000000000..dd4b3bb6350 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_002_pos.ksh @@ -0,0 +1,94 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_export_002_pos.ksh 1.3 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_export_002_pos +# +# DESCRIPTION: +# The 'zpool export' command must fail when a pool is +# busy i.e. mounted. +# +# STRATEGY: +# 1. Try and export the default pool when mounted and busy. +# 2. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dir=$(get_device_dir $DISKS) + cd $olddir || \ + log_fail "Couldn't cd back to $olddir" + + datasetexists "$TESTPOOL/$TESTFS" || \ + log_must $ZPOOL import -d $dir $TESTPOOL + + ismounted "$TESTPOOL/$TESTFS" + (( $? != 0 )) && \ + log_must $ZFS mount $TESTPOOL/$TESTFS + + [[ -e $TESTDIR/$TESTFILE0 ]] && \ + log_must $RM -rf $TESTDIR/$TESTFILE0 +} + +olddir=$PWD + +log_onexit cleanup + +log_assert "Verify a busy ZPOOL cannot be exported." + +ismounted "$TESTPOOL/$TESTFS" +(( $? != 0 )) && \ + log_fail "$TESTDIR not mounted. Unable to continue." + +cd $TESTDIR || \ + log_fail "Couldn't cd to $TESTDIR" + +log_mustnot $ZPOOL export $TESTPOOL + +poolexists $TESTPOOL || \ + log_fail "$TESTPOOL not found in 'zpool list' output." + +log_pass "Unable to export a busy ZPOOL as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_003_neg.ksh new file mode 100644 index 00000000000..9a5f793bd87 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_003_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_export_003_neg.ksh 1.2 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_export_003_neg +# +# DESCRIPTION: +# 'zpool export' should return an error with badly formed parameters, +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute 'zpool export' +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + typeset dir=$(get_device_dir $DISKS) + datasetexists "$TESTPOOL/$TESTFS" || \ + log_must $ZPOOL import -d $dir $TESTPOOL + + ismounted "$TESTPOOL/$TESTFS" + (( $? != 0 )) && \ + log_must $ZFS mount $TESTPOOL/$TESTFS +} + +log_onexit cleanup + +set -A args "" "-f" "-? $TESTPOOL" "-QWERTYUIO $TESTPOOL" + +log_assert "'zpool export' should return an error with badly-formed parameters." + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZPOOL export ${args[i]} + ((i = i + 1)) +done + +log_pass "'zpool export' badly formed parameters fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_004_pos.ksh new file mode 100644 index 00000000000..1df52d9ac91 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_004_pos.ksh @@ -0,0 +1,117 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_export_004_pos.ksh 1.2 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_export_004_pos +# +# DESCRIPTION: +# Verify zpool export succeed or fail with spare. +# +# STRATEGY: +# 1. Create two mirror pools with same spare. +# 2. Verify zpool export one pool succeed. +# 3. Import the pool. +# 4. Replace one device with the spare and detach it in one pool. +# 5. Verify zpool export the pool succeed. +# 6. Import the pool. +# 7. Replace one device with the spare in one pool. +# 8. Verify zpool export the pool fail. +# 9. Verify zpool export the pool with "-f" succeed. +# 10. Import the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-03-10) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + restart_zfsd + + mntpnt=$(get_prop mountpoint $TESTPOOL) + datasetexists $TESTPOOL1 || log_must $ZPOOL import -d $mntpnt $TESTPOOL1 + datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1 + datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2 + typeset -i i=0 + while ((i < 5)); do + if [[ -e $mntpnt/vdev$i ]]; then + log_must $RM -f $mntpnt/vdev$i + fi + ((i += 1)) + done +} + + +log_assert "Verify zpool export succeed or fail with spare." +log_onexit cleanup +# Stop ZFSD because it interferes with our manually activated spares +stop_zfsd + +mntpnt=$(get_prop mountpoint $TESTPOOL) + +typeset -i i=0 +while ((i < 5)); do + log_must create_vdevs $mntpnt/vdev$i + eval vdev$i=$mntpnt/vdev$i + ((i += 1)) +done + +log_must $ZPOOL create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4 +log_must $ZPOOL create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4 + +log_must $ZPOOL export $TESTPOOL1 +log_must $ZPOOL import -d $mntpnt $TESTPOOL1 + +log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4 +log_must $ZPOOL detach $TESTPOOL1 $vdev4 +log_must $ZPOOL export $TESTPOOL1 +log_must $ZPOOL import -d $mntpnt $TESTPOOL1 + +log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4 +log_mustnot $ZPOOL export $TESTPOOL1 + +log_must $ZPOOL export -f $TESTPOOL1 +log_must $ZPOOL import -d $mntpnt $TESTPOOL1 + +log_pass "Verify zpool export succeed or fail with spare." + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_test.sh new file mode 100755 index 00000000000..cfb49d1f8b5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_export/zpool_export_test.sh @@ -0,0 +1,132 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_export_001_pos cleanup +zpool_export_001_pos_head() +{ + atf_set "descr" "Verify a pool can be exported." + atf_set "require.progs" zfs zpool +} +zpool_export_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_export_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_export_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_export_002_pos cleanup +zpool_export_002_pos_head() +{ + atf_set "descr" "Verify a busy ZPOOL cannot be exported." + atf_set "require.progs" zfs zpool +} +zpool_export_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_export_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_export_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_export_003_neg cleanup +zpool_export_003_neg_head() +{ + atf_set "descr" "'zpool export' should return an error with badly-formed parameters." + atf_set "require.progs" zfs zpool +} +zpool_export_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_export_003_neg.ksh || atf_fail "Testcase failed" +} +zpool_export_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_export_004_pos cleanup +zpool_export_004_pos_head() +{ + atf_set "descr" "Verify zpool export succeed or fail with spare." + atf_set "require.progs" zpool +} +zpool_export_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_export_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_export_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_export.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_export_001_pos + atf_add_test_case zpool_export_002_pos + atf_add_test_case zpool_export_003_neg + atf_add_test_case zpool_export_004_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/Makefile new file mode 100644 index 00000000000..bbf123b85a6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_get +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_get_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_get_002_pos.ksh +${PACKAGE}FILES+= zpool_get_003_pos.ksh +${PACKAGE}FILES+= zpool_get.cfg +${PACKAGE}FILES+= zpool_get_001_pos.ksh +${PACKAGE}FILES+= zpool_get_004_neg.ksh +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/cleanup.ksh new file mode 100644 index 00000000000..9fdf9435910 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 08/05/14 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +verify_runnable "both" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/setup.ksh new file mode 100644 index 00000000000..05ab19d8b5e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/setup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 08/05/14 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib +verify_runnable "both" + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get.cfg new file mode 100644 index 00000000000..3f4ad97c6b6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get.cfg @@ -0,0 +1,71 @@ +#!/bin/ksh -p +# vim: filetype=sh +# +# 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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_get.cfg 1.6 09/06/22 SMI" +# + +# $FreeBSD$ + +# Set the expected properties of zpool +typeset -a properties=( + "size" + "capacity" + "altroot" + "health" + "guid" + "version" + "bootfs" + "delegation" + "autoreplace" + "cachefile" + "failmode" + "listsnapshots" + "autoexpand" + "dedupditto" + "dedupratio" + "free" + "allocated" + "readonly" + "comment" + "expandsize" + "freeing" + "fragmentation" + "leaked" + "feature@async_destroy" + "feature@empty_bpobj" + "feature@lz4_compress" + "feature@multi_vdev_crash_dump" + "feature@spacemap_histogram" + "feature@enabled_txg" + "feature@hole_birth" + "feature@extensible_dataset" + "feature@embedded_data" + "feature@bookmarks" + "feature@filesystem_limits" + "feature@large_blocks" + "feature@sha512" + "feature@skein" + # "feature@edonr" Edonr is not yet implemented on FreeBSD +) diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_001_pos.ksh new file mode 100644 index 00000000000..de3994b040c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_001_pos.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_get_001_pos.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_get_001_pos +# +# DESCRIPTION: +# +# Zpool get usage message is displayed when called with no arguments +# +# STRATEGY: +# 1. Run zpool get +# 2. Check that exit status is set to 2 +# 3. Check usage message contains text "usage" +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-06) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "Zpool get usage message is displayed when called with no arguments." + +$ZPOOL get > /dev/null 2>&1 +RET=$? +if [ $RET != 2 ] +then + log_fail "\"zpool get\" exit status $RET should be equal to 2." +fi + +OUTPUT=$($ZPOOL get 2>&1 | $GREP -i usage) +RET=$? +if [ $RET != 0 ] +then + log_fail "Usage message for zpool get did not contain the word 'usage'." +fi + +log_pass "Zpool get usage message is displayed when called with no arguments." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_002_pos.ksh new file mode 100644 index 00000000000..8d79b54a5d7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_002_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_get_002_pos.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_get/zpool_get.cfg + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_get_002_pos +# +# DESCRIPTION: +# +# zpool get all works as expected +# +# STRATEGY: +# +# 1. Using zpool get, retrieve all default values +# 2. Verify that the header is printed +# 3. Verify that we can see all the properties we expect to see +# 4. Verify that the total output contains just those properties + header. +# +# Test for those properties are expected to check whether their +# default values are sane, or whether they can be changed with zpool set. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "Zpool get all works as expected" + +typeset -i i=0; + +if ! is_global_zone ; then + TESTPOOL=${TESTPOOL%%/*} +fi + +log_must $ZPOOL get all $TESTPOOL +$ZPOOL get all $TESTPOOL > $TMPDIR/values.${TESTCASE_ID} + +log_note "Checking zpool get all output for a header." +$GREP ^"NAME " $TMPDIR/values.${TESTCASE_ID} > /dev/null 2>&1 +if [ $? -ne 0 ] +then + log_fail "The header was not printed from zpool get all" +fi + + +while [ $i -lt "${#properties[@]}" ] +do + log_note "Checking for ${properties[$i]} property" + $GREP "$TESTPOOL *${properties[$i]}" $TMPDIR/values.${TESTCASE_ID} > /dev/null 2>&1 + if [ $? -ne 0 ] + then + log_fail "zpool property ${properties[$i]} was not found\ + in pool output." + fi + i=$(( $i + 1 )) +done + +# increment the counter to include the header line +i=$(( $i + 1 )) + +COUNT=$($WC $TMPDIR/values.${TESTCASE_ID} | $AWK '{print $1}') +if [ $i -ne $COUNT ] +then + log_fail "Length of output $COUNT was not equal to number of props + 1." +fi + + + +$RM $TMPDIR/values.${TESTCASE_ID} +log_pass "Zpool get all works as expected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_003_pos.ksh new file mode 100644 index 00000000000..0c1166a29b8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_003_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_get_003_pos.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_get/zpool_get.cfg + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_get_003_pos +# +# DESCRIPTION: +# +# Zpool get returns values for all known properties +# +# STRATEGY: +# 1. For all properties, verify zpool get retrieves a value +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "Zpool get returns values for all known properties" + +if ! is_global_zone ; then + TESTPOOL=${TESTPOOL%%/*} +fi + +typeset -i i=0; + +while [ $i -lt "${#properties[@]}" ] +do + log_note "Checking for ${properties[$i]} property" + log_must eval "$ZPOOL get ${properties[$i]} $TESTPOOL > $TMPDIR/value.${TESTCASE_ID}" + $GREP "${properties[$i]}" $TMPDIR/value.${TESTCASE_ID} > /dev/null 2>&1 + if [ $? -ne 0 ] + then + log_fail "${properties[$i]} not seen in output" + fi + $GREP "^NAME " $TMPDIR/value.${TESTCASE_ID} > /dev/null 2>&1 + # only need to check this once. + if [ $i -eq 0 ] && [ $? -ne 0 ] + then + log_fail "Header not seen in zpool get output" + fi + i=$(( $i + 1 )) +done + +$RM $TMPDIR/value.${TESTCASE_ID} +log_pass "Zpool get returns values for all known properties" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_004_neg.ksh new file mode 100644 index 00000000000..5d8ce214c40 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_004_neg.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_get_004_neg.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_get_004_neg +# +# DESCRIPTION: +# +# Malformed zpool get commands are rejected +# +# STRATEGY: +# +# 1. Run several different "zpool get" commands that should fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "Malformed zpool get commands are rejected" + +if ! is_global_zone ; then + TESTPOOL=${TESTPOOL%%/*} +fi + +set -A arguments "$TESTPOOL $TESTPOOL" "$TESTPOOL rubbish" "-v $TESTPOOL" \ + "nosuchproperty $TESTPOOL" "--$TESTPOOL" "all all" \ + "type $TESTPOOL" "usage: $TESTPOOL" "bootfs $TESTPOOL@" \ + "bootfs,bootfs $TESTPOOL" "name $TESTPOOL" "t%d%s" \ + "bootfs,delegation $TESTPOOL" "delegation $TESTPOOL@" + +for arg in $arguments +do + log_mustnot $ZPOOL get $arg +done + +log_pass "Malformed zpool get commands are rejected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_test.sh new file mode 100755 index 00000000000..ddd29e8b098 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_get/zpool_get_test.sh @@ -0,0 +1,130 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_get_001_pos cleanup +zpool_get_001_pos_head() +{ + atf_set "descr" "Zpool get usage message is displayed when called with no arguments." + atf_set "require.progs" zpool +} +zpool_get_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + ksh93 $(atf_get_srcdir)/zpool_get_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_get_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_get_002_pos cleanup +zpool_get_002_pos_head() +{ + atf_set "descr" "Zpool get all works as expected" + atf_set "require.progs" zpool +} +zpool_get_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_get_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_get_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_get_003_pos cleanup +zpool_get_003_pos_head() +{ + atf_set "descr" "Zpool get returns values for all known properties" + atf_set "require.progs" zpool +} +zpool_get_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_get_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_get_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_get_004_neg cleanup +zpool_get_004_neg_head() +{ + atf_set "descr" "Malformed zpool get commands are rejected" + atf_set "require.progs" zpool +} +zpool_get_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_get_004_neg.ksh || atf_fail "Testcase failed" +} +zpool_get_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_get.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_get_001_pos + atf_add_test_case zpool_get_002_pos + atf_add_test_case zpool_get_003_pos + atf_add_test_case zpool_get_004_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_history/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/Makefile new file mode 100644 index 00000000000..8752b63ae34 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_history +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_history_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_history_001_neg.ksh +${PACKAGE}FILES+= zpool_history_002_pos.ksh +${PACKAGE}FILES+= zpool_history.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_history/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/cleanup.ksh new file mode 100644 index 00000000000..bd026cc21f5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +$ZPOOL history > /dev/null +(($? != 0)) && log_unsupported + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_history/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/setup.ksh new file mode 100644 index 00000000000..491e9e1fa03 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +default_container_volume_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history.cfg new file mode 100644 index 00000000000..d189b0ed611 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history.cfg @@ -0,0 +1,30 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_001_neg.ksh new file mode 100644 index 00000000000..077ea783d9e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_001_neg.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_history_001_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_history_001_neg +# +# DESCRIPTION: +# Verify 'zpool history' can deal with non-existent pools and garbage +# to the command. +# +# STRATEGY: +# 1. Create pool, volume & snap +# 2. Verify 'zpool history' can cope with incorret arguments. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +snap=$TESTPOOL/$TESTFS@snap +clone=$TESTPOOL/clone + +set -A neg_opt "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" "-t $TESTPOOL" \ + "-v $TESTPOOL" "$snap" "$clone" "nonexist" "TESTPOOL" + +function cleanup +{ + datasetexists $clone && log_must $ZFS destroy $clone + datasetexists $snap && log_must $ZFS destroy $snap +} + +log_assert "Verify 'zpool history' can deal with non-existent pools and " \ + "garbage to the command." +log_onexit cleanup + +log_must $ZFS snapshot $snap +log_must $ZFS clone $snap $clone + +for opt in "${neg_opt[@]}"; do + log_mustnot eval "$ZPOOL history $opt > /dev/null" +done + +log_pass "'zpool history' command line negation test passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_002_pos.ksh new file mode 100644 index 00000000000..25233cef3f0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_002_pos.ksh @@ -0,0 +1,70 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_history_002_pos.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_history_002_pos +# +# DESCRIPTION: +# Verify zpool history can handle options [-il] correctly. +# +# STRATEGY: +# 1. Create varied combinations of option -i & -l. +# 2. Verify 'zpool history' can cope with these combination correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-11-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +$ZFS 2>&1 | $GREP "allow" > /dev/null +(($? != 0)) && log_unsupported + +log_assert "Verify zpool history can handle options [-il] correctly." + +options="-i -l -il -li -lil -ili -lli -iill -liil" + +for opt in $options; do + log_must eval "$ZPOOL history $opt $TESTPOOL > /dev/null 2>&1" +done + +log_pass "Verify zpool history can handle options [-il] passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_test.sh new file mode 100755 index 00000000000..6468f3b5e10 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_history/zpool_history_test.sh @@ -0,0 +1,82 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_history_001_neg cleanup +zpool_history_001_neg_head() +{ + atf_set "descr" "Verify 'zpool history' can deal with non-existent pools andgarbage to the command." + atf_set "require.progs" zfs zpool +} +zpool_history_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_history.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_history_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_history_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_history_002_pos cleanup +zpool_history_002_pos_head() +{ + atf_set "descr" "Verify zpool history can handle options [-il] correctly." + atf_set "require.progs" zfs zpool +} +zpool_history_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_history.cfg + + verify_disk_count "$DISK" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_history_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_history_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_history_001_neg + atf_add_test_case zpool_history_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/Makefile new file mode 100644 index 00000000000..8885c9a3983 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/Makefile @@ -0,0 +1,43 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_import +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_import_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_import_006_pos.ksh +${PACKAGE}FILES+= zpool_import_002_pos.ksh +${PACKAGE}FILES+= zpool_import_missing_003_pos.ksh +${PACKAGE}FILES+= zpool_import_all_001_pos.ksh +${PACKAGE}FILES+= zpool_import.cfg +${PACKAGE}FILES+= zpool_import_corrupt_001_pos.ksh +${PACKAGE}FILES+= zpool_import_destroyed_001_neg.ksh +${PACKAGE}FILES+= zpool_import_destroyed_002_neg.ksh +${PACKAGE}FILES+= zpool_import_012_pos.ksh +${PACKAGE}FILES+= zpool_import_013_neg.ksh +${PACKAGE}FILES+= zpool_import_007_pos.ksh +${PACKAGE}FILES+= zpool_import_003_pos.ksh +${PACKAGE}FILES+= zpool_import_rename_001_pos.ksh +${PACKAGE}FILES+= zpool_import_missing_002_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_import_010_pos.ksh +${PACKAGE}FILES+= zpool_import_014_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_import_011_neg.ksh +${PACKAGE}FILES+= zpool_import_missing_004_pos.ksh +${PACKAGE}FILES+= zpool_import_missing_005_pos.ksh +${PACKAGE}FILES+= zpool_import_005_pos.ksh +${PACKAGE}FILES+= zpool_import_009_neg.ksh +${PACKAGE}FILES+= zpool_import_missing_001_pos.ksh +${PACKAGE}FILES+= zpool_import_008_pos.ksh +${PACKAGE}FILES+= zpool_import_004_pos.ksh +${PACKAGE}FILES+= zpool_import.kshlib + +SUBDIR+= blockfiles + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/Makefile new file mode 100644 index 00000000000..4462afe8637 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/Makefile @@ -0,0 +1,12 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= README +${PACKAGE}FILES+= unclean_export.dat.bz2 + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/README b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/README new file mode 100644 index 00000000000..853afdfcdbf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/README @@ -0,0 +1,31 @@ +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright (c) 2012 by Delphix. All rights reserved. +# + +Unless otherwise noted, all files in this distribution are released +under the Common Development and Distribution License (CDDL). + +This directory contains compressed blockfiles for zpool import testing. diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/unclean_export.dat.bz2 b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/unclean_export.dat.bz2 new file mode 100644 index 00000000000..a7e042b523d Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/blockfiles/unclean_export.dat.bz2 differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/cleanup.ksh new file mode 100644 index 00000000000..c7da5449150 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/cleanup.ksh @@ -0,0 +1,62 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +for pool in "$TESTPOOL" "$TESTPOOL1"; do + datasetexists $pool/$TESTFS && \ + log_must $ZFS destroy -Rf $pool/$TESTFS + destroy_pool "$pool" +done + +ismounted $DEVICE_DIR ufs +(( $? == 0 )) && log_must $UMOUNT -f $DEVICE_DIR + +for dir in "$TESTDIR" "$TESTDIR1" "$DEVICE_DIR" ; do + [[ -d $dir ]] && \ + log_must $RM -rf $dir +done + +# recreate and destroy a zpool over the disks to restore the partitions to +# normal +case $DISK_COUNT in +0|1) + log_note "No disk devices to restore" + ;; +*) + log_must cleanup_devices $ZFS_DISK1 + log_must cleanup_devices $ZFS_DISK2 + ;; +esac + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/setup.ksh new file mode 100644 index 00000000000..d179e99dfdc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/setup.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +for dev in $ZFS_DISK1 $ZFS_DISK2 ; do + log_must cleanup_devices $dev +done + +typeset -i i=0 +if [[ $DISK_COUNT -lt 2 ]]; then + partition_disk $PART_SIZE $ZFS_DISK1 $GROUP_NUM +fi + +create_pool "$TESTPOOL" "$ZFSSIDE_DISK1" + +if [[ -d $TESTDIR ]]; then + $RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR + $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR +fi + +log_must $ZFS create $TESTPOOL/$TESTFS +log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +# Limit the filesystem size to 32GiB; this should be sufficient. +(( MAXSECTS = 32 * 1024 * 1024 )) +NUMSECTS=`diskinfo ${ZFSSIDE_DISK2} | awk '{print $4}'` +if [[ $NUMSECTS -gt $MAXSECTS ]]; then + NUMSECTS=$MAXSECTS +fi + +$ECHO "y" | $NEWFS -s $NUMSECTS $ZFSSIDE_DISK2 >/dev/null 2>&1 +(( $? != 0 )) && + log_untested "Unable to setup a UFS file system" + +[[ ! -d $DEVICE_DIR ]] && \ + log_must $MKDIR -p $DEVICE_DIR + +log_must $MOUNT $ZFSSIDE_DISK2 $DEVICE_DIR + +i=0 +while (( i < $MAX_NUM )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + (( i = i + 1 )) +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import.cfg new file mode 100644 index 00000000000..2847fdf840f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import.cfg @@ -0,0 +1,135 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + + +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import.cfg 1.6 08/11/03 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +. $STF_SUITE/include/libtest.kshlib + +set -A disk_array $(find_disks $DISKS) +case "${#disk_array[*]}" in +0) + # + # on stf_configure, disk_freelist returns empty. + # + DISK_COUNT=0 + ;; +1) + # We need to repartition the single disk to two slices. + DISK_COUNT=1 + ZFS_DISK1=${disk_array[0]} + ZFSSIDE_DISK1=${ZFS_DISK1}p1 + ZFS_DISK2=${disk_array[0]} + ZFSSIDE_DISK2=${ZFS_DISK2}p2 + ;; +*) + # We don't need to repartition anything + DISK_COUNT=2 + ZFS_DISK1=${disk_array[0]} + ZFSSIDE_DISK1=${ZFS_DISK1} + ZFS_DISK2=${disk_array[1]} + ZFSSIDE_DISK2=${ZFS_DISK2} + ;; +esac + +export DISK_COUNT ZFS_DISK1 ZFSSIDE_DISK1 ZFS_DISK2 ZFSSIDE_DISK2 + +export FS_SIZE=2gb +export FILE_SIZE=64m +export PART_SIZE=128m +export MAX_NUM=5 +export GROUP_NUM=3 +export DEVICE_DIR=${TMPDIR}/dev${TESTCASE_ID} +export BACKUP_DEVICE_DIR=/bakdev${TESTCASE_ID} +export DEVICE_FILE=disk +export DEVICE_ARCHIVE=${TMPDIR}/archive${TESTCASE_ID}.tar +# MYTESTFILE can be any file that exists and we have r access to +export MYTESTFILE=$STF_SUITE/include/default.cfg + +# NB: It's easier just to repeat the expansion patterns than to reuse. +for (( num=0 ; $num < $GROUP_NUM ; num += 1 )); do + eval export VDEV\${num}F="${DEVICE_FILE}${num}" + eval export VDEV\${num}="${DEVICE_DIR}/${DEVICE_FILE}${num}" + DEVICE_FILES="$DEVICE_FILES ${DEVICE_DIR}/${DEVICE_FILE}${num}" +done +export DEVICE_FILES +for (( num = GROUP_NUM ; $num < $MAX_NUM ; num += 1 )); do + eval export VDEV\${num}F="${DEVICE_FILE}${num}" + eval export VDEV\${num}="${DEVICE_DIR}/${DEVICE_FILE}${num}" +done + +export ALTER_ROOT=/alter${TESTCASE_ID} +export STF_TIMEOUT=2400 + +export ZPOOL_VERSION=$(get_zpool_version) + +# Version 1 pools +export ZPOOL_VERSION_1_FILES="zfs-pool-v1.dat" +export ZPOOL_VERSION_1_NAME="v1-pool" + +# Version 2 pools +export ZPOOL_VERSION_2_FILES="zfs-pool-v2.dat" +export ZPOOL_VERSION_2_NAME="v2-pool" + +# This is a v3 pool +export ZPOOL_VERSION_3_FILES="zfs-pool-v3.dat" +export ZPOOL_VERSION_3_NAME="v3-pool" + +# This is a v6 pool +export ZPOOL_VERSION_6_FILES="zfs-pool-v6.dat" +export ZPOOL_VERSION_6_NAME="v6-pool" + +# This is a v7 pool +export ZPOOL_VERSION_7_FILES="zfs-pool-v7.dat" +export ZPOOL_VERSION_7_NAME="v7-pool" + +# This is a v8 pool +export ZPOOL_VERSION_8_FILES="zfs-pool-v8.dat" +export ZPOOL_VERSION_8_NAME="v8-pool" + +# This statement builds up a list of configurations we should be able to +# upgrade, for each pool version. Once we've built this variable, we'll +# call the functions above for each value. +case $ZPOOL_VERSION in +6) + CONFIGS="6" + ;; +7) + CONFIGS="6 7" + ;; +8) + CONFIGS="6 7 8" + ;; +*) + # we should be able to upgrade pools of version 1, 2 & 3 + # but we should also log a note about the unknown pool version + CONFIGS="6 7 8" + ;; +esac +export CONFIGS diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import.kshlib new file mode 100644 index 00000000000..43ff35efa26 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import.kshlib @@ -0,0 +1,35 @@ +# vim: filetype=sh +# Common routines used by zpool_import*. + +# $FreeBSD$ + +function setup_missing_test_pool # +{ + typeset tvd_type=$1 + + setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 \ + "" $tvd_type + log_must $CP $MYTESTFILE $TESTDIR1/$TESTFILE0 + log_must $ZPOOL export $TESTPOOL1 +} + +function recreate_missing_files +{ + destroy_pool $TESTPOOL1 + log_must $RM -rf $DEVICE_DIR/* + for (( devnum=0 ; $devnum < $MAX_NUM ; devnum += 1 )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$devnum + done +} + +function cleanup_missing +{ + log_note "State of pools at the end of the test:" + poolexists $TESTPOOL1 && log_must $ZPOOL status $TESTPOOL1 + log_note "State of $DEVICE_DIR at the end of the test:" + log_cmd $ZPOOL import -d $DEVICE_DIR + destroy_pool $TESTPOOL1 + log_must $RM -rf $DEVICE_DIR/* + [[ -d $ALTER_ROOT ]] && log_must $RM -rf $ALTER_ROOT + [[ -d $BACKUP_DEVICE_DIR ]] && log_must $RM -rf $BACKUP_DEVICE_DIR +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_002_pos.ksh new file mode 100644 index 00000000000..4b0ac28b7eb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_002_pos.ksh @@ -0,0 +1,166 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_002_pos.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_002_pos +# +# DESCRIPTION: +# Verify that an exported pool cannot be imported +# more than once. +# +# STRATEGY: +# 1. Populate the default test directory and unmount it. +# 2. Export the default test pool. +# 3. Import it using the various combinations. +# - Regular import +# - Alternate Root Specified +# 4. Verify it shows up under 'zpool list'. +# 5. Verify it contains a file. +# 6. Attempt to import it for a second time. Verify this fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A pools "$TESTPOOL" "$TESTPOOL1" +set -A devs "" "-d $DEVICE_DIR" +set -A options "" "-R $ALTER_ROOT" +set -A mtpts "$TESTDIR" "$TESTDIR1" + + +function cleanup +{ + typeset -i i=0 + while (( i < ${#pools[*]} )); do + poolexists ${pools[i]} && \ + log_must $ZPOOL export ${pools[i]} + + datasetexists "${pools[i]}/$TESTFS" || \ + log_must $ZPOOL import ${devs[i]} ${pools[i]} + + ismounted "${pools[i]}/$TESTFS" || \ + log_must $ZFS mount ${pools[i]}/$TESTFS + + [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \ + log_must $RM -rf ${mtpts[i]}/$TESTFILE0 + + ((i = i + 1)) + done + + cleanup_filesystem $TESTPOOL1 $TESTFS + + destroy_pool $TESTPOOL1 + + [[ -d $ALTER_ROOT ]] && \ + log_must $RM -rf $ALTER_ROOT +} + +log_onexit cleanup + +log_assert "Verify that an exported pool cannot be imported more than once." + +setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +typeset -i i=0 +typeset -i j=0 +typeset basedir + +function inner_test +{ + typeset pool=$1 + typeset target=$2 + typeset devs=$3 + typeset opts=$4 + typeset mtpt=$5 + + log_must $ZPOOL import ${devs} ${opts} $target + log_must poolexists $pool + log_must ismounted $pool/$TESTFS + + basedir=$mtpt + [ -n "$opts" ] && basedir="$ALTER_ROOT/$mtpt" + + [ ! -e "$basedir/$TESTFILE0" ] && \ + log_fail "ERROR: $basedir/$TESTFILE0 missing after import." + + checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "ERROR: Checksums differ ($checksum1 != $checksum2)" + + log_mustnot $ZPOOL import $devs $target +} + +while (( i < ${#pools[*]} )); do + log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0 + + log_must $ZFS umount ${mtpts[i]} + + j=0 + while (( j < ${#options[*]} )); do + typeset pool=${pools[i]} + typeset vdevdir="" + + log_must $ZPOOL export $pool + + [ "$pool" = "$TESTPOOL1" ] && vdevdir="$DEVICE_DIR" + guid=$(get_config $pool pool_guid $vdevdir) + log_must test -n "$guid" + log_note "Importing '$pool' by guid '$guid'" + inner_test $pool $guid "${devs[i]}" "${options[j]}" ${mtpts[i]} + + log_must $ZPOOL export $pool + + log_note "Importing '$pool' by name." + inner_test $pool $pool "${devs[i]}" "${options[j]}" ${mtpts[i]} + + ((j = j + 1)) + done + + ((i = i + 1)) + +done + +log_pass "Able to import exported pools and import only once." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_003_pos.ksh new file mode 100644 index 00000000000..0eda0eb794f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_003_pos.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_003_pos +# +# DESCRIPTION: +# Destroyed pools are not listed unless with -D option is specified. +# +# STRATEGY: +# 1. Create test pool A. +# 2. Destroy pool A. +# 3. Verify only 'import -D' can list pool A. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + log_must $RM $VDEV0 $VDEV1 +} + +log_assert "Destroyed pools are not listed unless with -D option is specified." +log_onexit cleanup + +log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 +log_must $ZPOOL destroy $TESTPOOL1 + +# +# 'pool:' is the keywords of 'zpool import -D' output. +# +log_mustnot eval "$ZPOOL import -d $DEVICE_DIR | $GREP pool:" +log_must eval "$ZPOOL import -d $DEVICE_DIR -D | $GREP pool:" + +log_pass "Destroyed pool only can be listed with -D option." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_004_pos.ksh new file mode 100644 index 00000000000..7e7765e25e1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_004_pos.ksh @@ -0,0 +1,110 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_004_pos.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_004_pos +# +# DESCRIPTION: +# Destroyed pools devices was moved to another directory, it still can be +# imported correctly. +# +# STRATEGY: +# 1. Create test pool A with several devices. +# 2. Destroy pool A. +# 3. Move devices to another directory. +# 4. Verify 'zpool import -D' succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + log_must $RM -rf $DEVICE_DIR/* +} + +function perform_test +{ + target=$1 + + assert_pool_in_cachefile $TESTPOOL1 + log_must $ZPOOL destroy $TESTPOOL1 + + log_note "Devices was moved to different directories." + log_must $MKDIR -p $DEVICE_DIR/newdir1 $DEVICE_DIR/newdir2 + log_must $MV $VDEV1 $DEVICE_DIR/newdir1 + log_must $MV $VDEV2 $DEVICE_DIR/newdir2 + log_must $ZPOOL import -d $DEVICE_DIR/newdir1 -d $DEVICE_DIR/newdir2 \ + -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy -f $TESTPOOL1 + + log_note "Devices was moved to same directory." + log_must $MV $VDEV0 $DEVICE_DIR/newdir2 + log_must $MV $DEVICE_DIR/newdir1/* $DEVICE_DIR/newdir2 + log_must $ZPOOL import -d $DEVICE_DIR/newdir2 -D -f $target + log_must $ZPOOL destroy -f $TESTPOOL1 + + # Revert at the end so this test can be rerun. + log_must $MV $DEVICE_DIR/newdir2/$VDEV0F $VDEV0 + log_must $MV $DEVICE_DIR/newdir2/$VDEV1F $VDEV1 + log_must $MV $DEVICE_DIR/newdir2/$VDEV2F $VDEV2 +} + +log_assert "Destroyed pools devices was moved to another directory," \ + "it still can be imported correctly." +log_onexit cleanup + +log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2 +log_note "Testing import by name '$TESTPOOL1'." +perform_test $TESTPOOL1 + +log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2 +log_must $ZPOOL status $TESTPOOL1 +log_must $ZDB -C $TESTPOOL1 +typeset guid=$(get_config $TESTPOOL1 pool_guid) +log_note "Testing import by GUID '${guid}'." +perform_test $guid + +log_pass "Destroyed pools devices was moved, 'zpool import -D' passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_005_pos.ksh new file mode 100644 index 00000000000..fd46c965e2b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_005_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_005_pos.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_005_pos +# +# DESCRIPTION: +# Destroyed pools devices was renamed, it still can be imported correctly. +# +# STRATEGY: +# 1. Create test pool A with several devices. +# 2. Destroy pool A and rename devices name. +# 3. Verify 'zpool import -D' succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + + log_must $RM -rf $DEVICE_DIR/* + typeset i=0 + while (( i < $MAX_NUM )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + ((i += 1)) + done +} + +log_assert "Destroyed pools devices was renamed, it still can be imported " \ + "correctly." +log_onexit cleanup + +function perform_test +{ + typeset target=$1 + + assert_pool_in_cachefile $TESTPOOL1 + log_must $ZPOOL destroy $TESTPOOL1 + + log_note "Testing some devices renamed in the same directory." + log_must $MV $VDEV0 $DEVICE_DIR/vdev0-new + log_must $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy -f $TESTPOOL1 + + log_note "Testing all devices moved to different directories." + log_must $MKDIR -p $DEVICE_DIR/newdir1 $DEVICE_DIR/newdir2 + log_must $MV $VDEV1 $DEVICE_DIR/newdir1/vdev1-new + log_must $MV $VDEV2 $DEVICE_DIR/newdir2/vdev2-new + log_must $ZPOOL import -d $DEVICE_DIR/newdir1 -d $DEVICE_DIR/newdir2 \ + -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy -f $TESTPOOL1 + + # Restore the vdevs to their old location so this can be re-run + log_note "Restoring vdev files for any further runs." + log_must $MV $DEVICE_DIR/vdev0-new $VDEV0 + log_must $MV $DEVICE_DIR/newdir1/vdev1-new $VDEV1 + log_must $MV $DEVICE_DIR/newdir2/vdev2-new $VDEV2 +} + +log_note "Testing import by name." +log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2 +perform_test $TESTPOOL1 + +log_note "Testing import by GUID." +log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2 +typeset guid=$(get_config $TESTPOOL1 pool_guid) +perform_test $guid + +log_pass "Destroyed pools devices was renamed, 'zpool import -D' passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_006_pos.ksh new file mode 100644 index 00000000000..ee8626ebb9c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_006_pos.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_006_pos.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_006_pos +# +# DESCRIPTION: +# For mirror, N-1 destroyed pools devices was removed or used by other +# pool, it still can be imported correctly. +# +# STRATEGY: +# 1. Create mirror with N disks. +# 2. Destroy this mirror. +# 3. Create another pool with N-1 disks which was used by this mirror. +# 4. Verify import mirror can succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL2 + destroy_pool $TESTPOOL1 + + log_must $RM -rf $DEVICE_DIR/* + typeset i=0 + while (( i < $MAX_NUM )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + ((i += 1)) + done +} + +log_assert "For mirror, N-1 destroyed pools devices was removed or used " \ + "by other pool, it still can be imported correctly." +log_onexit cleanup + +function perform_test +{ + typeset target=$1 + + assert_pool_in_cachefile $TESTPOOL1 + log_must $ZPOOL destroy $TESTPOOL1 + + create_pool $TESTPOOL2 $VDEV0 $VDEV2 + log_must $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy $TESTPOOL1 + + log_must $ZPOOL destroy $TESTPOOL2 + log_must $RM -rf $VDEV2 + log_must $ZPOOL import -d $DEVICE_DIR -D -f $target + + # Restore the vdev. + log_must create_vdevs $VDEV2 +} + +log_note "Testing import by name." +create_pool $TESTPOOL1 mirror $VDEV0 $VDEV1 $VDEV2 +perform_test $TESTPOOL1 + +log_note "Testing import by GUID." +create_pool $TESTPOOL1 mirror $VDEV0 $VDEV1 $VDEV2 +typeset guid=$(get_config $TESTPOOL1 pool_guid) +perform_test $guid + +log_pass "zpool import -D mirror passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_007_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_007_pos.ksh new file mode 100644 index 00000000000..ad03559f61d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_007_pos.ksh @@ -0,0 +1,111 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_007_pos.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_007_pos +# +# DESCRIPTION: +# For raidz, one destroyed pools devices was removed or used by other +# pool, it still can be imported correctly. +# +# STRATEGY: +# 1. Create a raidz pool A with N disks. +# 2. Destroy this pool A. +# 3. Create another pool B with 1 disk which was used by pool A. +# 4. Verify import this raidz pool can succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL2 + destroy_pool $TESTPOOL1 + + log_must $RM -rf $DEVICE_DIR/* + typeset i=0 + while (( i < $MAX_NUM )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + ((i += 1)) + done +} + +log_assert "For raidz, one destroyed pools devices was removed or used by " \ + "other pool, it still can be imported correctly." +log_onexit cleanup + +function perform_test +{ + typeset target=$1 + + assert_pool_in_cachefile $TESTPOOL1 + log_must $ZPOOL destroy $TESTPOOL1 + + log_must $ZPOOL create $TESTPOOL2 $VDEV0 + log_must $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy $TESTPOOL1 + + log_must $ZPOOL destroy $TESTPOOL2 + log_must $RM -rf $VDEV0 + log_must $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy $TESTPOOL1 + + log_note "For raidz, two destroyed pool's devices were used, import failed." + log_must create_vdevs $VDEV0 + log_must $ZPOOL create $TESTPOOL2 $VDEV0 $VDEV1 + log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy $TESTPOOL2 +} + +log_note "Testing import by name." +log_must $ZPOOL create $TESTPOOL1 raidz $VDEV0 $VDEV1 $VDEV2 $VDEV3 +perform_test $TESTPOOL1 + +log_note "Testing import by GUID." +log_must $ZPOOL create $TESTPOOL1 raidz $VDEV0 $VDEV1 $VDEV2 $VDEV3 +typeset guid=$(get_config $TESTPOOL1 pool_guid) +perform_test $guid + +log_pass "zpool import -D raidz passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_008_pos.ksh new file mode 100644 index 00000000000..96beb8af8de --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_008_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_008_pos.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_008_pos +# +# DESCRIPTION: +# For raidz2, two destroyed pool's devices were removed or used by other +# pool, it still can be imported correctly. +# +# STRATEGY: +# 1. Create a raidz2 pool A with N disks. +# 2. Destroy this pool A. +# 3. Create another pool B with two disks which were used by pool A. +# 4. Verify import this raidz2 pool can succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL2 + destroy_pool $TESTPOOL1 + + log_must $RM -rf $DEVICE_DIR/* + typeset i=0 + while (( i < $MAX_NUM )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + ((i += 1)) + done +} + +function perform_test +{ + typeset target=$1 + + assert_pool_in_cachefile $TESTPOOL1 + log_must $ZPOOL destroy $TESTPOOL1 + + log_must $ZPOOL create $TESTPOOL2 $VDEV0 $VDEV1 + log_must $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy $TESTPOOL1 + + log_must $ZPOOL destroy $TESTPOOL2 + log_must $RM -rf $VDEV0 $VDEV1 + log_must $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy $TESTPOOL1 + + log_note "For raidz2, more than two destroyed pool's devices were used, " \ + "import failed." + log_must create_vdevs $VDEV0 $VDEV1 + log_must $ZPOOL create $TESTPOOL2 $VDEV0 $VDEV1 $VDEV2 + log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target + log_must $ZPOOL destroy $TESTPOOL2 +} + +log_assert "For raidz2, two destroyed pools devices was removed or used by " \ + "other pool, it still can be imported correctly." +log_onexit cleanup + +log_note "Testing import by name." +log_must $ZPOOL create $TESTPOOL1 raidz2 $VDEV0 $VDEV1 $VDEV2 $VDEV3 +perform_test $TESTPOOL1 + +log_note "Testing import by GUID." +log_must $ZPOOL create $TESTPOOL1 raidz2 $VDEV0 $VDEV1 $VDEV2 $VDEV3 +typeset guid=$(get_config $TESTPOOL1 pool_guid) +perform_test $guid + +log_pass "zpool import -D raidz2 passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_009_neg.ksh new file mode 100644 index 00000000000..2eda68fecd8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_009_neg.ksh @@ -0,0 +1,115 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_009_neg.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# __stc_assertion_start +# +# ID: zpool_import_009_neg +# +# DESCRIPTION: +# Try each 'zpool import' with inapplicable scenarios to make sure +# it returns an error. include: +# * A non-existent pool name is given +# * '-d', but no device directory specified +# * '-R', but no alter root directory specified +# * '-a', but a pool name specified either +# * more than 2 pool names is given +# * The new pool name specified already exists +# * Contain invalid characters not allowed in the ZFS namespace +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute the sub-command +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A args "blah" "-d" "-R" "-a $TESTPOOL" \ + "$TESTPOOL ${TESTPOOL}-new ${TESTPOOL}-new" \ + "$TESTPOOL $TESTPOOL1" \ + "$TESTPOOL ${TESTPOOL1}*" "$TESTPOOL ${TESTPOOL1}?" + +set -A pools "$TESTPOOL" "$TESTPOOL1" +set -A devs "" "-d $DEVICE_DIR" + +function cleanup +{ + typeset -i i=0 + typeset -i j=0 + + while (( i < ${#pools[*]} )); do + + poolexists ${pools[i]} && \ + log_must $ZPOOL export ${pools[i]} + + datasetexists "${pools[i]}/$TESTFS" || \ + log_must $ZPOOL import ${devs[i]} ${pools[i]} + + ismounted "${pools[i]}/$TESTFS" || \ + log_must $ZFS mount ${pools[i]}/$TESTFS + + ((i = i + 1)) + done + + cleanup_filesystem $TESTPOOL1 $TESTFS + + destroy_pool $TESTPOOL1 +} + +log_onexit cleanup + +log_assert "Badly-formed 'zpool import' with inapplicable scenarios " \ + "should return an error." + +setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 + +log_must $ZPOOL export $TESTPOOL + +typeset -i i=0 +while (( i < ${#args[*]} )); do + log_mustnot $ZPOOL import ${args[i]} + ((i = i + 1)) +done + +log_pass "Badly formed 'zpool import' with inapplicable scenarios " \ + "fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_010_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_010_pos.ksh new file mode 100644 index 00000000000..be074b58f3b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_010_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_010_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_010_pos +# +# DESCRIPTION: +# 'zpool -D -a' can import all the specified directories destroyed pools. +# +# STRATEGY: +# 1. Create a 5 ways mirror pool A with dev0/1/2/3/4, then destroy it. +# 2. Create a stripe pool B with dev1. Then destroy it. +# 3. Create a raidz2 pool C with dev2/3/4. Then destroy it. +# 4. Create a raidz pool D with dev3/4. Then destroy it. +# 5. Create a stripe pool E with dev4. Then destroy it. +# 6. Verify 'zpool import -D -a' recover all the pools. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dt + for dt in $poolE $poolD $poolC $poolB $poolA; do + destroy_pool $dt + done + + log_must $RM -rf $DEVICE_DIR/* + typeset i=0 + while (( i < $MAX_NUM )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + ((i += 1)) + done +} + +log_assert "'zpool -D -a' can import all the specified directories " \ + "destroyed pools." +log_onexit cleanup + +poolA=poolA.${TESTCASE_ID} +poolB=poolB.${TESTCASE_ID} +poolC=poolC.${TESTCASE_ID} +poolD=poolD.${TESTCASE_ID} +poolE=poolE.${TESTCASE_ID} + +log_must $ZPOOL create $poolA mirror $VDEV0 $VDEV1 $VDEV2 $VDEV3 $VDEV4 +log_must $ZPOOL destroy $poolA + +log_must $ZPOOL create $poolB $VDEV1 +log_must $ZPOOL destroy $poolB + +log_must $ZPOOL create $poolC raidz2 $VDEV2 $VDEV3 $VDEV4 +log_must $ZPOOL destroy $poolC + +log_must $ZPOOL create $poolD raidz $VDEV3 $VDEV4 +log_must $ZPOOL destroy $poolD + +log_must $ZPOOL create $poolE $VDEV4 +log_must $ZPOOL destroy $poolE + +log_must $ZPOOL import -d $DEVICE_DIR -D -f -a + +for dt in $poolA $poolB $poolC $poolD $poolE; do + log_must datasetexists $dt +done + +log_pass "'zpool -D -a' test passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_011_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_011_neg.ksh new file mode 100644 index 00000000000..6888d1c2a85 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_011_neg.ksh @@ -0,0 +1,94 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_011_neg.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_011_neg +# +# DESCRIPTION: +# For strip pool, any destroyed pool devices was demaged, zpool import -D +# will failed. +# +# STRATEGY: +# 1. Create strip pool A with three devices. +# 2. Destroy this pool B. +# 3. Create pool B with one of devices in step 1. +# 4. Verify 'import -D' pool A will failed whenever pool B was destroyed +# or not. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + destroy_pool $TESTPOOL2 + + # + # Recreate virtual devices to avoid destroyed pool information on files. + # + log_must $RM -rf $VDEV0 $VDEV1 $VDEV2 + log_must create_vdevs $VDEV0 $VDEV1 $VDEV2 +} + +log_assert "For strip pool, any destroyed pool devices was demaged," \ + "zpool import -D will failed." +log_onexit cleanup + +log_must $ZPOOL create $TESTPOOL1 $VDEV0 $VDEV1 $VDEV2 +typeset guid=$(get_config $TESTPOOL1 pool_guid) +typeset target=$TESTPOOL1 +if (( RANDOM % 2 == 0 )) ; then + target=$guid + log_note "Import by guid." +fi +log_must $ZPOOL destroy $TESTPOOL1 +log_must $ZPOOL create $TESTPOOL2 $VDEV2 + +log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target + +log_must $ZPOOL destroy $TESTPOOL2 +log_mustnot $ZPOOL import -d $DEVICE_DIR -D -f $target + +log_pass "Any strip pool devices damaged, pool can't be import passed." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_012_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_012_pos.ksh new file mode 100644 index 00000000000..65ca2af590a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_012_pos.ksh @@ -0,0 +1,194 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_012_pos.ksh 1.4 09/05/19 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_012_pos +# +# DESCRIPTION: +# Once a pool has been exported, it should be recreated after a +# successful import, all the sub-filesystems within it should all be restored, +# include mount & share status. Verify that is true. +# +# STRATEGY: +# 1. Create the test pool and hierarchical filesystems. +# 2. Export the test pool, or destroy the test pool, +# depend on testing import [-Df]. +# 3. Import it using the various combinations. +# - Regular import +# - Alternate Root Specified +# 4. Verify the mount & share status is restored. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-11-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A pools "$TESTPOOL" "$TESTPOOL1" +set -A devs "" "-d $DEVICE_DIR" +set -A options "" "-R $ALTER_ROOT" +set -A mtpts "$TESTDIR" "$TESTDIR1" + + +function cleanup +{ + typeset -i i=0 + + while (( i < ${#pools[*]} )); do + if poolexists ${pools[i]} ; then + log_must $ZPOOL export ${pools[i]} + log_note "Try to import ${devs[i]} ${pools[i]}" + $ZPOOL import ${devs[i]} ${pools[i]} + else + log_note "Try to import $option ${devs[i]} ${pools[i]}" + $ZPOOL import $option ${devs[i]} ${pools[i]} + fi + + if poolexists ${pools[i]} ; then + is_shared ${pools[i]} && \ + log_must $ZFS set sharenfs=off ${pools[i]} + + ismounted "${pools[i]}/$TESTFS" || \ + log_must $ZFS mount ${pools[i]}/$TESTFS + fi + + ((i = i + 1)) + done + + destroy_pool $TESTPOOL1 + + if datasetexists $TESTPOOL/$TESTFS ; then + log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS + fi + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + [[ -d $ALTER_ROOT ]] && \ + log_must $RM -rf $ALTER_ROOT +} + +log_onexit cleanup + +log_assert "Verify all mount & share status of sub-filesystems within a pool \ + can be restored after import [-Df]." + +setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 +for pool in ${pools[@]} ; do + log_must $ZFS create $pool/$TESTFS/$TESTCTR + log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1 + log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR + log_must $ZFS set canmount=off $pool/$TESTFS/$TESTCTR/$TESTCTR1 + log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTFS1 + log_must $ZFS create $pool/$TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1 + log_must $ZFS create $pool/$TESTFS/$TESTFS1 + log_must $ZFS snapshot $pool/$TESTFS/$TESTFS1@snap + log_must $ZFS clone $pool/$TESTFS/$TESTFS1@snap $pool/$TESTCLONE1 +done + +typeset mount_fs="$TESTFS $TESTFS/$TESTFS1 $TESTCLONE1 \ + $TESTFS/$TESTCTR/$TESTFS1 $TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1" +typeset nomount_fs="$TESTFS/$TESTCTR $TESTFS/$TESTCTR/$TESTCTR1" + +typeset -i i=0 +typeset -i j=0 +typeset basedir + +for option in "" "-Df" ; do + i=0 + while (( i < ${#pools[*]} )); do + pool=${pools[i]} + guid=$(get_config $pool pool_guid) + j=0 + while (( j < ${#options[*]} )); do + typeset f_share="" + if ((RANDOM % 2 == 0)); then + log_note "Set sharenfs=on $pool" + log_must $ZFS set sharenfs=on $pool + log_must is_shared $pool + f_share="true" + fi + + if [[ -z $option ]]; then + log_must $ZPOOL export $pool + else + log_must $ZPOOL destroy $pool + fi + + typeset target=$pool + if (( RANDOM % 2 == 0 )) ; then + log_note "Import by guid." + if [[ -z $guid ]]; then + log_fail "guid should not be empty!" + else + target=$guid + fi + fi + log_must $ZPOOL import $option \ + ${devs[i]} ${options[j]} $target + + log_must poolexists $pool + + for fs in $mount_fs ; do + log_must ismounted $pool/$fs + [[ -n $f_share ]] && \ + log_must is_shared $pool/$fs + done + + for fs in $nomount_fs ; do + log_mustnot ismounted $pool/$fs + log_mustnot is_shared $pool/$fs + done + + if [[ -n $f_share ]] ; then + log_must $ZFS set sharenfs=off $pool + log_mustnot is_shared $pool + fi + + ((j = j + 1)) + done + + ((i = i + 1)) + done +done + +log_pass "All mount & share status of sub-filesystems within a pool \ + can be restored after import [-Df]." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_013_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_013_neg.ksh new file mode 100644 index 00000000000..91f3d59499b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_013_neg.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_013_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_013_neg +# +# DESCRIPTION: +# For pool may be in use from other system, +# 'zpool import' will prompt the warning and fails. +# +# STRATEGY: +# 1. Prepare rawfile that are created from other system. +# 2. Verify 'zpool import' will fail. +# 3. Verify 'zpool import -f' succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +POOL_NAME=unclean_export +POOL_FILE=unclean_export.dat + +function uncompress_pool +{ + log_note "Creating pool from $POOL_FILE" + log_must $BZCAT \ + $STF_SUITE/tests/cli_root/zpool_import/blockfiles/$POOL_FILE.bz2 \ + > $TMPDIR/$POOL_FILE + return 0 +} + +function cleanup +{ + poolexists $POOL_NAME && log_must zpool destroy $POOL_NAME + [[ -e $TMPDIR/$POOL_FILE ]] && rm $TMPDIR/$POOL_FILE + return 0 +} + +log_assert "'zpool import' fails for pool that was not cleanly exported" +log_onexit cleanup + +uncompress_pool +log_mustnot zpool import -d $TMPDIR $POOL_NAME +log_must zpool import -d $TMPDIR -f $POOL_NAME + +log_pass "'zpool import' fails for pool that was not cleanly exported" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_014_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_014_pos.ksh new file mode 100644 index 00000000000..71c084d70ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_014_pos.ksh @@ -0,0 +1,66 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_014_pos +# +# DESCRIPTION: +# "'zpool import' can import destroyed disk-backed pools" +# +# STRATEGY: +# 1. Create test pool A. +# 2. Destroy pool A. +# 3. Verify 'import -D' can import pool A. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2013-03-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Destroyed pools are not listed unless with -D option is specified." + +log_must $ZPOOL create $TESTPOOL ${DISKS[0]} +log_must $ZPOOL destroy $TESTPOOL +log_mustnot $ZPOOL import $TESTPOOL +log_must $ZPOOL import -D $TESTPOOL +log_must poolexists $TESTPOOL + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_all_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_all_001_pos.ksh new file mode 100644 index 00000000000..e1f4421c739 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_all_001_pos.ksh @@ -0,0 +1,238 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_all_001_pos.ksh 1.5 08/11/03 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_all_001_pos +# +# DESCRIPTION: +# Verify that 'zpool import -a' succeeds as root. +# +# STRATEGY: +# 1. Create a group of pools with specified vdev. +# 2. Create zfs filesystems within the given pools. +# 3. Export the pools. +# 4. Verify that import command succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A options "" "-R $ALTER_ROOT" + +typeset -i number=0 +typeset -i id=0 +typeset -i i=0 +typeset checksum1 +typeset unwantedpool + +function setup_single_disk #disk #pool #fs #mtpt +{ + typeset disk=$1 + typeset pool=$2 + typeset fs=${3##/} + typeset mtpt=$4 + + setup_filesystem "$disk" "$pool" "$fs" "$mtpt" + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 + + log_must $ZPOOL export $pool + + [[ -d $mtpt ]] && \ + $RM -rf $mtpt +} + +function cleanup_all +{ + typeset -i id=0 + + # + # Try import individually if 'import -a' failed. + # + for pool in `$ZPOOL import | $GREP "pool:" | $AWK '{print $2}'`; do + $ZPOOL import -f $pool + done + + for pool in `$ZPOOL import -d $DEVICE_DIR | $GREP "pool:" | $AWK '{print $2}'`; do + log_must $ZPOOL import -d $DEVICE_DIR -f $pool + done + + while (( id < number )); do + if ! poolexists ${TESTPOOL}-$id ; then + (( id = id + 1 )) + continue + fi + + if (( id == 0 )); then + log_must $ZPOOL export ${TESTPOOL}-$id + + [[ -d /${TESTPOOL}-$id ]] && \ + log_must $RM -rf /${TESTPOOL}-$id + + log_must $ZPOOL import -f ${TESTPOOL}-$id $TESTPOOL + + [[ -e $TESTDIR/$TESTFILE0 ]] && \ + log_must $RM -rf $TESTDIR/$TESTFILE0 + else + cleanup_filesystem "${TESTPOOL}-$id" $TESTFS + + destroy_pool ${TESTPOOL}-$id + fi + + (( id = id + 1 )) + done + + [[ -d $ALTER_ROOT ]] && \ + $RM -rf $ALTER_ROOT +} + +function checksum_all #alter_root +{ + typeset alter_root=$1 + typeset -i id=0 + typeset file + typeset checksum2 + + while (( id < number )); do + if (( id == 2 )); then + (( id = id + 1 )) + continue + fi + + if (( id == 0 )); then + file=${alter_root}/$TESTDIR/$TESTFILE0 + else + file=${alter_root}/$TESTDIR.$id/$TESTFILE0 + fi + [[ ! -e $file ]] && \ + log_fail "$file missing after import." + + checksum2=$($SUM $file | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2)" + + (( id = id + 1 )) + done + + return 0 +} + + +log_assert "Verify that 'zpool import -a' succeeds as root." + +log_onexit cleanup_all + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +log_must $ZPOOL export $TESTPOOL +log_must $ZPOOL import $TESTPOOL ${TESTPOOL}-0 +log_must $CP $MYTESTFILE $TESTDIR/$TESTFILE0 +log_must $ZPOOL export ${TESTPOOL}-0 +[[ -d /${TESTPOOL}-0 ]] && \ + log_must $RM -rf /${TESTPOOL}-0 + +# +# setup exported pools on normal devices +# +number=1 +while (( number <= $GROUP_NUM )); do + if [[ `$UNAME -s` != "FreeBSD" ]]; then + if (( number == 2)); then + (( number = number + 1 )) + continue + fi + fi + set_partition $number "" $PART_SIZE ${ZFS_DISK2} + + setup_single_disk "${ZFS_DISK2}p${number}" \ + "${TESTPOOL}-$number" \ + "$TESTFS" \ + "$TESTDIR.$number" + + (( number = number + 1 )) +done + +# +# setup exported pools on raw files +# +for disk in $DEVICE_FILES +do + + setup_single_disk "$disk" \ + "${TESTPOOL}-$number" \ + "$TESTFS" \ + "$TESTDIR.$number" + + (( number = number + 1 )) +done + +while (( i < ${#options[*]} )); do + + log_must $ZPOOL import -d /dev -d $DEVICE_DIR ${options[i]} -a -f + + # destroy unintentional imported pools + typeset exclude=`eval $ECHO \"'(${KEEP})'\"` + for unwantedpool in $($ZPOOL list -H -o name \ + | $EGREP -v "$exclude" | $GREP -v $TESTPOOL); do + log_must $ZPOOL export $unwantedpool + done + + if [[ -n ${options[i]} ]]; then + checksum_all $ALTER_ROOT + else + checksum_all + fi + + id=0 + while (( id < number )); do + if poolexists ${TESTPOOL}-$id ; then + log_must $ZPOOL export ${TESTPOOL}-$id + fi + (( id = id + 1 )) + done + + (( i = i + 1 )) +done + +log_pass "'zpool import -a' succeeds as root." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_corrupt_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_corrupt_001_pos.ksh new file mode 100644 index 00000000000..01a1650ed9a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_corrupt_001_pos.ksh @@ -0,0 +1,130 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_014_pos +# +# DESCRIPTION: +# Verify that a disk-backed exported pool with some of its vdev labels +# corrupted can still be imported +# STRATEGY: +# 1. Create a disk-backed pool +# 2. Export it +# 3. Overwrite one or more of its vdev labels +# 4. Use zdb to verify that the labels are damaged +# 5. Verify 'zpool import' can import it +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2013-03-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +# ZFS has four vdev labels per vdev +typeset -i N_VDEV_LABELS=4 +# Size of a single label, in bytes +typeset -i VDEV_LABEL_SIZE=$(( 256 * 1024)) + + +# +# The authoritative version of this calculation can be found in the function of +# the same name in vdev_label.c. The rounding of psize is based on the +# calculation in vdev_disk_read_rootlabel in vdev_disk.c +# +# arg1: vdev size in bytes +# arg2: label index, 0 through 3 +# +function vdev_label_offset +{ + typeset -il psize=$1 + typeset -i l=$2 + typeset -il offset + typeset -il roundsize + + roundsize=$(( $psize & -$VDEV_LABEL_SIZE )) + if [[ $l -lt $(( N_VDEV_LABELS / 2 )) ]]; then + offset=$(( l * $VDEV_LABEL_SIZE)) + else + offset=$(( l * $VDEV_LABEL_SIZE + $roundsize - $N_VDEV_LABELS * $VDEV_LABEL_SIZE )) + fi + echo $offset +} + +log_assert "Verify that a disk-backed exported pool with some of its vdev labels corrupted can still be imported" + +typeset -i i +typeset -i j +set -A DISKS_ARRAY $DISKS +typeset DISK=${DISKS_ARRAY[0]} +typeset PROV=${DISK#/dev/} +typeset -il psize=$(geom disk list $PROV | awk '/Mediasize/ {print $2}') +if [[ -z $psize ]]; then + log_fail "Could not determine the capacity of $DISK" +fi + +for ((i=0; $i<$N_VDEV_LABELS; i=$i+1 )); do + log_must $ZPOOL create -f $TESTPOOL $DISK + log_must $ZPOOL export $TESTPOOL + + # Corrupt all labels except the ith + for ((j=0; $j<$N_VDEV_LABELS; j=$j+1 )); do + typeset -il offset + + [[ $i -eq $j ]] && continue + + log_note offset=vdev_label_offset $psize $j + offset=$(vdev_label_offset $psize $j) + log_must $DD if=/dev/zero of=$DISK bs=1024 \ + count=$(( $VDEV_LABEL_SIZE / 1024 )) \ + oseek=$(( $offset / 1024 )) \ + conv=notrunc + done + + typeset -i num_labels=$( $ZDB -l $DISK | $GREP pool_guid | wc -l ) + if [[ $num_labels -ne 1 ]]; then + $ZDB -l $DISK + log_fail "Expected 1 vdev label but found $num_labels" + fi + + log_must $ZPOOL import $TESTPOOL + destroy_pool $TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_destroyed_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_destroyed_001_neg.ksh new file mode 100644 index 00000000000..1593fbfc224 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_destroyed_001_neg.ksh @@ -0,0 +1,66 @@ +#!/usr/local/bin/ksh93 +# +# Copyright (c) 2017 Spectra Logic Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions, and the following disclaimer, +# without modification. +# 2. Redistributions in binary form must reproduce at minimum a disclaimer +# substantially similar to the "NO WARRANTY" disclaimer below +# ("Disclaimer") and any redistribution must be conditioned upon +# including a substantially similar Disclaimer requirement for further +# binary redistribution. +# +# NO WARRANTY +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGES. +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +set_disks + +# A destroyed pool cannot be imported, even if an out-of-date non-destroyed +# label is present +# +# This situation arose when a user activated a spare, removed the spare disk, +# destroyed the pool, reinserted the spare disk, and then tried to import the +# pool. Since the pool was destroyed, nothing should've happened. But the +# spare disk had a non-destroyed label, so zpool tried to import it. A panic +# ensued. +# +# More generally, this situation can happen any time the following things happen: +# 1) A disk gets removed with its label intact +# 2) The pool's configuration changes +# 3) The pool gets destroyed +# 4) Somebody tries to import the pool + +log_must $ZPOOL create -f $TESTPOOL mirror ${DISK0} ${DISK1} + +# Offline a disk so it's label won't get updated by the upcoming destroy +log_must $ZPOOL offline $TESTPOOL ${DISK0} + +# Now change the pool's configuration, so DISK0's label will be out-of-date +log_must $ZPOOL attach $TESTPOOL ${DISK1} ${DISK2} + +# Destroy the pool, so DISK1's and DISK2's labels will be in the destroyed +# state, leaving DISK0's label as the most recent non-destroyed label +log_must $ZPOOL destroy $TESTPOOL + +# Now try to import the pool. It should fail. +log_mustnot $ZPOOL import $TESTPOOL + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_destroyed_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_destroyed_002_neg.ksh new file mode 100644 index 00000000000..e6f4d049784 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_destroyed_002_neg.ksh @@ -0,0 +1,59 @@ +#!/usr/local/bin/ksh93 +# +# Copyright (c) 2017 Spectra Logic Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions, and the following disclaimer, +# without modification. +# 2. Redistributions in binary form must reproduce at minimum a disclaimer +# substantially similar to the "NO WARRANTY" disclaimer below +# ("Disclaimer") and any redistribution must be conditioned upon +# including a substantially similar Disclaimer requirement for further +# binary redistribution. +# +# NO WARRANTY +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGES. +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +set_disks + +# "zpool import" will not show destroyed pools, even if out-of-date +# non-destroyed label is present +# +# This situation can happen any time the following things happen: +# 1) A disk gets removed with its label intact +# 2) The pool gets destroyed +# 3) Somebody run "zpool import" to see importable pools + +log_must $ZPOOL create -f $TESTPOOL mirror ${DISK0} ${DISK1} + +# Offline a disk so it's label won't get updated by the upcoming destroy +log_must $ZPOOL offline $TESTPOOL ${DISK0} + +# Destroy the pool, so DISK1's and DISK2's labels will be in the destroyed +# state, leaving DISK0's label as the most recent non-destroyed label +log_must $ZPOOL destroy $TESTPOOL + +# Now try to import the pool. It should fail. +if $ZPOOL import | $GREP -q $TESTPOOL; then + $ZPOOL import + log_fail "ERROR: Destroyed pool visible" +else + log_pass +fi diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_001_pos.ksh new file mode 100644 index 00000000000..aa224d5d5d8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_001_pos.ksh @@ -0,0 +1,171 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_missing_001_pos.ksh 1.4 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib +. $STF_SUITE/tests/cli_root/zpool_import/zpool_import.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_missing_001_pos +# +# DESCRIPTION: +# Once a pool has been exported, and one or more devices are +# damaged or missing (d/m), import should handle this kind of situation +# as described: +# - Regular, report error while any number of devices failing. +# - Mirror could withstand (N-1) devices failing +# before data integrity is compromised +# - Raidz could withstand one devices failing +# before data integrity is compromised +# Verify those are true. +# +# STRATEGY: +# 1. Create test pool upon device files using the various combinations. +# - Regular pool +# - Mirror +# - Raidz +# 2. Create necessary filesystem and test files. +# 3. Export the test pool. +# 4. Remove one or more devices +# 5. Verify 'zpool import' will handle d/m device successfully. +# Using the various combinations. +# - Regular import +# - Alternate Root Specified +# It should be succeed with single d/m device upon 'raidz' & 'mirror', +# but failed against 'regular' or more d/m devices. +# 6. If import succeed, verify following is true: +# - The pool shows up under 'zpool list'. +# - The pool's health should be DEGRADED. +# - It contains the correct test file +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A vdevs "" "mirror" "raidz" +set -A options "" "-R $ALTER_ROOT" + +function perform_inner_test +{ + typeset action=$1 + typeset import_opts=$2 + typeset target=$3 + typeset basedir + + $action $ZPOOL import -d $DEVICE_DIR ${import_opts} $target + [[ $action == "log_mustnot" ]] && return + + log_must poolexists $TESTPOOL1 + + health=$($ZPOOL list -H -o health $TESTPOOL1) + [[ "$health" == "DEGRADED" ]] || \ + log_fail "ERROR: $TESTPOOL1: Incorrect health '$health'" + log_must ismounted $TESTPOOL1/$TESTFS + + basedir=$TESTDIR1 + [[ -n "${import_opts}" ]] && basedir=$ALTER_ROOT/$TESTDIR1 + [[ ! -e "$basedir/$TESTFILE0" ]] && \ + log_fail "ERROR: $basedir/$TESTFILE0 missing after import." + + checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "ERROR: Checksums differ ($checksum1 != $checksum2)" + + log_must $ZPOOL export $TESTPOOL1 +} + +log_onexit cleanup_missing + +log_assert "Verify that import could handle damaged or missing device." + +CWD=$PWD +cd $DEVICE_DIR || log_fail "ERROR: Unable change directory to $DEVICE_DIR" + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +typeset -i i=0 +while :; do + typeset vdtype="${vdevs[i]}" + + typeset -i j=0 + while (( j < ${#options[*]} )); do + typeset opts="${options[j]}" + [ -n "$vdtype" ] && typestr="$vdtype" || typestr="stripe" + + # Prepare the pool. + setup_missing_test_pool $vdtype + guid=$(get_config $TESTPOOL1 pool_guid $DEVICE_DIR) + log_note "*** Testing $typestr tvd guid $guid opts '${opts}'" + + typeset -i count=0 + for device in $DEVICE_FILES ; do + log_mustnot poolexists $TESTPOOL1 + log_must $RM -f $device + + (( count = count + 1 )) + + action=log_must + case "$vdtype" in + 'mirror') (( count == $GROUP_NUM )) && \ + action=log_mustnot + ;; + 'raidz') (( count > 1 )) && \ + action=log_mustnot + ;; + '') action=log_mustnot + ;; + esac + + log_note "Testing import by name; ${count} removed." + perform_inner_test $action "${opts}" $TESTPOOL1 + + log_note "Testing import by GUID; ${count} removed." + perform_inner_test $action "${opts}" $guid + done + + recreate_missing_files + (( j = j + 1 )) + done + (( i = i + 1 )) + (( i == ${#vdevs[*]} )) && break +done + +log_pass "Import could handle damaged or missing device." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_002_pos.ksh new file mode 100644 index 00000000000..7f2da86f651 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_002_pos.ksh @@ -0,0 +1,150 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_missing_002_pos.ksh 1.4 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib +. $STF_SUITE/tests/cli_root/zpool_import/zpool_import.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_missing_002_pos +# +# DESCRIPTION: +# Once a pool has been exported, and one or more devices are +# move to other place, import should handle this kind of situation +# as described: +# - Regular, report error while any number of devices failing. +# - Mirror could withstand (N-1) devices failing +# before data integrity is compromised +# - Raidz could withstand one devices failing +# before data integrity is compromised +# Verify that is true. +# +# STRATEGY: +# 1. Create test pool upon device files using the various combinations. +# - Regular pool +# - Mirror +# - Raidz +# 2. Create necessary filesystem and test files. +# 3. Export the test pool. +# 4. Move one or more device files to other directory +# 5. Verify 'zpool import -d' with the new directory +# will handle moved files successfullly. +# Using the various combinations. +# - Regular import +# - Alternate Root Specified +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A vdevs "" "mirror" "raidz" +set -A options "" "-R $ALTER_ROOT" + +log_onexit cleanup_missing + +log_assert "Verify that import could handle moving device." + +log_must $MKDIR -p $BACKUP_DEVICE_DIR +cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR" + +typeset -i i=0 +typeset -i count=0 +typeset action + +function try_import # [opts] +{ + typeset action=$1; shift + typeset poolish="$1"; shift + log_note "try_import action=$action poolish=$poolish opts='$1'" + if [ -z "$1" ]; then + $action $ZPOOL import -d $DEVICE_DIR $poolish + else + $action $ZPOOL import -d $DEVICE_DIR $1 $poolish + fi + [ "$action" = "log_mustnot" ] && return + log_must $ZPOOL export $TESTPOOL1 +} + +while :; do + typeset vdtype="${vdevs[i]}" + + typeset -i j=0 + while (( j < ${#options[*]} )); do + typeset opts="${options[j]}" + + [ -n "$vdtype" ] && typestr="$vdtype" || typestr="stripe" + setup_missing_test_pool $vdtype + guid=$(get_config $TESTPOOL1 pool_guid $DEVICE_DIR) + log_note "*** Testing $typestr tvd guid $guid opts '${opts}'" + + typeset -i count=0 + for device in $DEVICE_FILES ; do + log_mustnot poolexists $TESTPOOL1 + log_must $MV $device $BACKUP_DEVICE_DIR + + (( count = count + 1 )) + + action=log_mustnot + case "${vdevs[i]}" in + 'mirror') (( count < $GROUP_NUM )) && \ + action=log_must + ;; + 'raidz') (( count == 1 )) && \ + action=log_must + ;; + esac + + log_note "Testing import by name; ${count} moved." + try_import $action $TESTPOOL1 "$opts" + + log_note "Testing import by GUID; ${count} moved." + try_import $action $guid "$opts" + done + + log_must $RM -f $BACKUP_DEVICE_DIR/* + recreate_missing_files + ((j = j + 1)) + done + ((i = i + 1)) + (( i == ${#vdevs[*]} )) && break +done + +log_pass "Import could handle moving device." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_003_pos.ksh new file mode 100644 index 00000000000..41abbbee4f2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_003_pos.ksh @@ -0,0 +1,239 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_missing_003_pos.ksh 1.4 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_missing_003_pos +# +# DESCRIPTION: +# Once a pool has been exported, but one or more devices are +# overlapped with other exported pool, import should handle +# this kind of situation properly. +# +# STRATEGY: +# 1. Repeat 1-3, create two test pools upon device files separately. +# These two pools should have one or more devices are overlapped. +# using the various combinations. +# - Regular pool +# - Mirror +# - Raidz +# 2. Create necessary filesystem and test files. +# 3. Export the test pool. +# 4. Verify 'zpool import -d' with these two pools will have results +# as described: +# - Regular, report error while any number of devices failing. +# - Mirror could withstand (N-1) devices failing +# before data integrity is compromised +# - Raidz could withstand one devices failing +# before data integrity is compromised +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-10) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A vdevs "" "mirror" "raidz" + +function verify +{ + typeset pool=$1 + typeset fs=$2 + typeset mtpt=$3 + typeset health=$4 + typeset file=$5 + typeset checksum1=$6 + + typeset myhealth + typeset mymtpt + typeset checksum2 + + log_must poolexists $pool + + myhealth=$($ZPOOL list -H -o health $pool) + + [[ $myhealth == $health ]] || \ + log_fail "$pool: Incorrect health ($myhealth), " \ + "expected ($health)." + + log_must ismounted $pool/$fs + + mymtpt=$(get_prop mountpoint $pool/$fs) + [[ $mymtpt == $mtpt ]] || \ + log_fail "$pool/$fs: Incorrect mountpoint ($mymtpt), " \ + "expected ($mtpt)." + + [[ ! -e $mtpt/$file ]] && \ + log_fail "$mtpt/$file missing after import." + + checksum2=$($SUM $mymtpt/$file | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2)" + + return 0 + +} + +function cleanup +{ + cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR" + + for pool in $TESTPOOL1 $TESTPOOL2; do + if poolexists "$pool" ; then + cleanup_filesystem $pool $TESTFS + destroy_pool $pool + fi + done + + [[ -e $DEVICE_ARCHIVE ]] && log_must $TAR xf $DEVICE_ARCHIVE +} + +function cleanup_all +{ + cleanup + + # recover dev files + typeset i=0 + while (( i < $MAX_NUM )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + ((i += 1)) + done + + log_must $RM -f $DEVICE_ARCHIVE + cd $CWD || log_fail "Unable change directory to $CWD" + +} + +log_onexit cleanup_all + +log_assert "Verify that import could handle device overlapped." + +CWD=$PWD + +cd $DEVICE_DIR || log_fail "Unable change directory to $DEVICE_DIR" +log_must $TAR cf $DEVICE_ARCHIVE ${DEVICE_FILE}* + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +typeset -i i=0 +typeset -i j=0 +typeset -i count=0 +typeset -i num=0 +typeset vdev1="" +typeset vdev2="" +typeset action + +while (( num < $GROUP_NUM )); do + vdev1="$vdev1 ${DEVICE_DIR}/${DEVICE_FILE}$num" + (( num = num + 1 )) +done + +while (( i < ${#vdevs[*]} )); do + j=0 + while (( j < ${#vdevs[*]} )); do + + (( j != 0 )) && \ + log_must $TAR xf $DEVICE_ARCHIVE + + typeset -i overlap=1 + typeset -i begin + typeset -i end + + while (( overlap <= $GROUP_NUM )); do + vdev2="" + (( begin = $GROUP_NUM - overlap )) + (( end = 2 * $GROUP_NUM - overlap - 1 )) + (( num = begin )) + while (( num <= end )); do + vdev2="$vdev2 ${DEVICE_DIR}/${DEVICE_FILE}$num" + (( num = num + 1 )) + done + + setup_filesystem "$vdev1" $TESTPOOL1 $TESTFS $TESTDIR1 \ + "" ${vdevs[i]} + log_must $CP $MYTESTFILE $TESTDIR1/$TESTFILE0 + log_must $ZFS umount $TESTDIR1 + poolexists $TESTPOOL1 && \ + log_must $ZPOOL export $TESTPOOL1 + + setup_filesystem "$vdev2" $TESTPOOL2 $TESTFS $TESTDIR2 \ + "" ${vdevs[j]} + log_must $CP $MYTESTFILE $TESTDIR2/$TESTFILE0 + log_must $ZFS umount $TESTDIR2 + poolexists $TESTPOOL2 && \ + log_must $ZPOOL export $TESTPOOL2 + + action=log_must + case "${vdevs[i]}" in + 'mirror') (( overlap == $GROUP_NUM )) && \ + action=log_mustnot + ;; + 'raidz') (( overlap > 1 )) && \ + action=log_mustnot + ;; + '') action=log_mustnot + ;; + esac + + $action $ZPOOL import -d $DEVICE_DIR $TESTPOOL1 + log_must $ZPOOL import -d $DEVICE_DIR $TESTPOOL2 + + if [[ $action == log_must ]]; then + verify "$TESTPOOL1" "$TESTFS" "$TESTDIR1" \ + "DEGRADED" "$TESTFILE0" "$checksum1" + fi + + verify "$TESTPOOL2" "$TESTFS" "$TESTDIR2" \ + "ONLINE" "$TESTFILE0" "$checksum1" + + cleanup + + (( overlap = overlap + 1 )) + + done + + ((j = j + 1)) + done + + ((i = i + 1)) +done + +log_pass "Import could handle device overlapped." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_004_pos.ksh new file mode 100644 index 00000000000..9655b77e461 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_004_pos.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_missing_004_pos +# +# DESCRIPTION: +# Once a pool has been exported and one or more devices are missing +# "zpool import" with no pool argument should exit with error code 0. +# +# STRATEGY: +# 1. Create test pool upon device files using the various combinations. +# - Striped pool +# - Mirror +# - Raidz +# 2. Export the test pool. +# 3. Remove one or more devices +# 4. Verify 'zpool import' will handle missing devices successfully. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2013-07-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A vdevs "mirror" "raidz" "" + +function cleanup +{ + destroy_pool $TESTPOOL1 + log_must $RM -rf $DEVICE_DIR/* +} + +function recreate_files +{ + cleanup + typeset -i i=0 + for (( ; $i < $GROUP_NUM; i += 1 )); do + log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i + done + log_must $SYNC +} + +log_onexit cleanup + +log_assert "Verify that zpool import succeeds when devices are missing" + +typeset rootvdev +typeset option +log_must $MKDIR -p $DEVICE_DIR +for rootvdev in "${vdevs[@]}"; do + recreate_files + poolexists $TESTPOOL1 || \ + create_pool $TESTPOOL1 "${rootvdev}" $DEVICE_FILES + + # Remove all devices but the last, one at a time + for device in ${DEVICE_FILES% *} ; do + poolexists $TESTPOOL1 && log_must $ZPOOL export $TESTPOOL1 + log_must $RM -f $device + log_must $ZPOOL import -d $DEVICE_DIR + done +done + +log_pass "zpool import succeeded when devices were missing" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_005_pos.ksh new file mode 100644 index 00000000000..9ff138c3b90 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_missing_005_pos.ksh @@ -0,0 +1,124 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2016 Spectra Logic All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_import_missing_005_pos +# +# DESCRIPTION: +# Verify that a pool can still be imported even if its devices' names +# have changed, for all types of devices. This is a test of vdev_geom's +# import_by_guid functionality. +# STRATEGY: +# 1. Create a supply of file-backed md devices +# 2. Create a disk-backed pool with regular, cache, log, and spare vdevs +# 3. Export it +# 4. Cause all the md devices names to change +# 5. Verify 'zpool import' can import it +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2015-01-4) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify that all types of vdevs of a disk-backed exported pool can be imported even if they have been renamed" + +# Create md devices so we can control their devnames +# Use high devnames so we'll be unlikely to have collisions +typeset -i REGULAR_U=4000 +typeset -i LOG_U=4001 +typeset -i CACHE_U=4002 +typeset -i SPARE_U=4003 +typeset -i REGULAR_ALTU=5000 +typeset -i LOG_ALTU=5001 +typeset -i CACHE_ALTU=5002 +typeset -i SPARE_ALTU=5003 +typeset REGULAR=${TMPDIR}/regular +typeset LOG=${TMPDIR}/log +typeset CACHE=${TMPDIR}/cache +typeset SPARE=${TMPDIR}/spare + +function cleanup +{ + destroy_pool $TESTPOOL + $MDCONFIG -d -u $REGULAR_U 2>/dev/null + $MDCONFIG -d -u $LOG_U 2>/dev/null + $MDCONFIG -d -u $CACHE_U 2>/dev/null + $MDCONFIG -d -u $SPARE_U 2>/dev/null + $MDCONFIG -d -u $REGULAR_ALTU 2>/dev/null + $MDCONFIG -d -u $LOG_ALTU 2>/dev/null + $MDCONFIG -d -u $CACHE_ALTU 2>/dev/null + $MDCONFIG -d -u $SPARE_ALTU 2>/dev/null + $RM -f $REGULAR + $RM -f $CACHE + $RM -f $LOG + $RM -f $SPARE +} +log_onexit cleanup + +log_must $TRUNCATE -s 64m $REGULAR +log_must $TRUNCATE -s 64m $LOG +log_must $TRUNCATE -s 64m $CACHE +log_must $TRUNCATE -s 64m $SPARE +log_must $MDCONFIG -t vnode -a -f $REGULAR -u $REGULAR_U +log_must $MDCONFIG -t vnode -a -f $LOG -u $LOG_U +log_must $MDCONFIG -t vnode -a -f $CACHE -u $CACHE_U +log_must $MDCONFIG -t vnode -a -f $SPARE -u $SPARE_U + +log_must $ZPOOL create $TESTPOOL md$REGULAR_U log md$LOG_U cache md$CACHE_U spare md$SPARE_U +log_must $ZPOOL export $TESTPOOL +# Now destroy the md devices, then recreate them with different names +log_must $MDCONFIG -d -u $REGULAR_U +log_must $MDCONFIG -d -u $LOG_U +log_must $MDCONFIG -d -u $CACHE_U +log_must $MDCONFIG -d -u $SPARE_U +log_must $MDCONFIG -t vnode -a -f $REGULAR -u $REGULAR_ALTU +log_must $MDCONFIG -t vnode -a -f $LOG -u $LOG_ALTU +log_must $MDCONFIG -t vnode -a -f $CACHE -u $CACHE_ALTU +log_must $MDCONFIG -t vnode -a -f $SPARE -u $SPARE_ALTU + +log_must $ZPOOL import $TESTPOOL +zpool status $TESTPOOL +log_must check_state $TESTPOOL md${REGULAR_ALTU} ONLINE +log_must check_state $TESTPOOL md${LOG_ALTU} ONLINE +log_must check_state $TESTPOOL md${CACHE_ALTU} ONLINE +log_must check_state $TESTPOOL md${SPARE_ALTU} AVAIL + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_rename_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_rename_001_pos.ksh new file mode 100644 index 00000000000..84d13957585 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_rename_001_pos.ksh @@ -0,0 +1,181 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_rename_001_pos.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_mount/zfs_mount.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_rename_001_pos +# +# DESCRIPTION: +# An exported pool can be imported under a different name. Hence +# we test that a previously exported pool can be renamed. +# +# STRATEGY: +# 1. Copy a file into the default test directory. +# 2. Umount the default directory. +# 3. Export the pool. +# 4. Import the pool using the name ${TESTPOOL}-new, +# and using the various combinations. +# - Regular import +# - Alternate Root Specified +# 5. Verify it exists in the 'zpool list' output. +# 6. Verify the default file system is mounted and that the file +# from step (1) is present. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A pools "$TESTPOOL" "$TESTPOOL1" +set -A devs "" "-d $DEVICE_DIR" +set -A options "" "-R $ALTER_ROOT" +set -A mtpts "$TESTDIR" "$TESTDIR1" + + +function cleanup +{ + typeset -i i=0 + while (( i < ${#pools[*]} )); do + if poolexists "${pools[i]}-new" ; then + log_must $ZPOOL export "${pools[i]}-new" + + [[ -d /${pools[i]}-new ]] && \ + log_must $RM -rf /${pools[i]}-new + + log_must $ZPOOL import ${devs[i]} \ + "${pools[i]}-new" ${pools[i]} + fi + + datasetexists "${pools[i]}" || \ + log_must $ZPOOL import ${devs[i]} ${pools[i]} + + ismounted "${pools[i]}/$TESTFS" || \ + log_must $ZFS mount ${pools[i]}/$TESTFS + + [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \ + log_must $RM -rf ${mtpts[i]}/$TESTFILE0 + + ((i = i + 1)) + + done + + cleanup_filesystem $TESTPOOL1 $TESTFS $TESTDIR1 + + destroy_pool $TESTPOOL1 + + [[ -d $ALTER_ROOT ]] && \ + log_must $RM -rf $ALTER_ROOT +} + +function perform_inner_test +{ + target=$1 + + log_must $ZPOOL import ${devs[i]} ${options[j]} \ + $target ${pools[i]}-new + + log_must poolexists "${pools[i]}-new" + + log_must ismounted ${pools[i]}-new/$TESTFS + + basedir=${mtpts[i]} + [[ -n ${options[j]} ]] && \ + basedir=$ALTER_ROOT/${mtpts[i]} + + [[ ! -e $basedir/$TESTFILE0 ]] && \ + log_fail "$basedir/$TESTFILE0 missing after import." + + checksum2=$($SUM $basedir/$TESTFILE0 | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2)" + + log_must $ZPOOL export "${pools[i]}-new" + + [[ -d /${pools[i]}-new ]] && \ + log_must $RM -rf /${pools[i]}-new + + target=${pools[i]}-new + if (( RANDOM % 2 == 0 )) ; then + target=$guid + fi + log_must $ZPOOL import ${devs[i]} $target ${pools[i]} +} + +log_onexit cleanup + +log_assert "Verify that an imported pool can be renamed." + +setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +typeset -i i=0 +typeset -i j=0 +typeset basedir + +while (( i < ${#pools[*]} )); do + guid=$(get_config ${pools[i]} pool_guid) + log_must $CP $MYTESTFILE ${mtpts[i]}/$TESTFILE0 + + log_must $ZFS umount ${mtpts[i]} + + j=0 + while (( j < ${#options[*]} )); do + log_must $ZPOOL export ${pools[i]} + + [[ -d /${pools[i]} ]] && \ + log_must $RM -rf /${pools[i]} + + log_note "Testing import by name." + perform_inner_test ${pools[i]} + + log_must $ZPOOL export ${pools[i]} + + log_note "Testing import by GUID." + perform_inner_test $guid + + ((j = j + 1)) + done + + ((i = i + 1)) +done + +log_pass "Successfully imported and renamed a ZPOOL" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_test.sh new file mode 100755 index 00000000000..76e6728ee64 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_import/zpool_import_test.sh @@ -0,0 +1,589 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_import_002_pos cleanup +zpool_import_002_pos_head() +{ + atf_set "descr" "Verify that an exported pool can be imported and cannot be imported more than once." + atf_set "require.progs" zfs zpool sum zdb + atf_set "timeout" 2400 +} +zpool_import_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_003_pos cleanup +zpool_import_003_pos_head() +{ + atf_set "descr" "Destroyed pools are not listed unless with -D option is specified." + atf_set "require.progs" zpool zfs + atf_set "timeout" 2400 +} +zpool_import_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_004_pos cleanup +zpool_import_004_pos_head() +{ + atf_set "descr" "Destroyed pools devices was moved to another directory,it still can be imported correctly." + atf_set "require.progs" zpool zfs zdb + atf_set "timeout" 2400 +} +zpool_import_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_005_pos cleanup +zpool_import_005_pos_head() +{ + atf_set "descr" "Destroyed pools devices was renamed, it still can be importedcorrectly." + atf_set "require.progs" zpool zfs zdb + atf_set "timeout" 2400 +} +zpool_import_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_005_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_006_pos cleanup +zpool_import_006_pos_head() +{ + atf_set "descr" "For mirror, N-1 destroyed pools devices was removed or usedby other pool, it still can be imported correctly." + atf_set "require.progs" zpool zfs zdb + atf_set "timeout" 2400 +} +zpool_import_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_006_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_007_pos cleanup +zpool_import_007_pos_head() +{ + atf_set "descr" "For raidz, one destroyed pools devices was removed or used byother pool, it still can be imported correctly." + atf_set "require.progs" zpool zfs zdb + atf_set "timeout" 2400 +} +zpool_import_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_007_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_008_pos cleanup +zpool_import_008_pos_head() +{ + atf_set "descr" "For raidz2, two destroyed pools devices was removed or used byother pool, it still can be imported correctly." + atf_set "require.progs" zpool zfs zdb + atf_set "timeout" 2400 +} +zpool_import_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_008_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_009_neg cleanup +zpool_import_009_neg_head() +{ + atf_set "descr" "Badly-formed 'zpool import' with inapplicable scenariosshould return an error." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2400 +} +zpool_import_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_009_neg.ksh || atf_fail "Testcase failed" +} +zpool_import_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_010_pos cleanup +zpool_import_010_pos_head() +{ + atf_set "descr" "'zpool -D -a' can import all the specified directoriesdestroyed pools." + atf_set "require.progs" zpool zfs + atf_set "timeout" 2400 +} +zpool_import_010_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_010_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_011_neg cleanup +zpool_import_011_neg_head() +{ + atf_set "descr" "For strip pool, any destroyed pool devices was demaged,zpool import -D will failed." + atf_set "require.progs" zpool zfs zdb + atf_set "timeout" 2400 +} +zpool_import_011_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_011_neg.ksh || atf_fail "Testcase failed" +} +zpool_import_011_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_012_pos cleanup +zpool_import_012_pos_head() +{ + atf_set "descr" "Verify all mount & share status of sub-filesystems within a poolcan be restored after import [-Df]." + atf_set "require.progs" zfs zpool zdb share + atf_set "timeout" 2400 +} +zpool_import_012_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_012_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_012_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_013_neg +zpool_import_013_neg_head() +{ + atf_set "descr" "'zpool import' fails for pool that was not cleanly exported" + atf_set "require.progs" zfs zpool +} +zpool_import_013_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/zpool_import_013_neg.ksh || atf_fail "Testcase failed" +} + + +atf_test_case zpool_import_014_pos cleanup +zpool_import_014_pos_head() +{ + atf_set "descr" "'zpool import' can import destroyed disk-backed pools" + atf_set "require.progs" zfs zpool +} +zpool_import_014_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/zpool_import_014_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_014_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_all_001_pos cleanup +zpool_import_all_001_pos_head() +{ + atf_set "descr" "Verify that 'zpool import -a' succeeds as root." + atf_set "require.progs" zfs zpool sum + atf_set "timeout" 2400 +} +zpool_import_all_001_pos_body() +{ + atf_skip "This test relies heavily on Solaris slices. It could be ported, but that is difficult due to the high degree of obfuscation in the code" + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_all_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_all_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_missing_001_pos cleanup +zpool_import_missing_001_pos_head() +{ + atf_set "descr" "Verify that import could handle damaged or missing device." + atf_set "require.progs" zfs sum zpool zdb + atf_set "timeout" 2400 +} +zpool_import_missing_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_missing_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_missing_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_missing_002_pos cleanup +zpool_import_missing_002_pos_head() +{ + atf_set "descr" "Verify that import could handle moving device." + atf_set "require.progs" zpool zfs zdb + atf_set "timeout" 2400 +} +zpool_import_missing_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_missing_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_missing_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_missing_003_pos cleanup +zpool_import_missing_003_pos_head() +{ + atf_set "descr" "Verify that import could handle device overlapped." + atf_set "require.progs" zpool sum zfs + atf_set "timeout" 2400 +} +zpool_import_missing_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_missing_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_missing_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zpool_import_missing_004_pos +zpool_import_missing_004_pos_head() +{ + atf_set "descr" "Verify that zpool import succeeds when devices are missing" + atf_set "require.progs" zfs zpool + atf_set "timeout" 300 +} +zpool_import_missing_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/zpool_import_missing_004_pos.ksh || atf_fail "Testcase failed" +} + +atf_test_case zpool_import_missing_005_pos +zpool_import_missing_005_pos_head() +{ + atf_set "descr" "Verify that zpool import succeeds when devices of all types have been renamed" + atf_set "require.progs" mdconfig zfs zpool + atf_set "timeout" 300 +} +zpool_import_missing_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/zpool_import_missing_005_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case zpool_import_rename_001_pos cleanup +zpool_import_rename_001_pos_head() +{ + atf_set "descr" "Verify that an imported pool can be renamed." + atf_set "require.progs" zfs zpool sum zdb + atf_set "timeout" 2400 +} +zpool_import_rename_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_rename_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_rename_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zpool_import_corrupt_001_pos cleanup +zpool_import_corrupt_001_pos_head() +{ + atf_set "descr" "Verify that a disk-backed exported pool with some of its vdev labels corrupted can still be imported" + atf_set "require.progs" zfs zpool zdb + atf_set "timeout" 2400 +} +zpool_import_corrupt_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/zpool_import_corrupt_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_import_corrupt_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_import.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zpool_import_destroyed_001_neg cleanup +zpool_import_destroyed_001_neg_head() +{ + atf_set "descr" "'zpool import' will not show destroyed pools, even if an out-of-date non-destroyed label remains" + atf_set "require.progs" zpool +} +zpool_import_destroyed_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + verify_disk_count "$DISKS" 3 + ksh93 $(atf_get_srcdir)/zpool_import_destroyed_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_import_destroyed_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + destroy_pool "$TESTPOOL" + cleanup_devices "$DISKS" +} + +atf_test_case zpool_import_destroyed_002_neg cleanup +zpool_import_destroyed_002_neg_head() +{ + atf_set "descr" "'zpool import' will not show destroyed pools, even if an out-of-date non-destroyed label remains" + atf_set "require.progs" zpool +} +zpool_import_destroyed_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/zpool_import_destroyed_002_neg.ksh || atf_fail "Testcase failed" +} +zpool_import_destroyed_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + destroy_pool "$TESTPOOL" + cleanup_devices "$DISKS" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_import_002_pos + atf_add_test_case zpool_import_003_pos + atf_add_test_case zpool_import_004_pos + atf_add_test_case zpool_import_005_pos + atf_add_test_case zpool_import_006_pos + atf_add_test_case zpool_import_007_pos + atf_add_test_case zpool_import_008_pos + atf_add_test_case zpool_import_009_neg + atf_add_test_case zpool_import_010_pos + atf_add_test_case zpool_import_011_neg + atf_add_test_case zpool_import_012_pos + atf_add_test_case zpool_import_013_neg + atf_add_test_case zpool_import_014_pos + atf_add_test_case zpool_import_all_001_pos + atf_add_test_case zpool_import_missing_001_pos + atf_add_test_case zpool_import_missing_002_pos + atf_add_test_case zpool_import_missing_003_pos + atf_add_test_case zpool_import_missing_004_pos + atf_add_test_case zpool_import_missing_005_pos + atf_add_test_case zpool_import_rename_001_pos + atf_add_test_case zpool_import_corrupt_001_pos + atf_add_test_case zpool_import_destroyed_001_neg + atf_add_test_case zpool_import_destroyed_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/Makefile new file mode 100644 index 00000000000..09c126d5447 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_offline +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_offline_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_offline_002_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_offline_001_pos.ksh +${PACKAGE}FILES+= zpool_offline.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/cleanup.ksh new file mode 100644 index 00000000000..b5a6a6c0f9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/setup.ksh new file mode 100644 index 00000000000..e4db7febd63 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +default_mirror_setup $DISKS diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline.cfg new file mode 100644 index 00000000000..92b86c249ce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_offline.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_001_pos.ksh new file mode 100644 index 00000000000..64749a8d10f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_001_pos.ksh @@ -0,0 +1,138 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_offline_001_pos.ksh 1.3 09/05/19 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_offline_001_pos +# +# DESCRIPTION: +# Executing 'zpool offline' with valid parameters succeeds. +# +# STRATEGY: +# 1. Create an array of correctly formed 'zpool offline' options +# 2. Execute each element of the array. +# 3. Verify use of each option is successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +DISKLIST=$(get_disklist $TESTPOOL) +set -A disks $DISKLIST +typeset -i num=${#disks[*]} + +set -A args "" "-t" + +function cleanup +{ + # + # Ensure we don't leave disks in the offline state + # + for disk in $DISKLIST; do + log_must $ZPOOL online $TESTPOOL $disk + check_state $TESTPOOL $disk "online" + if [[ $? != 0 ]]; then + log_fail "Unable to online $disk" + fi + + done +} + +log_assert "Executing 'zpool offline' with correct options succeeds" + +log_onexit cleanup + +if [[ -z $DISKLIST ]]; then + log_fail "DISKLIST is empty." +fi + +typeset -i i=0 +typeset -i j=1 + +for disk in $DISKLIST; do + i=0 + while [[ $i -lt ${#args[*]} ]]; do + if (( j < num )) ; then + log_must $ZPOOL offline ${args[$i]} $TESTPOOL $disk + check_state $TESTPOOL $disk "offline" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL did not match offline state" + fi + else + log_mustnot $ZPOOL offline ${args[$i]} $TESTPOOL $disk + check_state $TESTPOOL $disk "online" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL did not match online state" + fi + fi + + (( i = i + 1 )) + done + (( j = j + 1 )) +done + +log_note "Issuing repeated 'zpool offline' commands succeeds." + +typeset -i iters=20 +typeset -i index=0 + +for disk in $DISKLIST; do + i=0 + while [[ $i -lt $iters ]]; do + index=`expr $RANDOM % ${#args[*]}` + log_must $ZPOOL offline ${args[$index]} $TESTPOOL $disk + check_state $TESTPOOL $disk "offline" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL is not offline." + fi + + (( i = i + 1 )) + done + + log_must $ZPOOL online $TESTPOOL $disk + check_state $TESTPOOL $disk "online" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL did not match online state" + fi +done + +log_pass "'zpool offline' with correct options succeeded" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_002_neg.ksh new file mode 100644 index 00000000000..713ba57674d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_002_neg.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_offline_002_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_offline_002_neg +# +# DESCRIPTION: +# Executing 'zpool offline' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool offline' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +DISKLIST=$(get_disklist $TESTPOOL) + +set -A args "" "-?" "-t fakepool" "-f fakepool" "-ev fakepool" "fakepool" \ + "-t $TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \ + "-t $TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \ + "-t $TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \ + "-t $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "-t $TESTPOOL/$TESTVOL $DISKLIST" \ + "-t $DISKLIST" \ + "-f $TESTPOOL" "-f $TESTPOOL/$TESTFS" "-f $TESTPOOL/$TESTFS $DISKLIST" \ + "-f $TESTPOOL/$TESTCTR" "-f $TESTPOOL/$TESTCTR/$TESTFS1" \ + "-f $TESTPOOL/$TESTCTR $DISKLIST" "-f $TESTPOOL/$TESTVOL" \ + "-f $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "-f $TESTPOOL/$TESTVOL $DISKLIST" \ + "-f $DISKLIST" \ + "-ft $TESTPOOL" "-ft $TESTPOOL/$TESTFS" \ + "-ft $TESTPOOL/$TESTFS $DISKLIST" \ + "-ft $TESTPOOL/$TESTCTR" "-ft $TESTPOOL/$TESTCTR/$TESTFS1" \ + "-ft $TESTPOOL/$TESTCTR $DISKLIST" "-ft $TESTPOOL/$TESTVOL" \ + "-ft $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "-ft $TESTPOOL/$TESTVOL $DISKLIST" \ + "-ft $DISKLIST" \ + "-tf $TESTPOOL" "-tf $TESTPOOL/$TESTFS" \ + "-tf $TESTPOOL/$TESTFS $DISKLIST" \ + "-tf $TESTPOOL/$TESTCTR" "-tf $TESTPOOL/$TESTCTR/$TESTFS1" \ + "-tf $TESTPOOL/$TESTCTR $DISKLIST" "-tf $TESTPOOL/$TESTVOL" \ + "-tf $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "-tf $TESTPOOL/$TESTVOL $DISKLIST" \ + "-tf $DISKLIST" \ + "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $DISKLIST" \ + "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTPOOL/$TESTCTR $DISKLIST" "$TESTPOOL/$TESTVOL" \ + "$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" "$TESTPOOL/$TESTVOL $DISKLIST" \ + "$DISKLIST" + +log_assert "Executing 'zpool offline' with bad options fails" + +if [[ -z $DISKLIST ]]; then + log_fail "DISKLIST is empty." +fi + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL offline ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool offline' command with bad options failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_test.sh new file mode 100755 index 00000000000..2e31238091f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_offline/zpool_offline_test.sh @@ -0,0 +1,82 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_offline_001_pos cleanup +zpool_offline_001_pos_head() +{ + atf_set "descr" "Executing 'zpool offline' with correct options succeeds" + atf_set "require.progs" zpool +} +zpool_offline_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_offline.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_offline_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_offline_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_offline.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_offline_002_neg cleanup +zpool_offline_002_neg_head() +{ + atf_set "descr" "Executing 'zpool offline' with bad options fails" + atf_set "require.progs" zpool +} +zpool_offline_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_offline.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_offline_002_neg.ksh || atf_fail "Testcase failed" +} +zpool_offline_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_offline.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_offline_001_pos + atf_add_test_case zpool_offline_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_online/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/Makefile new file mode 100644 index 00000000000..06d92adafe9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_online +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_online_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_online.cfg +${PACKAGE}FILES+= zpool_online_002_neg.ksh +${PACKAGE}FILES+= zpool_online_001_pos.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_online/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/cleanup.ksh new file mode 100644 index 00000000000..b5a6a6c0f9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_online/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/setup.ksh new file mode 100644 index 00000000000..e4db7febd63 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +default_mirror_setup $DISKS diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online.cfg new file mode 100644 index 00000000000..e98bec592a4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_online.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_001_pos.ksh new file mode 100644 index 00000000000..1d9c848c2fe --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_001_pos.ksh @@ -0,0 +1,126 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_online_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_online_001 +# +# DESCRIPTION: +# Executing 'zpool online' with valid parameters succeeds. +# +# STRATEGY: +# 1. Create an array of correctly formed 'zpool online' options +# 2. Execute each element of the array. +# 3. Verify use of each option is successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +DISKLIST=$(get_disklist $TESTPOOL) + +set -A args "" + +function cleanup +{ + # + # Ensure we don't leave disks in temporary online state (-t) + # + for disk in $DISKLIST; do + log_must $ZPOOL online $TESTPOOL $disk + check_state $TESTPOOL $disk "online" + if [[ $? != 0 ]]; then + log_fail "Unable to online $disk" + fi + + done +} + +log_assert "Executing 'zpool online' with correct options succeeds" + +log_onexit cleanup + +if [[ -z $DISKLIST ]]; then + log_fail "DISKLIST is empty." +fi + +typeset -i i=0 + +for disk in $DISKLIST; do + i=0 + while [[ $i -lt ${#args[*]} ]]; do + log_must $ZPOOL offline $TESTPOOL $disk + check_state $TESTPOOL $disk "offline" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL did not match offline state" + fi + + log_must $ZPOOL online ${args[$i]} $TESTPOOL $disk + check_state $TESTPOOL $disk "online" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL did not match online state" + fi + + (( i = i + 1 )) + done +done + +log_note "Issuing repeated 'zpool online' commands succeeds." + +typeset -i iters=20 +typeset -i index=0 + +for disk in $DISKLIST; do + i=0 + while [[ $i -lt $iters ]]; do + index=`expr $RANDOM % ${#args[*]}` + log_must $ZPOOL online ${args[$index]} $TESTPOOL $disk + check_state $TESTPOOL $disk "online" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL did not match online state" + fi + + (( i = i + 1 )) + done +done + +log_pass "'zpool online' with correct options succeeded" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_002_neg.ksh new file mode 100644 index 00000000000..2760aa34ded --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_002_neg.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_online_002_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_online_002_neg +# +# DESCRIPTION: +# Executing 'zpool online' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool online' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-30) +# +# __stc_assertion_end +# +################################################################################ +verify_runnable "global" + +DISKLIST=$(get_disklist $TESTPOOL) + +set -A args "" "-?" "-e fakepool" "-v fakepool" "-ev fakepool" "-ve fakepool" \ + "-t $TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \ + "-t $TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \ + "-t $TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \ + "-t $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "-t $TESTPOOL/$TESTVOL $DISKLIST" \ + "-t $DISKLIST" \ + "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTFS $DISKLIST" \ + "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTPOOL/$TESTCTR $DISKLIST" "$TESTPOOL/$TESTVOL" \ + "$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" "$TESTPOOL/$TESTVOL $DISKLIST" \ + "$DISKLIST" + +log_assert "Executing 'zpool online' with bad options fails" + +if [[ -z $DISKLIST ]]; then + log_fail "DISKLIST is empty." +fi + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL online ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool online' command with bad options failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_test.sh new file mode 100755 index 00000000000..8955925ccc7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_online/zpool_online_test.sh @@ -0,0 +1,82 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_online_001_pos cleanup +zpool_online_001_pos_head() +{ + atf_set "descr" "Executing 'zpool online' with correct options succeeds" + atf_set "require.progs" zpool +} +zpool_online_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_online.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_online_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_online_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_online.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_online_002_neg cleanup +zpool_online_002_neg_head() +{ + atf_set "descr" "Executing 'zpool online' with bad options fails" + atf_set "require.progs" zpool +} +zpool_online_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_online.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_online_002_neg.ksh || atf_fail "Testcase failed" +} +zpool_online_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_online.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_online_001_pos + atf_add_test_case zpool_online_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/Makefile new file mode 100644 index 00000000000..0187bf60813 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_remove +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_remove_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_remove_001_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_remove.cfg +${PACKAGE}FILES+= zpool_remove_002_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_remove_003_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/cleanup.ksh new file mode 100644 index 00000000000..15c71e16bd8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +cleanup_devices $DISKS + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/setup.ksh new file mode 100644 index 00000000000..c328d811786 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/setup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +verify_runnable "global" + +partition_disk $SIZE $DISK 6 + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove.cfg new file mode 100644 index 00000000000..f88b9da7d85 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_remove.cfg 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg + +export DISK=${DISKS%% *} +export SIZE="200m" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_001_neg.ksh new file mode 100644 index 00000000000..3c45ca151ae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_001_neg.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_remove_001_neg.ksh 1.2 08/11/03 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_remove_001_neg +# +# DESCRIPTION: +# Verify that 'zpool can not remove device except inactive hot spares from pool' +# +# STRATEGY: +# 1. Create all kinds of pool (strip, mirror, raidz, hotspare) +# 2. Try to remove device from the pool +# 3. Verify that the remove failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-18) +# +# __stc_assertion_end +# +################################################################################ + +typeset disk=${DISK} +typeset vdev_devs="${disk}p1" +typeset mirror_devs="${disk}p1 ${disk}p2" +typeset raidz_devs=${mirror_devs} +typeset raidz1_devs=${mirror_devs} +typeset raidz2_devs="${mirror_devs} ${disk}p3" +typeset spare_devs1="${disk}p1" +typeset spare_devs2="${disk}p2" + +function check_remove +{ + typeset pool=$1 + typeset devs="$2" + typeset dev + + for dev in $devs; do + log_mustnot $ZPOOL remove $dev + done + + destroy_pool $pool + +} + +function cleanup +{ + if poolexists $TESTPOOL; then + destroy_pool $TESTPOOL + fi +} + +set -A create_args "$vdev_devs" "mirror $mirror_devs" \ + "raidz $raidz_devs" "raidz $raidz1_devs" \ + "raidz2 $raidz2_devs" \ + "$spare_devs1 spare $spare_devs2" + +set -A verify_disks "$vdev_devs" "$mirror_devs" "$raidz_devs" \ + "$raidz1_devs" "$raidz2_devs" "$spare_devs1" + + +log_assert "Check zpool remove can not remove " \ + "active device from pool" + +log_onexit cleanup + +typeset -i i=0 +while [[ $i -lt ${#create_args[*]} ]]; do + log_must $ZPOOL create $TESTPOOL ${create_args[i]} + check_remove $TESTPOOL "${verify_disks[i]}" + (( i = i + 1)) +done + +log_pass "'zpool remove fail as expected .'" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_002_pos.ksh new file mode 100644 index 00000000000..323c94b90ae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_002_pos.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_remove_002_pos.ksh 1.1 07/07/31 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_remove_002_pos +# +# DESCRIPTION: +# Verify that 'zpool can only remove inactive hot spare devices from pool' +# +# STRATEGY: +# 1. Create a hotspare pool +# 2. Try to remove the inactive hotspare device from the pool +# 3. Verify that the remove succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-18) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + destroy_pool $TESTPOOL +} + +log_onexit cleanup +typeset disk=${DISK} + +typeset spare_devs1="${disk}p1" +typeset spare_devs2="${disk}p2" + +log_assert "zpool remove can only remove inactive hotspare device from pool" + +log_note "check hotspare device which is created by zpool create" +log_must $ZPOOL create $TESTPOOL $spare_devs1 spare $spare_devs2 +log_must $ZPOOL remove $TESTPOOL $spare_devs2 + +log_note "check hotspare device which is created by zpool add" +log_must $ZPOOL add $TESTPOOL spare $spare_devs2 +log_must $ZPOOL remove $TESTPOOL $spare_devs2 +log_must $ZPOOL destroy $TESTPOOL + +log_pass "zpool remove can only remove inactive hotspare device from pool" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_003_pos.ksh new file mode 100644 index 00000000000..9b6f55156b6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_003_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_remove_003_pos.ksh 1.2 08/11/03 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_remove_003_pos +# +# DESCRIPTION: +# Verify that 'zpool can remove hotspare devices from pool when it state +# switch from active to inactive' +# +# STRATEGY: +# 1. Create a hotspare pool +# 2. Try to replace the inactive hotspare device to active device in the pool +# 3. Try to detach active (spare) device to make it inactive +# 3. Verify that the zpool remove succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-18) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + restart_zfsd + + if poolexists $TESTPOOL; then + destroy_pool $TESTPOOL + fi +} + +# Stop ZFSD because it interferes with our manually activated spares +stop_zfsd + +log_onexit cleanup +typeset disk=${DISK} + +typeset spare_devs1="${disk}p1" +typeset spare_devs2="${disk}p2" +typeset spare_devs3="${disk}p3" +typeset spare_devs4="${disk}p4" + +log_assert "zpool remove can remove hotspare device which state go though" \ + " active to inactive in pool" + +log_note "Check spare device which state go through active to inactive" +log_must $ZPOOL create $TESTPOOL $spare_devs1 $spare_devs2 spare \ + $spare_devs3 $spare_devs4 +log_must $ZPOOL replace $TESTPOOL $spare_devs2 $spare_devs3 +log_mustnot $ZPOOL remove $TESTPOOL $spare_devs3 +log_must $ZPOOL detach $TESTPOOL $spare_devs3 +log_must $ZPOOL remove $TESTPOOL $spare_devs3 + +log_pass "'zpool remove device passed as expected.'" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_test.sh new file mode 100755 index 00000000000..2cbcd955494 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_remove/zpool_remove_test.sh @@ -0,0 +1,107 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_remove_001_neg cleanup +zpool_remove_001_neg_head() +{ + atf_set "descr" "Check zpool remove can not removeactive device from pool" + atf_set "require.progs" zpool +} +zpool_remove_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_remove.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_remove_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_remove_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_remove.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_remove_002_pos cleanup +zpool_remove_002_pos_head() +{ + atf_set "descr" "zpool remove can only remove inactive hotspare device from pool" + atf_set "require.progs" zpool +} +zpool_remove_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_remove.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_remove_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_remove_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_remove.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_remove_003_pos cleanup +zpool_remove_003_pos_head() +{ + atf_set "descr" "zpool remove can remove hotspare device which state go though active to inactive in pool" + atf_set "require.progs" zpool +} +zpool_remove_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_remove.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_remove_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_remove_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_remove.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_remove_001_neg + atf_add_test_case zpool_remove_002_pos + atf_add_test_case zpool_remove_003_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/Makefile new file mode 100644 index 00000000000..59dd9846bf0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_replace +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_replace_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_replace_001_neg.ksh +${PACKAGE}FILES+= zpool_replace_002_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_replace.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/cleanup.ksh new file mode 100644 index 00000000000..b5a6a6c0f9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/setup.ksh new file mode 100644 index 00000000000..e4db7febd63 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +default_mirror_setup $DISKS diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace.cfg new file mode 100644 index 00000000000..6d85532146b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_replace.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_001_neg.ksh new file mode 100644 index 00000000000..d19e26a6b14 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_001_neg.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_replace_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_replace_001_neg +# +# DESCRIPTION: +# Executing 'zpool replace' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool replace' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +DISKLIST=$(get_disklist $TESTPOOL) + +set -A args "" "-f" "-?" "-z fakepool" "-f fakepool" "-ev fakepool" "fakepool" \ + "$TESTPOOL" "-t $TESTPOOL/$TESTFS" "-t $TESTPOOL/$TESTFS $DISKLIST" \ + "$TESTPOOL/$TESTCTR" "-t $TESTPOOL/$TESTCTR/$TESTFS1" \ + "$TESTPOOL/$TESTCTR $DISKLIST" "-t $TESTPOOL/$TESTVOL" \ + "$TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "$TESTPOOL/$TESTVOL $DISKLIST" \ + "$DISKLIST" \ + "fakepool fakedevice" "fakepool fakedevice fakenewdevice" \ + "$TESTPOOL fakedevice" "$TESTPOOL $DISKLIST" \ + "$TESTPOOL fakedevice fakenewdevice fakenewdevice" \ + "-f $TESTPOOL" "-f $TESTPOOL/$TESTFS" "-f $TESTPOOL/$TESTFS $DISKLIST" \ + "-f $TESTPOOL/$TESTCTR" "-f $TESTPOOL/$TESTCTR/$TESTFS1" \ + "-f $TESTPOOL/$TESTCTR $DISKLIST" "-f $TESTPOOL/$TESTVOL" \ + "-f $TESTPOOL/$TESTCTR/$TESTFS1 $DISKLIST" \ + "-f $TESTPOOL/$TESTVOL $DISKLIST" \ + "-f $DISKLIST" \ + "-f fakepool fakedevice" "-f fakepool fakedevice fakenewdevice" \ + "-f $TESTPOOL fakedevice fakenewdevice fakenewdevice" \ + "-f $TESTPOOL fakedevice" "-f $TESTPOOL $DISKLIST" + +log_assert "Executing 'zpool replace' with bad options fails" + +if [[ -z $DISKLIST ]]; then + log_fail "DISKLIST is empty." +fi + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL replace ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool replace' command with bad options failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_002_neg.ksh new file mode 100644 index 00000000000..03cd222efad --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_002_neg.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +log_assert "'zpool replace' should fail if the new device is too small" + +log_must $TRUNCATE -s 1024m bigfile +log_must $TRUNCATE -s 512m smallfile + +log_must $ZPOOL create $TESTPOOL $PWD/bigfile +log_mustnot $ZPOOL replace $TESTPOOL $PWD/bigfile $PWD/smallfile + +log_pass "'zpool replace' should fail if the new device is too small" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_test.sh new file mode 100755 index 00000000000..f8f85d16807 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_replace/zpool_replace_test.sh @@ -0,0 +1,79 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_replace_001_neg cleanup +zpool_replace_001_neg_head() +{ + atf_set "descr" "Executing 'zpool replace' with bad options fails" + atf_set "require.progs" zpool +} +zpool_replace_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_replace.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_replace_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_replace_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_replace.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zpool_replace_002_neg cleanup +zpool_replace_002_neg_head() +{ + atf_set "descr" "'zpool replace' should fail if the new device is too small" + atf_set "require.progs" zpool +} +zpool_replace_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_replace.cfg + + ksh93 $(atf_get_srcdir)/zpool_replace_002_neg.ksh || atf_fail "Testcase failed" +} +zpool_replace_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_replace.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_replace_001_neg + atf_add_test_case zpool_replace_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/Makefile new file mode 100644 index 00000000000..7fc238b2025 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_scrub +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_scrub_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_scrub_001_neg.ksh +${PACKAGE}FILES+= zpool_scrub_004_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_scrub_005_pos.ksh +${PACKAGE}FILES+= zpool_scrub.cfg +${PACKAGE}FILES+= zpool_scrub_003_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_scrub_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/cleanup.ksh new file mode 100644 index 00000000000..963d13b8b7e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +destroy_mirrors diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/setup.ksh new file mode 100644 index 00000000000..95a1c426213 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/setup.ksh @@ -0,0 +1,45 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_mirror_setup_noexit $DISK1 $DISK2 + +mntpnt=$(get_prop mountpoint $TESTPOOL) +typeset -i i=0 +while ((i < 10)); do + log_must $MKFILE 500M $mntpnt/bigfile.$i + ((i += 1)) +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub.cfg new file mode 100644 index 00000000000..c5d4e38a365 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub.cfg @@ -0,0 +1,34 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_scrub.cfg 1.3 07/10/09 SMI" +# +. $STF_SUITE/tests/cli_root/cli.cfg + +export DISK1=$($ECHO $DISKS | $AWK '{print $1}') +export DISK2=$($ECHO $DISKS | $AWK '{print $2}') diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh new file mode 100644 index 00000000000..ccde48731aa --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_001_neg.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_scrub_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_scrub_001_neg +# +# DESCRIPTION: +# A badly formed parameter passed to 'zpool scrub' should +# return an error. +# +# STRATEGY: +# 1. Create an array containing bad 'zpool scrub' parameters. +# 2. For each element, execute the sub-command. +# 3. Verify it returns an error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A args "" "-?" "blah blah" "-%" "--?" "-*" "-=" \ + "-a" "-b" "-c" "-d" "-e" "-f" "-g" "-h" "-i" "-j" "-k" "-l" \ + "-m" "-n" "-o" "-p" "-q" "-r" "-s" "-t" "-u" "-v" "-w" "-x" "-y" "-z" \ + "-A" "-B" "-C" "-D" "-E" "-F" "-G" "-H" "-I" "-J" "-K" "-L" \ + "-M" "-N" "-O" "-P" "-Q" "-R" "-S" "-T" "-U" "-V" "-W" "-X" "-W" "-Z" + + +log_assert "Execute 'zpool scrub' using invalid parameters." + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZPOOL scrub ${args[i]} + + ((i = i + 1)) +done + +log_pass "Badly formed 'zpool scrub' parameters fail as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh new file mode 100644 index 00000000000..d32ef918c05 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_002_pos.ksh @@ -0,0 +1,66 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_scrub_002_pos.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_scrub_002_pos +# +# DESCRIPTION: +# Verify scrub -s works correctly. +# +# STRATEGY: +# 1. Create pool and fill with hundreds data. +# 2. zpool scrub the pool +# 3. Verify zpool scrub -s succeed when the system is scrubbing. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-08) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify scrub -s works correctly." + +log_must $ZPOOL scrub $TESTPOOL +log_must $ZPOOL scrub -s $TESTPOOL +log_must is_pool_scrub_stopped $TESTPOOL + +log_pass "Verify scrub -s works correctly." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh new file mode 100644 index 00000000000..5181e8d1dcc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_003_pos.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_scrub_003_pos.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_scrub_003_pos +# +# DESCRIPTION: +# scrub command terminates the existing scrub process and starts +# a new scrub. +# +# STRATEGY: +# 1. Setup a pool and fill with data +# 2. Kick off a scrub +# 3. Check the completed percent and invoke another scrub +# 4. Check the percent again, verify a new scrub started. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function get_scrub_percent +{ + typeset -i percent + percent=$($ZPOOL status $TESTPOOL | $GREP "^ scrub" | \ + $AWK '{print $7}' | $AWK -F. '{print $1}') + if is_pool_scrubbed $TESTPOOL ; then + percent=100 + fi + $ECHO $percent +} + +log_assert "scrub command terminates the existing scrub process and starts" \ + "a new scrub." + +log_must $ZPOOL scrub $TESTPOOL +typeset -i PERCENT=30 percent=0 +while ((percent < PERCENT)) ; do + percent=$(get_scrub_percent) +done + +log_must $ZPOOL scrub $TESTPOOL +percent=$(get_scrub_percent) +if ((percent > PERCENT)); then + log_fail "zpool scrub don't stop existing scrubbing process." +fi + +log_pass "scrub command terminates the existing scrub process and starts" \ + "a new scrub." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh new file mode 100644 index 00000000000..e8b4c7346d1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_004_pos.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_scrub_004_pos.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_scrub_004_pos +# +# DESCRIPTION: +# Resilver prevent scrub from starting until the resilver completes +# +# STRATEGY: +# 1. Setup a mirror pool and filled with data. +# 2. Detach one of devices +# 3. Verify scrub failed until the resilver completed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Resilver prevent scrub from starting until the resilver completes" + +log_must $ZPOOL detach $TESTPOOL $DISK2 +log_must $ZPOOL attach $TESTPOOL $DISK1 $DISK2 +log_must is_pool_resilvering $TESTPOOL +log_mustnot $ZPOOL scrub $TESTPOOL + +while true; do + if is_pool_resilvered $TESTPOOL ; then + $SLEEP 3 + break + fi +done + +log_must $ZPOOL scrub $TESTPOOL + +log_pass "Resilver prevent scrub from starting until the resilver completes" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh new file mode 100644 index 00000000000..667205d86ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_scrub_005_pos.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zpool_scrub_005_pos +# +# DESCRIPTION: +# When scrubbing, detach device should not break system. +# +# STRATEGY: +# 1. Setup filesys with data. +# 2. Detaching and attaching the device when scrubbing. +# 3. Try it twice, verify both of them work fine. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-16) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "When scrubbing, detach device should not break system." + +log_must $ZPOOL scrub $TESTPOOL +log_must $ZPOOL detach $TESTPOOL $DISK2 +log_must $ZPOOL attach $TESTPOOL $DISK1 $DISK2 + +while true ; do + if is_pool_resilvered $TESTPOOL ; then + $SLEEP 3 + break + fi +done + +log_must $ZPOOL scrub $TESTPOOL +log_must $ZPOOL detach $TESTPOOL $DISK1 +log_must $ZPOOL attach $TESTPOOL $DISK2 $DISK1 + +log_pass "When scrubbing, detach device should not break system." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_test.sh new file mode 100755 index 00000000000..4e0bbbd9cf2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_scrub/zpool_scrub_test.sh @@ -0,0 +1,157 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_scrub_001_neg cleanup +zpool_scrub_001_neg_head() +{ + atf_set "descr" "Execute 'zpool scrub' using invalid parameters." + atf_set "require.progs" zpool +} +zpool_scrub_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_scrub_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_scrub_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_scrub_002_pos cleanup +zpool_scrub_002_pos_head() +{ + atf_set "descr" "Verify scrub -s works correctly." + atf_set "require.progs" zpool +} +zpool_scrub_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_scrub_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_scrub_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_scrub_003_pos cleanup +zpool_scrub_003_pos_head() +{ + atf_set "descr" "scrub command terminates the existing scrub process and starts a new scrub." + atf_set "require.progs" zpool +} +zpool_scrub_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_scrub_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_scrub_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_scrub_004_pos cleanup +zpool_scrub_004_pos_head() +{ + atf_set "descr" "Resilver prevent scrub from starting until the resilver completes" + atf_set "require.progs" zpool +} +zpool_scrub_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_scrub_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_scrub_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_scrub_005_pos cleanup +zpool_scrub_005_pos_head() +{ + atf_set "descr" "When scrubbing, detach device should not break system." + atf_set "require.progs" zpool +} +zpool_scrub_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_scrub_005_pos.ksh || atf_fail "Testcase failed" +} +zpool_scrub_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_scrub.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_scrub_001_neg + atf_add_test_case zpool_scrub_002_pos + atf_add_test_case zpool_scrub_003_pos + atf_add_test_case zpool_scrub_004_pos + atf_add_test_case zpool_scrub_005_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_set/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/Makefile new file mode 100644 index 00000000000..22b601daddd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/Makefile @@ -0,0 +1,17 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_set +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_set_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_set_002_neg.ksh +${PACKAGE}FILES+= zpool_set_003_neg.ksh +${PACKAGE}FILES+= zpool_set_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_001_pos.ksh new file mode 100644 index 00000000000..894a2cef21d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_001_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_set_001_pos.ksh 1.3 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_set_001_pos +# +# DESCRIPTION: +# +# Zpool set usage message is displayed when called with no arguments +# +# STRATEGY: +# 1. Run zpool set +# 2. Check that exit status is set to 2 +# 3. Check usage message contains text "usage" +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zpool set usage message is displayed when called with no arguments" + +$ZPOOL upgrade -v 2>&1 | $GREP "bootfs pool property" > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "Pool properties not supported on this release." +fi + +$ZPOOL set > /dev/null 2>&1 +RET=$? +if [ $RET != 2 ] +then + log_fail "\"zpool set\" exit status $RET should be equal to 2." +fi + +OUTPUT=$($ZPOOL set 2>&1 | $GREP -i usage) +if [ $? != 0 ] +then + log_fail "Usage message for zpool set did not contain the word 'usage'." +fi + +log_pass "zpool set usage message is displayed when called with no arguments" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_002_neg.ksh new file mode 100644 index 00000000000..adde0464256 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_002_neg.ksh @@ -0,0 +1,144 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_set_002_neg.ksh 1.3 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_set_002_neg +# +# DESCRIPTION: +# +# Malformed zpool set commands are rejected +# +# STRATEGY: +# 1. Create an array of many different malformed zfs set arguments +# 2. Run zpool set for each arg checking each will exit with status code 1 +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-03-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +# note to self - need to make sure there isn't a pool called bootfs +# before running this test... +function cleanup { + destroy_pool bootfs + $RM $TMPDIR/zpool_set_002.${TESTCASE_ID}.dat +} + +$ZPOOL upgrade -v 2>&1 | $GREP "bootfs pool property" > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "Pool properties not supported on this release." +fi + + +log_assert "Malformed zpool set commands are rejected" + +if poolexists bootfs +then + log_unsupported "Unable to run test on a machine with a pool called \ + bootfs" +fi + +log_onexit cleanup + +# build up an array of bad arguments. +set -A arguments "rubbish " \ + "foo@bar= " \ + "@@@= +pool " \ + "zpool bootfs " \ + "bootfs " \ + "bootfs +" \ + "bootfs=bootfs/123 " \ + "bootfs=bootfs@val " \ + "Bootfs=bootfs " \ + "- " \ + "== " \ + "set " \ + "@@ " \ + "12345 " \ + "€にほんご " \ + "/ " \ + "bootfs=bootfs /" \ + "bootfs=a%d%s " + + +# here, we build up a large string. +# a word to the ksh-wary, ${#array[@]} gives you the +# total number of entries in an array, so array[${#array[@]}] +# will index the last entry+1, ksh arrays start at index 0. +COUNT=0 +while [ $COUNT -le 1025 ] +do + bigname="${bigname}o" + COUNT=$(( $COUNT + 1 )) +done + +# add an argument of maximum length property name +arguments[${#arguments[@]}]="$bigname=value" + +# add an argument of maximum length property value +arguments[${#arguments[@]}]="bootfs=$bigname" + +# Create a pool called bootfs (so-called, so as to trip any clashes between +# property name, and pool name) +# Also create a filesystem in this pool +VDEV=$TMPDIR/zpool_set_002.${TESTCASE_ID}.vdev +log_must create_vdevs $VDEV +log_must $ZPOOL create bootfs $VDEV +log_must $ZFS create bootfs/root + +typeset -i i=0; +while [ $i -lt "${#arguments[@]}" ] +do + log_mustnot eval "$ZPOOL set ${arguments[$i]} > /dev/null 2>&1" + + # now also try with a valid pool in the argument list + log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs > /dev/null 2>&1" + + # now also try with two valid pools in the argument list + log_mustnot eval "$ZPOOL set ${arguments[$i]}bootfs bootfs > /dev/null" + i=$(( $i + 1)) +done + +log_pass "Malformed zpool set commands are rejected" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_003_neg.ksh new file mode 100644 index 00000000000..69c5a597aa2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_003_neg.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_set_003_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_set_003_neg +# +# DESCRIPTION: +# +# zpool set cannot set a readonly property +# +# STRATEGY: +# 1. Create a pool +# 2. Verify that we can't set readonly properties on that pool +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL + $RM $TMPDIR/zpool_set_003.${TESTCASE_ID}.dat +} + +set -A props "available" "capacity" "guid" "health" "size" "used" +set -A vals "100" "10" "12345" "HEALTHY" "10" "10" + +$ZPOOL upgrade -v 2>&1 | $GREP "bootfs pool property" > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "Pool properties not supported on this release." +fi + + + +log_onexit cleanup + +log_assert "zpool set cannot set a readonly property" + +VDEV=$TMPDIR/zpool_set_003.${TESTCASE_ID}.vdev +log_must create_vdevs $VDEV +log_must $ZPOOL create $TESTPOOL $VDEV + +typeset -i i=0; +while [ $i -lt "${#props[@]}" ] +do + # try to set each property in the prop list with it's corresponding val + log_mustnot eval "$ZPOOL set ${props[$i]}=${vals[$i]} $TESTPOOL \ + > /dev/null 2>&1" + i=$(( $i + 1)) +done + +log_pass "zpool set cannot set a readonly property" + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_test.sh new file mode 100755 index 00000000000..348e27c1052 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_set/zpool_set_test.sh @@ -0,0 +1,77 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_set_001_pos +zpool_set_001_pos_head() +{ + atf_set "descr" "zpool set usage message is displayed when called with no arguments" + atf_set "require.progs" zpool +} +zpool_set_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + ksh93 $(atf_get_srcdir)/zpool_set_001_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case zpool_set_002_neg +zpool_set_002_neg_head() +{ + atf_set "descr" "Malformed zpool set commands are rejected" + atf_set "require.progs" zpool zfs +} +zpool_set_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + ksh93 $(atf_get_srcdir)/zpool_set_002_neg.ksh || atf_fail "Testcase failed" +} + + +atf_test_case zpool_set_003_neg +zpool_set_003_neg_head() +{ + atf_set "descr" "zpool set cannot set a readonly property" + atf_set "require.progs" zpool +} +zpool_set_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + ksh93 $(atf_get_srcdir)/zpool_set_003_neg.ksh || atf_fail "Testcase failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_set_001_pos + atf_add_test_case zpool_set_002_neg + atf_add_test_case zpool_set_003_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_status/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/Makefile new file mode 100644 index 00000000000..cd8d2328971 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_status +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_status_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_status.cfg +${PACKAGE}FILES+= zpool_status_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_status_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_status/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_status/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status.cfg new file mode 100644 index 00000000000..5fbd0429b05 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_status.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_001_pos.ksh new file mode 100644 index 00000000000..8db50bdf92c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_001_pos.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_status_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_status_001_pos +# +# DESCRIPTION: +# Executing 'zpool status' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool status' options +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A args "" "-?" "-x fakepool" "-v fakepool" "-xv fakepool" "-vx fakepool" \ + "-x $TESTPOOL/$TESTFS" "-v $TESTPOOL/$TESTFS" "-xv $TESTPOOL/$TESTFS" \ + "-vx $TESTPOOL/$TESTFS" + +log_assert "Executing 'zpool status' with bad options fails" + +typeset -i i=1 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL status ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool status' command with bad options failed as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_002_pos.ksh new file mode 100644 index 00000000000..a313f8af598 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_002_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_status_002_pos.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_status_002_pos +# +# DESCRIPTION: +# Executing 'zpool status' with correct options succeeds +# +# STRATEGY: +# 1. Create an array of correctly formed 'zpool status' options +# 2. Execute each element of the array. +# 3. Verify use of each option is successful. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset testpool +if is_global_zone; then + testpool=$TESTPOOL +else + testpool=${TESTPOOL%%/*} +fi + +set -A args "" "-x" "-v" "-x $testpool" "-v $testpool" "-xv $testpool" \ + "-vx $testpool" + +log_assert "Executing 'zpool status' with correct options succeeds" + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_must $ZPOOL status ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool status' with correct options succeeded" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_test.sh new file mode 100755 index 00000000000..df9a1377b99 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_status/zpool_status_test.sh @@ -0,0 +1,82 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_status_001_pos cleanup +zpool_status_001_pos_head() +{ + atf_set "descr" "Executing 'zpool status' with bad options fails" + atf_set "require.progs" zpool +} +zpool_status_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_status.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_status_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_status_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_status.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_status_002_pos cleanup +zpool_status_002_pos_head() +{ + atf_set "descr" "Executing 'zpool status' with correct options succeeds" + atf_set "require.progs" zpool +} +zpool_status_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_status.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_status_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_status_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_status.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_status_001_pos + atf_add_test_case zpool_status_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/Makefile new file mode 100644 index 00000000000..0b8cf24d147 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/Makefile @@ -0,0 +1,29 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_upgrade +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_upgrade_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_upgrade_003_pos.ksh +${PACKAGE}FILES+= zpool_upgrade_007_pos.ksh +${PACKAGE}FILES+= zpool_upgrade_006_neg.ksh +${PACKAGE}FILES+= zpool_upgrade_002_pos.ksh +${PACKAGE}FILES+= zpool_upgrade.cfg +${PACKAGE}FILES+= zpool_upgrade_004_pos.ksh +${PACKAGE}FILES+= zpool_upgrade_008_pos.ksh +${PACKAGE}FILES+= zpool_upgrade_005_neg.ksh +${PACKAGE}FILES+= zpool_upgrade_009_neg.ksh +${PACKAGE}FILES+= zpool_upgrade.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_upgrade_001_pos.ksh + +SUBDIR+= blockfiles + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/Makefile b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/Makefile new file mode 100644 index 00000000000..0d73edae1b9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/Makefile @@ -0,0 +1,65 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= README +${PACKAGE}FILES+= zfs-broken-mirror1.dat.Z +${PACKAGE}FILES+= zfs-broken-mirror2.dat.Z +${PACKAGE}FILES+= zfs-pool-v1.dat.Z +${PACKAGE}FILES+= zfs-pool-v10.dat.Z +${PACKAGE}FILES+= zfs-pool-v11.dat.Z +${PACKAGE}FILES+= zfs-pool-v12.dat.Z +${PACKAGE}FILES+= zfs-pool-v13.dat.Z +${PACKAGE}FILES+= zfs-pool-v14.dat.Z +${PACKAGE}FILES+= zfs-pool-v15.dat.Z +${PACKAGE}FILES+= zfs-pool-v1mirror1.dat.Z +${PACKAGE}FILES+= zfs-pool-v1mirror2.dat.Z +${PACKAGE}FILES+= zfs-pool-v1mirror3.dat.Z +${PACKAGE}FILES+= zfs-pool-v1raidz1.dat.Z +${PACKAGE}FILES+= zfs-pool-v1raidz2.dat.Z +${PACKAGE}FILES+= zfs-pool-v1raidz3.dat.Z +${PACKAGE}FILES+= zfs-pool-v1stripe1.dat.Z +${PACKAGE}FILES+= zfs-pool-v1stripe2.dat.Z +${PACKAGE}FILES+= zfs-pool-v1stripe3.dat.Z +${PACKAGE}FILES+= zfs-pool-v2.dat.Z +${PACKAGE}FILES+= zfs-pool-v28.dat.Z +${PACKAGE}FILES+= zfs-pool-v2mirror1.dat.Z +${PACKAGE}FILES+= zfs-pool-v2mirror2.dat.Z +${PACKAGE}FILES+= zfs-pool-v2mirror3.dat.Z +${PACKAGE}FILES+= zfs-pool-v2raidz1.dat.Z +${PACKAGE}FILES+= zfs-pool-v2raidz2.dat.Z +${PACKAGE}FILES+= zfs-pool-v2raidz3.dat.Z +${PACKAGE}FILES+= zfs-pool-v2stripe1.dat.Z +${PACKAGE}FILES+= zfs-pool-v2stripe2.dat.Z +${PACKAGE}FILES+= zfs-pool-v2stripe3.dat.Z +${PACKAGE}FILES+= zfs-pool-v3.dat.Z +${PACKAGE}FILES+= zfs-pool-v3hotspare1.dat.Z +${PACKAGE}FILES+= zfs-pool-v3hotspare2.dat.Z +${PACKAGE}FILES+= zfs-pool-v3hotspare3.dat.Z +${PACKAGE}FILES+= zfs-pool-v3mirror1.dat.Z +${PACKAGE}FILES+= zfs-pool-v3mirror2.dat.Z +${PACKAGE}FILES+= zfs-pool-v3mirror3.dat.Z +${PACKAGE}FILES+= zfs-pool-v3raidz1.dat.Z +${PACKAGE}FILES+= zfs-pool-v3raidz2.dat.Z +${PACKAGE}FILES+= zfs-pool-v3raidz21.dat.Z +${PACKAGE}FILES+= zfs-pool-v3raidz22.dat.Z +${PACKAGE}FILES+= zfs-pool-v3raidz23.dat.Z +${PACKAGE}FILES+= zfs-pool-v3raidz3.dat.Z +${PACKAGE}FILES+= zfs-pool-v3stripe1.dat.Z +${PACKAGE}FILES+= zfs-pool-v3stripe2.dat.Z +${PACKAGE}FILES+= zfs-pool-v3stripe3.dat.Z +${PACKAGE}FILES+= zfs-pool-v4.dat.Z +${PACKAGE}FILES+= zfs-pool-v5.dat.Z +${PACKAGE}FILES+= zfs-pool-v5000.dat.Z +${PACKAGE}FILES+= zfs-pool-v6.dat.Z +${PACKAGE}FILES+= zfs-pool-v7.dat.Z +${PACKAGE}FILES+= zfs-pool-v8.dat.Z +${PACKAGE}FILES+= zfs-pool-v9.dat.Z +${PACKAGE}FILES+= zfs-pool-v999.dat.Z +${PACKAGE}FILES+= zfs-pool-vBROKEN.dat.Z + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/README b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/README new file mode 100644 index 00000000000..741af2641ea --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/README @@ -0,0 +1,34 @@ +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)README 1.1 07/03/14 SMI" +# + +Unless otherwise noted, all files in this distribution are released +under the Common Development and Distribution License (CDDL). + +This directory contains compressed blockfiles for zpool upgrade testing. diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror1.dat.Z new file mode 100644 index 00000000000..8e0b7ea48aa Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror2.dat.Z new file mode 100644 index 00000000000..82eadecadc3 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-broken-mirror2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.Z new file mode 100644 index 00000000000..0b68f7edb52 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v10.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v10.dat.Z new file mode 100644 index 00000000000..b2723de64c2 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v10.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v11.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v11.dat.Z new file mode 100644 index 00000000000..67e928ad84e Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v11.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v12.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v12.dat.Z new file mode 100644 index 00000000000..6877889bdff Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v12.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v13.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v13.dat.Z new file mode 100644 index 00000000000..3f99a092f4b Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v13.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v14.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v14.dat.Z new file mode 100644 index 00000000000..964ebe70bd9 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v14.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v15.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v15.dat.Z new file mode 100644 index 00000000000..f8d01534da4 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v15.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror1.dat.Z new file mode 100644 index 00000000000..4ae51c47bbb Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror2.dat.Z new file mode 100644 index 00000000000..4f36f67c106 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror3.dat.Z new file mode 100644 index 00000000000..363628e86f8 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1mirror3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz1.dat.Z new file mode 100644 index 00000000000..6290398f49d Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz2.dat.Z new file mode 100644 index 00000000000..0b4ce2cc23d Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz3.dat.Z new file mode 100644 index 00000000000..9dbd653d0a4 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1raidz3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe1.dat.Z new file mode 100644 index 00000000000..60a161cab57 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe2.dat.Z new file mode 100644 index 00000000000..cc532872678 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe3.dat.Z new file mode 100644 index 00000000000..d34b27bb4dd Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v1stripe3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2.dat.Z new file mode 100644 index 00000000000..bb34970a3d7 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v28.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v28.dat.Z new file mode 100644 index 00000000000..ebdcbab1f14 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v28.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror1.dat.Z new file mode 100644 index 00000000000..a2b9263cbd3 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror2.dat.Z new file mode 100644 index 00000000000..42696960bb2 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror3.dat.Z new file mode 100644 index 00000000000..b8a8ba6e6ee Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2mirror3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz1.dat.Z new file mode 100644 index 00000000000..bff2ecd1089 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz2.dat.Z new file mode 100644 index 00000000000..a703a7ca749 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz3.dat.Z new file mode 100644 index 00000000000..0e0fa0be796 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2raidz3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe1.dat.Z new file mode 100644 index 00000000000..a06e279827f Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe2.dat.Z new file mode 100644 index 00000000000..ab9f4b4ca95 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe3.dat.Z new file mode 100644 index 00000000000..629bff8da0a Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v2stripe3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3.dat.Z new file mode 100644 index 00000000000..63a1882252f Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare1.dat.Z new file mode 100644 index 00000000000..cd1c13828f0 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare2.dat.Z new file mode 100644 index 00000000000..c4f7543e0af Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare3.dat.Z new file mode 100644 index 00000000000..bf2cc65f8f5 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3hotspare3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror1.dat.Z new file mode 100644 index 00000000000..0616fcc145c Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror2.dat.Z new file mode 100644 index 00000000000..ca21f8511d2 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror3.dat.Z new file mode 100644 index 00000000000..ba31451a538 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3mirror3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz1.dat.Z new file mode 100644 index 00000000000..2ac5260bab3 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz2.dat.Z new file mode 100644 index 00000000000..631658e2f16 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz21.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz21.dat.Z new file mode 100644 index 00000000000..5957973a940 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz21.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz22.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz22.dat.Z new file mode 100644 index 00000000000..77de3d686d6 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz22.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz23.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz23.dat.Z new file mode 100644 index 00000000000..9b956c0547f Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz23.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz3.dat.Z new file mode 100644 index 00000000000..9f7716e41c6 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3raidz3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe1.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe1.dat.Z new file mode 100644 index 00000000000..53e5a7ab73d Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe1.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe2.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe2.dat.Z new file mode 100644 index 00000000000..7c57b69587e Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe2.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe3.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe3.dat.Z new file mode 100644 index 00000000000..fb09ae7b2ad Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v3stripe3.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v4.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v4.dat.Z new file mode 100644 index 00000000000..8a90b5f006f Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v4.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5.dat.Z new file mode 100644 index 00000000000..8715d2cb53b Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5000.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5000.dat.Z new file mode 100644 index 00000000000..da4982db985 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v5000.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v6.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v6.dat.Z new file mode 100644 index 00000000000..a476c091a36 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v6.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v7.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v7.dat.Z new file mode 100644 index 00000000000..6d9f828e261 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v7.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v8.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v8.dat.Z new file mode 100644 index 00000000000..d983516e34e Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v8.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v9.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v9.dat.Z new file mode 100644 index 00000000000..943b11e87a8 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v9.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v999.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v999.dat.Z new file mode 100644 index 00000000000..c77c47b0fc6 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-v999.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-vBROKEN.dat.Z b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-vBROKEN.dat.Z new file mode 100644 index 00000000000..bc8d0c908a1 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/blockfiles/zfs-pool-vBROKEN.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/cleanup.ksh new file mode 100644 index 00000000000..ef9e02b83f3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/cleanup.ksh @@ -0,0 +1,55 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.4 07/07/31 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib + +function destroy_upgraded_pool { + for VERSION in $@ + do + POOL_FILES=$($ENV | $GREP "ZPOOL_VERSION_${VERSION}_FILES"\ + | $AWK -F= '{print $2}') + POOL_NAME=$($ENV | $GREP "ZPOOL_VERSION_${VERSION}_NAME"\ + | $AWK -F= '{print $2}') + poolexists $POOL_NAME + if [ $? == 0 ] + then + log_must $ZPOOL destroy -f $POOL_NAME + fi + + done +} + +for config in $CONFIGS +do + destroy_upgraded_pool $config +done diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/create_upgrade_pool_dat.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/create_upgrade_pool_dat.sh new file mode 100755 index 00000000000..ddb95a753cc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/create_upgrade_pool_dat.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +# $FreeBSD$ + +scriptpath=$(realpath $0) +parent=$(dirname $scriptpath) +blockfiles=${parent}/blockfiles + +version=$1 +if [ -z "$version" ]; then + echo "Must specify ZFS pool version" + exit 1 +fi + +# In case we need to test feature enabling? +#avail_features=$(zpool upgrade -v | awk '/^[a-z]/ && !/^see the/ { print $1 }') + +zpool_opts="" +# For v5000, the rest of the arguments are =. +if [ "$version" = "5000" ]; then + shift + for feature in $*; do + zpool_opts="$zpool_opts -o feature@${feature}" + done +else + zpool_opts="-o version=${version}" +fi + +dir=$(pwd) +datfile=zfs-pool-v${version}.dat +dat=${dir}/${datfile} +poolname=v${version}-pool + +rm -f ${dat} ${dat}.Z +set -e +set -x +dd if=/dev/zero of=${dat} bs=1M count=64 +zpool create ${zpool_opts} ${poolname} ${dat} +zpool export ${poolname} +compress ${dat} +cp ${dat}.Z ${blockfiles} +ls -l ${blockfiles}/${datfile}.Z diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/setup.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/setup.ksh new file mode 100644 index 00000000000..022542f2f5a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/setup.ksh @@ -0,0 +1,44 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.5 09/05/19 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +# This should have been set by the .cfg script - verify it's set to something +# (we check that something later on) +if [ -z "$ZPOOL_VERSION" ] +then + log_unresolved "Unable to determine ZFS Pool version of this machine" +else + log_note "This machine is running ZFS version $ZPOOL_VERSION" +fi diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade.cfg b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade.cfg new file mode 100644 index 00000000000..7fb54649217 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade.cfg @@ -0,0 +1,293 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade.cfg 1.7 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +. $STF_SUITE/include/libtest.kshlib + +export STF_TIMEOUT=1800 + +# We need to determine which version of ZFS we're running on, so as to +# work out which types of pool we should be able to upgrade on this +# system. +export ZPOOL_VERSION=$(get_zpool_version) + + +# The following variable names describe files, stored as gzip compressed files +# in the test directory which can be used to construct a pool of a given +# version. The variable names are important, in that the construction +# ZPOOL_VERSION_$var_FILES describes the files the pool is made from, and +# ZPOOL_VERSION_$var_NAME describes the pool name. + +# Version 1 pools +export ZPOOL_VERSION_1_FILES="zfs-pool-v1.dat" +export ZPOOL_VERSION_1_NAME="v1-pool" +# v1 stripe +export ZPOOL_VERSION_1stripe_FILES="zfs-pool-v1stripe1.dat \ +zfs-pool-v1stripe2.dat zfs-pool-v1stripe3.dat" +export ZPOOL_VERSION_1stripe_NAME="pool-v1stripe" +# v1 raidz +export ZPOOL_VERSION_1raidz_FILES="zfs-pool-v1raidz1.dat zfs-pool-v1raidz2.dat \ +zfs-pool-v1raidz3.dat" +export ZPOOL_VERSION_1raidz_NAME="pool-v1raidz" +# v1 mirror +export ZPOOL_VERSION_1mirror_FILES="zfs-pool-v1mirror1.dat \ +zfs-pool-v1mirror2.dat zfs-pool-v1mirror3.dat" +export ZPOOL_VERSION_1mirror_NAME="pool-v1mirror" + + +# Version 2 pools +export ZPOOL_VERSION_2_FILES="zfs-pool-v2.dat" +export ZPOOL_VERSION_2_NAME="v2-pool" +# v2 stripe +export ZPOOL_VERSION_2stripe_FILES="zfs-pool-v2stripe1.dat \ +zfs-pool-v2stripe2.dat zfs-pool-v2stripe3.dat" +export ZPOOL_VERSION_2stripe_NAME="pool-v2stripe" +# v2 raidz +export ZPOOL_VERSION_2raidz_FILES="zfs-pool-v2raidz1.dat zfs-pool-v2raidz2.dat \ +zfs-pool-v2raidz3.dat" +export ZPOOL_VERSION_2raidz_NAME="pool-v2raidz" +# v2 mirror +export ZPOOL_VERSION_2mirror_FILES="zfs-pool-v2mirror1.dat \ +zfs-pool-v2mirror2.dat zfs-pool-v2mirror3.dat" +export ZPOOL_VERSION_2mirror_NAME="pool-v2mirror" + + +# This is a v3 pool +export ZPOOL_VERSION_3_FILES="zfs-pool-v3.dat" +export ZPOOL_VERSION_3_NAME="v3-pool" +# v3 stripe +export ZPOOL_VERSION_3stripe_FILES="zfs-pool-v3stripe1.dat \ +zfs-pool-v3stripe2.dat zfs-pool-v3stripe3.dat" +export ZPOOL_VERSION_3stripe_NAME="pool-v3stripe" +# v3 raidz +export ZPOOL_VERSION_3raidz_FILES="zfs-pool-v3raidz1.dat zfs-pool-v3raidz2.dat \ +zfs-pool-v3raidz3.dat" +export ZPOOL_VERSION_3raidz_NAME="pool-v3raidz" +# v3 mirror +export ZPOOL_VERSION_3mirror_FILES="zfs-pool-v3mirror1.dat \ +zfs-pool-v3mirror2.dat zfs-pool-v3mirror3.dat" +export ZPOOL_VERSION_3mirror_NAME="pool-v3mirror" +# v3 raidz2 +export ZPOOL_VERSION_3dblraidz_FILES="zfs-pool-v3raidz21.dat \ +zfs-pool-v3raidz22.dat zfs-pool-v3raidz23.dat" +export ZPOOL_VERSION_3dblraidz_NAME="pool-v3raidz2" +# v3 hotspares +export ZPOOL_VERSION_3hotspare_FILES="zfs-pool-v3hotspare1.dat \ +zfs-pool-v3hotspare2.dat zfs-pool-v3hotspare3.dat" +export ZPOOL_VERSION_3hotspare_NAME="pool-v3hotspare" + +# v4 pool +export ZPOOL_VERSION_4_FILES="zfs-pool-v4.dat" +export ZPOOL_VERSION_4_NAME="v4-pool" + +# v5 pool +export ZPOOL_VERSION_5_FILES="zfs-pool-v5.dat" +export ZPOOL_VERSION_5_NAME="v5-pool" + +# v6 pool +export ZPOOL_VERSION_6_FILES="zfs-pool-v6.dat" +export ZPOOL_VERSION_6_NAME="v6-pool" + +# v7 pool +export ZPOOL_VERSION_7_FILES="zfs-pool-v7.dat" +export ZPOOL_VERSION_7_NAME="v7-pool" + +# v8 pool +export ZPOOL_VERSION_8_FILES="zfs-pool-v8.dat" +export ZPOOL_VERSION_8_NAME="v8-pool" + +# v9 pool +export ZPOOL_VERSION_9_FILES="zfs-pool-v9.dat" +export ZPOOL_VERSION_9_NAME="v9-pool" + +# v10 pool +export ZPOOL_VERSION_10_FILES="zfs-pool-v10.dat" +export ZPOOL_VERSION_10_NAME="v10-pool" + +# v11 pool +export ZPOOL_VERSION_11_FILES="zfs-pool-v11.dat" +export ZPOOL_VERSION_11_NAME="v11-pool" + +# v12 pool +export ZPOOL_VERSION_12_FILES="zfs-pool-v12.dat" +export ZPOOL_VERSION_12_NAME="v12-pool" + +# v13 pool +export ZPOOL_VERSION_13_FILES="zfs-pool-v13.dat" +export ZPOOL_VERSION_13_NAME="v13-pool" + +# v14 pool +export ZPOOL_VERSION_14_FILES="zfs-pool-v14.dat" +export ZPOOL_VERSION_14_NAME="v14-pool" + +# v15 pool +export ZPOOL_VERSION_15_FILES="zfs-pool-v15.dat" +export ZPOOL_VERSION_15_NAME="v15-pool" + +# v28 pool +export ZPOOL_VERSION_28_FILES="zfs-pool-v28.dat" +export ZPOOL_VERSION_28_NAME="v28-pool" + +# v5000 pool +export ZPOOL_VERSION_5000_FILES="zfs-pool-v5000.dat" +export ZPOOL_VERSION_5000_NAME="v5000-pool" + +# This pool is a v2 pool, with device problems on one side of the mirror +# so that the pool appears as DEGRADED +export ZPOOL_VERSION_2brokenmirror_FILES="zfs-broken-mirror1.dat \ +zfs-broken-mirror2.dat" +export ZPOOL_VERSION_2brokenmirror_NAME="zfs-broken-mirror" + + +# This pool is a v999 pool (an unknown version) which can be used to check +# whether upgrade, import or other tests that should fail against unknown +# pool versions should fail. It should not be listed in the CONFIGS +# variable below, as these are pool versions that can be imported and upgraded +export ZPOOL_VERSION_9999_FILES="zfs-pool-v999.dat" +export ZPOOL_VERSION_9999_NAME="v999-pool" + + +# This statement builds up a list of configurations we should be able to +# upgrade, for each pool version. Once we've built this variable, we'll +# call the functions above for each value. +case $ZPOOL_VERSION in +1) + # we should be able to upgrade pools of version 1 + CONFIGS="1 1stripe 1raidz 1mirror" + ;; + +2) + # we should be able to upgrade pools of version 1 & 2 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror" + ;; +3) + # we should be able to upgrade pools of version 1, 2 & 3 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare" + ;; +4) + # we should be able to upgrade pools of version 1, 2, 3 & 4 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4" + ;; +5) + # we should be able to upgrade pools up to version 5 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5" + ;; +6) + # we should be able to upgrade pools up to version 6 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6" + ;; +7) + # we should be able to upgrade pools up to version 7 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7" + ;; +8) + # we should be able to upgrade pools up to version 8 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8" + ;; +9) + # we should be able to upgrade pools up to version 9 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9" + ;; +10) + # we should be able to upgrade pools up to version 10 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10" + ;; +11) + # we should be able to upgrade pools up to version 11 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11" + ;; +12) + # we should be able to upgrade pools up to version 12 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12" + ;; +13) + # we should be able to upgrade pools up to version 13 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13" + ;; +14) + # we should be able to upgrade pools up to version 14 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14" + ;; +15) + # we should be able to upgrade pools up to version 15 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15" + ;; +28) + # we should be able to upgrade pools up to version 15 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15 28" + ;; +5000) + # we should be able to upgrade pools up to version 15 + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15 28 5000" + ;; +*) + # we should be able to upgrade pools up to version 15 + # but we should also log a note about the unknown pool version + CONFIGS="1 1stripe 1raidz 1mirror \ + 2 2stripe 2raidz 2mirror 2brokenmirror \ + 3 3stripe 3raidz 3mirror 3dblraidz 3hotspare 4 5 6 7 8 9 10 11 12 13 14 15" + + log_note "Unknown ZFS version $ZPOOL_VERSION encountered:\ + Test suite may need updating." + ;; +esac +export CONFIGS diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib new file mode 100644 index 00000000000..832a3b57b36 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib @@ -0,0 +1,162 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade.kshlib 1.5 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# This part of the test suite relies on variables being setup in the +# zpool_upgrade.cfg script. Those variables give us details about which +# files make up the pool, and what the pool name is. + + +# A function to import a pool from files we have stored in the test suite +# We import the pool, and create some random data in the pool. +# $1 a version number we can use to get information about the pool +function create_old_pool +{ + VERSION=$1 + POOL_FILES=$($ENV | grep "ZPOOL_VERSION_${VERSION}_FILES"\ + | $AWK -F= '{print $2}') + POOL_NAME=$($ENV|grep "ZPOOL_VERSION_${VERSION}_NAME"\ + | $AWK -F= '{print $2}') + + log_note "Creating $POOL_NAME from $POOL_FILES" + for pool_file in $POOL_FILES; do + $CP -f $STF_SUITE/tests/cli_root/zpool_upgrade/blockfiles/$pool_file.Z \ + $TMPDIR + $UNCOMPRESS $TMPDIR/$pool_file.Z + done + log_must $ZPOOL import -d $TMPDIR $POOL_NAME + + # Now put some random contents into the pool. + COUNT=0 + while [ "$COUNT" -lt 1024 ]; do + $DD if=/dev/urandom of=/$POOL_NAME/random.$COUNT \ + count=1 bs=1024 > /dev/null 2>&1 + COUNT=$(( $COUNT + 1 )) + done +} + + +# A function to check the contents of a pool, upgrade it to the current version +# and then verify that the data is consistent after upgrading. Note that we're +# not using "zpool status -x" to see if the pool is healthy, as it's possible +# to also upgrade faulted, or degraded pools. +# $1 a version number we can use to get information about the pool +function check_upgrade { + VERSION=$1 + POOL_NAME=$($ENV| $GREP "ZPOOL_VERSION_${VERSION}_NAME"\ + | $AWK -F= '{print $2}') + POOL_FILES=$($ENV | $GREP "ZPOOL_VERSION_${VERSION}_FILES"\ + | $AWK -F= '{print $2}') + + log_note "Checking if we can upgrade from ZFS version ${VERSION}." + PRE_UPGRADE_CHECKSUM=$(check_pool $POOL_NAME pre ) + log_must $ZPOOL upgrade $POOL_NAME > /dev/null + POST_UPGRADE_CHECKSUM=$(check_pool $POOL_NAME post ) + + log_note "Checking that there are no differences between checksum output" + log_must $DIFF $PRE_UPGRADE_CHECKSUM $POST_UPGRADE_CHECKSUM + $RM $PRE_UPGRADE_CHECKSUM $POST_UPGRADE_CHECKSUM +} + +# A function to destroy an upgraded pool, plus the files it was based on. +# $1 a version number we can use to get information about the pool +function destroy_upgraded_pool { + VERSION=$1 + POOL_NAME=$($ENV|grep "ZPOOL_VERSION_${VERSION}_NAME"\ + | $AWK -F= '{print $2}') + POOL_FILES=$($ENV | grep "ZPOOL_VERSION_${VERSION}_FILES"\ + | $AWK -F= '{print $2}') + if poolexists "$POOL_NAME"; then + log_must $ZPOOL destroy $POOL_NAME + fi + for file in $POOL_FILES; do + if [ -e "$TMPDIR/$file" ]; then + $RM $TMPDIR/$file + fi + done +} + +# This function does a basic sanity check on the pool by computing the +# checksums of all files in the pool, printing the name of the file containing +# the checksum results. +# $1 the name of the pool +# $2 a flag we can use to determine when this check is being performed +# (ie. pre or post pool-upgrade) +function check_pool { # pool state + POOL=$1 + STATE=$2 + $FIND /$POOL -type f -exec $CKSUM {} + > \ + $TMPDIR/pool-checksums.$POOL.$STATE + print $TMPDIR/pool-checksums.$POOL.$STATE +} + +# This function simply checks that a pool has a particular version number +# as reported by zdb and zpool upgrade -v +# $1 the name of the pool +# $2 the version of the pool we expect to see +function check_poolversion { # pool version + + POOL=$1 + VERSION=$2 + + # check version using zdb + ACTUAL=$(get_config $POOL version) + [ "$ACTUAL" != "$VERSION" ] && log_fail \ + "ERROR: $POOL not upgraded: wanted '$VERSION', got '$ACTUAL'" + + # check version using zpool upgrade + ACTUAL=$($ZPOOL upgrade | $GREP $POOL$ | \ + $AWK '{print $1}' | $SED -e 's/ //g') + [ "$ACTUAL" != "$VERSION" ] && + log_fail "$POOL reported version '$ACTUAL', expected '$VERSION'" +} + +# A simple function to get a random number between two bounds +# probably not the most efficient for large ranges, but it's okay. +# Note since we're using $RANDOM, 32767 is the largest number we +# can accept as the upper bound. +# $1 lower bound +# $2 upper bound +function random { # min max + + typeset MIN=$1 + typeset MAX=$2 + typeset RAND=0 + + while [ "$RAND" -lt "$MIN" ] + do + RAND=$(( $RANDOM % $MAX + 1)) + done + + print $RAND +} + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh new file mode 100644 index 00000000000..8f4082d2803 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_001_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_001_pos.ksh 1.3 08/02/27 SMI" +# +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_001_pos +# +# DESCRIPTION: +# Executing 'zpool upgrade -v' command succeeds, and also prints a description +# of at least the current ZFS version. +# +# STRATEGY: +# 1. Execute the command +# 2. Verify a 0 exit status +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Executing 'zpool upgrade -v' command succeeds." + +log_must $ZPOOL upgrade -v + +# we also check that the usage message contains at least a description +# of the current ZFS version. + +$ZPOOL upgrade -v > $TMPDIR/zpool-versions.${TESTCASE_ID} +COUNT=$( $WC -l $TMPDIR/zpool-versions.${TESTCASE_ID} | $AWK '{print $1}' ) +COUNT=$(( $COUNT - 1 )) +$TAIL -${COUNT} $TMPDIR/zpool-versions.${TESTCASE_ID} > $TMPDIR/zpool-versions-desc.${TESTCASE_ID} + +# +# Current output for 'zpool upgrade -v' has different indent space +# for single and double digit version number. For example, +# 9 refquota and refreservation properties +# 10 Cache devices +# +log_note "Checking to see we have a description for the current ZFS version." +if (( ZPOOL_VERSION < 10 )); then + log_must $GREP "$ZPOOL_VERSION " $TMPDIR/zpool-versions-desc.${TESTCASE_ID} +elif (( ZPOOL_VERSION >= 5000 )); then + log_must $GREP "The following features are supported" \ + $TMPDIR/zpool-versions-desc.${TESTCASE_ID} +else + log_must $GREP "$ZPOOL_VERSION " $TMPDIR/zpool-versions-desc.${TESTCASE_ID} +fi +$RM $TMPDIR/zpool-versions.${TESTCASE_ID} +$RM $TMPDIR/zpool-versions-desc.${TESTCASE_ID} + +log_pass "Executing 'zpool upgrade -v' command succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh new file mode 100644 index 00000000000..4adae292f11 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_002_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_002_pos.ksh 1.3 08/08/15 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_002_pos +# +# DESCRIPTION: +# import pools of all versions - zpool upgrade on each pools works +# +# STRATEGY: +# 1. Execute the command with several invalid options +# 2. Verify a 0 exit status for each +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_upgraded_pool $config +} + +log_assert "Import pools of all versions - zpool upgrade on each pools works" +log_onexit cleanup + +# $CONFIGS gets set in the .cfg script +for config in $CONFIGS +do + create_old_pool $config + check_upgrade $config + destroy_upgraded_pool $config +done + +log_pass "Import pools of all versions - zpool upgrade on each pools works" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh new file mode 100644 index 00000000000..0d6bff1ae0e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_003_pos.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_003_pos.ksh 1.3 08/08/15 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_003_pos +# +# DESCRIPTION: +# Upgrading a pool that has already been upgraded succeeds. +# +# STRATEGY: +# 1. Upgrade a pool, then try to upgrade it again +# 2. Verify a 0 exit status +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_upgraded_pool 1 +} + +log_assert "Upgrading a pool that has already been upgraded succeeds." +log_onexit cleanup + +# we just create a version 1 pool here +create_old_pool 1 +check_upgrade 1 +check_upgrade 1 +destroy_upgraded_pool 1 + +log_pass "Upgrading a pool that has already been upgraded succeeds." diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh new file mode 100644 index 00000000000..c12a031d487 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_004_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_004_pos.ksh 1.6 09/06/22 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_004_pos +# +# DESCRIPTION: +# zpool upgrade -a works +# +# STRATEGY: +# 1. Create all upgradable pools for this system, then upgrade -a +# 2. Verify a 0 exit status +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + for config in $CONFIGS ; do + destroy_upgraded_pool $config + done +} + +log_assert "zpool upgrade -a works" + +log_onexit cleanup + +# Now build all of our pools +for config in $CONFIGS +do + POOL_NAME=$($ENV | $GREP "ZPOOL_VERSION_${config}_NAME"\ + | $AWK -F= '{print $2}') + + create_old_pool $config + # a side effect of the check_pool here, is that we get a checksum written + # called $TMPDIR/pool-checksums.$POOL.pre + check_pool $POOL_NAME pre > /dev/null +done + +# upgrade them all at once +log_must $ZPOOL upgrade -a > /dev/null + +# verify their contents then destroy them +for config in $CONFIGS +do + POOL_NAME=$($ENV | $GREP "ZPOOL_VERSION_${config}_NAME"\ + | $AWK -F= '{print $2}') + + check_pool $POOL_NAME post > /dev/null + + # a side effect of the check_pool here, is that we get a checksum written + # called $TMPDIR/pool-checksums.$POOL_NAME.post + log_must $DIFF $TMPDIR/pool-checksums.$POOL_NAME.pre \ + $TMPDIR/pool-checksums.$POOL_NAME.post + + $RM $TMPDIR/pool-checksums.$POOL_NAME.pre $TMPDIR/pool-checksums.$POOL_NAME.post + destroy_upgraded_pool $config +done + +log_pass "zpool upgrade -a works" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh new file mode 100644 index 00000000000..87d59262064 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_005_neg.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_005_neg.ksh 1.3 07/10/09 SMI" +# +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_005_neg +# +# DESCRIPTION: +# Variations of upgrade -v print usage message, return with non-zero status +# +# STRATEGY: +# 1. Execute the command with several invalid options +# 2. Verify a 0 exit status for each +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A args "/tmp" "-?" "-va" "-v fakepool" "-a fakepool" + +log_assert "Variations of upgrade -v print usage message, \ + return with non-zero status" + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL upgrade ${args[$i]} > /dev/null + + (( i = i + 1 )) +done + +log_pass "Variations of upgrade -v print usage message, \ + return with non-zero status" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh new file mode 100644 index 00000000000..997dec8b601 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_006_neg.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_006_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_006_neg +# +# DESCRIPTION: +# Attempting to upgrade a non-existent pool will return an error +# +# STRATEGY: +# 1. Verify a pool doesn't exist, then try to upgrade it +# 2. Verify a 0 exit status +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "Attempting to upgrade a non-existent pool will return an error" +NO_POOL=notapool +FOUND="" + +while [ -z "$FOUND" ] +do + $ZPOOL list $NO_POOL 2>&1 > /dev/null + if [ $? -ne 0 ] + then + FOUND="true" + log_mustnot $ZPOOL upgrade $NO_POOL + else + NO_POOL="${NO_POOL}x" + fi +done + +log_pass "Attempting to upgrade a non-existent pool will return an error" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh new file mode 100644 index 00000000000..e675249b8d7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_007_pos.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_007_pos.ksh 1.3 08/08/15 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib +. $STF_SUITE/tests/cli_root/zfs_upgrade/zfs_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_007_pos +# +# DESCRIPTION: +# import pools of all versions - verify the following operation not break. +# * zfs create -o version= +# * zfs upgrade [-V vers] +# * zfs set version= +# +# STRATEGY: +# 1. Import pools of all versions +# 2. Setup a test enviorment over the old pools. +# 3. Verify the commands related to 'zfs upgrade' succeed as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-28) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +if ! fs_prop_exist "version" ; then + log_unsupported "version is not supported by this release." +fi + +function cleanup +{ + destroy_upgraded_pool $config +} + +log_assert "Import pools of all versions - 'zfs upgrade' on each pools works" +log_onexit cleanup + +# $CONFIGS gets set in the .cfg script +for config in $CONFIGS +do + create_old_pool $config + pool=$($ENV| $GREP "ZPOOL_VERSION_${config}_NAME" \ + | $AWK -F= '{print $2}') + + default_check_zfs_upgrade $pool + destroy_upgraded_pool $config +done + +log_pass "Import pools of all versions - 'zfs upgrade' on each pools works" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh new file mode 100644 index 00000000000..4bf78752165 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_008_pos.ksh @@ -0,0 +1,99 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_008_pos.ksh 1.5 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_008_pos +# +# DESCRIPTION: +# +# Zpool upgrade should be able to upgrade pools to a given version using -V +# +# STRATEGY: +# 1. For all versions pools that can be upgraded on a given OS version +# (latest pool version - 1) +# 2. Pick a version that's a random number, greater than the version +# we're running. +# 3. Attempt to upgrade that pool to the given version +# 4. Check the pool was upgraded correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-09-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_upgraded_pool $config +} + +log_assert \ + "Zpool upgrade should be able to upgrade pools to a given version using -V" + +$ZPOOL upgrade --help 2>&1 | $GREP "V version" > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "Zpool upgrade -V not supported on this release." +fi +log_onexit cleanup + +# We're just using the single disk version of the pool, which should be +# enough to determine if upgrade works correctly. Also set a MAX_VER +# variable, which specifies the highest version that we should expect +# a zpool upgrade operation to succeed from. (latest version - 1) +CONFIGS="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 28" +MAX_VER=28 + +for config in $CONFIGS +do + create_old_pool $config + pool=$($ENV| $GREP "ZPOOL_VERSION_${config}_NAME" \ + | $AWK -F= '{print $2}') + NEXT=$(random $config $MAX_VER) + log_must $ZPOOL upgrade -V $NEXT $pool + check_poolversion $pool $NEXT + destroy_upgraded_pool $config +done + +log_pass \ + "Zpool upgrade should be able to upgrade pools to a given version using -V" diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh new file mode 100644 index 00000000000..c2e04ed1bee --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_009_neg.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_009_neg.ksh 1.4 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_upgrade/zpool_upgrade.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_009_neg +# +# DESCRIPTION: +# +# Zpool upgrade -V shouldn't be able to upgrade a pool to an unknown version +# +# STRATEGY: +# 1. Take an existing pool +# 2. Attempt to upgrade it to an unknown version +# 3. Verify that the upgrade failed, and the pool version was still the original +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-09-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_upgraded_pool $config +} + +log_assert \ +"Zpool upgrade -V shouldn't be able to upgrade a pool to an unknown version" + +$ZPOOL upgrade --help 2>&1 | $GREP "V version" > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "Zpool upgrade -V not supported on this release." +fi +log_onexit cleanup + +# Create a version 2 pool +typeset -i config=2 +create_old_pool $config +pool=$($ENV| $GREP "ZPOOL_VERSION_${config}_NAME" | $AWK -F= '{print $2}') + +# Attempt to upgrade it +log_mustnot $ZPOOL upgrade -V 999 $pool +log_mustnot $ZPOOL upgrade -V 999 + +# Verify we're still on the old version +check_poolversion $pool $config +destroy_upgraded_pool $config + +log_pass \ + "Zpool upgrade -V shouldn't be able to upgrade a pool to an unknown version" + diff --git a/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_test.sh b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_test.sh new file mode 100755 index 00000000000..3eed23ffc99 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_root/zpool_upgrade/zpool_upgrade_test.sh @@ -0,0 +1,290 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_upgrade_001_pos cleanup +zpool_upgrade_001_pos_head() +{ + atf_set "descr" "Executing 'zpool upgrade -v' command succeeds." + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_002_pos cleanup +zpool_upgrade_002_pos_head() +{ + atf_set "descr" "Import pools of all versions - zpool upgrade on each pools works" + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_003_pos cleanup +zpool_upgrade_003_pos_head() +{ + atf_set "descr" "Upgrading a pool that has already been upgraded succeeds." + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_003_pos.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_004_pos cleanup +zpool_upgrade_004_pos_head() +{ + atf_set "descr" "zpool upgrade -a works" + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_005_neg cleanup +zpool_upgrade_005_neg_head() +{ + atf_set "descr" "Variations of upgrade -v print usage message,return with non-zero status" + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_005_neg.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_006_neg cleanup +zpool_upgrade_006_neg_head() +{ + atf_set "descr" "Attempting to upgrade a non-existent pool will return an error" + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_006_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_006_neg.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_007_pos cleanup +zpool_upgrade_007_pos_head() +{ + atf_set "descr" "Import pools of all versions - 'zfs upgrade' on each pools works" + atf_set "require.progs" zpool + # This test can take quite a while, especially on debug builds + atf_set "timeout" 7200 +} +zpool_upgrade_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + atf_skip "PR 225877 - panic: solaris assert: newds == os->os_dsl_dataset during" + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_007_pos.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_008_pos cleanup +zpool_upgrade_008_pos_head() +{ + atf_set "descr" "Zpool upgrade should be able to upgrade pools to a given version using -V" + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_008_pos.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_009_neg cleanup +zpool_upgrade_009_neg_head() +{ + atf_set "descr" "Zpool upgrade -V shouldn't be able to upgrade a pool to an unknown version" + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +zpool_upgrade_009_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_009_neg.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_upgrade.kshlib + . $(atf_get_srcdir)/zpool_upgrade.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_upgrade_001_pos + atf_add_test_case zpool_upgrade_002_pos + atf_add_test_case zpool_upgrade_003_pos + atf_add_test_case zpool_upgrade_004_pos + atf_add_test_case zpool_upgrade_005_neg + atf_add_test_case zpool_upgrade_006_neg + atf_add_test_case zpool_upgrade_007_pos + atf_add_test_case zpool_upgrade_008_pos + atf_add_test_case zpool_upgrade_009_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_user/Makefile b/tests/sys/cddl/zfs/tests/cli_user/Makefile new file mode 100644 index 00000000000..e992479ff20 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_user +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= cli.cfg +${PACKAGE}FILES+= cli_user.kshlib + +TESTS_SUBDIRS+= zpool_iostat +TESTS_SUBDIRS+= zpool_list +TESTS_SUBDIRS+= zfs_list +TESTS_SUBDIRS+= misc + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_user/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_user/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_user/cli.cfg b/tests/sys/cddl/zfs/tests/cli_user/cli.cfg new file mode 100644 index 00000000000..f1767ce27e8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/cli.cfg @@ -0,0 +1,36 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cli.cfg 1.3 08/08/15 SMI" +# + +export TESTSNAP=testsnap${TESTCASE_ID} +export TESTCLCT=testclct${TESTCASE_ID} +export TESTFILE0=testfile0.${TESTCASE_ID} +export TESTFILE1=testfile1.${TESTCASE_ID} +export UNPRIVILEGED_USER=`atf_config_get unprivileged_user` diff --git a/tests/sys/cddl/zfs/tests/cli_user/cli_user.kshlib b/tests/sys/cddl/zfs/tests/cli_user/cli_user.kshlib new file mode 100644 index 00000000000..7d85db1e8db --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/cli_user.kshlib @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. + +. $STF_SUITE/include/libtest.kshlib + +# Executes $@ without root privileges +function run_unprivileged +{ + echo "$@" | su -m "$UNPRIVILEGED_USER" +} diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/Makefile b/tests/sys/cddl/zfs/tests/cli_user/misc/Makefile new file mode 100644 index 00000000000..afed3c66b6f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/Makefile @@ -0,0 +1,59 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_user/misc +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= misc_test +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_rename_001_neg.ksh +${PACKAGE}FILES+= zpool_remove_001_neg.ksh +${PACKAGE}FILES+= zfs_destroy_001_neg.ksh +${PACKAGE}FILES+= zpool_import_001_neg.ksh +${PACKAGE}FILES+= zfs_unshare_001_neg.ksh +${PACKAGE}FILES+= zpool_export_001_neg.ksh +${PACKAGE}FILES+= zfs_set_001_neg.ksh +${PACKAGE}FILES+= zpool_upgrade_001_neg.ksh +${PACKAGE}FILES+= zpool_replace_001_neg.ksh +${PACKAGE}FILES+= misc.cfg +${PACKAGE}FILES+= zfs_receive_001_neg.ksh +${PACKAGE}FILES+= zpool_online_001_neg.ksh +${PACKAGE}FILES+= zpool_history_001_neg.ksh +${PACKAGE}FILES+= zpool_create_001_neg.ksh +${PACKAGE}FILES+= zpool_create_002_pos.ksh +${PACKAGE}FILES+= zfs_promote_001_neg.ksh +${PACKAGE}FILES+= zfs_get_001_neg.ksh +${PACKAGE}FILES+= zfs_share_001_neg.ksh +${PACKAGE}FILES+= zfs_rollback_001_neg.ksh +${PACKAGE}FILES+= zfs_unallow_001_neg.ksh +${PACKAGE}FILES+= zfs_send_001_neg.ksh +${PACKAGE}FILES+= zpool_clear_001_neg.ksh +${PACKAGE}FILES+= zpool_add_001_neg.ksh +${PACKAGE}FILES+= zpool_add_002_pos.ksh +${PACKAGE}FILES+= zpool_import_002_neg.ksh +${PACKAGE}FILES+= zpool_set_001_neg.ksh +${PACKAGE}FILES+= zfs_inherit_001_neg.ksh +${PACKAGE}FILES+= zfs_unmount_001_neg.ksh +${PACKAGE}FILES+= zpool_destroy_001_neg.ksh +${PACKAGE}FILES+= zpool_detach_001_neg.ksh +${PACKAGE}FILES+= zfs_create_001_neg.ksh +${PACKAGE}FILES+= zpool_attach_001_neg.ksh +${PACKAGE}FILES+= zpool_001_neg.ksh +${PACKAGE}FILES+= zdb_001_neg.ksh +${PACKAGE}FILES+= zfs_001_neg.ksh +${PACKAGE}FILES+= zfs_upgrade_001_neg.ksh +${PACKAGE}FILES+= zpool_scrub_001_neg.ksh +${PACKAGE}FILES+= zfs_mount_001_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_get_001_neg.ksh +${PACKAGE}FILES+= zfs_allow_001_neg.ksh +${PACKAGE}FILES+= zpool_offline_001_neg.ksh +${PACKAGE}FILES+= zfs_clone_001_neg.ksh +${PACKAGE}FILES+= zpool_status_001_neg.ksh +${PACKAGE}FILES+= zfs_snapshot_001_neg.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/cleanup.ksh new file mode 100644 index 00000000000..99608537328 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/cleanup.ksh @@ -0,0 +1,42 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +destroy_pool $TESTPOOL.virt +destroy_pool v1-pool + +if [[ -f $TMPDIR/zfstest_datastream.dat ]] +then + log_must $RM -f $TMPDIR/zfstest_datastream.dat +fi + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/misc.cfg b/tests/sys/cddl/zfs/tests/cli_user/misc/misc.cfg new file mode 100644 index 00000000000..1abeceab490 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/misc.cfg @@ -0,0 +1,72 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)misc.cfg 1.1 07/10/09 SMI" +# + +. $STF_SUITE/tests/cli_user/cli.cfg + + +# these are the set of setable ZFS properties +PROP_NAMES="\ + aclinherit aclmode atime \ + checksum compression devices \ + exec mountpoint quota readonly \ + recordsize reservation setuid shareiscsi \ + sharenfs snapdir " + +# these are a set of values we apply, for use when testing the +# zfs get/set subcommands - ordered as per the list above so we +# can iterate over both sets in an array +PROP_VALS="\ + secure discard on \ + fletcher2 on on \ + on legacy none on \ + 128k none on on \ + on visible " + +# these are an alternate set of property values +PROP_ALTVALS="\ + noallow groupmask off \ + fletcher4 lzjb off \ + off $TMPDIR/zfstest 100m off \ + 512 10m off off \ + off hidden " + + + +# additional properties to worry about: canmount copies xattr zoned version + +POOL_PROPS="\ + bootfs autoreplace" + +POOL_VALS="\ + $TESTPOOL/$TESTFS on" + +POOL_ALTVALS="\ + $TESTPOOL/$TESTFS/$TESTFS2 off" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/misc_test.sh b/tests/sys/cddl/zfs/tests/cli_user/misc/misc_test.sh new file mode 100755 index 00000000000..5b65ea2cfa1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/misc_test.sh @@ -0,0 +1,1174 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zdb_001_neg cleanup +zdb_001_neg_head() +{ + atf_set "descr" "zdb can't run as a user on datasets, but can run without arguments" + atf_set "require.progs" zfs fgrep zpool zdb + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zdb_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zdb_001_neg.ksh || atf_fail "Testcase failed" +} +zdb_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_001_neg cleanup +zfs_001_neg_head() +{ + atf_set "descr" "zfs shows a usage message when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_001_neg cleanup +zfs_allow_001_neg_head() +{ + atf_set "descr" "zfs allow returns an error when run as a user" + atf_set "require.progs" zfs fgrep logname zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_allow_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_allow_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_clone_001_neg cleanup +zfs_clone_001_neg_head() +{ + atf_set "descr" "zfs clone returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_clone_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_clone_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_clone_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_create_001_neg cleanup +zfs_create_001_neg_head() +{ + atf_set "descr" "Verify zfs create without parameters fails." + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_create_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_create_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_create_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_destroy_001_neg cleanup +zfs_destroy_001_neg_head() +{ + atf_set "descr" "zfs destroy [-f|-r] [fs|snap]" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_destroy_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_destroy_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_destroy_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_get_001_neg cleanup +zfs_get_001_neg_head() +{ + atf_set "descr" "zfs get works when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_get_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_get_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_get_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_inherit_001_neg cleanup +zfs_inherit_001_neg_head() +{ + atf_set "descr" "zfs inherit returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_inherit_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_inherit_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_inherit_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_mount_001_neg cleanup +zfs_mount_001_neg_head() +{ + atf_set "descr" "zfs mount returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_mount_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_mount_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_mount_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_promote_001_neg cleanup +zfs_promote_001_neg_head() +{ + atf_set "descr" "zfs promote returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_promote_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_promote_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_promote_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_receive_001_neg cleanup +zfs_receive_001_neg_head() +{ + atf_set "descr" "zfs receive returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_receive_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_receive_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_receive_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rename_001_neg cleanup +zfs_rename_001_neg_head() +{ + atf_set "descr" "zfs rename returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_rename_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rename_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_rename_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_rollback_001_neg cleanup +zfs_rollback_001_neg_head() +{ + atf_set "descr" "zfs rollback returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_rollback_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_rollback_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_rollback_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_send_001_neg cleanup +zfs_send_001_neg_head() +{ + atf_set "descr" "zfs send returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_send_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_send_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_send_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_set_001_neg cleanup +zfs_set_001_neg_head() +{ + atf_set "descr" "zfs set returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_set_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_set_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_set_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_share_001_neg cleanup +zfs_share_001_neg_head() +{ + atf_set "descr" "zfs share returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_share_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_share_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_share_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_snapshot_001_neg cleanup +zfs_snapshot_001_neg_head() +{ + atf_set "descr" "zfs snapshot returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_snapshot_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_snapshot_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_snapshot_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_001_neg cleanup +zfs_unallow_001_neg_head() +{ + atf_set "descr" "zfs unallow returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_unallow_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_unallow_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unmount_001_neg cleanup +zfs_unmount_001_neg_head() +{ + atf_set "descr" "zfs u[n]mount [-f] [mountpoint|fs|snap]" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_unmount_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unmount_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_unmount_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unshare_001_neg cleanup +zfs_unshare_001_neg_head() +{ + atf_set "descr" "zfs unshare returns an error when run as a user" + atf_set "require.progs" zfs fgrep share zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_unshare_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unshare_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_unshare_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_upgrade_001_neg cleanup +zfs_upgrade_001_neg_head() +{ + atf_set "descr" "zfs upgrade returns an error when run as a user" + atf_set "require.progs" zfs fgrep zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zfs_upgrade_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_upgrade_001_neg.ksh || atf_fail "Testcase failed" +} +zfs_upgrade_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_001_neg cleanup +zpool_001_neg_head() +{ + atf_set "descr" "zpool shows a usage message when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_001_neg cleanup +zpool_add_001_neg_head() +{ + atf_set "descr" "zpool add [-fn] pool_name vdev" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_add_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_add_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_add_002_pos cleanup +zpool_add_002_pos_head() +{ + atf_set "descr" "zpool add [-f] -n succeeds for unpriveleged users" + atf_set "require.progs" zfs zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_add_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_add_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_add_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_attach_001_neg cleanup +zpool_attach_001_neg_head() +{ + atf_set "descr" "zpool attach returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_attach_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_attach_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_attach_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_clear_001_neg cleanup +zpool_clear_001_neg_head() +{ + atf_set "descr" "zpool clear returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_clear_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_clear_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_clear_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_create_001_neg +zpool_create_001_neg_head() +{ + atf_set "descr" "zpool create [-f] fails for unpriveleged users" + atf_set "require.progs" zfs zpool + atf_set "require.user" unprivileged +} +zpool_create_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/zpool_create_001_neg.ksh || atf_fail "Testcase failed" +} + + +atf_test_case zpool_create_002_pos +zpool_create_002_pos_head() +{ + atf_set "descr" "zpool create [-f] -n succeeds for unpriveleged users" + atf_set "require.progs" zfs zpool + atf_set "require.user" unprivileged +} +zpool_create_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/zpool_create_002_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case zpool_destroy_001_neg cleanup +zpool_destroy_001_neg_head() +{ + atf_set "descr" "zpool destroy [-f] [pool_name ...]" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_destroy_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_destroy_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_destroy_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_detach_001_neg cleanup +zpool_detach_001_neg_head() +{ + atf_set "descr" "zpool detach returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_detach_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_detach_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_detach_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_export_001_neg cleanup +zpool_export_001_neg_head() +{ + atf_set "descr" "zpool export returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_export_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_export_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_export_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_get_001_neg cleanup +zpool_get_001_neg_head() +{ + atf_set "descr" "zpool get works when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_get_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_get_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_get_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_history_001_neg cleanup +zpool_history_001_neg_head() +{ + atf_set "descr" "zpool history returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_history_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_history_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_history_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_001_neg cleanup +zpool_import_001_neg_head() +{ + atf_set "descr" "zpool import returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_import_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_import_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_import_002_neg cleanup +zpool_import_002_neg_head() +{ + atf_set "descr" "Executing 'zpool import' by regular user fails" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_import_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_import_002_neg.ksh || atf_fail "Testcase failed" +} +zpool_import_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_offline_001_neg cleanup +zpool_offline_001_neg_head() +{ + atf_set "descr" "zpool offline returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_offline_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_offline_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_offline_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_online_001_neg cleanup +zpool_online_001_neg_head() +{ + atf_set "descr" "zpool online returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_online_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_online_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_online_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_remove_001_neg cleanup +zpool_remove_001_neg_head() +{ + atf_set "descr" "zpool remove returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_remove_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_remove_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_remove_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_replace_001_neg cleanup +zpool_replace_001_neg_head() +{ + atf_set "descr" "zpool replace returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_replace_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_replace_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_replace_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_scrub_001_neg cleanup +zpool_scrub_001_neg_head() +{ + atf_set "descr" "zpool scrub returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_scrub_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_scrub_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_scrub_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_set_001_neg cleanup +zpool_set_001_neg_head() +{ + atf_set "descr" "zpool set returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_set_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_set_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_set_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_status_001_neg cleanup +zpool_status_001_neg_head() +{ + atf_set "descr" "zpool status works when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_status_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_status_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_status_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_upgrade_001_neg cleanup +zpool_upgrade_001_neg_head() +{ + atf_set "descr" "zpool upgrade returns an error when run as a user" + atf_set "require.progs" zfs zpool fgrep + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_upgrade_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_upgrade_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_upgrade_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zdb_001_neg + atf_add_test_case zfs_001_neg + atf_add_test_case zfs_allow_001_neg + atf_add_test_case zfs_clone_001_neg + atf_add_test_case zfs_create_001_neg + atf_add_test_case zfs_destroy_001_neg + atf_add_test_case zfs_get_001_neg + atf_add_test_case zfs_inherit_001_neg + atf_add_test_case zfs_mount_001_neg + atf_add_test_case zfs_promote_001_neg + atf_add_test_case zfs_receive_001_neg + atf_add_test_case zfs_rename_001_neg + atf_add_test_case zfs_rollback_001_neg + atf_add_test_case zfs_send_001_neg + atf_add_test_case zfs_set_001_neg + atf_add_test_case zfs_share_001_neg + atf_add_test_case zfs_snapshot_001_neg + atf_add_test_case zfs_unallow_001_neg + atf_add_test_case zfs_unmount_001_neg + atf_add_test_case zfs_unshare_001_neg + atf_add_test_case zfs_upgrade_001_neg + atf_add_test_case zpool_001_neg + atf_add_test_case zpool_add_001_neg + atf_add_test_case zpool_add_002_pos + atf_add_test_case zpool_attach_001_neg + atf_add_test_case zpool_clear_001_neg + atf_add_test_case zpool_create_001_neg + atf_add_test_case zpool_create_002_pos + atf_add_test_case zpool_destroy_001_neg + atf_add_test_case zpool_detach_001_neg + atf_add_test_case zpool_export_001_neg + atf_add_test_case zpool_get_001_neg + atf_add_test_case zpool_history_001_neg + atf_add_test_case zpool_import_001_neg + atf_add_test_case zpool_import_002_neg + atf_add_test_case zpool_offline_001_neg + atf_add_test_case zpool_online_001_neg + atf_add_test_case zpool_remove_001_neg + atf_add_test_case zpool_replace_001_neg + atf_add_test_case zpool_scrub_001_neg + atf_add_test_case zpool_set_001_neg + atf_add_test_case zpool_status_001_neg + atf_add_test_case zpool_upgrade_001_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/setup.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/setup.ksh new file mode 100644 index 00000000000..a9c02febadd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/setup.ksh @@ -0,0 +1,173 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# This setup script is moderately complex, as it creates scenarios for all +# of the tests included in this directory. Usually we'd want each test case +# to setup/teardown it's own configuration, but this would be time consuming +# given the nature of these tests. However, as a side-effect, one test +# leaving the system in an unknown state could impact other test cases. + + +DISK=${DISKS%% *} +VOLSIZE=150m +TESTVOL=testvol + +# Create a default setup that includes a volume +default_setup_noexit "$DISK" "" "volume" + +# +# The rest of this setup script creates a ZFS filesystem configuration +# that is used to test the rest of the zfs subcommands in this directory. +# + +# create a snapshot and a clone to test clone promote +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap +log_must $ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS/clone +# create a file in the filesystem that isn't in the above snapshot +$TOUCH /$TESTDIR/file.txt + + +# create a non-default property and a child we can use to test inherit +log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2 +log_must $ZFS set snapdir=hidden $TESTPOOL/$TESTFS + + +# create an unmounted filesystem to test unmount +log_must $ZFS create $TESTPOOL/$TESTFS/$TESTFS2.unmounted +log_must $ZFS unmount $TESTPOOL/$TESTFS/$TESTFS2.unmounted + + +# send our snapshot to a known file in $TMPDIR +$ZFS send $TESTPOOL/$TESTFS@snap > $TMPDIR/zfstest_datastream.dat +if [ ! -s $TMPDIR/zfstest_datastream.dat ] +then + log_fail "Zfs send datafile was not created!" +fi +log_must $CHMOD 644 $TMPDIR/zfstest_datastream.dat + + +# create a filesystem that has particular properties to test set/get +log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/prop +set -A props $PROP_NAMES +set -A prop_vals $PROP_VALS +typeset -i i=0 + +while [[ $i -lt ${#props[*]} ]] +do + prop_name=${props[$i]} + prop_val=${prop_vals[$i]} + log_must $ZFS set $prop_name=$prop_val $TESTPOOL/$TESTFS/prop + i=$(( $i + 1 )) +done + + +# create a filesystem we don't mind renaming +log_must $ZFS create $TESTPOOL/$TESTFS/renameme + + +if is_global_zone +then + # create a filesystem we can share + log_must $ZFS create $TESTPOOL/$TESTFS/unshared + log_must $ZFS set sharenfs=off $TESTPOOL/$TESTFS/unshared + + # create a filesystem that we can unshare + log_must $ZFS create $TESTPOOL/$TESTFS/shared + log_must $ZFS set sharenfs=on $TESTPOOL/$TESTFS/shared +fi + + +# check for upgrade support +$ZFS upgrade > /dev/null 2>&1 +HAS_UPGRADE=$? + +if [ $HAS_UPGRADE -eq 0 ] +then + log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/version1 +fi + +$ZFS 2>&1 | $GREP "allow" > /dev/null +if (( $? == 0 )); then + log_must $ZFS create -o version=1 $TESTPOOL/$TESTFS/allowed + log_must $ZFS allow everyone create $TESTPOOL/$TESTFS/allowed +fi + +if is_global_zone; then + # Now create several virtual disks to test zpool with + log_must create_vdevs \ + /$TESTDIR/disk1.dat \ + /$TESTDIR/disk2.dat \ + /$TESTDIR/disk3.dat \ + /$TESTDIR/disk-additional.dat \ + /$TESTDIR/disk-export.dat \ + /$TESTDIR/disk-offline.dat \ + /$TESTDIR/disk-spare1.dat \ + /$TESTDIR/disk-spare2.dat + + # and create a pool we can perform attach remove replace, + # etc. operations with + log_must $ZPOOL create $TESTPOOL.virt mirror /$TESTDIR/disk1.dat \ + /$TESTDIR/disk2.dat /$TESTDIR/disk3.dat /$TESTDIR/disk-offline.dat \ + spare /$TESTDIR/disk-spare1.dat + + # Offline one of the disks to test online + log_must $ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-offline.dat + + # create an exported pool to test import + log_must $ZPOOL create $TESTPOOL.exported /$TESTDIR/disk-export.dat + log_must $ZPOOL export $TESTPOOL.exported + + # Now setup pool properties if they're supported + GET=$($ZPOOL 2>&1 | $FGREP "get $TMPDIR/zdb.${TESTCASE_ID} + $GREP "Dataset mos" $TMPDIR/zdb.${TESTCASE_ID} + if [ $? -eq 0 ] + then + log_fail "$@ exited 0 when run as a non root user!" + fi + $RM $TMPDIR/zdb.${TESTCASE_ID} +} + + +function cleanup +{ + if [ -e $TMPDIR/zdb_001_neg.${TESTCASE_ID}.txt ] + then + $RM $TMPDIR/zdb_001_neg.${TESTCASE_ID}.txt + fi + +} + +verify_runnable "global" + +log_assert "zdb can't run as a user on datasets, but can run without arguments" +log_onexit cleanup + +run_unprivileged $ZDB > $TMPDIR/zdb_001_neg.${TESTCASE_ID}.txt || log_fail "$ZDB failed" +# verify the output looks okay +log_must $GREP pool_guid $TMPDIR/zdb_001_neg.${TESTCASE_ID}.txt + +# we shouldn't able to run it on any dataset +check_zdb $ZDB $TESTPOOL +check_zdb $ZDB $TESTPOOL/$TESTFS +check_zdb $ZDB $TESTPOOL/$TESTFS@snap +check_zdb $ZDB $TESTPOOL/$TESTFS.clone + +log_pass "zdb can't run as a user on datasets, but can run without arguments" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_001_neg.ksh new file mode 100644 index 00000000000..17d01651dad --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_001_neg.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_001_neg +# +# DESCRIPTION: +# +# zfs shows a usage message when run as a user +# +# STRATEGY: +# 1. Run zfs as a user +# 2. Verify it produces a usage message +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + if [ -e $TMPDIR/zfs_001_neg.${TESTCASE_ID}.txt ] + then + $RM $TMPDIR/zfs_001_neg.${TESTCASE_ID}.txt + fi +} + +log_onexit cleanup +log_assert "zfs shows a usage message when run as a user" + +run_unprivileged "$ZFS" > $TMPDIR/zfs_001_neg.${TESTCASE_ID}.txt 2>&1 +log_must $GREP "usage: zfs command args" $TMPDIR/zfs_001_neg.${TESTCASE_ID}.txt + +log_pass "zfs shows a usage message when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_allow_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_allow_001_neg.ksh new file mode 100644 index 00000000000..e45e48b385c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_allow_001_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_001_neg.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_allow_001_neg +# +# DESCRIPTION: +# +# zfs allow returns an error when run as a user +# +# STRATEGY: +# +# 1. Verify that trying to show allows works as a user +# 2. Verify that trying to set allows fails as a user +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +# check to see if we have zfs allow +$ZFS 2>&1 | $GREP "allow" > /dev/null +if (($? != 0)) then + log_unsupported "ZFS allow not supported on this machine." +fi + +log_assert "zfs allow returns an error when run as a user" + +log_must run_unprivileged "$ZFS allow $TESTPOOL/$TESTFS" +log_mustnot run_unprivileged "$ZFS allow `$LOGNAME` create $TESTPOOL/$TESTFS" + +# now verify that the above command actually did nothing by +# checking for any allow output. ( if no allows are granted, +# nothing should be output ) +OUTPUT=$(run_unprivileged "$ZFS allow $TESTPOOL/$TESTFS" | $GREP "Local+Descendent" ) +if [ -n "$OUTPUT" ] +then + log_fail "zfs allow permissions were granted on $TESTPOOL/$TESTFS" +fi + +log_pass "zfs allow returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_clone_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_clone_001_neg.ksh new file mode 100644 index 00000000000..eb643dc0bc7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_clone_001_neg.ksh @@ -0,0 +1,69 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_clone_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_clone_001_neg +# +# DESCRIPTION: +# +# zfs clone returns an error when run as a user +# +# STRATEGY: +# +# 1. Verify that we're unable to clone snapshots as a user +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs clone returns an error when run as a user" +log_mustnot run_unprivileged "$ZFS clone $TESTPOOL/$TESTFS@snap $TESTPOOL/$TESTFS.myclone" + +# check to see that the above command really did nothing +if datasetexists $TESTPOOL/$TESTFS.myclone +then + log_fail "Dataset $TESTPOOL/$TESTFS.myclone should not exist!" +fi +log_pass "zfs clone returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_create_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_create_001_neg.ksh new file mode 100644 index 00000000000..7e2065a0fe5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_create_001_neg.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_create_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_create_001_neg +# +# DESCRIPTION: +# Executing various badly formed 'zfs create' should fail. +# +# STRATEGY: +# 1. Create an array of badly formed sub-commands. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A args "" "create $TESTPOOL/$TESTFS" \ + "create $TESTPOOL/$TESTFS@$TESTSNAP" \ + "create $TESTPOOL/$TESTCLCT/$TESTFS" \ + "create $TESTFS/$TESTPOOL/$TESTCLCT" + +log_assert "Verify zfs create without parameters fails." + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot run_unprivileged "$ZFS ${args[i]}" + ((i = i + 1)) +done + +log_pass "The sub-command 'create' fails as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_destroy_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_destroy_001_neg.ksh new file mode 100644 index 00000000000..b635042eeeb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_destroy_001_neg.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_destroy_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_cli_006_neg +# +# DESCRIPTION: +# Verify that 'zfs destroy' fails as non-root. +# +# STRATEGY: +# 1. Create an array of options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + + +set -A args "destroy" "destroy $TESTPOOL/$TESTFS" \ + "destroy -f" "destroy -f $TESTPOOL/$TESTFS" \ + "destroy -r" "destroy -r $TESTPOOL/$TESTFS" \ + "destroy -rf $TESTPOOL/$TESTFS" \ + "destroy -fr $TESTPOOL/$TESTFS" \ + "destroy $TESTPOOL/$TESTFS@$TESTSNAP" \ + "destroy -f $TESTPOOL/$TESTFS@$TESTSNAP" \ + "destroy -r $TESTPOOL/$TESTFS@$TESTSNAP" \ + "destroy -rf $TESTPOOL/$TESTFS@$TESTSNAP" \ + "destroy -fr $TESTPOOL/$TESTFS@$TESTSNAP" + +log_assert "zfs destroy [-f|-r] [fs|snap]" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot run_unprivileged "$ZFS ${args[i]}" + ((i = i + 1)) +done + +log_pass "The sub-command 'destroy' fails as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_get_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_get_001_neg.ksh new file mode 100644 index 00000000000..495e353a55c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_get_001_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_get_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_get_001_neg +# +# DESCRIPTION: +# +# zfs get works when run as a user +# +# STRATEGY: +# 1. Run zfs get with an array of different arguments +# 2. Verify for each property, we get the value that's expected +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs get works when run as a user" + +typeset -i i=0 + +set -A props $PROP_NAMES +set -A prop_vals $PROP_VALS + +while [[ $i -lt ${#args[*]} ]] +do + PROP=${props[$i]} + EXPECTED=${prop_vals[$i]} + ACTUAL=$( run_unprivileged "$ZFS get $PROP -o value -H snapdir $TESTPOOl/$TESTFS/prop" ) + if [ "$ACTUAL" != "$EXPECTED" ] + then + log_fail "Property $PROP value was $ACTUAL, expected $EXPECTED" + fi + i=$(( $i + 1 )) +done + +log_pass "zfs get works when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_inherit_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_inherit_001_neg.ksh new file mode 100644 index 00000000000..426a2a597ff --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_inherit_001_neg.ksh @@ -0,0 +1,71 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_inherit_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_inherit_001_neg +# +# DESCRIPTION: +# +# zfs inherit returns an error when run as a user +# +# STRATEGY: +# +# 1. Verify that we can't inherit a property when running as a user +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs inherit returns an error when run as a user" +log_mustnot run_unprivileged "$ZFS inherit snapdir $TESTPOOL/$TESTFS/$TESTFS2" + +# check to see that the above command really did nothing +PROP=$($ZFS get snapdir $TESTPOOL/$TESTFS) +if [ "$PROP" = "visible" ] +then + log_fail "snapdir property inherited from the $TESTPOOL/$TESTFS!" +fi + +log_pass "zfs inherit returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_mount_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_mount_001_neg.ksh new file mode 100644 index 00000000000..06263056e82 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_mount_001_neg.ksh @@ -0,0 +1,71 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_mount_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_mount_001_neg +# +# DESCRIPTION: +# +# zfs mount returns an error when run as a user +# +# STRATEGY: +# +# 1. Verify that we can't mount the unmounted filesystem created in setup +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs mount returns an error when run as a user" + +log_mustnot run_unprivileged "$ZFS mount $TESTPOOL/$TESTFS/$TESTFS2.unmounted" + +# now verify that the above command didn't do anything +MOUNTED=$($MOUNT | $GREP $TESTPOOL/$TESTFS/$TESTFS2.unmounted) +if [ -n "$MOUNTED" ] +then + log_fail "Filesystem $TESTPOOL/$TESTFS/$TESTFS2.unmounted was mounted!" +fi + +log_pass "zfs mount returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_promote_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_promote_001_neg.ksh new file mode 100644 index 00000000000..55f8a9f00f3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_promote_001_neg.ksh @@ -0,0 +1,71 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_promote_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_promote_001_neg +# +# DESCRIPTION: +# +# zfs promote returns an error when run as a user +# +# STRATEGY: +# +# 1. Verify we don't have permissions to promote a clone +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs promote returns an error when run as a user" + +log_mustnot run_unprivileged "$ZFS promote $TESTPOOL/$TESTFS/clone" + +# Now verify that the above command didn't do anything +if datasetexists $TESTPOOL/$TESTFS/clone@snap +then + log_fail "Clone $TESTPOOl/$TESTFS/clone was actually promoted!" +fi + +log_pass "zfs promote returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_receive_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_receive_001_neg.ksh new file mode 100644 index 00000000000..a9aba765a8d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_receive_001_neg.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_receive_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_receive_001_neg +# +# DESCRIPTION: +# +# zfs receive returns an error when run as a user +# +# STRATEGY: +# +# 1. Attempt to receive a datastream as a user +# 2. Verify that the dataset wasn't created +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs receive returns an error when run as a user" + +log_mustnot run_unprivileged "$ZFS receive -d $TESTPOOL/$TESTFS/$TESTFS2" \ + < $TMPDIR/zfstest_datastream.dat + +# verify that command actually did nothing + +if datasetexists $TESTPOOL/$TESTFS/$TESTFS2/$TESTFS +then + log_fail "$TESTPOOL/$TESTFS/$TESTFS2/$TESTFS was received!" +fi + +log_pass "zfs receive returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_rename_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_rename_001_neg.ksh new file mode 100644 index 00000000000..eb67f99c262 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_rename_001_neg.ksh @@ -0,0 +1,71 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rename_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rename_001_neg +# +# DESCRIPTION: +# +# zfs rename returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to rename a dataset +# 2. Verify that the renamed dataset does not exist. +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs rename returns an error when run as a user" + +log_mustnot run_unprivileged "$ZFS rename $TESTPOOL/$TESTFS/renameme $TESTPOOL/$TESTFS/renameme1" + +# now verify the above command didn't actually do anything +if datasetexists $TESTPOOL/$TESTFS/renameme1 +then + log_fail "The dataset $TESTPOOL/$TESTFS/renameme was renamed!" +fi + +log_pass "zfs rename returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_rollback_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_rollback_001_neg.ksh new file mode 100644 index 00000000000..fe181082404 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_rollback_001_neg.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_rollback_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_rollback_001_neg +# +# DESCRIPTION: +# +# zfs rollback returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to rollback a snapshot +# 2. Verify that a file which doesn't exist in the snapshot still exists +# (showing the snapshot rollback failed) +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs rollback returns an error when run as a user" + +log_mustnot run_unprivileged "$ZFS rollback $TESTPOOL/$TESTFS@snap" + +# now verify the above command didn't actually do anything + +# in the above filesystem there's a file that should not exist once +# the snapshot is rolled back - we check for it +if [ ! -e /$TESTDIR/file.txt ] +then + log_fail "Rollback of snapshot $TESTPOOL/$TESTFS@snap succeeded!" +fi + +log_pass "zfs rollback returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_send_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_send_001_neg.ksh new file mode 100644 index 00000000000..397ad25f421 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_send_001_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_send_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_send_001_neg +# +# DESCRIPTION: +# +# zfs send returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to send a dataset to a file +# 2. Verify the file created has zero-size +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + if [ -e $TMPDIR/zfstest_datastream.${TESTCASE_ID} ] + then + log_must $RM $TMPDIR/zfstest_datastream.${TESTCASE_ID} + fi +} + +log_assert "zfs send returns an error when run as a user" +log_onexit cleanup + +run_unprivileged "$ZFS send $TESTPOOL/$TESTFS@snap" > $TMPDIR/zfstest_datastream.${TESTCASE_ID} && log_fail "zfs send unexpectedly succeeded!" + +# Now check that the above command actually did nothing + +# We should have a non-zero-length file in $TMPDIR +if [ -s $TMPDIR/zfstest_datastream.${TESTCASE_ID} ] +then + log_fail "A zfs send file was created in $TMPDIR/zfstest_datastream.${TESTCASE_ID} !" +fi + +log_pass "zfs send returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_set_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_set_001_neg.ksh new file mode 100644 index 00000000000..bb9edddffdc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_set_001_neg.ksh @@ -0,0 +1,84 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_set_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_set_001_neg +# +# DESCRIPTION: +# +# zfs set returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to set an array of properties on a dataset +# 2. Verify that those properties were not set and retain their original values. +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs set returns an error when run as a user" + +typeset -i i=0 + +set -A props $PROP_NAMES +set -A prop_vals $PROP_VALS +set -A prop_new $PROP_ALTVALS + +while [[ $i -lt ${#args[*]} ]] +do + PROP=${props[$i]} + EXPECTED=${prop_vals[$i]} + NEW=${prop_new[$i]} + log_mustnot run_unprivileged "$ZFS set $PROP=$NEW $TESTPOOL/$TESTFS/prop" + + # Now verify that the above command did nothing + ACTUAL=$($ZFS get $PROP -o value -H snapdir $TESTPOOl/$TESTFS/prop ) + if [ "$ACTUAL" != "$EXPECTED" ] + then + log_fail "Property $PROP was set to $ACTUAL, expected $EXPECTED" + fi + i=$(( $i + 1 )) +done + +log_pass "zfs set returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_share_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_share_001_neg.ksh new file mode 100644 index 00000000000..f28ef6f1418 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_share_001_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_share_001_neg.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_share_001_neg +# +# DESCRIPTION: +# +# zfs share returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to share a dataset +# 2. Verify the dataset was not shared. +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zfs share returns an error when run as a user" + +if is_shared $TESTDIR/unshared +then + log_fail "$TESTPOOL/$TESTFS/unshared was incorrectly shared initially!" +fi + +log_mustnot run_unprivileged "$ZFS share $TESTPOOL/$TESTFS/unshared" + +# Now verify that the above command didn't actually do anything +if is_shared $TESTDIR/unshared +then + log_fail "$TESTPOOL/$TESTFS/unshared was actually shared!" +fi + +log_pass "zfs share returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_snapshot_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_snapshot_001_neg.ksh new file mode 100644 index 00000000000..98f0440a22b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_snapshot_001_neg.ksh @@ -0,0 +1,70 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_snapshot_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_snapshot_001_neg +# +# DESCRIPTION: +# +# zfs snapshot returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to snapshot a dataset +# 2. Verify the snapshot wasn't taken +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "zfs snapshot returns an error when run as a user" + +log_mustnot run_unprivileged "$ZFS snapshot $TESTPOOL/$TESTFS@usersnap1" + +# Now verify that the above command didn't actually do anything +if datasetexists $TESTPOOL/$TESTFS@usersnap1 +then + log_fail "Snapshot $TESTPOOL/$TESTFS@usersnap1 was taken !" +fi + +log_pass "zfs snapshot returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unallow_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unallow_001_neg.ksh new file mode 100644 index 00000000000..54849a5aa10 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unallow_001_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_001_neg.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_unallow_001_neg +# +# DESCRIPTION: +# +# zfs unallow returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to unallow a set of permissions +# 2. Verify the unallow wasn't performed +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +# check to see if we have zfs unallow +$ZFS 2>&1 | $GREP "unallow" > /dev/null +if (($? != 0)) then + log_unsupported "ZFS unallow not supported on this machine." +fi + +log_assert "zfs unallow returns an error when run as a user" + +log_mustnot run_unprivileged "$ZFS unallow everyone $TESTPOOL/$TESTFS/allowed" + +# now check with zfs allow to see if the permissions are still there +OUTPUT=$($ZFS allow $TESTPOOL/$TESTFS/allowed | $GREP "Local+Descendent" ) +if [ -z "$OUTPUT" ] +then + log_fail "Error - create permissions were unallowed on \ + $TESTPOOL/$TESTFS/allowed" +fi + +log_pass "zfs unallow returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unmount_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unmount_001_neg.ksh new file mode 100644 index 00000000000..0c2711153a9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unmount_001_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unmount_001_neg.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_unmount_001_neg +# +# DESCRIPTION: +# Verify that 'zfs umount' and its variants fail as non-root. +# +# STRATEGY: +# 1. Create an array of options. +# 2. Execute each element of the array. +# 3. Verify that the commands fail with an error code. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A args "umount" "umount -f" "unmount" "unmount -f" \ + "umount $TESTPOOL/$TESTFS" "umount -f $TESTPOOL/$TESTFS" \ + "unmount $TESTPOOL/$TESTFS" "unmount -f $TESTPOOL/$TESTFS" \ + "umount $TESTPOOL/$TESTFS@$TESTSNAP" \ + "umount -f $TESTPOOL/$TESTFS@$TESTSNAP" \ + "unmount $TESTPOOL/$TESTFS@$TESTSNAP" \ + "unmount -f $TESTPOOL/$TESTFS@$TESTSNAP" \ + "umount $TESTDIR" "umount -f $TESTDIR" \ + "unmount $TESTDIR" "unmount -f $TESTDIR" + +log_assert "zfs u[n]mount [-f] [mountpoint|fs|snap]" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot run_unprivileged "$ZFS ${args[i]}" + ((i = i + 1)) +done + +log_pass "The sub-command 'u[n]mount' fails as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unshare_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unshare_001_neg.ksh new file mode 100644 index 00000000000..168b0cc6b95 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_unshare_001_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unshare_001_neg.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_unshare_001_neg +# +# DESCRIPTION: +# +# zfs unshare returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to unshare a shared dataset +# 2. Verify the dataset is still shared +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zfs unshare returns an error when run as a user" + +# verify that the filesystem was shared initially +if not_shared $TESTDIR/shared +then + log_fail "$TESTPOOL/$TESTFS/shared was not shared initially at all!" +fi + +log_mustnot run_unprivileged "$ZFS unshare $TESTPOOL/$TESTFS/shared" + +# now verify that the above command didn't do anything +if not_shared $TESTDIR/shared +then + log_fail "$TESTPOOL/$TESTFS/shared was actually unshared!" +fi + +log_pass "zfs unshare returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_upgrade_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_upgrade_001_neg.ksh new file mode 100644 index 00000000000..392891e7305 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zfs_upgrade_001_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_upgrade_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_upgrade_001_neg +# +# DESCRIPTION: +# +# zfs upgrade returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to upgrade a version1 dataset +# 2. Verify the dataset wasn't upgraded +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +# check to see if we have upgrade capability +$ZFS upgrade > /dev/null 2>&1 +HAS_UPGRADE=$? +if [ $HAS_UPGRADE -ne 0 ] +then + log_unsupported "Zfs upgrade not supported" +fi + +log_assert "zfs upgrade returns an error when run as a user" + + +log_mustnot run_unprivileged "$ZFS upgrade $TESTPOOL/$TESTFS/version1" + +# now check to see the above command didn't do anything +VERSION=$($ZFS upgrade $TESTPOOL/$TESTFS/version1 2>&1 \ + | $GREP "already at this version") +if [ -n "$VERSION" ] +then + log_fail "A filesystem was upgraded!" +fi + +log_pass "zfs upgrade returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_001_neg.ksh new file mode 100644 index 00000000000..a4f636f5c4d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_001_neg.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_001_neg +# +# DESCRIPTION: +# +# zpool shows a usage message when run as a user +# +# STRATEGY: +# 1. Run the zpool command +# 2. Verify that a usage message is produced +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + if [ -e $TMPDIR/zpool_001_neg.${TESTCASE_ID}.txt ] + then + $RM $TMPDIR/zpool_001_neg.${TESTCASE_ID}.txt + fi +} + +log_onexit cleanup +log_assert "zpool shows a usage message when run as a user" + +run_unprivileged "$ZPOOL" > $TMPDIR/zpool_001_neg.${TESTCASE_ID}.txt 2>&1 +log_must $GREP "usage: zpool command args" $TMPDIR/zpool_001_neg.${TESTCASE_ID}.txt + +log_pass "zpool shows a usage message when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_add_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_add_001_neg.ksh new file mode 100644 index 00000000000..36b149799db --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_add_001_neg.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p + +# $FreeBSD$ + +# 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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_add_001_neg.ksh 1.4 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_add_001_neg +# +# DESCRIPTION: +# Verify that 'zpool add' fails as non-root. +# +# STRATEGY: +# 1. Create an array of options. +# 2. Execute each element of the array. +# 3. Verify that an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set_disks + +set -A args "add $TESTPOOL $DISK1" "add -f $TESTPOOL $DISK1" + +log_assert "zpool add [-fn] pool_name vdev" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot run_unprivileged "$ZPOOL ${args[i]}" + ((i = i + 1)) +done + +log_pass "The sub-command 'add' and its options fail as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_add_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_add_002_pos.ksh new file mode 100644 index 00000000000..a3d4bab2c08 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_add_002_pos.ksh @@ -0,0 +1,45 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + + +set_disks + +set -A args "add -n $TESTPOOL $DISK1" "add -fn $TESTPOOL $DISK1" + +log_assert "zpool add [-f] -n succeeds for unpriveleged users" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_must run_unprivileged "$ZPOOL ${args[i]}" + ((i = i + 1)) +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_attach_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_attach_001_neg.ksh new file mode 100644 index 00000000000..72dcbf4dcbb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_attach_001_neg.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_attach_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_attach_001_neg +# +# DESCRIPTION: +# +# zpool attach returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to attach a disk to a pool +# 2.Verify that the attach failed +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function check_for_attach +{ + RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-additional.dat) + if [ -n "$RESULT" ] + then + log_fail "A disk was attached to the pool!" + fi +} + +verify_runnable "global" + +log_assert "zpool attach returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL attach $TESTPOOL.virt /$TESTDIR/disk1.dat /$TESTDIR/disk-additional.dat" +check_for_attach + +log_mustnot run_unprivileged "$ZPOOL attach -f $TESTPOOL.virt /$TESTDIR/disk1.dat /$TESTDIR/disk-additional.dat" +check_for_attach + +log_pass "zpool attach returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_clear_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_clear_001_neg.ksh new file mode 100644 index 00000000000..4f3b575794f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_clear_001_neg.ksh @@ -0,0 +1,66 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_clear_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_clear_001_neg +# +# DESCRIPTION: +# +# zpool clear returns an error when run as a user +# +# STRATEGY: +# +# 1. Attempt to clear errors on a zpool +# 2. Verify that the command fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool clear returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL clear $TESTPOOL" + +log_pass "zpool clear returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_create_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_create_001_neg.ksh new file mode 100644 index 00000000000..7b65141af13 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_create_001_neg.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_create_001_neg.ksh 1.4 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_create_001_neg +# +# DESCRIPTION: +# Verify that 'zpool create' fails as a non-root user. +# +# STRATEGY: +# 1. Create an array of options. +# 2. Execute each element of the array. +# 3. Verify that an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +ADD_DISK="${DISKS%% }" +ADD_DISK="${ADD_DISK##* }" + +[[ -z $ADD_DISK ]] && \ + log_fail "No spare disks available." + +set -A args "create $TESTPOOL $ADD_DISK" "create -f $TESTPOOL $ADD_DISK" + +log_assert "zpool create [-fn] pool_name vdev" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZPOOL ${args[i]} + ((i = i + 1)) +done + +log_pass "The sub-command 'create' and its options fail as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_create_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_create_002_pos.ksh new file mode 100644 index 00000000000..9cdb6844540 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_create_002_pos.ksh @@ -0,0 +1,44 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% } +DISK=${DISKS##* } + +set -A args "create -n $TESTPOOL $DISK" "create -fn $TESTPOOL $DISK" + +log_assert "zpool create [-f] -n as an unpriveleged user succeeds" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_must $ZPOOL ${args[i]} + ((i = i + 1)) +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_destroy_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_destroy_001_neg.ksh new file mode 100644 index 00000000000..cbcc7ba33b9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_destroy_001_neg.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_destroy_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_destroy_001_neg +# +# DESCRIPTION: +# Verify that 'zpool destroy' fails as non-root. +# +# STRATEGY: +# 1. Create an array of options. +# 2. Execute each element of the array. +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A args "destroy" "destroy -f" \ + "destroy $TESTPOOL" "destroy -f $TESTPOOL" \ + "destroy $TESTPOOL $TESTPOOL" + +log_assert "zpool destroy [-f] [pool_name ...]" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot run_unprivileged "$ZPOOL ${args[i]}" + ((i = i + 1)) +done + +log_pass "The sub-command 'destroy' and its options fail as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_detach_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_detach_001_neg.ksh new file mode 100644 index 00000000000..140e1c17380 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_detach_001_neg.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_detach_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_detach_001_neg +# +# DESCRIPTION: +# +# zpool detach returns an error when run as a user +# +# STRATEGY: +# +# 1. Attempt to detach a device from a pool +# 2. Verify the command fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool detach returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL detach $TESTPOOL.virt /$TESTDIR/disk1.dat" + +RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk1.dat) +if [ -z "$RESULT" ] +then + log_fail "A disk was detached from the pool!" +fi + +log_pass "zpool detach returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_export_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_export_001_neg.ksh new file mode 100644 index 00000000000..8e6ee218d15 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_export_001_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_export_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_export_001_neg +# +# DESCRIPTION: +# +# zpool export returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to export a pool +# 2. Verify the command fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function check_for_export +{ + RESULT=$($ZPOOL list | $GREP $TESTPOOL.virt ) + if [ -z "$RESULT" ] + then + log_fail "A pool was exported!" + fi + +} + +verify_runnable "global" + +log_assert "zpool export returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL export $TESTPOOL.virt" +check_for_export + +log_mustnot run_unprivileged "$ZPOOL export -f $TESTPOOL.virt" +check_for_export + +log_pass "zpool export returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_get_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_get_001_neg.ksh new file mode 100644 index 00000000000..2f0c865a1e1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_get_001_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_get_001_neg.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_get_001_neg +# +# DESCRIPTION: +# +# zpool get works when run as a user +# +# STRATEGY: +# +# 1. For each property, get that property +# 2. Verify the property was the same as that set in setup +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool get works when run as a user" + +set -A props $POOL_PROPS +set -A prop_vals $POOL_VALS + +while [[ $i -lt ${#args[*]} ]] +do + PROP=${props[$i]} + EXPECTED=${prop_vals[$i]} + ACTUAL=$( $ZPOOL get $PROP $TESTPOOL | $GREP $PROP | $AWK '{print $1}' ) + if [ "$ACTUAL" != "$EXPECTED" ] + then + log_fail "Property $PROP value was $ACTUAL, expected $EXPECTED" + fi + i=$(( $i + 1 )) +done + +log_must run_unprivileged "$ZPOOL get all $TESTPOOL" + +log_pass "zpool get works when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_history_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_history_001_neg.ksh new file mode 100644 index 00000000000..996001644ab --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_history_001_neg.ksh @@ -0,0 +1,68 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_history_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_history_001_neg +# +# DESCRIPTION: +# +# zpool history works when run as a user +# +# STRATEGY: +# 1. Attempt to get history on a test pool +# 2. Verify the command fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool history returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL history" +log_mustnot run_unprivileged "$ZPOOL history $TESTPOOL" +log_mustnot run_unprivileged "$ZPOOL history -i $TESTPOOL" +log_mustnot run_unprivileged "$ZPOOL history -l $TESTPOOL" +log_mustnot run_unprivileged "$ZPOOL history -il $TESTPOOL" +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_import_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_import_001_neg.ksh new file mode 100644 index 00000000000..ca1b972b0de --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_import_001_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_001_neg +# +# DESCRIPTION: +# +# zpool import returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to import an exported pool +# 2. Verify the command fails +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function check_for_import +{ + RESULT=$($ZPOOL list -H -o name | $GREP $TESTPOOL.exported) + if [ -n "$RESULT" ] + then + log_fail "Pool $TESTPOOL.export was successfully imported!" + fi +} + +verify_runnable "global" + +log_assert "zpool import returns an error when run as a user" +log_mustnot run_unprivileged "$ZPOOL import" + +log_mustnot run_unprivileged "$ZPOOL import -a" +check_for_import + +log_mustnot run_unprivileged "$ZPOOL import -d /$TESTDIR $TESTPOOL.exported" +check_for_import + +log_pass "zpool import returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_import_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_import_002_neg.ksh new file mode 100644 index 00000000000..b18e5d3f8ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_import_002_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_import_002_neg.ksh 1.1 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_import_002_neg +# +# DESCRIPTION: +# Executing 'zpool import' as regular user should denied. +# +# STRATEGY: +# 1. Create an array of options try to detect exported/destroyed pools. +# 2. Execute 'zpool import' with each element of the array by regular user. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset testpool +if is_global_zone ; then + testpool=$TESTPOOL.exported +else + testpool=${TESTPOOL%%/*} +fi + +set -A args "" "-D" "-Df" "-f" "-f $TESTPOOL" "-Df $TESTPOOL" "-a" + +log_assert "Executing 'zpool import' by regular user fails" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot run_unprivileged "$ZPOOL import ${args[i]}" + ((i = i + 1)) +done + +log_pass "Executing 'zpool import' by regular user fails as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_offline_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_offline_001_neg.ksh new file mode 100644 index 00000000000..69892338702 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_offline_001_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_offline_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_offline_001_neg +# +# DESCRIPTION: +# +# zpool offline returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to offline a device in a pool +# 2. Verify that the command fails +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function check_for_offline +{ + RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-1.dat \ + | $GREP OFFLINE ) + if [ -n "$RESULT" ] + then + log_fail "A disk was taken offline!" + fi +} + +verify_runnable "global" + +log_assert "zpool offline returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL offline $TESTPOOL.virt /$TESTDIR/disk-1.dat" +check_for_offline + +log_mustnot run_unprivileged "$ZPOOL offline -t $TESTPOOL.virt /$TESTDIR/disk-1.dat" +check_for_offline + +log_pass "zpool offline returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_online_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_online_001_neg.ksh new file mode 100644 index 00000000000..58742687bde --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_online_001_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_online_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_online_001_neg +# +# DESCRIPTION: +# +# zpool online returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to online a device in a pool +# 2. Verify the command fails +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function check_for_online +{ + RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-offline.dat \ + | $GREP ONLINE ) + if [ -n "$RESULT" ] + then + log_fail "A disk was brough online!" + fi +} + +verify_runnable "global" + +log_assert "zpool online returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL online $TESTPOOL.virt /$TESTDIR/disk-offline.dat" +check_for_online + +log_mustnot run_unprivileged "$ZPOOL online -t $TESTPOOL.virt /$TESTDIR/disk-offline.dat" +check_for_online + +log_pass "zpool online returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_remove_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_remove_001_neg.ksh new file mode 100644 index 00000000000..5caf8108a44 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_remove_001_neg.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_remove_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_remove_001_neg +# +# DESCRIPTION: +# +# zpool remove returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to remove a device from a pool +# 2. Verify the command fails +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool remove returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL remove $TESTPOOL.virt /$TESTDIR/disk-spare1.dat" + +RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-spare1.dat) +if [ -z "$RESULT" ] +then + log_fail "A disk was removed from the pool!" +fi + + +log_pass "zpool remove returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_replace_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_replace_001_neg.ksh new file mode 100644 index 00000000000..58e9581f8bb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_replace_001_neg.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_replace_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_replace_001_neg +# +# DESCRIPTION: +# +# zpool replace returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to replace a device in a pool +# 2. Verify the command fails +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +function check_for_replace +{ + $SLEEP 10 + RESULT=$($ZPOOL status -v $TESTPOOL.virt | $GREP disk-additional.dat) + if [ -n "$RESULT" ] + then + log_fail "A disk was replaced in the pool!" + fi +} + +verify_runnable "global" + +log_assert "zpool replace returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL replace $TESTPOOL.virt /$TESTDIR/disk-1.dat /$TESTDIR/disk-additional.dat" +check_for_replace + +log_mustnot run_unprivileged "$ZPOOL replace -f $TESTPOOL.virt /$TESTDIR/disk-1.dat /$TESTDIR/disk-additional.dat" +check_for_replace + +log_pass "zpool replace returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_scrub_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_scrub_001_neg.ksh new file mode 100644 index 00000000000..2ad46b524d9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_scrub_001_neg.ksh @@ -0,0 +1,67 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_scrub_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_scrub_001_neg +# +# DESCRIPTION: +# +# zpool scrub returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to start a scrub on a pool +# 2. Verify the command fails +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool scrub returns an error when run as a user" + +log_mustnot run_unprivileged "$ZPOOL scrub $TESTPOOL" +log_mustnot run_unprivileged "$ZPOOL scrub -s $TESTPOOL" + +log_pass "zpool scrub returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_set_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_set_001_neg.ksh new file mode 100644 index 00000000000..5714b771602 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_set_001_neg.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_set_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_set_001_neg +# +# DESCRIPTION: +# +# zpool set returns an error when run as a user +# +# STRATEGY: +# 1. Attempt to set some properties on a pool +# 2. Verify the command fails +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool set returns an error when run as a user" + +set -A props $POOL_NAMES +set -A prop_vals $POOL_VALS +set -A prop_new $POOL_ALTVALS + +while [[ $i -lt ${#args[*]} ]] +do + PROP=${props[$i]} + EXPECTED=${prop_vals[$i]} + NEW=${prop_new[$i]} + log_mustnot run_unprivileged "$ZPOOL set $PROP=$NEW $TESTPOOL" + + # Now verify that the above command did nothing + ACTUAL=$( $ZPOOL get $PROP $TESTPOOL | $GREP $PROP | $AWK '{print $1}' ) + if [ "$ACTUAL" != "$EXPECTED" ] + then + log_fail "Property $PROP was set to $ACTUAL, expected $EXPECTED" + fi + i=$(( $i + 1 )) +done + + +log_pass "zpool set returns an error when run as a user" diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_status_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_status_001_neg.ksh new file mode 100644 index 00000000000..7601ed179a4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_status_001_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_status_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_status_001_neg +# +# DESCRIPTION: +# +# zpool status works when run as a user +# +# STRATEGY: +# +# 1. Run zpool status as a user +# 2. Verify we get output +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool status works when run as a user" + +log_must run_unprivileged "$ZPOOL status" | $GREP -q "pool:" || \ + log_fail "No Pool: string found in zpool status output" +log_must run_unprivileged "$ZPOOL status -v" | $GREP -q "pool:" || \ + log_fail "No Pool: string found in zpool status output" +log_must run_unprivileged "$ZPOOL status $TESTPOOL" | $GREP -q "pool:" || \ + log_fail "No Pool: string found in zpool status output" +log_must run_unprivileged "$ZPOOL status -v $TESTPOOL" | $GREP -q "pool:" || \ + log_fail "No Pool: string found in zpool status output" + +# $TESTPOOL.virt has an offline device, so -x will show it +log_must run_unprivileged "$ZPOOL status -x $TESTPOOL.virt" | \ + $GREP -q "pool:" || \ + log_fail "No Pool: string found in zpool status output" + +log_pass "zpool status works when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_upgrade_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_upgrade_001_neg.ksh new file mode 100644 index 00000000000..a53f194ebe8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/misc/zpool_upgrade_001_neg.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_upgrade_001_neg.ksh 1.1 07/10/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_upgrade_001_neg +# +# DESCRIPTION: +# +# zpool upgrade returns an error when run as a user +# +# STRATEGY: +# +# 1. Attempt to upgrade a pool +# 2. Verify the command fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool upgrade returns an error when run as a user" + +log_onexit cleanup +# zpool upgrade returns 0 when it can't do anything +log_must run_unprivileged "$ZPOOL upgrade $TESTPOOL.virt" + +# Now try to upgrade our version 1 pool +log_mustnot run_unprivileged "$ZPOOL upgrade v1-pool" + +# if the pool has been upgraded, then v1-pool won't be listed in the output +# of zpool upgrade anymore +RESULT=$($ZPOOL upgrade | $GREP v1-pool) +if [ -z "$RESULT" ] +then + log_fail "A pool was upgraded successfully!" +fi + +log_pass "zpool upgrade returns an error when run as a user" + diff --git a/tests/sys/cddl/zfs/tests/cli_user/setup.ksh b/tests/sys/cddl/zfs/tests/cli_user/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/Makefile b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/Makefile new file mode 100644 index 00000000000..6c046f21d9a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/Makefile @@ -0,0 +1,26 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_user/zfs_list +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_list_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zfs_list_006_pos.ksh +${PACKAGE}FILES+= zfs_list_002_pos.ksh +${PACKAGE}FILES+= zfs_list_007_pos.ksh +${PACKAGE}FILES+= zfs_list_003_pos.ksh +${PACKAGE}FILES+= zfs_list.cfg +${PACKAGE}FILES+= zfs_list_005_pos.ksh +${PACKAGE}FILES+= zfs_list_001_pos.ksh +${PACKAGE}FILES+= zfs_list.kshlib +${PACKAGE}FILES+= zfs_list_008_neg.ksh +${PACKAGE}FILES+= zfs_list_004_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/cleanup.ksh new file mode 100644 index 00000000000..6a5500c9ab0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/cleanup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.6 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/setup.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/setup.ksh new file mode 100644 index 00000000000..6cb25b2f820 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/setup.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.6 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib + +DISK=${DISKS%% *} + +default_setup_noexit $DISK + +# create datasets and set checksum options +set -A cksumarray $CKSUMOPTS +typeset -i index=0 +for dataset in $DATASETS +do + log_must $ZFS create $TESTPOOL/$TESTFS/$dataset + enc=$(get_prop encryption $TESTPOOL/$TESTFS/$dataset) + if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + log_unsupported "checksum property can't be changed \ +when encryption is set to on." + fi + $SLEEP 1 + log_must $ZFS snapshot $TESTPOOL/$TESTFS/${dataset}@snap + + $SLEEP 1 + if is_global_zone ; then + log_must $ZFS create -V 64M $TESTPOOL/$TESTFS/${dataset}-vol + $SLEEP 1 + log_must $ZFS snapshot $TESTPOOL/$TESTFS/${dataset}-vol@snap + fi + + # sleep to ensure that the datasets have different creation dates + $SLEEP 1 + log_must $ZFS set checksum=${cksumarray[$index]} \ + $TESTPOOL/$TESTFS/$dataset + if datasetexists $TESTPOOL/$TESTFS/${dataset}-vol; then + log_must $ZFS set checksum=${cksumarray[$index]} \ + $TESTPOOL/$TESTFS/${dataset}-vol + fi + + index=$((index + 1)) +done + +if zfs_get_list_d_supported ; then + depth_fs_setup +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list.cfg b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list.cfg new file mode 100644 index 00000000000..e8c07f27086 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list.cfg @@ -0,0 +1,40 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list.cfg 1.3 07/06/05 SMI" +# + +. $STF_SUITE/tests/cli_user/cli.cfg + +# Datasets (in order of creation date) and which checksum options +# we want to set for each dataset. +# These are used by various zfs list tests +export DATASETS="Apple Banana Carrot Orange apple banana carrot" +export CKSUMOPTS="on sha256 sha256 sha256 fletcher4 off fletcher2" + + diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list.kshlib b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list.kshlib new file mode 100644 index 00000000000..6e779a3f76e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list.kshlib @@ -0,0 +1,119 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list.kshlib 1.1 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# A function that verifies sort order. It takes as input +# a command, which gets executed. We then iterate over the results +# comparing that the sort order passed in via the list +# +function verify_sort { # command list name + + # now verify we've sorted by creation date: + typeset CMD=$1 + typeset list=$2 + typeset name=$3 + + typeset -i RET=0 + typeset -i index=1 + + # run the command to verify that it works + log_must eval "$CMD > /dev/null" + + # Now check the sort order + for dataset in $( $CMD ) + do + ACTUAL=$(basename $dataset) + if [ "$dataset" != "$TESTPOOL/$TESTFS" ] + then + EXPECTED=$($ECHO $list | $AWK "{print \$$index}") + if [ "$ACTUAL" != "$EXPECTED" ] + then + log_note "WARNING:" \ + "'$ACTUAL' does not equal '$EXPECTED'" + log_fail "ERROR: Sort by $name fails." + fi + + ((index = index + 1)) + fi + done + + # finally check to see if we have the expected number of elements + if [ $index -ne $($ECHO $list | $AWK '{print split($0,arr)+1}') ] + then + log_fail "Warning: " \ + "unexpected number of filesystems found in list output!" + fi +} + +# A function that verifies reverse sort order. It takes as input +# a command, which gets executed. We then iterate over the results +# comparing that the sort order passed in via the list +# +function verify_reverse_sort { # command list name + + typeset CMD=$1 + typeset list=$2 + typeset name=$3 + + # set our index to the be number of elements in the list + typeset -i index=$($ECHO $list | $AWK '{print split($0,arr)}') + + log_note "Checking reverse sort by '$name'," \ + "expecting the reverse of '$list'" + log_must eval "$CMD > /dev/null" + + for dataset in $( $CMD ) + do + ACTUAL=$(basename $dataset) + if [ "$dataset" != "$TESTPOOL/$TESTFS" ] + then + EXPECTED=$($ECHO $list | $AWK "{print \$$index}") + if [ "$ACTUAL" != "$EXPECTED" ] + then + log_note "Warning:" \ + "'$ACTUAL' does not equal to" \ + "the reverse of '$EXPECTED'" + log_fail "ERROR: Reverse sort by '$name' fails." + fi + + ((index = index - 1)) + fi + done + + # finally check to see if we have the expected number of elements + if [ $index -ne 0 ] + then + log_fail "Warning: " \ + "unexpected number of filesystems found in list output!" + fi +} diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_001_pos.ksh new file mode 100644 index 00000000000..46d43672f3a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_001_pos.ksh @@ -0,0 +1,134 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_001_pos.ksh 1.5 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_list_001_pos +# +# DESCRIPTION: +# Executing well-formed 'zfs list' commands should return success. +# +# STRATEGY: +# 1. Create an array of valid options. +# 2. Execute each element in the array. +# 3. Verify success is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A args "list" "list -r" "list -H" \ + "list $TESTPOOL/$TESTFS" \ + "list -r $TESTPOOL/$TESTFS" "list -H $TESTPOOL/$TESTFS" \ + "list -rH $TESTPOOL/$TESTFS" "list -Hr $TESTPOOL/$TESTFS" \ + "list -o name $TESTPOOL/$TESTFS" "list -r -o name $TESTPOOL/$TESTFS" \ + "list -H -o name $TESTPOOL/$TESTFS" "list -rH -o name $TESTPOOL/$TESTFS" \ + "list -Hr -o name $TESTPOOL/$TESTFS" + +if zfs_get_list_d_supported ; then + set -A d_args " " "-r" "-H" \ + "$TESTPOOL/$TESTFS" \ + "-r $TESTPOOL/$TESTFS" "-H $TESTPOOL/$TESTFS" \ + "-rH $TESTPOOL/$TESTFS" "-Hr $TESTPOOL/$TESTFS" \ + "-o name $TESTPOOL/$TESTFS" "-r -o name $TESTPOOL/$TESTFS" \ + "-H -o name $TESTPOOL/$TESTFS" "-rH -o name $TESTPOOL/$TESTFS" \ + "-Hr -o name $TESTPOOL/$TESTFS" + + typeset -i m=${#args[*]} + typeset -i n=0 + typeset -i k=0 + while (( n<${#depth_options[*]} )); + do + (( k=0 )) + while (( k<${#d_args[*]} )); + do + args[$m]="list"" -${depth_options[$n]}"" ${d_args[$k]}" + (( k+=1 )) + (( m+=1 )) + done + (( n+=1 )) + done +fi + +set -A pathargs "list -r $TESTDIR" "list -H $TESTDIR" \ + "list -r ./../$TESTDIR" "list -H ./../$TESTDIR" + +if zfs_get_list_d_supported ; then +set -A d_pathargs " $TESTDIR" "-r $TESTDIR" "-H $TESTDIR" \ + "-r ./../$TESTDIR" "-H ./../$TESTDIR" + + (( m=${#pathargs[*]} )) + (( n=0 )) + (( k=0 )) + while (( n<${#depth_options[*]} )); + do + (( k=0 )) + while (( k<${#d_pathargs[*]} )); + do + pathargs[$m]="list"" -${depth_options[$n]}"" ${d_pathargs[$k]}" + (( k+=1 )) + (( m+=1 )) + done + (( n+=1 )) + done +fi + +log_assert "Verify 'zfs list [-rH] [-o property[,prop]*] [fs|clct|vol]'." + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_must run_unprivileged "eval $ZFS ${args[i]} > /dev/null" + ((i = i + 1)) +done + +# Verify 'zfs list ' will succeed on absolute or relative path. + +cd /tmp +typeset -i i=0 +while [[ $i -lt ${#pathargs[*]} ]]; do + log_must run_unprivileged "eval $ZFS ${pathargs[i]} > /dev/null" + ((i = i + 1)) +done + +log_pass "The sub-command 'list' succeeds as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_002_pos.ksh new file mode 100644 index 00000000000..95d04e2194a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_002_pos.ksh @@ -0,0 +1,190 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_002_pos.ksh 1.6 08/11/03 SMI" +# +. $STF_SUITE/tests/cli_user/zfs_list/zfs_list.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_list_002_pos +# +# DESCRIPTION: +# The sort functionality in 'zfs list' works as expected. +# +# STRATEGY: +# 1. Using several zfs datasets with names, creation dates, checksum options +# 2. Sort the datasets by name, checksum options, creation date. +# 3. Verify that the datasets are sorted correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-08) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# datasets ordered by name +fs_name="Apple Banana Carrot Orange apple banana carrot" +vol_name="Apple-vol Banana-vol Carrot-vol Orange-vol apple-vol" +vol_name="$vol_name banana-vol carrot-vol" +if is_global_zone ; then + snap_name="Apple-vol@snap Apple@snap Banana-vol@snap Banana@snap" + snap_name="$snap_name Carrot-vol@snap Carrot@snap Orange-vol@snap Orange@snap" + snap_name="$snap_name apple-vol@snap apple@snap banana-vol@snap banana@snap" + snap_name="$snap_name carrot-vol@snap carrot@snap" +else + snap_name="Apple@snap Banana@snap" + snap_name="$snap_name Carrot@snap Orange@snap" + snap_name="$snap_name apple@snap banana@snap" + snap_name="$snap_name carrot@snap" +fi + +fs_creation=$fs_name +vol_creation=$vol_name +if is_global_zone ; then + snap_creation="Apple@snap Apple-vol@snap Banana@snap Banana-vol@snap" + snap_creation="$snap_creation Carrot@snap Carrot-vol@snap Orange@snap Orange-vol@snap" + snap_creation="$snap_creation apple@snap apple-vol@snap banana@snap banana-vol@snap" + snap_creation="$snap_creation carrot@snap carrot-vol@snap" +else + snap_creation="Apple@snap Banana@snap" + snap_creation="$snap_creation Carrot@snap Orange@snap" + snap_creation="$snap_creation apple@snap banana@snap" + snap_creation="$snap_creation carrot@snap" +fi + +# +# datsets ordered by checksum options (note, Orange, Carrot & Banana have the +# same checksum options, so ZFS should revert to sorting them alphabetically by +# name) +# +fs_cksum="carrot apple banana Apple Banana Carrot Orange" +vol_cksum="carrot-vol apple-vol banana-vol Apple-vol Banana-vol" +vol_cksum="$vol_cksum Carrot-vol Orange-vol" +snap_cksum=$snap_creation + +fs_rev_cksum="carrot apple banana Apple Orange Carrot Banana" +vol_rev_cksum="carrot-vol apple-vol banana-vol Apple-vol Orange-vol" +vol_rev_cksum="$vol_rev_cksum Carrot-vol Banana-vol" + +log_assert "The sort functionality in 'zfs list' works as expected." + +# +# we must be in the C locale here, as running in other locales +# will make zfs use that locale's sort order. +# +LC_ALL=C; export LC_ALL + +# sort by creation +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s creation -t filesystem $TESTPOOL/$TESTFS" \ + "$fs_creation" "creation date" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s creation -t volume $TESTPOOL/$TESTFS" \ + "$vol_creation" "creation date" +fi +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s creation -t snapshot $TESTPOOL/$TESTFS" \ + "$snap_creation" "creation date" + +# sort by checksum +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s checksum -t filesystem $TESTPOOL/$TESTFS" \ + "$fs_cksum" "checksum" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s checksum -t volume $TESTPOOL/$TESTFS" \ + "$vol_cksum" "checksum" +fi +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s checksum -t snapshot $TESTPOOL/$TESTFS" \ + "$snap_cksum" "checksum" +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -S checksum -t snapshot $TESTPOOL/$TESTFS" \ + "$snap_cksum" "checksum" + +# sort by name +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s name -t filesystem $TESTPOOL/$TESTFS" \ + "$fs_name" "name" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s name -t volume $TESTPOOL/$TESTFS" \ + "$vol_name" "name" +fi +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s name -t snapshot $TESTPOOL/$TESTFS" \ + "$snap_name" "name" + +# reverse sort by creation +verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S creation -t filesystem $TESTPOOL/$TESTFS" \ + "$fs_creation" "creation date" +if is_global_zone ; then + verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S creation -t volume $TESTPOOL/$TESTFS" \ + "$vol_creation" "creation date" +fi +verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S creation -t snapshot $TESTPOOL/$TESTFS" \ + "$snap_creation" "creation date" + +# reverse sort by checksum +verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S checksum -t filesystem $TESTPOOL/$TESTFS" \ + "$fs_rev_cksum" "checksum" +if is_global_zone ; then + verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S checksum -t volume $TESTPOOL/$TESTFS" \ + "$vol_rev_cksum" "checksum" +fi + +# reverse sort by name +verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S name -t filesystem $TESTPOOL/$TESTFS"\ + "$fs_name" "name" +if is_global_zone ; then + verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S name -t volume $TESTPOOL/$TESTFS"\ + "$vol_name" "name" +fi +verify_reverse_sort \ + "run_unprivileged $ZFS list -H -r -o name -S name -t snapshot $TESTPOOL/$TESTFS"\ + "$snap_name" "name" + +log_pass "The sort functionality in 'zfs list' works as expected." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_003_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_003_pos.ksh new file mode 100644 index 00000000000..5ed72c388a0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_003_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_003_pos.ksh 1.1 07/06/05 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_list_003_pos +# +# DESCRIPTION: +# Verify 'zfs list -r' could recursively display any children +# of the dataset. +# +# STRATEGY: +# 1. Prepare a set of datasets by hierarchy. +# 2. Execute 'zfs list -r' at the top of these datasets. +# 3. Verify all child datasets are all be shown. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-05-24) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup +{ + if [[ -f $tmpfile ]]; then + $RM -f $tmpfile + fi +} + +verify_runnable "both" +log_onexit cleanup + +log_assert "Verify 'zfs list -r' could display any children recursively." + +tmpfile=$TMPDIR/zfslist.out.${TESTCASE_ID} +children="$TESTPOOL/$TESTFS" + +for fs in $DATASETS ; do + children="$children $TESTPOOL/$TESTFS/$fs" +done + +cd /tmp + +for path in $TESTPOOL/$TESTFS $TESTDIR ./../$TESTDIR ; do + run_unprivileged $ZFS list -rH -o name $path > $tmpfile + for fs in $children ; do + $GREP -q "^${fs}$" $tmpfile + if (( $? != 0 )); then + cat $tmpfile + log_fail "$fs not shown in the output list." + fi + done +done + +log_pass "'zfs list -r' could display any children recursively." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_004_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_004_neg.ksh new file mode 100644 index 00000000000..eb520b3dd48 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_004_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_004_neg.ksh 1.1 07/06/05 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_list_004_neg +# +# DESCRIPTION: +# Verify 'zfs list [-r]' should fail while +# * the given dataset does not exist +# * the given path does not exist. +# * the given path does not belong to zfs. +# +# STRATEGY: +# 1. Create an array of invalid options. +# 2. Execute each element in the array. +# 3. Verify failure is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-05-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify 'zfs list [-r]' should fail while the given " \ + "dataset/path does not exist or not belong to zfs." + +paths="$TESTPOOL/NONEXISTFS $TESTPOOL/$TESTFS/NONEXISTFS \ + /$TESTDIR/NONEXISTFS /dev" + +cd /tmp + +for fs in $paths ; do + log_mustnot run_unprivileged $ZFS list $fs + log_mustnot run_unprivileged $ZFS list -r $fs +done + +log_pass "'zfs list [-r]' fails while the given dataset/path does not exist " \ + "or not belong to zfs." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_005_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_005_pos.ksh new file mode 100644 index 00000000000..ee6fa5c3f49 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_005_pos.ksh @@ -0,0 +1,197 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_005_pos.ksh 1.2 08/11/03 SMI" +# +. $STF_SUITE/tests/cli_user/zfs_list/zfs_list.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_list_005_pos +# +# DESCRIPTION: +# Verify 'zfs list' evaluate multiple '-s' options from left to right +# in decreasing order of importance. +# +# STRATEGY: +# 1. Setting user property f:color for filesystem and volume. +# 2. Setting user property f:amount for filesystem and volume. +# 3. Setting reservation for filesystem and volume +# 3. Verify 'zfs list' evaluated multiple -s options from left to right. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-07-23) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify 'zfs list' evaluate multiple '-s' options " \ + "from left to right in decreasing order of importance." + +COLOR="red yellow green blue red yellow white" +AMOUNT="0217 812 0217 0781 7 1364 687" +RESERVATION="2048K 1024 2048K 512K 16M 3072 128K" + +basefs=$TESTPOOL/$TESTFS +typeset -i n=0 +for ds in $DATASETS ; do + color=$($ECHO $COLOR | $AWK '{print $1}') + log_must $ZFS set f:color=$color $basefs/$ds + if is_global_zone ; then + log_must $ZFS set f:color=$color $basefs/${ds}-vol + fi + eval COLOR=\${COLOR#$color } + + amount=$($ECHO $AMOUNT | $AWK '{print $1}') + log_must $ZFS set f:amount=$amount $basefs/$ds + if is_global_zone ; then + log_must $ZFS set f:amount=$amount $basefs/${ds}-vol + fi + eval AMOUNT=\${AMOUNT#$amount } + + reserv=$($ECHO $RESERVATION | $AWK '{print $1}') + log_must $ZFS set reservation=$reserv $basefs/$ds + if is_global_zone ; then + log_must $ZFS set reservation=$reserv $basefs/${ds}-vol + fi + eval RESERVATION=\${RESERVATION#$reserv } +done + +# +# we must be in the C locale here, as running in other locales +# will make zfs use that locale's sort order. +# +LC_ALL=C; export LC_ALL + +fs_color_amount="Orange Carrot Apple apple carrot banana Banana" +fs_amount_color="Carrot Apple Orange banana carrot apple Banana" +fs_color_reserv="Orange Carrot Apple apple carrot Banana banana" +fs_reserv_color="Banana banana carrot Orange Carrot Apple apple" +fs_reserv_amount_color="Banana banana carrot Orange Carrot Apple apple" + +vol_color_amount="Orange-vol Carrot-vol Apple-vol apple-vol carrot-vol" +vol_color_amount="$vol_color_amount banana-vol Banana-vol" + +vol_amount_color="Carrot-vol Apple-vol Orange-vol banana-vol carrot-vol" +vol_amount_color="$vol_amount_color apple-vol Banana-vol" + +vol_color_reserv="Orange-vol Carrot-vol Apple-vol apple-vol carrot-vol" +vol_color_reserv="$vol_color_reserv Banana-vol banana-vol" + +vol_reserv_color="Banana-vol banana-vol carrot-vol Orange-vol Carrot-vol" +vol_reserv_color="$vol_reserv_color Apple-vol apple-vol" + +vol_reserv_amount_color="Banana-vol banana-vol carrot-vol Orange-vol Carrot-vol" +vol_reserv_amount_color="$vol_reserv_amount_color Apple-vol apple-vol" + +if is_global_zone ; then + snap_list="Apple@snap Apple-vol@snap Banana@snap Banana-vol@snap" + snap_list="$snap_list Carrot@snap Carrot-vol@snap Orange@snap Orange-vol@snap" + snap_list="$snap_list apple@snap apple-vol@snap banana@snap banana-vol@snap" + snap_list="$snap_list carrot@snap carrot-vol@snap" +else + snap_list="Apple@snap Banana@snap" + snap_list="$snap_list Carrot@snap Orange@snap" + snap_list="$snap_list apple@snap banana@snap" + snap_list="$snap_list carrot@snap" +fi +# Sort by color,amount +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:color -s f:amount -t filesystem $basefs" \ + "$fs_color_amount" "f:color,f:amount" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:color -s f:amount -t volume $basefs" \ + "$vol_color_amount" "f:color,f:amount" +fi +# Sort by amount,color +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:amount -s f:color -t filesystem $basefs" \ + "$fs_amount_color" "f:amount,f:color" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:amount -s f:color -t volume $basefs" \ + "$vol_amount_color" "f:amount,f:color" +fi + +# Sort by color reservation +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:color -s reserv -t filesystem $basefs" \ + "$fs_color_reserv" "f:color,reserv" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:color -s reserv -t volume $basefs" \ + "$vol_color_reserv" "f:color,reserv" +fi +# Sort by reserv, color +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s reserv -s f:color -t filesystem $basefs" \ + "$fs_reserv_color" "reserv,f:color" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s reserv -s f:color -t volume $basefs" \ + "$vol_reserv_color" "reserv,f:color" +fi + +# Sort by reservation, amount, color +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s reserv -s reserv -s f:amount -s f:color -t filesystem $basefs" \ + "$fs_reserv_amount_color" "reserv,:amount,f:color" +if is_global_zone ; then + verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s reserv -s f:amount -s f:color -t volume $basefs" \ + "$vol_reserv_amount_color" "reserv,:amount,f:color" +fi +# User property and reservation was not stored in snapshot +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:amount -s f:color -t snapshot $basefs" \ + "$snap_list" "f:amount,f:color" +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:color -s f:amount -t snapshot $basefs" \ + "$snap_list" "f:color,f:amount" +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s f:color -s reserv -t snapshot $basefs" \ + "$snap_list" "f:color,reservation" +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s reserv -s f:color -t snapshot $basefs" \ + "$snap_list" "reserv,f:color" +verify_sort \ + "run_unprivileged $ZFS list -H -r -o name -s reserv -s f:amount -s f:color -t snapshot $basefs" \ + "$snap_list" "reservation,f:color,f:amount" + +log_pass "Verify 'zfs list' evaluate multiple '-s' options " \ + "from left to right in decreasing order of importance." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_006_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_006_pos.ksh new file mode 100644 index 00000000000..2588361fad1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_006_pos.ksh @@ -0,0 +1,126 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_006_pos.ksh 1.1 09/05/19 SMI" +# +. $STF_SUITE/tests/cli_user/zfs_list/zfs_list.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_list_006_pos +# +# DESCRIPTION: +# Verify 'zfs list' exclude list of snapshot. +# +# STRATEGY: +# 1. Verify snapshot not shown in the list: +# zfs list [-r] +# 2. Verify snapshot will be shown by following case: +# zfs list [-r] -t snapshot +# zfs list [-r] -t all +# zfs list +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-24) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! pool_prop_exist "listsnapshots" ; then + log_unsupported "Pool property of 'listsnapshots' not supported." +fi + +log_assert "Verify 'zfs list' exclude list of snapshot." + +set -A hide_options "--" "-t filesystem" "-t volume" +set -A show_options "--" "-t snapshot" "-t all" + +typeset pool=${TESTPOOL%%/*} +typeset dataset=${DATASETS%% *} +typeset BASEFS=$TESTPOOL/$TESTFS + +for newvalue in "" "on" "off" ; do + + if [[ -n $newvalue ]] && ! is_global_zone ; then + break + fi + + if [[ -n $newvalue ]] ; then + log_must $ZPOOL set listsnapshots=$newvalue $pool + fi + + if [ -z "$newvalue" -o "off" = "$newvalue" ] ; then + run_unprivileged $ZFS list -r -H -o name $pool | $GREP -q '@' && \ + log_fail "zfs list included snapshots but shouldn't have" + else + run_unprivileged $ZFS list -r -H -o name $pool | $GREP -q '@' || \ + log_fail "zfs list failed to include snapshots" + fi + + + typeset -i i=0 + while (( i < ${#hide_options[*]} )) ; do + run_unprivileged $ZFS list -r -H -o name ${hide_options[i]} $pool | \ + $GREP -q '@' && \ + log_fail "zfs list included snapshots but shouldn't have" + + (( i = i + 1 )) + done + + (( i = 0 )) + + while (( i < ${#show_options[*]} )) ; do + run_unprivileged $ZFS list -r -H -o name ${show_options[i]} $pool | \ + $GREP -q '@' || \ + log_fail "zfs list failed to include snapshots" + (( i = i + 1 )) + done + + output=$(run_unprivileged $ZFS list -H -o name $BASEFS/${dataset}@snap) + if [[ $output != $BASEFS/${dataset}@snap ]] ; then + log_fail "zfs list not show $BASEFS/${dataset}@snap" + fi + + if is_global_zone ; then + output=$(run_unprivileged $ZFS list -H -o name $BASEFS/${dataset}-vol@snap) + if [[ $output != $BASEFS/${dataset}-vol@snap ]] ; then + log_fail "zfs list not show $BASEFS/${dataset}-vol@snap" + fi + fi +done + +log_pass "'zfs list' exclude list of snapshot." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_007_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_007_pos.ksh new file mode 100644 index 00000000000..13fa593cd80 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_007_pos.ksh @@ -0,0 +1,111 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_007_pos.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_list_007_pos +# +# DESCRIPTION: +# 'zfs list -d ' should get expected output. +# +# STRATEGY: +# 1. 'zfs list -d ' to get the output. +# 2. 'zfs list -r|egrep' to get the expected output. +# 3. Compare the two outputs, they shoud be same. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-05-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! zfs_get_list_d_supported ; then + log_unsupported "'zfs list -d' is not supported." +fi + +set -A fs_type "all" "filesystem" "snapshot" +if is_global_zone ; then + set -A fs_type ${fs_type[*]} "volume" +fi + +function cleanup +{ + log_must $RM -f $DEPTH_OUTPUT + log_must $RM -f $EXPECT_OUTPUT +} + +log_onexit cleanup +log_assert "'zfs list -d ' should get expected output." + +mntpnt=$TMPDIR +DEPTH_OUTPUT="$mntpnt/depth_output" +EXPECT_OUTPUT="$mntpnt/expect_output" +typeset -i old_val=0 +typeset -i j=0 +typeset -i fs=0 +typeset eg_opt="$DEPTH_FS"$ +for dp in ${depth_array[@]}; do + (( j=old_val+1 )) + while (( j<=dp && j<=MAX_DEPTH )); do + eg_opt="$eg_opt""|d""$j"$ + (( j+=1 )) + done + (( fs=0 )) + while (( fs<${#fs_type[*]} )); do + if [[ "$dp" == "0" ]] && \ + [[ "${fs_type[$fs]}" == "volume" || "${fs_type[$fs]}" == "snapshot" ]]; then + log_must eval "run_unprivileged $ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT" + [[ -s "$DEPTH_OUTPUT" ]] && \ + log_fail "$DEPTH_OUTPUT should be null." + log_mustnot run_unprivileged $ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt' + else + log_must eval "run_unprivileged $ZFS list -H -d $dp -o name -t ${fs_type[$fs]} $DEPTH_FS > $DEPTH_OUTPUT" + log_must eval "run_unprivileged $ZFS list -rH -o name -t ${fs_type[$fs]} $DEPTH_FS | $EGREP -e '$eg_opt' > $EXPECT_OUTPUT" + log_must $DIFF $DEPTH_OUTPUT $EXPECT_OUTPUT + fi + (( fs+=1 )) + done + (( old_val=dp )) +done + +log_pass "'zfs list -d ' should get expected output." + diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_008_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_008_neg.ksh new file mode 100644 index 00000000000..34287ab2d36 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_008_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_list_008_neg.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/tests/cli_root/zfs_get/zfs_get_list_d.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zfs_list_008_neg +# +# DESCRIPTION: +# A negative depth or a non numeric depth should fail in 'zfs list -d ' +# +# STRATEGY: +# 1. Run zfs list -d with negative depth or non numeric depth +# 2. Verify that zfs list returns error +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-05-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! zfs_get_list_d_supported ; then + log_unsupported "'zfs list -d' is not supported." +fi + +log_assert "A negative depth or a non numeric depth should fail in 'zfs list -d '" + +set -A badargs "a" "AB" "aBc" "2A" "a2b" "aB2" "-1" "-32" "-999" + +typeset -i i=0 +while (( i < ${#badargs[*]} )) +do + log_mustnot eval "run_unprivileged $ZFS list -d ${badargs[i]} $DEPTH_FS >/dev/null 2>&1" + (( i = i + 1 )) +done + +log_pass "A negative depth or a non numeric depth should fail in 'zfs list -d '" + + diff --git a/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_test.sh b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_test.sh new file mode 100755 index 00000000000..a69aaf64968 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zfs_list/zfs_list_test.sh @@ -0,0 +1,265 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_list_001_pos cleanup +zfs_list_001_pos_head() +{ + atf_set "descr" "Verify 'zfs list [-rH] [-o property[,prop]*] [fs|clct|vol]'." + atf_set "require.progs" zfs + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_list_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_list_002_pos cleanup +zfs_list_002_pos_head() +{ + atf_set "descr" "The sort functionality in 'zfs list' works as expected." + atf_set "require.progs" zfs + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_list_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_list_003_pos cleanup +zfs_list_003_pos_head() +{ + atf_set "descr" "Verify 'zfs list -r' could display any children recursively." + atf_set "require.progs" zfs + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_list_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_list_004_neg cleanup +zfs_list_004_neg_head() +{ + atf_set "descr" "Verify 'zfs list [-r]' should fail while the givendataset/path does not exist or not belong to zfs." + atf_set "require.progs" zfs + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_004_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_004_neg.ksh || atf_fail "Testcase failed" +} +zfs_list_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_list_005_pos cleanup +zfs_list_005_pos_head() +{ + atf_set "descr" "Verify 'zfs list' evaluate multiple '-s' optionsfrom left to right in decreasing order of importance." + atf_set "require.progs" zfs + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + atf_expect_fail "https://www.illumos.org/issues/8599 Snapshots don't preserve user properties" + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_list_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_list_006_pos cleanup +zfs_list_006_pos_head() +{ + atf_set "descr" "Verify 'zfs list' exclude list of snapshot." + atf_set "require.progs" zfs zpool + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_list_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_list_007_pos cleanup +zfs_list_007_pos_head() +{ + atf_set "descr" "'zfs list -d ' should get expected output." + atf_set "require.progs" zfs + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_007_pos.ksh || atf_fail "Testcase failed" +} +zfs_list_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_list_008_neg cleanup +zfs_list_008_neg_head() +{ + atf_set "descr" "A negative depth or a non numeric depth should fail in 'zfs list -d '" + atf_set "require.progs" zfs + atf_set "require.user" root + atf_set "require.config" "unprivileged_user" +} +zfs_list_008_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_list_008_neg.ksh || atf_fail "Testcase failed" +} +zfs_list_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zfs_list.kshlib + . $(atf_get_srcdir)/zfs_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_list_001_pos + atf_add_test_case zfs_list_002_pos + atf_add_test_case zfs_list_003_pos + atf_add_test_case zfs_list_004_neg + atf_add_test_case zfs_list_005_pos + atf_add_test_case zfs_list_006_pos + atf_add_test_case zfs_list_007_pos + atf_add_test_case zfs_list_008_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/Makefile b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/Makefile new file mode 100644 index 00000000000..90f80207ef6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_user/zpool_iostat +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_iostat_test +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_iostat.cfg +${PACKAGE}FILES+= zpool_iostat_003_neg.ksh +${PACKAGE}FILES+= zpool_iostat_002_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zpool_iostat_001_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/setup.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat.cfg b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat.cfg new file mode 100644 index 00000000000..169b368eb5a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_iostat.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_user/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh new file mode 100644 index 00000000000..cde88d89081 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_001_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_iostat_001_neg.ksh 1.3 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_iostat_001_neg +# +# DESCRIPTION: +# Verify that 'zpool iostat' can be executed as non-root. +# +# STRATEGY: +# 1. Create an array of options. +# 2. Execute each element of the array. +# 3. Verify that a success is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset testpool +if is_global_zone ; then + testpool=$TESTPOOL +else + testpool=${TESTPOOL%%/*} +fi + +set -A args "iostat" "iostat $testpool" + +log_assert "zpool iostat [pool_name ...] [interval]" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_must run_unprivileged $ZPOOL ${args[i]} + ((i = i + 1)) +done + +log_pass "The sub-command 'iostat' succeeds as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh new file mode 100644 index 00000000000..1efbee8cf2c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_002_pos.ksh @@ -0,0 +1,84 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_iostat_002_pos.ksh 1.2 08/05/14 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_iostat_002_pos +# +# DESCRIPTION: +# Verify that 'zpool iostat [interval [count]' can be executed as non-root. +# +# STRATEGY: +# 1. set the interval=2 and count=3 +# 2. sleep 30 seconds +# 3. Verify that the output have 3 record. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset tmpfile=$TMPDIR/zfsiostat.out.${TESTCASE_ID} +typeset -i stat_count=0 + +function cleanup +{ + if [[ -f $tmpfile ]]; then + $RM -f $tmpfile + fi +} + +log_onexit cleanup +log_assert "zpool iostat [pool_name ...] [interval] [count]" + +if ! is_global_zone ; then + TESTPOOL=${TESTPOOL%%/*} +fi + +run_unprivileged $ZPOOL iostat $TESTPOOL 2 3 > $tmpfile 2>&1 +stat_count=$($GREP $TESTPOOL $tmpfile | $WC -l) + +if [[ $stat_count -ne 3 ]]; then + log_fail "zpool iostat [pool_name] [interval] [count] failed" +fi + +log_pass "zpool iostat [pool_name ...] [interval] [count] passed" diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_003_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_003_neg.ksh new file mode 100644 index 00000000000..16679c47b96 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_003_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_iostat_003_neg.ksh 1.1 07/10/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_iostat_003_neg +# +# DESCRIPTION: +# Executing 'zpool iostat' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool iostat' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset testpool +if is_global_zone ; then + testpool=$TESTPOOL +else + testpool=${TESTPOOL%%/*} +fi + +set -A args "" "-?" "-f" "nonexistpool" "$TESTPOOL/$TESTFS" \ + "$testpool 1.23" "$testpool 0" "$testpool -1" "$testpool 1 0" \ + "$testpool 0 0" + +log_assert "Executing 'zpool iostat' with bad options fails" + +typeset -i i=1 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZPOOL iostat ${args[i]} + ((i = i + 1)) +done + +log_pass "Executing 'zpool iostat' with bad options fails" diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_test.sh b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_test.sh new file mode 100755 index 00000000000..7cc83e9afb8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_iostat/zpool_iostat_test.sh @@ -0,0 +1,103 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_iostat_001_neg cleanup +zpool_iostat_001_neg_head() +{ + atf_set "descr" "zpool iostat [pool_name ...] [interval]" + atf_set "require.progs" zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_iostat_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_iostat.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_iostat_001_neg.ksh || atf_fail "Testcase failed" +} +zpool_iostat_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_iostat.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_iostat_002_pos cleanup +zpool_iostat_002_pos_head() +{ + atf_set "descr" "zpool iostat [pool_name ...] [interval] [count]" + atf_set "require.progs" zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_iostat_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_iostat.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_iostat_002_pos.ksh || atf_fail "Testcase failed" +} +zpool_iostat_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_iostat.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_iostat_003_neg +zpool_iostat_003_neg_head() +{ + atf_set "descr" "Executing 'zpool iostat' with bad options fails" + atf_set "require.progs" zpool + atf_set "require.user" unprivileged +} +zpool_iostat_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_iostat.cfg + + ksh93 $(atf_get_srcdir)/zpool_iostat_003_neg.ksh || atf_fail "Testcase failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zpool_iostat_001_neg + atf_add_test_case zpool_iostat_002_pos + atf_add_test_case zpool_iostat_003_neg +} diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_list/Makefile b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/Makefile new file mode 100644 index 00000000000..c43dc562d1e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_user/zpool_list +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zpool_list_test +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zpool_list_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zpool_list.cfg +${PACKAGE}FILES+= zpool_list_002_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_list/cleanup.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_list/setup.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list.cfg b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list.cfg new file mode 100644 index 00000000000..9d84b2ebed9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_list.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/cli_user/cli.cfg diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_001_pos.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_001_pos.ksh new file mode 100644 index 00000000000..ef69c1eb917 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_001_pos.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_list_001_pos.ksh 1.5 08/05/14 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_user/cli_user.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_list_001_pos +# +# DESCRIPTION: +# Verify that 'zpool list' succeeds as non-root. +# +# STRATEGY: +# 1. Create an array of options. +# 2. Execute each element of the array. +# 3. Verify the command succeeds. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +if ! is_global_zone ; then + TESTPOOL=${TESTPOOL%%/*} +fi + +set -A args "list $TESTPOOL" "list -H $TESTPOOL" "list" "list -H" \ + "list -H -o name $TESTPOOL" "list -o name $TESTPOOL" \ + "list -o name,size,capacity,health,altroot $TESTPOOL" \ + "list -H -o name,size,capacity,health,altroot $TESTPOOL" + +log_assert "zpool list [-H] [-o filed[,filed]*] [ ...]" + +typeset -i i=0 +while [[ $i -lt ${#args[*]} ]]; do + log_must run_unprivileged $ZPOOL ${args[i]} + + ((i = i + 1)) +done + +log_pass "The sub-command 'list' succeeds as non-root." diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_002_neg.ksh b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_002_neg.ksh new file mode 100644 index 00000000000..196cfd7d995 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_002_neg.ksh @@ -0,0 +1,70 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zpool_list_002_neg.ksh 1.2 08/05/14 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_list_002_neg +# +# DESCRIPTION: +# Executing 'zpool list' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool list' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A args "" "-?" "-f" "-o" \ + "-o fakeproperty" "-o name,size,fakeproperty" + +log_assert "Executing 'zpool list' with bad options fails" + +typeset -i i=1 +while [[ $i -lt ${#args[*]} ]]; do + log_mustnot $ZPOOL list ${args[i]} + ((i = i + 1)) +done + +log_pass "Executing 'zpool list' with bad options fails" diff --git a/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_test.sh b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_test.sh new file mode 100755 index 00000000000..a34e60d5d80 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/cli_user/zpool_list/zpool_list_test.sh @@ -0,0 +1,75 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zpool_list_001_pos cleanup +zpool_list_001_pos_head() +{ + atf_set "descr" "zpool list [-H] [-o filed[,filed]*] [ ...]" + atf_set "require.progs" zpool + atf_set "require.user" root + atf_set "require.config" unprivileged_user +} +zpool_list_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_list.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zpool_list_001_pos.ksh || atf_fail "Testcase failed" +} +zpool_list_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_list.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zpool_list_002_neg +zpool_list_002_neg_head() +{ + atf_set "descr" "Executing 'zpool list' with bad options fails" + atf_set "require.progs" zpool + atf_set "require.user" unprivileged +} +zpool_list_002_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_list.cfg + + ksh93 $(atf_get_srcdir)/zpool_list_002_neg.ksh || atf_fail "Testcase failed" +} + +atf_init_test_cases() +{ + + atf_add_test_case zpool_list_001_pos + atf_add_test_case zpool_list_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/compression/Makefile b/tests/sys/cddl/zfs/tests/compression/Makefile new file mode 100644 index 00000000000..2dcca81826c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/compression +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= compression_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= compress_004_pos.ksh +${PACKAGE}FILES+= compress_001_pos.ksh +${PACKAGE}FILES+= compress_003_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= compress.cfg +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/compression/cleanup.ksh b/tests/sys/cddl/zfs/tests/compression/cleanup.ksh new file mode 100644 index 00000000000..c514e32197c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +default_container_cleanup diff --git a/tests/sys/cddl/zfs/tests/compression/compress.cfg b/tests/sys/cddl/zfs/tests/compression/compress.cfg new file mode 100644 index 00000000000..774c1d40fe3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/compress.cfg @@ -0,0 +1,39 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)compress.cfg 1.4 08/08/15 SMI" +# + +export TESTFILE0=testfile0.${TESTCASE_ID} +export TESTFILE1=testfile1.${TESTCASE_ID} + +export BLOCKSZ=8192 +export NUM_WRITES=65536 +export DATA=13 +export STF_TIMEOUT=1200 + diff --git a/tests/sys/cddl/zfs/tests/compression/compress_001_pos.ksh b/tests/sys/cddl/zfs/tests/compression/compress_001_pos.ksh new file mode 100644 index 00000000000..d3d2eefb65c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/compress_001_pos.ksh @@ -0,0 +1,86 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)compress_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: compress_001_pos +# +# DESCRIPTION: +# Create two files of exactly the same size. One with compression +# and one without. Ensure the compressed file is smaller. +# +# STRATEGY: +# Use "zfs set" to turn on compression and create files before +# and after the set call. The compressed file should be smaller. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset OP=create + +log_assert "Ensure that compressed files are smaller." + +log_note "Ensure compression is off" +log_must $ZFS set compression=off $TESTPOOL/$TESTFS + +log_note "Writing file without compression..." +log_must $FILE_WRITE -o $OP -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA + +log_note "Add compression property to the dataset and write another file" +log_must $ZFS set compression=on $TESTPOOL/$TESTFS + +log_must $FILE_WRITE -o $OP -f $TESTDIR/$TESTFILE1 -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA + +log_must $SYNC $TESTDIR + +FILE0_BLKS=`$DU -k $TESTDIR/$TESTFILE0 | $AWK '{ print $1}'` +FILE1_BLKS=`$DU -k $TESTDIR/$TESTFILE1 | $AWK '{ print $1}'` + +if [[ $FILE0_BLKS -le $FILE1_BLKS ]]; then + log_fail "$TESTFILE0 is smaller than $TESTFILE1" \ + "($FILE0_BLKS <= $FILE1_BLKS)" +fi + +log_pass "$TESTFILE0 is bigger than $TESTFILE1 ($FILE0_BLKS > $FILE1_BLKS)" diff --git a/tests/sys/cddl/zfs/tests/compression/compress_003_pos.ksh b/tests/sys/cddl/zfs/tests/compression/compress_003_pos.ksh new file mode 100644 index 00000000000..fee884a46a7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/compress_003_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)compress_003_pos.ksh 1.3 07/06/06 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: compress_003_pos +# +# DESCRIPTION: +# With 'compression' or 'compress' set, changing filesystem blocksize cannot +# cause system panic +# +# STRATEGY: +# 1. Set 'compression' or "compress" to on +# 2. Set different blocksize with ZFS filesystem +# 3. Use 'mkfile' create single block and multi-block files +# 4. Verify the system continued work +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -f $TESTDIR/* +} + +log_assert "Changing blocksize doesn't casue system panic with compression settings" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +single_blk_file=$TESTDIR/singleblkfile.${TESTCASE_ID} +multi_blk_file=$TESTDIR/multiblkfile.${TESTCASE_ID} +typeset -i blksize=512 +typeset -i fsize=0 +typeset -i offset=0 + +for propname in "compression" "compress" +do + for value in $(get_compress_opts zfs_compress) + do + log_must $ZFS set $propname=$value $fs + if [[ $value == "gzip-6" ]]; then + value="gzip" + fi + real_val=$(get_prop $propname $fs) + [[ $real_val != $value ]] && \ + log_fail "Set property $propname=$value failed." + + (( blksize = 512 )) + while (( blksize <= 131072 )); do + log_must $ZFS set recordsize=$blksize $fs + (( offset = $RANDOM )) + if (( offset > blksize )); then + (( offset = offset % blksize )) + fi + if (( (offset % 2) == 0 )); then + #keep offset as non-power-of-2 + (( offset = offset + 1 )) + fi + (( fsize = offset )) + log_must $MKFILE $fsize $single_blk_file + (( fsize = blksize + offset )) + log_must $MKFILE $fsize $multi_blk_file + + (( blksize = blksize * 2 )) + done + done +done + +log_pass "The system works as expected while changing blocksize with compression settings" diff --git a/tests/sys/cddl/zfs/tests/compression/compress_004_pos.ksh b/tests/sys/cddl/zfs/tests/compression/compress_004_pos.ksh new file mode 100644 index 00000000000..a8f06d19c5d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/compress_004_pos.ksh @@ -0,0 +1,146 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)compress_004_pos.ksh 1.3 07/06/06 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: compress_004_pos +# +# DESCRIPTION: +# With 'compression' set, a file with non-power-of-2 blocksize storage space +# can be freed as will normally. +# +# STRATEGY: +# 1. Set 'compression' or 'compress' to on or lzjb +# 2. Set different recordsize with ZFS filesystem +# 3. Repeatedly using 'randfree_file' to create a file and then free its +# storage space with different range, the system should work normally. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -f $TESTDIR/* +} + +function create_free_testing # +{ + typeset -i fsz=$1 + typeset file=$2 + typeset -i start=0 + typeset -i len=0 + typeset -i dist=0 + + for start in 0 `expr $RANDOM % $fsz` + do + (( dist = fsz - start )) + for len in `expr $RANDOM % $dist` $dist \ + `expr $start + $dist`; do + log_must $RANDFREE_FILE -l fsz -s $start \ + -n $len $file + [[ -e $file ]] && \ + log_must $RM -f $file + done + done +} + + +log_assert "Creating non-power-of-2 blocksize file and freeing the file \ + storage space at will should work normally with compression setting" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +single_blk_file=$TESTDIR/singleblkfile.${TESTCASE_ID} +multi_blk_file=$TESTDIR/multiblkfile.${TESTCASE_ID} +typeset -i blksize=512 +typeset -i fsize=0 +typeset -i avail=0 +typeset -i blknum=0 + +for propname in "compression" "compress" +do + for value in $(get_compress_opts zfs_compress) + do + log_must $ZFS set compression=$value $fs + real_val=$(get_prop $propname $fs) + if [[ $value == "gzip-6" ]]; then + value="gzip" + fi + [[ $real_val != $value ]] && \ + log_fail "Set property $propname=$value failed." + + (( blksize = 512 )) + while (( blksize <= 131072 )); do + log_must $ZFS set recordsize=$blksize $fs + + # doing single block testing + (( fsize = $RANDOM )) + if (( fsize > blksize )); then + (( fsize = fsize % blksize )) + fi + if (( (fsize % 2) == 0 )); then + #make sure fsize is non-power-of-2 + (( fsize = fsize + 1 )) + fi + create_free_testing $fsize $single_blk_file + + # doing multiple blocks testing + avail=$(get_prop available $fs) + (( blknum = avail / blksize )) + # we just test <10 multi-blocks to limit testing time + (( blknum = blknum % 9 )) + while (( blknum < 2 )); do + (( blknum = blknum + $RANDOM % 9 )) + done + if (( (blknum % 2) == 0 )); then + (( blknum = blknum + 1 )) # keep blknum as odd + fi + (( fsize = blknum * blksize )) + create_free_testing $fsize $multi_blk_file + + (( blksize = blksize * 2 )) + done + done +done + +log_pass "Creating and freeing non-power-of-2 blocksize file work as expected." diff --git a/tests/sys/cddl/zfs/tests/compression/compression_test.sh b/tests/sys/cddl/zfs/tests/compression/compression_test.sh new file mode 100755 index 00000000000..dfabcd6f408 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/compression_test.sh @@ -0,0 +1,110 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case compress_001_pos cleanup +compress_001_pos_head() +{ + atf_set "descr" "Ensure that compressed files are smaller." + atf_set "require.progs" zfs +} +compress_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/compress.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/compress_001_pos.ksh || atf_fail "Testcase failed" +} +compress_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/compress.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case compress_003_pos cleanup +compress_003_pos_head() +{ + atf_set "descr" "Changing blocksize doesn't casue system panic with compression settings" + atf_set "require.progs" zfs +} +compress_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/compress.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/compress_003_pos.ksh || atf_fail "Testcase failed" +} +compress_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/compress.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case compress_004_pos cleanup +compress_004_pos_head() +{ + atf_set "descr" "Creating non-power-of-2 blocksize file and freeing the filestorage space at will should work normally with compression setting" + atf_set "require.progs" zfs +} +compress_004_pos_body() +{ + if [[ $(uname) = "FreeBSD" ]]; then + atf_skip "FreeBSD does not implement F_FREESP in fcntl()" + fi + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/compress.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/compress_004_pos.ksh || atf_fail "Testcase failed" +} +compress_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/compress.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case compress_001_pos + atf_add_test_case compress_003_pos + atf_add_test_case compress_004_pos +} diff --git a/tests/sys/cddl/zfs/tests/compression/setup.ksh b/tests/sys/cddl/zfs/tests/compression/setup.ksh new file mode 100644 index 00000000000..1c30df46ae8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/compression/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_container_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/ctime/Makefile b/tests/sys/cddl/zfs/tests/ctime/Makefile new file mode 100644 index 00000000000..ec0b356df32 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/ctime/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/ctime +FILESDIR=${TESTSDIR} +BINDIR=${TESTSDIR} + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= ctime.cfg + +PROG= ctime_001_pos +MAN= +ATF_TESTS_KSH93= ctime_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +.include diff --git a/tests/sys/cddl/zfs/tests/ctime/cleanup.ksh b/tests/sys/cddl/zfs/tests/ctime/cleanup.ksh new file mode 100644 index 00000000000..2ee7cfb6028 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/ctime/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/ctime/ctime.cfg b/tests/sys/cddl/zfs/tests/ctime/ctime.cfg new file mode 100644 index 00000000000..d601d5d88e3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/ctime/ctime.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)ctime.cfg 1.2 08/08/15 SMI" +# + +export TESTFILE=testfile${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/ctime/ctime_001_pos.c b/tests/sys/cddl/zfs/tests/ctime/ctime_001_pos.c new file mode 100644 index 00000000000..afccda1a884 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/ctime/ctime_001_pos.c @@ -0,0 +1,381 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)ctime_001_pos.c 1.1 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ST_ATIME 0 +#define ST_CTIME 1 +#define ST_MTIME 2 + +#define ALL_MODE (mode_t)(S_IRWXU|S_IRWXG|S_IRWXO) + +typedef struct timetest { + int type; + char *name; + int (*func)(const char *pfile); +} timetest_t; + +#ifdef __stc_assertion__ + +/* + * ID: ctime_001_pos + * + * DESCRIPTION: + * Verify time will be changed correctly according to relevant operating. + * + * STRATEGY: + * 1. Define time test array. + * 2. loop each item in this array. + * 3. Verify the time will be changed after relevant operating. + * + * TESTABILITY: explicit + * + * TEST_AUTOMATION_LEVEL: automated + * + * CODING_STATUS: COMPLETED (2007-01-30) + * + */ + +#endif /* __stc_assertion__ */ + +/* + * Get file specific time information. + */ +int get_file_time(char *pfile, int what, time_t *ptr); + +int do_read(const char *pfile); +int do_write(const char *pfile); +int do_link(const char *pfile); +int do_creat(const char *pfile); +int do_utime(const char *pfile); +int do_chmod(const char *pfile); +int do_chown(const char *pfile); + +static char tfile[BUFSIZ] = { 0 }; +static char msg[BUFSIZ] = { 0 }; + +static timetest_t timetest_table[] = { + { ST_ATIME, "st_atime", do_read }, + { ST_ATIME, "st_atime", do_utime }, + { ST_MTIME, "st_mtime", do_creat }, + { ST_MTIME, "st_mtime", do_write }, + { ST_MTIME, "st_mtime", do_utime }, + { ST_CTIME, "st_ctime", do_creat }, + { ST_CTIME, "st_ctime", do_write }, + { ST_CTIME, "st_ctime", do_chmod }, + { ST_CTIME, "st_ctime", do_chown }, + { ST_CTIME, "st_ctime", do_link }, + { ST_CTIME, "st_ctime", do_utime }, +}; + +#define NCOMMAND (sizeof (timetest_table) / sizeof (timetest_table[0])) + +int +main(int argc, char *argv[]) +{ + int i, ret, fd; + const char *env_names[2] = {"TESTDIR", "TESTFILE"}; + char *env_vals[2]; + + /* + * Get envirnment variable value + */ + for (i = 0; i < sizeof (env_names) / sizeof (char *); i++) { + if ((env_vals[i] = getenv(env_names[i])) == NULL) { + fprintf(stderr, "getenv(%s) returned NULL\n", + env_names[i]); + exit(1); + } + } + (void) snprintf(tfile, sizeof (tfile), "%s/%s", env_vals[0], + env_vals[1]); + + /* + * If the test file is existing, remove it firstly + */ + if (access(tfile, F_OK) == 0) { + unlink(tfile); + } + fd = open(tfile, O_WRONLY | O_CREAT | O_TRUNC, ALL_MODE); + if (fd < 0) { + perror("open"); + exit(1); + } + (void) close(fd); + + for (i = 0; i < NCOMMAND; i++) { + time_t t1, t2; + + /* + * Get original time before operating. + */ + ret = get_file_time(tfile, timetest_table[i].type, &t1); + if (ret != 0) { + fprintf(stderr, + "ERROR: get_file_time(%s, %d, &t1) returned %d\n", + tfile, timetest_table[i].type, ret); + exit(1); + } + + /* + * Sleep 2 seconds to be sure that the timeofday has changed, + * then invoke command on given file + */ + sleep(2); + timetest_table[i].func(tfile); + + /* + * Get time after operating. + */ + ret = get_file_time(tfile, timetest_table[i].type, &t2); + if (ret != 0) { + fprintf(stderr, "get_file_time(%s, %d, &t2)\n", + tfile, timetest_table[i].type); + exit(1); + } + + if (t1 == t2) { + fprintf(stderr, "%s: t1(%ld) == t2(%ld)\n", + timetest_table[i].name, (long)t1, (long)t2); + exit(1); + } + } + + (void) unlink(tfile); + + return (0); +} + +int +get_file_time(char *pfile, int what, time_t *ptr) +{ + struct stat stat_buf; + + if (pfile == NULL || ptr == NULL) { + return (-1); + } + + if (stat(pfile, &stat_buf) == -1) { + return (-1); + } + + switch (what) { + case ST_ATIME: + *ptr = stat_buf.st_atime; + return (0); + case ST_CTIME: + *ptr = stat_buf.st_ctime; + return (0); + case ST_MTIME: + *ptr = stat_buf.st_mtime; + return (0); + default: + return (-1); + } +} + +int +do_read(const char *pfile) +{ + int fd, ret = 0; + char buf[BUFSIZ] = { 0 }; + + if (pfile == NULL) { + return (-1); + } + + if ((fd = open(pfile, O_RDONLY, ALL_MODE)) == -1) { + return (-1); + } + if (read(fd, buf, sizeof (buf)) == -1) { + ret = errno; + } + (void) close(fd); + + if (ret != 0) { + fprintf(stderr, "read(%d, buf, %d)\n", fd, sizeof (buf)); + exit(1); + } + + return (ret); +} + +int +do_write(const char *pfile) +{ + int fd, ret = 0; + char buf[BUFSIZ] = "call function do_write()"; + + if (pfile == NULL) { + return (-1); + } + + if ((fd = open(pfile, O_WRONLY, ALL_MODE)) == -1) { + return (-1); + } + if (write(fd, buf, strlen(buf)) == -1) { + ret = errno; + } + (void) close(fd); + + if (ret != 0) { + fprintf(stderr, "write(%d, buf, %d)\n", fd, strlen(buf)); + exit(1); + } + + return (ret); +} + +int +do_link(const char *pfile) +{ + int ret = 0; + char link_file[BUFSIZ] = { 0 }; + char *ptr = link_file; + + if (pfile == NULL) { + return (-1); + } + + /* + * Figure out source file directory name, and create + * the link file in the same directory. + */ + snprintf(link_file, sizeof (link_file), "%s", pfile); + ptr = strrchr(link_file, '/'); + snprintf(ptr + 1, + sizeof (link_file) - (ptr + 1 - link_file), "link_file"); + + if (link(pfile, link_file) == -1) { + ret = errno; + } + if (ret != 0) { + fprintf(stderr, "link(%s, %s)\n", pfile, link_file); + exit(1); + } + + unlink(link_file); + return (ret); +} + +int +do_creat(const char *pfile) +{ + int fd, ret = 0; + + if (pfile == NULL) { + return (-1); + } + + if ((fd = creat(pfile, ALL_MODE)) == -1) { + ret = errno; + } + if (fd != -1) { + (void) close(fd); + } + + if (ret != 0) { + fprintf(stderr, "creat(%s, ALL_MODE)\n", pfile); + exit(1); + } + + return (ret); +} + +int +do_utime(const char *pfile) +{ + int ret = 0; + + if (pfile == NULL) { + return (-1); + } + + /* + * Times of the file are set to the current time + */ + if (utime(pfile, NULL) == -1) { + ret = errno; + } + if (ret != 0) { + fprintf(stderr, "utime(%s, NULL)\n", pfile); + exit(1); + } + + return (ret); +} + +int +do_chmod(const char *pfile) +{ + int ret = 0; + + if (pfile == NULL) { + return (-1); + } + + if (chmod(pfile, ALL_MODE) == -1) { + ret = errno; + } + if (ret != 0) { + fprintf(stderr, "chmod(%s, ALL_MODE)\n", pfile); + exit(1); + } + + return (ret); +} + +int +do_chown(const char *pfile) +{ + int ret = 0; + + if (pfile == NULL) { + return (-1); + } + + if (chown(pfile, getuid(), getgid()) == -1) { + ret = errno; + } + if (ret != 0) { + fprintf(stderr, "chown(%s, %d, %d)\n", pfile, (int)getuid(), + (int)getgid()); + exit(1); + } + + return (ret); +} diff --git a/tests/sys/cddl/zfs/tests/ctime/ctime_test.sh b/tests/sys/cddl/zfs/tests/ctime/ctime_test.sh new file mode 100755 index 00000000000..d4a1c52c776 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/ctime/ctime_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case ctime_001_pos cleanup +ctime_001_pos_head() +{ + atf_set "descr" "A file's ctime should change when the file is modified" + atf_set "require.progs" zfs +} +ctime_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/ctime.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + $(atf_get_srcdir)/ctime_001_pos || atf_fail "Testcase failed" +} +ctime_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/ctime.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case ctime_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/ctime/setup.ksh b/tests/sys/cddl/zfs/tests/ctime/setup.ksh new file mode 100644 index 00000000000..e3aad622ec2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/ctime/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/delegate/Makefile b/tests/sys/cddl/zfs/tests/delegate/Makefile new file mode 100644 index 00000000000..905d62621ee --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/Makefile @@ -0,0 +1,40 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/delegate +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfs_allow_test +ATF_TESTS_KSH93+= zfs_unallow_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= delegate.cfg +${PACKAGE}FILES+= delegate_common.kshlib +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs_allow_001_pos.ksh +${PACKAGE}FILES+= zfs_allow_002_pos.ksh +${PACKAGE}FILES+= zfs_allow_003_pos.ksh +${PACKAGE}FILES+= zfs_allow_004_pos.ksh +${PACKAGE}FILES+= zfs_allow_005_pos.ksh +${PACKAGE}FILES+= zfs_allow_006_pos.ksh +${PACKAGE}FILES+= zfs_allow_007_pos.ksh +${PACKAGE}FILES+= zfs_allow_008_pos.ksh +${PACKAGE}FILES+= zfs_allow_009_neg.ksh +${PACKAGE}FILES+= zfs_allow_010_pos.ksh +${PACKAGE}FILES+= zfs_allow_011_neg.ksh +${PACKAGE}FILES+= zfs_allow_012_neg.ksh +${PACKAGE}FILES+= zfs_unallow_001_pos.ksh +${PACKAGE}FILES+= zfs_unallow_002_pos.ksh +${PACKAGE}FILES+= zfs_unallow_003_pos.ksh +${PACKAGE}FILES+= zfs_unallow_004_pos.ksh +${PACKAGE}FILES+= zfs_unallow_005_pos.ksh +${PACKAGE}FILES+= zfs_unallow_006_pos.ksh +${PACKAGE}FILES+= zfs_unallow_007_neg.ksh +${PACKAGE}FILES+= zfs_unallow_008_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/delegate/cleanup.ksh b/tests/sys/cddl/zfs/tests/delegate/cleanup.ksh new file mode 100644 index 00000000000..58ee9b63f91 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +cleanup_user_group + +default_cleanup +log_pass diff --git a/tests/sys/cddl/zfs/tests/delegate/delegate.cfg b/tests/sys/cddl/zfs/tests/delegate/delegate.cfg new file mode 100644 index 00000000000..ce42196878d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/delegate.cfg @@ -0,0 +1,62 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)delegate.cfg 1.3 08/08/15 SMI" +# + +export STF_TIMEOUT=1800 + +export NISSTAFILE=$TMPDIR/nis_state + +export STAFF_GROUP=zfsgrp +export STAFF1=staff1 +export STAFF2=staff2 + +export OTHER_GROUP=othergrp +export OTHER1=other1 +export OTHER2=other2 + +export EVERYONE="$STAFF1 $STAFF2 $OTHER1 $OTHER2" + +export LOCAL_SET="snapshot" +export LOCAL_DESC_SET="readonly,checksum" +export DESC_SET="compression" + +export TESTVOL=testvol.${TESTCASE_ID} +export VOLSIZE=150m + +export ROOT_TESTVOL=$TESTPOOL/$TESTVOL +export ROOT_TESTFS=$TESTPOOL/$TESTFS +export SUBFS=$ROOT_TESTFS/SUBFS +export SUBFS2=$ROOT_TESTFS/SUBFS2 + +DATASETS="$ROOT_TESTFS" +if is_global_zone ; then + DATASETS="$DATASETS $ROOT_TESTVOL" +fi +export DATASETS diff --git a/tests/sys/cddl/zfs/tests/delegate/delegate_common.kshlib b/tests/sys/cddl/zfs/tests/delegate/delegate_common.kshlib new file mode 100644 index 00000000000..bbf5985aef4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/delegate_common.kshlib @@ -0,0 +1,1902 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)delegate_common.kshlib 1.6 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Cleanup exist user/group. +# +function cleanup_user_group +{ + typeset i + for i in $STAFF1 $STAFF2 $OTHER1 $OTHER2 ; do + del_user $i + done + for i in $STAFF_GROUP $OTHER_GROUP ; do + del_group $i + done + + return 0 +} + +# +# Restore test file system to the original status. +# +function restore_root_datasets +{ + if datasetexists $ROOT_TESTFS ; then + log_must $ZFS destroy -Rf $ROOT_TESTFS + fi + log_must $ZFS create $ROOT_TESTFS + + if is_global_zone ; then + if datasetexists $ROOT_TESTVOL ; then + log_must $ZFS destroy -Rf $ROOT_TESTVOL + fi + log_must $ZFS create -V $VOLSIZE $ROOT_TESTVOL + fi + + return 0 +} + +# +# Verify the specified user have permission on the dataset +# +# $1 dataset +# $2 permissions which are separated by comma(,) +# $3-n users +# +function verify_perm +{ + typeset dtst=$1 + typeset permissions=$2 + shift 2 + + if [[ -z $@ || -z $permissions || -z $dtst ]]; then + return 1 + fi + + typeset type=$(get_prop type $dtst) + permissions=$($ECHO $permissions | $TR -s "," " ") + + typeset user + for user in $@; do + typeset perm + for perm in $permissions; do + typeset -i ret=1 + if [[ $type == "filesystem" ]]; then + check_fs_perm $user $perm $dtst + ret=$? + elif [[ $type == "volume" ]]; then + check_vol_perm $user $perm $dtst + ret=$? + fi + + if ((ret != 0)) ; then + log_note "Fail: $user should have $perm " \ + "on $dtst" + return 1 + fi + done + done + + return 0 +} + +# +# Verify the specified user have no permission on the dataset +# +# $1 dataset +# $2 permissions which are separated by comma(,) +# $3-n users +# +function verify_noperm +{ + typeset dtst=$1 + typeset permissions=$2 + shift 2 + + if [[ -z $@ || -z $permissions || -z $dtst ]]; then + return 1 + fi + + typeset type=$(get_prop type $dtst) + permissions=$($ECHO $permissions | $TR -s "," " ") + + typeset user + for user in $@; do + typeset perm + for perm in $permissions; do + typeset -i ret=1 + if [[ $type == "filesystem" ]]; then + check_fs_perm $user $perm $dtst + ret=$? + elif [[ $type == "volume" ]]; then + check_vol_perm $user $perm $dtst + ret=$? + fi + + if ((ret == 0)) ; then + log_note "Fail: $user should not have $perm " \ + "on $dtst" + return 1 + fi + done + done + + return 0 +} + +function user_run +{ + typeset user=$1 + typeset group=$($GROUPS $user) + + shift + + eval \$RUNWATTR -u \$user -g \$group \"$@\" > /dev/null 2>&1 + return $? +} + +function common_perm +{ + typeset user=$1 + typeset perm=$2 + typeset dtst=$3 + + typeset -i ret=1 + case $perm in + send) + verify_send $user $perm $dtst + ret=$? + ;; + allow) + verify_allow $user $perm $dtst + ret=$? + ;; + userprop) + verify_userprop $user $perm $dtst + ret=$? + ;; + compression|checksum|readonly) + verify_ccr $user $perm $dtst + ret=$? + ;; + copies) + verify_copies $user $perm $dtst + ret=$? + ;; + reservation) + verify_reservation $user $perm $dtst + ret=$? + ;; + *) + ret=1 + ;; + esac + + return $ret +} + +function check_fs_perm +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset -i ret=1 + case $perm in + create) + verify_fs_create $user $perm $fs + ret=$? + ;; + destroy) + verify_fs_destroy $user $perm $fs + ret=$? + ;; + snapshot) + verify_fs_snapshot $user $perm $fs + ret=$? + ;; + rollback) + verify_fs_rollback $user $perm $fs + ret=$? + ;; + clone) + verify_fs_clone $user $perm $fs + ret=$? + ;; + rename) + verify_fs_rename $user $perm $fs + ret=$? + ;; + mount) + verify_fs_mount $user $perm $fs + ret=$? + ;; + share) + verify_fs_share $user $perm $fs + ret=$? + ;; + mountpoint) + verify_fs_mountpoint $user $perm $fs + ret=$? + ;; + promote) + verify_fs_promote $user $perm $fs + ret=$? + ;; + canmount) + verify_fs_canmount $user $perm $fs + ret=$? + ;; + recordsize) + verify_fs_recordsize $user $perm $fs + ret=$? + ;; + quota) + verify_fs_quota $user $perm $fs + ret=$? + ;; + aclmode) + verify_fs_aclmode $user $perm $fs + ret=$? + ;; + aclinherit) + verify_fs_aclinherit $user $perm $fs + ret=$? + ;; + snapdir) + verify_fs_snapdir $user $perm $fs + ret=$? + ;; + atime|exec|devices|setuid|xattr) + verify_fs_aedsx $user $perm $fs + ret=$? + ;; + zoned) + verify_fs_zoned $user $perm $fs + ret=$? + ;; + sharenfs) + verify_fs_sharenfs $user $perm $fs + ret=$? + ;; + shareiscsi) + verify_fs_shareiscsi $user $perm $fs + ret=$? + ;; + receive) + verify_fs_receive $user $perm $fs + ret=$? + ;; + *) + common_perm $user $perm $fs + ret=$? + ;; + esac + + return $ret +} + +function check_vol_perm +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset -i ret=1 + case $perm in + destroy) + verify_vol_destroy $user $perm $vol + ret=$? + ;; + snapshot) + verify_vol_snapshot $user $perm $vol + ret=$? + ;; + rollback) + verify_vol_rollback $user $perm $vol + ret=$? + ;; + clone) + verify_vol_clone $user $perm $vol + ret=$? + ;; + rename) + verify_vol_rename $user $perm $vol + ret=$? + ;; + promote) + verify_vol_promote $user $perm $vol + ret=$? + ;; + volsize) + verify_vol_volsize $user $perm $vol + ret=$? + ;; + shareiscsi) + verify_vol_shareiscsi $user $perm $vol + ret=$? + ;; + *) + common_perm $user $perm $vol + ret=$? + ;; + esac + + return $ret +} + +function setup_unallow_testenv +{ + log_must restore_root_datasets + + log_must $ZFS create $SUBFS + + for dtst in $DATASETS ; do + log_must $ZFS allow -l $STAFF1 $LOCAL_SET $dtst + log_must $ZFS allow -d $STAFF2 $DESC_SET $dtst + log_must $ZFS allow $OTHER1 $LOCAL_DESC_SET $dtst + log_must $ZFS allow $OTHER2 $LOCAL_DESC_SET $dtst + + log_must verify_perm $dtst $LOCAL_SET $STAFF1 + log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER1 + log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER2 + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must verify_perm $SUBFS $DESC_SET $STAFF2 + log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER1 + log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER2 + fi + done + + return 0 +} + +# +# Verify permission send for specified user on the dataset +# $1 user +# $2 permission +# $3 dataset +# +function verify_send +{ + typeset user=$1 + typeset perm=$2 + typeset dtst=$3 + + typeset oldval + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset snap=$dtst@snap.$stamp + + typeset -i ret=1 + + log_must $ZFS snapshot $snap + typeset bak_user=$TMPDIR/bak.$user.$stamp + typeset bak_root=$TMPDIR/bak.root.$stamp + + user_run $user eval "$ZFS send $snap > $bak_user" + log_must eval "$ZFS send $snap > $bak_root" + + if [[ $(checksum $bak_user) == $(checksum $bak_root) ]]; then + ret=0 + fi + + $RM -rf $bak_user > /dev/null + $RM -rf $bak_root > /dev/null + + return $ret +} + +function verify_fs_receive +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset newfs=$fs/newfs.$stamp + typeset newvol=$fs/newvol.$stamp + typeset bak_user=$TMPDIR/bak.$user.$stamp + typeset bak_root=$TMPDIR/bak.root.$stamp + + log_must $ZFS create $newfs + typeset datasets="$newfs" + if is_global_zone ; then + log_must $ZFS create -V $VOLSIZE $newvol + datasets="$newfs $newvol" + fi + + for dtst in $datasets ; do + + typeset dtstsnap=$dtst@snap.$stamp + log_must $ZFS snapshot $dtstsnap + + log_must eval "$ZFS send $dtstsnap > $bak_root" + log_must $ZFS destroy -rf $dtst + + user_run $user eval "$ZFS receive $dtst < $bak_root" + if datasetexists $dtstsnap ; then + return 1 + fi + + log_must $ZFS allow $user create $fs + user_run $user eval "$ZFS receive $dtst < $bak_root" + log_must $ZFS unallow $user create $fs + if datasetexists $dtstsnap ; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user eval "$ZFS receive $dtst < $bak_root" + log_must $ZFS unallow $user mount $fs + if datasetexists $dtstsnap ; then + return 1 + fi + + log_must $ZFS allow $user mount,create $fs + user_run $user eval "$ZFS receive $dtst < $bak_root" + log_must $ZFS unallow $user mount,create $fs + if ! datasetexists $dtstsnap ; then + return 1 + fi + + # check the data integrity + log_must eval "$ZFS send $dtstsnap > $bak_user" + log_must $ZFS destroy -rf $dtst + log_must eval "$ZFS receive $dtst < $bak_root" + log_must eval "$ZFS send $dtstsnap > $bak_root" + log_must $ZFS destroy -rf $dtst + if [[ $(checksum $bak_user) != $(checksum $bak_root) ]]; then + return 1 + fi + + $RM -rf $bak_user > /dev/null + $RM -rf $bak_root > /dev/null + + done + + return 0 +} + +function verify_userprop +{ + typeset user=$1 + typeset perm=$2 + typeset dtst=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + + user_run $user $ZFS set "$user:ts=$stamp" $dtst + if [[ $stamp != $(get_prop "$user:ts" $dtst) ]]; then + return 1 + fi + + return 0 +} + +function verify_ccr +{ + typeset user=$1 + typeset perm=$2 + typeset dtst=$3 + + typeset oldval + + set -A modes "on" "off" + oldval=$(get_prop $perm $dtst) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $dtst" + user_run $user $ZFS set $perm=${modes[$n]} $dtst + if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then + return 1 + fi + + return 0 +} + +function verify_copies +{ + typeset user=$1 + typeset perm=$2 + typeset dtst=$3 + + typeset oldval + + set -A modes 1 2 3 + oldval=$(get_prop $perm $dtst) + if [[ $oldval -eq 1 ]]; then + n=1 + elif [[ $oldval -eq 2 ]]; then + n=2 + elif [[ $oldval -eq 3 ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $dtst" + user_run $user $ZFS set $perm=${modes[$n]} $dtst + if [[ ${modes[$n]} != $(get_prop $perm $dtst) ]]; then + return 1 + fi + + return 0 +} + +function verify_reservation +{ + typeset user=$1 + typeset perm=$2 + typeset dtst=$3 + + typeset value32m=$(( 1024 * 1024 * 32 )) + typeset oldval=$(get_prop reservation $dtst) + user_run $user $ZFS set reservation=$value32m $dtst + if [[ $value32m != $(get_prop reservation $dtst) ]]; then + log_must $ZFS set reservation=$oldval $dtst + return 1 + fi + + log_must $ZFS set reservation=$oldval $dtst + return 0 +} + +function verify_fs_create +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset newfs=$fs/nfs.$stamp + typeset newvol=$fs/nvol.$stamp + typeset check_refrev=false + + user_run $user $ZFS create $newfs + if datasetexists $newfs ; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user $ZFS create $newfs + log_must $ZFS unallow $user mount $fs + if ! datasetexists $newfs ; then + return 1 + fi + if support_refrev $newfs; then + check_refrev=true + fi + log_must $ZFS destroy $newfs + + if is_global_zone ; then + # mount permission is required for sparse volume + user_run $user $ZFS create -V 150m -s $newvol + if datasetexists $newvol ; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user $ZFS create -V 150m -s $newvol + log_must $ZFS unallow $user mount $fs + if ! datasetexists $newvol ; then + return 1 + fi + log_must $ZFS destroy $newvol + + # mount and reserveration permission are + # required for normal volume + user_run $user $ZFS create -V 150m $newvol + if datasetexists $newvol ; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user $ZFS create -V 150m $newvol + log_must $ZFS unallow $user mount $fs + if datasetexists $newvol ; then + return 1 + fi + + log_must $ZFS allow $user reservation $fs + user_run $user $ZFS create -V 150m $newvol + log_must $ZFS unallow $user reservation $fs + if datasetexists $newvol ; then + return 1 + fi + + if [[ $check_refrev == true ]]; then + log_must $ZFS allow $user refreservation $fs + user_run $user $ZFS create -V 150m $newvol + log_must $ZFS unallow $user refreservation $fs + if datasetexists $newvol ; then + return 1 + fi + fi + + log_must $ZFS allow $user mount $fs + log_must $ZFS allow $user reservation $fs + if [[ $check_refrev == true ]]; then + log_must $ZFS allow $user refreservation $fs + fi + user_run $user $ZFS create -V 150m $newvol + log_must $ZFS unallow $user mount $fs + log_must $ZFS unallow $user reservation $fs + if [[ $check_refrev == true ]]; then + log_must $ZFS unallow $user refreservation $fs + fi + if ! datasetexists $newvol ; then + return 1 + fi + log_must $ZFS destroy $newvol + fi + + return 0 +} + +function verify_fs_destroy +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + if ! ismounted $fs ; then + user_run $user $ZFS destroy $fs + if datasetexists $fs ; then + return 1 + fi + fi + + if ismounted $fs ; then + user_run $user $ZFS destroy $fs + if ! datasetexists $fs ; then + return 1 + fi + + # mount permission is required + log_must $ZFS allow $user mount $fs + user_run $user $ZFS destroy $fs + if datasetexists $fs ; then + return 1 + fi + fi + + return 0 +} + +function verify_fs_snapshot +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset snap=$fs@snap.$stamp + typeset mntpt=$(get_prop mountpoint $fs) + + if [[ "yes" == $(get_prop mounted $fs) ]]; then + log_must $ZFS umount $fs + fi + user_run $user $ZFS snapshot $snap + if datasetexists $snap ; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user $ZFS snapshot $snap + log_must $ZFS unallow $user mount $fs + if ! datasetexists $snap ; then + return 1 + fi + log_must $ZFS destroy $snap + + if [[ "no" == $(get_prop mounted $fs) ]]; then + log_must $ZFS mount $fs + fi + user_run $user $ZFS snapshot $snap + if datasetexists $snap ; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user $ZFS snapshot $snap + log_must $ZFS unallow $user mount $fs + if ! datasetexists $snap ; then + return 1 + fi + log_must $ZFS destroy $snap + + typeset snapdir=${mntpt}/$(get_snapdir_name)/snap.$stamp + user_run $user $MKDIR $snapdir + if datasetexists $snap ; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user $MKDIR $snapdir + log_must $ZFS unallow $user mount $fs + if ! datasetexists $snap ; then + return 1 + fi + log_must $ZFS destroy $snap + + return 0 +} + +function verify_fs_rollback +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset snap=$fs@snap.$stamp + typeset mntpt=$(get_prop mountpoint $fs) + + oldval=$(datasetcksum $fs) + log_must $ZFS snapshot $snap + + if ! ismounted $fs; then + log_must $ZFS mount $fs + fi + log_must $TOUCH $mntpt/testfile.$stamp + + user_run $user $ZFS rollback -R $snap + $SLEEP 10 + if is_global_zone ; then + if [[ $oldval == $(datasetcksum $fs) ]]; then + return 1 + fi + else + # datasetcksum can not be used in local zone + if [[ ! -e $mntpt/testfile.$stamp ]]; then + return 1 + fi + fi + + # rollback on mounted fs has to be with mount permission + log_must $ZFS allow $user mount $fs + user_run $user $ZFS rollback -R $snap + log_must $ZFS unallow $user mount $fs + $SLEEP 10 + if is_global_zone ; then + if [[ $oldval != $(datasetcksum $fs) ]]; then + return 1 + fi + else + # datasetcksum can not be used in local zone + if [[ -e $mntpt/testfile.$stamp ]]; then + return 1 + fi + fi + + return 0 +} + +function verify_fs_clone +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basefs=${fs%/*} + typeset snap=$fs@snap.$stamp + typeset clone=$basefs/cfs.$stamp + + log_must $ZFS snapshot $snap + user_run $user $ZFS clone $snap $clone + if datasetexists $clone ; then + return 1 + fi + + log_must $ZFS allow $user create $basefs + user_run $user $ZFS clone $snap $clone + log_must $ZFS unallow $user create $basefs + if datasetexists $clone ; then + return 1 + fi + + log_must $ZFS allow $user mount $basefs + user_run $user $ZFS clone $snap $clone + log_must $ZFS unallow $user mount $basefs + if datasetexists $clone ; then + return 1 + fi + + log_must $ZFS allow $user mount $basefs + log_must $ZFS allow $user create $basefs + user_run $user $ZFS clone $snap $clone + log_must $ZFS unallow $user create $basefs + log_must $ZFS unallow $user mount $basefs + if ! datasetexists $clone ; then + return 1 + fi + + log_must $ZFS destroy -R $snap + + return 0 +} + +function verify_fs_rename +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basefs=${fs%/*} + typeset snap=$fs@snap.$stamp + typeset renamefs=$basefs/nfs.$stamp + + if ! ismounted $fs; then + log_must $ZFS mount $fs + fi + + # case 1 + user_run $user $ZFS rename $fs $renamefs + if datasetexists $renamefs ; then + return 1 + fi + + # case 2 + log_must $ZFS allow $user create $basefs + user_run $user $ZFS rename $fs $renamefs + log_must $ZFS unallow $user create $basefs + if datasetexists $renamefs ; then + return 1 + fi + + # case 3 + log_must $ZFS allow $user mount $basefs + user_run $user $ZFS rename $fs $renamefs + log_must $ZFS unallow $user mount $basefs + if datasetexists $renamefs ; then + return 1 + fi + + # case 4 + log_must $ZFS allow $user mount $fs + user_run $user $ZFS rename $fs $renamefs + if datasetexists $renamefs ; then + log_must $ZFS unallow $user mount $renamefs + return 1 + fi + log_must $ZFS unallow $user mount $fs + + # case 5 + log_must $ZFS allow $user create $basefs + log_must $ZFS allow $user mount $fs + user_run $user $ZFS rename $fs $renamefs + log_must $ZFS unallow $user create $basefs + if datasetexists $renamefs ; then + log_must $ZFS unallow $user mount $renamefs + return 1 + fi + log_must $ZFS unallow $user mount $fs + + # case 6 + log_must $ZFS allow $user mount $basefs + log_must $ZFS allow $user mount $fs + user_run $user $ZFS rename $fs $renamefs + log_must $ZFS unallow $user mount $basefs + if datasetexists $renamefs ; then + log_must $ZFS unallow $user mount $renamefs + return 1 + fi + log_must $ZFS unallow $user mount $fs + + # case 7 + log_must $ZFS allow $user create $basefs + log_must $ZFS allow $user mount $basefs + user_run $user $ZFS rename $fs $renamefs + log_must $ZFS unallow $user mount $basefs + log_must $ZFS unallow $user create $basefs + if ! datasetexists $renamefs ; then + return 1 + fi + + log_must $ZFS rename $renamefs $fs + + return 0 +} + +function verify_fs_mount +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset mntpt=$(get_prop mountpoint $fs) + typeset newmntpt=$TMPDIR/mnt.$stamp + + if ismounted $fs ; then + user_run $user $ZFS unmount $fs + if ismounted $fs ; then + return 1 + fi + fi + + if ! ismounted $fs ; then + log_must $ZFS set mountpoint=$newmntpt $fs + log_must $RM -rf $newmntpt + log_must $MKDIR $newmntpt + + user_run $user $ZFS mount $fs + if ismounted $fs ; then + return 1 + fi + + # mountpoint's owner must be the user + log_must $CHOWN $user $newmntpt + user_run $user $ZFS mount $fs + if ! ismounted $fs ; then + return 1 + fi + log_must $ZFS umount $fs + log_must $RM -rf $newmntpt + log_must $ZFS set mountpoint=$mntpt $fs + fi + + return 0 +} + +function verify_fs_share +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset mntpt=$(get_prop mountpoint $fs) + + typeset stat=$($SVCS -H -o STA nfs/server:default) + if [[ $stat != "ON" ]]; then + log_note "Current nfs/server status: $stat" + # legacy share + user_run $user $SHARE $mntpt + if is_shared $fs; then + return 1 + fi + + # sharenfs=on + log_must $ZFS set sharenfs=on $fs + user_run $user $ZFS share $fs + if is_shared $fs; then + log_must $ZFS set sharenfs=off $fs + return 1 + fi + log_must $ZFS set sharenfs=off $fs + fi + + # turn on nfs/server service if it is not enabled + typeset tmpshare=$TMPDIR/a.${TESTCASE_ID} + $RM -rf $tmpshare + log_must $MKDIR -p $tmpshare + log_must $SHARE $tmpshare + + # legacy share + user_run $user $SHARE $mntpt + if ! is_shared $fs ; then + log_must $UNSHARE $tmpshare + log_must $RM -rf $tmpshare + return 1 + fi + + user_run $user $UNSHARE $mntpt + if is_shared $fs ; then + log_must $UNSHARE $tmpshare + log_must $RM -rf $tmpshare + return 1 + fi + + # sharenfs=on + log_must $ZFS set sharenfs=on $fs + user_run $user $ZFS share $fs + if ! is_shared $fs; then + log_must $ZFS set sharenfs=off $fs + return 1 + fi + + user_run $user $ZFS unshare $fs + if is_shared $fs; then + log_must $ZFS set sharenfs=off $fs + return 1 + fi + log_must $ZFS set sharenfs=off $fs + + log_must $UNSHARE $tmpshare + log_must $RM -rf $tmpshare + + return 0 +} + +function verify_fs_mountpoint +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset mntpt=$(get_prop mountpoint $fs) + typeset newmntpt=$TMPDIR/mnt.$stamp + + if ! ismounted $fs ; then + user_run $user $ZFS set mountpoint=$newmntpt $fs + if [[ $newmntpt != \ + $(get_prop mountpoint $fs) ]] ; then + return 1 + fi + log_must $ZFS set mountpoint=$mntpt $fs + fi + + if ismounted $fs ; then + user_run $user $ZFS set mountpoint=$newmntpt $fs + if [[ $mntpt != $(get_prop mountpoint $fs) ]] ; + then + return 1 + fi + + # require mount permission when fs is mounted + log_must $ZFS allow $user mount $fs + user_run $user $ZFS set mountpoint=$newmntpt $fs + log_must $ZFS unallow $user mount $fs + if [[ $newmntpt != \ + $(get_prop mountpoint $fs) ]] ; then + return 1 + fi + log_must $ZFS set mountpoint=$mntpt $fs + fi + + return 0 +} + +function verify_fs_promote +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basefs=${fs%/*} + typeset snap=$fs@snap.$stamp + typeset clone=$basefs/cfs.$stamp + + log_must $ZFS snapshot $snap + log_must $ZFS clone $snap $clone + log_must $ZFS promote $clone + + typeset fs_orig=$(get_prop origin $fs) + typeset clone_orig=$(get_prop origin $clone) + + user_run $user $ZFS promote $fs + # promote should fail if original fs does not have + # promote permission + if [[ $fs_orig != $(get_prop origin $fs) || \ + $clone_orig != $(get_prop origin $clone) ]]; then + return 1 + fi + + log_must $ZFS allow $user promote $clone + user_run $user $ZFS promote $fs + log_must $ZFS unallow $user promote $clone + if [[ $fs_orig != $(get_prop origin $fs) || \ + $clone_orig != $(get_prop origin $clone) ]]; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + user_run $user $ZFS promote $fs + log_must $ZFS unallow $user mount $fs + if [[ $fs_orig != $(get_prop origin $fs) || \ + $clone_orig != $(get_prop origin $clone) ]]; then + return 1 + fi + + log_must $ZFS allow $user mount $fs + log_must $ZFS allow $user promote $clone + user_run $user $ZFS promote $fs + log_must $ZFS unallow $user promote $clone + log_must $ZFS unallow $user mount $fs + if [[ $snap != $(get_prop origin $clone) || \ + $clone_orig != $(get_prop origin $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_fs_canmount +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + + if ! ismounted $fs ; then + set -A modes "on" "off" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $fs" + user_run $user $ZFS set $perm=${modes[$n]} $fs + if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; + then + return 1 + fi + fi + + + # fs is mounted + if ismounted $fs ; then + # property value does not change if + # no mount permission + set -A modes "on" "off" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $fs" + log_must $ZFS allow $user mount $fs + user_run $user $ZFS set $perm=${modes[$n]} $fs + log_must $ZFS unallow $user mount $fs + if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; + then + return 1 + fi + fi + + return 0 +} + +function verify_fs_recordsize +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset value8k=$(( 1024 * 8 )) + user_run $user $ZFS set recordsize=$value8k $fs + if [[ $value8k != $(get_prop recordsize $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_fs_quota +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset value32m=$(( 1024 * 1024 * 32 )) + user_run $user $ZFS set quota=$value32m $fs + if [[ $value32m != $(get_prop quota $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_fs_aclmode +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + set -A modes "discard" "groupmask" "passthrough" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "discard" ]]; then + n=1 + elif [[ $oldval == "groupmask" ]]; then + n=2 + elif [[ $oldval == "passthrough" ]]; then + n=0 + fi + log_note "$user $ZFS set aclmode=${modes[$n]} $fs" + user_run $user $ZFS set aclmode=${modes[$n]} $fs + if [[ ${modes[$n]} != $(get_prop aclmode $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_fs_aclinherit +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + # + # PSARC/2008/231 change the default value of aclinherit to "restricted" + # but still keep the old interface of "secure" + # + + typeset oldval + set -A modes "discard" "noallow" "secure" "passthrough" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "discard" ]]; then + n=1 + elif [[ $oldval == "noallow" ]]; then + n=2 + elif [[ $oldval == "secure" || $oldval == "restricted" ]]; then + n=3 + elif [[ $oldval == "passthrough" ]]; then + n=0 + fi + log_note "$user $ZFS set aclinherit=${modes[$n]} $fs" + user_run $user $ZFS set aclinherit=${modes[$n]} $fs + + typeset newval=$(get_prop aclinherit $fs) + if [[ ${modes[$n]} == "secure" && $newval == "restricted" ]]; then + return 0 + elif [[ ${modes[$n]} != $(get_prop aclinherit $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_fs_snapdir +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + set -A modes "visible" "hidden" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "visible" ]]; then + n=1 + elif [[ $oldval == "hidden" ]]; then + n=0 + fi + log_note "$user $ZFS set snapdir=${modes[$n]} $fs" + user_run $user $ZFS set snapdir=${modes[$n]} $fs + if [[ ${modes[$n]} != $(get_prop snapdir $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_fs_aedsx +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + set -A modes "on" "off" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $fs" + user_run $user $ZFS set $perm=${modes[$n]} $fs + if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_fs_zoned +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + set -A modes "on" "off" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $fs" + if is_global_zone ; then + if ! ismounted $fs ; then + user_run $user $ZFS set \ + $perm=${modes[$n]} $fs + if [[ ${modes[$n]} != \ + $(get_prop $perm $fs) ]]; then + return 1 + fi + if [[ $n -eq 0 ]]; then + log_mustnot $ZFS mount $fs + else + log_must $ZFS mount $fs + fi + fi + + if ismounted $fs; then + # n always is 1 in this case + user_run $user $ZFS set \ + $perm=${modes[$n]} $fs + if [[ $oldval != \ + $(get_prop $perm $fs) ]]; then + return 1 + fi + + # mount permission is needed + # to make zoned=on + log_must $ZFS allow $user mount $fs + user_run $user $ZFS set \ + $perm=${modes[$n]} $fs + log_must $ZFS unallow $user mount $fs + if [[ ${modes[$n]} != \ + $(get_prop $perm $fs) ]]; then + return 1 + fi + fi + fi + + if ! is_global_zone; then + user_run $user $ZFS set $perm=${modes[$n]} $fs + if [[ $oldval != $(get_prop $perm $fs) ]]; then + return 1 + fi + fi + + return 0 +} + +function verify_fs_sharenfs +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + set -A modes "on" "off" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $fs" + user_run $user $ZFS set $perm=${modes[$n]} $fs + if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then + return 1 + fi + log_must $ZFS set $perm=$oldval $fs + + # turn on nfs/server service if it is not enabled + typeset tmpshare=$TMPDIR/a.${TESTCASE_ID} + $RM -rf $tmpshare + log_must $MKDIR -p $tmpshare + log_must $SHARE $tmpshare + + log_note "$user $ZFS set $perm=${modes[$n]} $fs" + user_run $user $ZFS set $perm=${modes[$n]} $fs + if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then + return 1 + fi + + user_run $user $ZFS share $fs + if is_shared $fs; then + return 1 + fi + + # share permission is needed + log_must $ZFS allow $user share $fs + user_run $user $ZFS share $fs + log_must $ZFS unallow $user share $fs + + if [[ $n -eq 0 ]] && ! is_shared $fs ; then + log_must $UNSHARE $tmpshare + log_must $RM -rf $tmpshare + return 1 + fi + + if [[ $n -eq 1 ]] && is_shared $fs ; then + log_must $UNSHARE $tmpshare + log_must $RM -rf $tmpshare + return 1 + fi + + log_must $UNSHARE $tmpshare + log_must $RM -rf $tmpshare + + return 0 +} + +function verify_fs_shareiscsi +{ + typeset user=$1 + typeset perm=$2 + typeset fs=$3 + + typeset oldval + set -A modes "on" "off" + oldval=$(get_prop $perm $fs) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $fs" + user_run $user $ZFS set $perm=${modes[$n]} $fs + if [[ ${modes[$n]} != $(get_prop $perm $fs) ]]; then + return 1 + fi + + return 0 +} + +function verify_vol_destroy +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + user_run $user $ZFS destroy $vol + if ! datasetexists $vol ; then + return 1 + fi + + # mount permission is required + log_must $ZFS allow $user mount $vol + user_run $user $ZFS destroy $vol + if datasetexists $vol ; then + return 1 + fi + + return 0 +} + +function verify_vol_snapshot +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basevol=${vol%/*} + typeset snap=$vol@snap.$stamp + + user_run $user $ZFS snapshot $snap + if datasetexists $snap ; then + return 1 + fi + + log_must $ZFS allow $user mount $vol + user_run $user $ZFS snapshot $snap + log_must $ZFS unallow $user mount $vol + if ! datasetexists $snap ; then + return 1 + fi + + return 0 +} + +function verify_vol_rollback +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basevol=${vol%/*} + typeset snap=$vol@snap.$stamp + + typeset oldval + log_must $ZFS snapshot $snap + oldval=$(datasetcksum $vol) + + log_must $DD if=/dev/random of=/dev/zvol/rdsk/$vol \ + bs=512 count=1 + + user_run $user $ZFS rollback -R $snap + $SLEEP 10 + if [[ $oldval == $(datasetcksum $vol) ]]; then + return 1 + fi + + # rollback on volume has to be with mount permission + log_must $ZFS allow $user mount $vol + user_run $user $ZFS rollback -R $snap + $SLEEP 10 + log_must $ZFS unallow $user mount $vol + if [[ $oldval != $(datasetcksum $vol) ]]; then + return 1 + fi + + return 0 +} + +function verify_vol_clone +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basevol=${vol%/*} + typeset snap=$vol@snap.$stamp + typeset clone=$basevol/cvol.$stamp + + log_must $ZFS snapshot $snap + + user_run $user $ZFS clone $snap $clone + if datasetexists $clone ; then + return 1 + fi + + log_must $ZFS allow $user create $basevol + user_run $user $ZFS clone $snap $clone + log_must $ZFS unallow $user create $basevol + if datasetexists $clone ; then + return 1 + fi + + log_must $ZFS allow $user mount $basevol + user_run $user $ZFS clone $snap $clone + log_must $ZFS unallow $user mount $basevol + if datasetexists $clone ; then + return 1 + fi + + # require create permission on parent and + # mount permission on itself as well + log_must $ZFS allow $user mount $basevol + log_must $ZFS allow $user create $basevol + user_run $user $ZFS clone $snap $clone + log_must $ZFS unallow $user create $basevol + log_must $ZFS unallow $user mount $basevol + if ! datasetexists $clone ; then + return 1 + fi + + return 0 +} + +function verify_vol_rename +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basevol=${vol%/*} + typeset snap=$vol@snap.$stamp + typeset clone=$basevol/cvol.$stamp + typeset renamevol=$basevol/nvol.$stamp + + user_run $user $ZFS rename $vol $renamevol + if datasetexists $renamevol ; then + return 1 + fi + + log_must $ZFS allow $user create $basevol + user_run $user $ZFS rename $vol $renamevol + log_must $ZFS unallow $user create $basevol + if datasetexists $renamevol ; then + return 1 + fi + + log_must $ZFS allow $user mount $basevol + user_run $user $ZFS rename $vol $renamevol + log_must $ZFS unallow $user mount $basevol + if datasetexists $renamevol ; then + return 1 + fi + + # require both create permission on parent and + # mount permission on parent as well + log_must $ZFS allow $user mount $basevol + log_must $ZFS allow $user create $basevol + user_run $user $ZFS rename $vol $renamevol + log_must $ZFS unallow $user mount $basevol + log_must $ZFS unallow $user create $basevol + if ! datasetexists $renamevol ; then + return 1 + fi + + log_must $ZFS rename $renamevol $vol + + return 0 +} + +function verify_vol_promote +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset stamp=${perm}.${user}.$($DATE +'%F-%R:%S') + typeset basevol=${vol%/*} + typeset snap=$vol@snap.$stamp + typeset clone=$basevol/cvol.$stamp + + log_must $ZFS snapshot $snap + log_must $ZFS clone $snap $clone + log_must $ZFS promote $clone + + typeset vol_orig=$(get_prop origin $vol) + typeset clone_orig=$(get_prop origin $clone) + + # promote should fail if $vol and $clone + # miss either mount or promote permission + # case 1 + user_run $user $ZFS promote $vol + if [[ $vol_orig != $(get_prop origin $vol) || \ + $clone_orig != $(get_prop origin $clone) ]]; + then + return 1 + fi + + # promote should fail if $vol and $clone + # miss either mount or promote permission + # case 2 + log_must $ZFS allow $user promote $clone + user_run $user $ZFS promote $vol + log_must $ZFS unallow $user promote $clone + if [[ $vol_orig != $(get_prop origin $vol) || \ + $clone_orig != $(get_prop origin $clone) ]]; + then + return 1 + fi + + # promote should fail if $vol and $clone + # miss either mount or promote permission + # case 3 + log_must $ZFS allow $user mount $vol + user_run $user $ZFS promote $vol + log_must $ZFS unallow $user mount $vol + if [[ $vol_orig != $(get_prop origin $vol) || \ + $clone_orig != $(get_prop origin $clone) ]]; + then + return 1 + fi + + # promote should fail if $vol and $clone + # miss either mount or promote permission + # case 4 + log_must $ZFS allow $user mount $clone + user_run $user $ZFS promote $vol + log_must $ZFS unallow $user mount $clone + if [[ $vol_orig != $(get_prop origin $vol) || \ + $clone_orig != $(get_prop origin $clone) ]]; + then + return 1 + fi + + # promote should fail if $vol and $clone + # miss either mount or promote permission + # case 5 + log_must $ZFS allow $user promote $clone + log_must $ZFS allow $user mount $vol + user_run $user $ZFS promote $vol + log_must $ZFS unallow $user promote $clone + log_must $ZFS unallow $user mount $vol + if [[ $vol_orig != $(get_prop origin $vol) || \ + $clone_orig != $(get_prop origin $clone) ]]; + then + return 1 + fi + + # promote should fail if $vol and $clone + # miss either mount or promote permission + # case 6 + log_must $ZFS allow $user promote $clone + log_must $ZFS allow $user mount $clone + user_run $user $ZFS promote $vol + log_must $ZFS unallow $user promote $clone + log_must $ZFS unallow $user mount $vol + if [[ $vol_orig != $(get_prop origin $vol) || \ + $clone_orig != $(get_prop origin $clone) ]]; + then + return 1 + fi + + # promote should fail if $vol and $clone + # miss either mount or promote permission + # case 7 + log_must $ZFS allow $user mount $vol + log_must $ZFS allow $user mount $clone + user_run $user $ZFS promote $vol + log_must $ZFS unallow $user mount $vol + log_must $ZFS unallow $user mount $clone + if [[ $vol_orig != $(get_prop origin $vol) || \ + $clone_orig != $(get_prop origin $clone) ]]; + then + return 1 + fi + + # promote only succeeds when $vol and $clone + # have both mount and promote permission + # case 8 + log_must $ZFS allow $user promote $clone + log_must $ZFS allow $user mount $vol + log_must $ZFS allow $user mount $clone + user_run $user $ZFS promote $vol + log_must $ZFS unallow $user promote $clone + log_must $ZFS unallow $user mount $vol + log_must $ZFS unallow $user mount $clone + if [[ $snap != $(get_prop origin $clone) || \ + $clone_orig != $(get_prop origin $vol) ]]; then + return 1 + fi + + return 0 +} + +function verify_vol_volsize +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset oldval + oldval=$(get_prop volsize $vol) + (( newval = oldval * 2 )) + + typeset check_refrev=false + if support_refrev $vol; then + check_refrev=true + fi + typeset reserv_size + + if [[ $check_refrev == true ]]; then + reserv_size=$(get_prop refreservation $vol) + else + reserv_size=$(get_prop reservation $vol) + fi + + if [[ "0" == $reserv_size ]]; then + # sparse volume + user_run $user $ZFS set volsize=$newval $vol + if [[ $oldval == $(get_prop volsize $vol) ]]; + then + return 1 + fi + + else + # normal volume, reservation permission + # is required + user_run $user $ZFS set volsize=$newval $vol + if [[ $newval == $(get_prop volsize $vol) ]]; + then + return 1 + fi + + log_must $ZFS allow $user reservation $vol + if [[ $check_refrev == true ]]; then + log_must $ZFS allow $user refreservation $vol + fi + user_run $user $ZFS set volsize=$newval $vol + log_must $ZFS unallow $user reservation $vol + if [[ $check_refrev == true ]]; then + log_must $ZFS unallow $user refreservation $vol + fi + if [[ $oldval == $(get_prop volsize $vol) ]]; + then + return 1 + fi + fi + + return 0 +} + +function verify_vol_shareiscsi +{ + typeset user=$1 + typeset perm=$2 + typeset vol=$3 + + typeset oldval + set -A modes "on" "off" + oldval=$(get_prop $perm $vol) + if [[ $oldval == "on" ]]; then + n=1 + elif [[ $oldval == "off" ]]; then + n=0 + fi + log_note "$user $ZFS set $perm=${modes[$n]} $vol" + user_run $user $ZFS set $perm=${modes[$n]} $vol + if [[ ${modes[$n]} != $(get_prop $perm $vol) ]]; then + return 1 + fi + + iscsitgt_setup + + if [[ $n -eq 1 ]] && is_iscsi_target $vol ; then + iscsitgt_cleanup + return 1 + fi + + if [[ $n -eq 0 ]] && ! is_iscsi_target $vol ; then + iscsitgt_cleanup + return 1 + fi + + iscsitgt_cleanup + + return 0 +} + +function verify_allow +{ + typeset user=$1 + typeset perm=$2 + typeset dtst=$3 + + typeset -i ret + + user_run $user $ZFS allow $user allow $dtst + ret=$? + if [[ $ret -eq 0 ]]; then + return 1 + fi + + log_must $ZFS allow $user copies $dtst + user_run $user $ZFS allow $user copies $dtst + ret=$? + log_must $ZFS unallow $user copies $dtst + if [[ $ret -eq 1 ]]; then + return 1 + fi + + return 0 + +} + +function support_refrev +{ + typeset dataset=$1 + + $ZFS get refreservation $dataset > /dev/null 2>&1 + if (( $? != 0 )); then + return 1 + fi + + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/delegate/setup.ksh b/tests/sys/cddl/zfs/tests/delegate/setup.ksh new file mode 100644 index 00000000000..aeb9bcca5ac --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/setup.ksh @@ -0,0 +1,50 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +cleanup_user_group + +# Create staff group and add two user to it +log_must add_group $STAFF_GROUP +log_must add_user $STAFF_GROUP $STAFF1 +log_must add_user $STAFF_GROUP $STAFF2 + +# Create other group and add two user to it +log_must add_group $OTHER_GROUP +log_must add_user $OTHER_GROUP $OTHER1 +log_must add_user $OTHER_GROUP $OTHER2 + +DISK=${DISKS%% *} +default_volume_setup $DISK +log_must $CHMOD 777 $TESTDIR + +log_pass diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_001_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_001_pos.ksh new file mode 100644 index 00000000000..fdc9b7f0011 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_001_pos.ksh @@ -0,0 +1,119 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_001_pos.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_001_pos +# +# DESCRIPTION: +# "everyone" is interpreted as the keyword "everyone" whatever the same +# name user or group is existing. +# +# STRATEGY: +# 1. Create user 'everyone'. +# 2. Verify 'everyone' is interpreted as keywords. +# 3. Create group 'everyone'. +# 4. Verify 'everyone' is interpreted as keywords. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-14) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if [[ $user_added == "TRUE" ]] ; then + del_user everyone + fi + if [[ $group_added == "TRUE" ]] ; then + del_group everyone + fi + + restore_root_datasets +} + +log_assert "everyone' is interpreted as a keyword even if a user " \ + "or group named 'everyone' exists." +log_onexit cleanup + +eval set -A dataset $DATASETS +enc=$(get_prop encryption $dataset) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + typeset perms="snapshot,reservation,compression,send,allow,\ +userprop" +else + typeset perms="snapshot,reservation,compression,checksum,\ +send,allow,userprop" +fi + +log_note "Create a user called 'everyone'." +if ! $ID everyone > /dev/null 2>&1; then + user_added="TRUE" + log_must $USERADD everyone +fi +for dtst in $DATASETS ; do + log_must $ZFS allow everyone $perms $dtst + log_must verify_perm $dtst $perms $EVERYONE "everyone" +done +log_must restore_root_datasets +if [[ $user_added == "TRUE" ]]; then + log_must $USERDEL everyone +fi + +log_note "Created a group called 'everyone'." +if ! $CAT /etc/group | $AWK -F: '{print $1}' | \ + $GREP -w 'everyone' > /dev/null 2>&1 +then + group_added="TRUE" + log_must $GROUPADD everyone +fi + +for dtst in $DATASETS ; do + log_must $ZFS allow everyone $perms $dtst + log_must verify_perm $dtst $perms $EVERYONE +done +log_must restore_root_datasets +if [[ $group_added == "TRUE" ]]; then + log_must $GROUPDEL everyone +fi + +log_pass "everyone is always interpreted as keyword passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_002_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_002_pos.ksh new file mode 100644 index 00000000000..ed1648c447a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_002_pos.ksh @@ -0,0 +1,100 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_002_pos.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_002_pos +# +# DESCRIPTION: +# argument is interpreted as a user if possible, then as a group as +# possible. +# +# STRATEGY: +# 1. Create user $STAFF_GROUP +# 2. Delegate permissions to $STAFF_GROUP +# 3. Verify user $STAFF_GROUP has the permissions. +# 4. Delete user $STAFF_GROUP and allow the permission to $STAFF_GROUP +# 5. Verify $STAFF_GROUP is interpreted as group. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-14) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if $ID $STAFF_GROUP > /dev/null 2>&1; then + log_must del_user $STAFF_GROUP + fi + + restore_root_datasets +} + +log_assert " is interpreted as user if possible, then as group." +log_onexit cleanup + +eval set -A dataset $DATASETS +enc=$(get_prop encryption $dataset) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + typeset perms="snapshot,reservation,compression,send,allow,\ +userprop" +else + typeset perms="snapshot,reservation,compression,checksum,\ +send,allow,userprop" +fi + +log_must $USERADD $STAFF_GROUP +for dtst in $DATASETS ; do + log_must $ZFS allow $STAFF_GROUP $perms $dtst + log_must verify_perm $dtst $perms $STAFF_GROUP + log_must verify_noperm $dtst $perms $STAFF1 $STAFF2 +done + +log_must restore_root_datasets + +log_must del_user $STAFF_GROUP +for dtst in $datasets ; do + log_must $ZFS allow $STAFF_GROUP $perms $dtst + log_must verify_perm $dtst $perms $STAFF1 $STAFF2 +done + +log_pass " is interpreted as user if possible, then as group passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_003_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_003_pos.ksh new file mode 100644 index 00000000000..6bc558ae9d5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_003_pos.ksh @@ -0,0 +1,118 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_003_pos.ksh 1.4 09/08/06 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_003_pos +# +# DESCRIPTION: +# Verify option '-l' only allow permission to the dataset itself. +# +# STRATEGY: +# 1. Create descendent datasets of $ROOT_TESTFS +# 2. Select user, group and everyone and set local permission separately. +# 3. Set locally permissions to $ROOT_TESTFS or $ROOT_TESTVOL. +# 4. Verify the permissions are only allow on $ROOT_TESTFS or +# $ROOT_TESTVOL. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify option '-l' only allow permission to the dataset itself." +log_onexit restore_root_datasets + +childfs=$ROOT_TESTFS/childfs + +eval set -A dataset $DATASETS +enc=$(get_prop encryption $dataset) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + typeset perms="snapshot,reservation,compression,allow,\ +userprop" +else + typeset perms="snapshot,reservation,compression,checksum,\ +allow,userprop" +fi + +if check_version "5.10" ; then + perms="${perms},send" +fi + +log_must $ZFS create $childfs + +for dtst in $DATASETS ; do + log_must $ZFS allow -l $STAFF1 $perms $dtst + log_must verify_perm $dtst $perms $STAFF1 + if [[ $dtst == $ROOT_TESTFS ]] ; then + log_must verify_noperm $childfs $perms \ + $STAFF1 $STAFF2 $OTHER1 $OTHER2 + fi +done + +log_must restore_root_datasets + +log_must $ZFS create $childfs +for dtst in $DATASETS ; do + log_must $ZFS allow -l -g $STAFF_GROUP $perms $dtst + log_must verify_perm $dtst $perms $STAFF1 $STAFF2 + if [[ $dtst == $ROOT_TESTFS ]] ; then + log_must verify_noperm $childfs $perms \ + $STAFF1 $STAFF2 $OTHER1 $OTHER2 + fi +done + +log_must restore_root_datasets + +log_must $ZFS create $childfs +for dtst in $DATASETS ; do + log_must $ZFS allow -l -e $perms $dtst + log_must verify_perm $dtst $perms $STAFF1 $STAFF2 $OTHER1 $OTHER2 + if [[ $dtst == $ROOT_TESTFS ]] ; then + log_must verify_noperm $childfs $perms \ + $STAFF1 $STAFF2 $OTHER1 $OTHER2 + fi +done + +log_must restore_root_datasets + +log_pass "Verify option '-l' only allow permission to the dataset itself pass." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_004_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_004_pos.ksh new file mode 100644 index 00000000000..7f0b4ae3acd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_004_pos.ksh @@ -0,0 +1,121 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_004_pos.ksh 1.4 09/08/06 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_004_pos +# +# DESCRIPTION: +# Verify option '-d' allow permission to the descendent datasets, and not +# for this dataset itself. +# +# STRATEGY: +# 1. Create descendent datasets of $ROOT_TESTFS +# 2. Select user, group and everyone and set descendent permission +# separately. +# 3. Set descendent permissions to $ROOT_TESTFS or $ROOT_TESTVOL. +# 4. Verify those permissions are allowed to $ROOT_TESTFS's +# descendent dataset. +# 5. Verify the permissions are not allowed to $ROOT_TESTFS or +# $ROOT_TESTVOL. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify option '-d' allow permission to the descendent datasets." +log_onexit restore_root_datasets + +childfs=$ROOT_TESTFS/childfs + +eval set -A dataset $DATASETS +enc=$(get_prop encryption $dataset) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + typeset perms="snapshot,reservation,compression,allow,\ +userprop" +else + typeset perms="snapshot,reservation,compression,checksum,\ +allow,userprop" +fi + +if check_version "5.10" ; then + perms="${perms},send" +fi + +# Verify option '-d' only affect sub-datasets +log_must $ZFS create $childfs +for dtst in $DATASETS ; do + log_must $ZFS allow -d $STAFF1 $perms $dtst + log_must verify_noperm $dtst $perms $STAFF1 + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must verify_perm $childfs $perms $STAFF1 + fi +done + +log_must restore_root_datasets + +# Verify option '-d + -g' affect group in sub-datasets. +log_must $ZFS create $childfs +for dtst in $DATASETS ; do + log_must $ZFS allow -d -g $STAFF_GROUP $perms $dtst + log_must verify_noperm $dtst $perms $STAFF2 + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must verify_perm $childfs $perms $STAFF2 + fi +done + +log_must restore_root_datasets + +# Verify option '-d + -e' affect everyone in sub-datasets. +log_must $ZFS create $childfs +for dtst in $DATASETS ; do + log_must $ZFS allow -d -e $perms $dtst + log_must verify_noperm $dtst $perms $OTHER1 $OTHER2 + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must verify_perm $childfs $perms $OTHER1 $OTHER2 + fi +done + +log_must restore_root_datasets + +log_pass "Verify option '-d' allow permission to the descendent datasets pass." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_005_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_005_pos.ksh new file mode 100644 index 00000000000..83aaa046749 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_005_pos.ksh @@ -0,0 +1,103 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_005_pos.ksh 1.4 09/08/06 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_005_pos +# +# DESCRIPTION: +# Verify option '-c' will be granted locally to the creator on any +# newly-created descendent file systems. +# +# STRATEGY: +# 1. Allow create permissions to everyone on $ROOT_TESTFS locally. +# 2. Allow '-c' create to $ROOT_TESTFS. +# 3. chmod 777 the mountpoint of $ROOT_TESTFS +# 4. Verify only creator can create descendent dataset on +# $ROOT_TESTFS/$user. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify option '-c' will be granted locally to the creator." +log_onexit restore_root_datasets + +eval set -A dataset $DATASETS +enc=$(get_prop encryption $dataset) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + typeset perms="snapshot,reservation,compression,allow,\ +userprop" +else + typeset perms="snapshot,reservation,compression,checksum,\ +allow,userprop" +fi + +if check_version "5.10" ; then + perms="${perms},send" +fi + +log_must $ZFS allow -l everyone create,mount $ROOT_TESTFS +log_must $ZFS allow -c $perms $ROOT_TESTFS + +mntpnt=$(get_prop mountpoint $ROOT_TESTFS) +log_must $CHMOD 777 $mntpnt + +for user in $EVERYONE; do + childfs=$ROOT_TESTFS/$user + + user_run $user $ZFS create $childfs + + for other in $EVERYONE; do + # + # Verify only the creator has the $perm time permissions. + # + if [[ $other == $user ]]; then + log_must verify_perm $childfs $perms $user + else + log_must verify_noperm $childfs $perms $other + fi + done +done + +log_pass "Verify option '-c' will be granted locally to the creator passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_006_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_006_pos.ksh new file mode 100644 index 00000000000..d726bb170c6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_006_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_006_pos.ksh 1.2 08/11/03 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_006_pos +# +# DESCRIPTION: +# Changing permissions in a set will change what is allowed wherever the +# set is used. +# +# STRATEGY: +# 1. Set create as set @basic. +# 2. Allow set @basic to $STAFF1 on $ROOT_TESTFS or $ROOT_TESTVOL +# 3. Verify $STAFF1 has create permissions. +# 4. Reset snapshot,allow to $basic +# 5. Verify now $STAFF1 have create,allow,destroy permissions. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Changing permissions in a set will change what is allowed " \ + "wherever the set is used." +log_onexit restore_root_datasets + +fs1=$ROOT_TESTFS/fs1; fs2=$ROOT_TESTFS/fs2 +log_must $ZFS create $fs1 +log_must $ZFS create $fs2 + +eval set -A dataset $DATASETS +enc=$(get_prop encryption $dataset) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + perms1="snapshot,checksum,reservation" +else + perms1="snapshot,reservation" +fi + +for dtst in $DATASETS $fs1 $fs2; do + log_must $ZFS allow -s @basic $perms1 $dtst + log_must $ZFS allow $STAFF1 @basic $dtst + log_must verify_perm $dtst $perms1 $STAFF1 +done + +perms2="allow,send,compression,userprop" +for dtst in $DATASETS $fs1 $fs2; do + log_must $ZFS allow -s @basic $perms2 $dtst + log_must verify_perm $dtst ${perms1},${perms2} $STAFF1 +done + +log_pass "Changing permissions in a set will change what is allowed passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_007_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_007_pos.ksh new file mode 100644 index 00000000000..00d6d8b0210 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_007_pos.ksh @@ -0,0 +1,122 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_007_pos.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_007_pos +# +# DESCRIPTION: +# Verify the permissions set will be masked on its descendent +# datasets by same name set. +# +# STRATEGY: +# 1. Create $ROOT_TESTFS/childfs +# 2. Set permission $perms1 to @set on $ROOT_TESTFS +# 3. Reset permission $perms2 to @set on $ROOT_TESTFS/childfs +# 4. Allow @set to $STAFF1 on $ROOT_TESTFS/childfs +# 5. Verify $perms2 is delegated on $ROOT_TESTFS/childfs and its +# descendent. +# 6. Allow @set to $STAFF1 on $ROOT_TESTFS +# 7. Verify $perms1 is not appended to $STAFF1 on $ROOT_TESTFS/childfs and +# its descendent since it is masked +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify permission set can be masked on descendent dataset." +log_onexit restore_root_datasets + +typeset perms1="snapshot,reservation,compression" +eval set -A dataset $DATASETS +enc=$(get_prop encryption $dataset) +if [[ $? -eq 0 ]] && [[ -n "$enc" ]] && [[ "$enc" != "off" ]]; then + typeset perms2="send,allow,userprop" +else + typeset perms2="checksum,send,allow,userprop" +fi + +# +# Define three level filesystems +# +childfs=$ROOT_TESTFS/childfs +grandchild=$childfs/grandchild +log_must $ZFS create $childfs +log_must $ZFS create $grandchild + +# +# Setting different permissions to the same set on two level. +# But only assign the user at one level. +# +log_must $ZFS allow -s @set $perms1 $ROOT_TESTFS +log_must $ZFS allow -s @set $perms2 $childfs +log_must $ZFS allow $STAFF1 @set $childfs + +# +# Verify only perms2 is valid to user on the level which he was assigned. +# +log_must verify_noperm $ROOT_TESTFS $perms1 $STAFF1 +for fs in $childfs $grandchild ; do + log_must verify_noperm $childfs $perms1 $STAFF1 + log_must verify_perm $childfs $perms2 $STAFF1 +done + +# +# Delegate @set to STAFF1 on ROOT_TESTFS, verify $perms1 will not be appended +# to its descendent datasets since it is masked +# +log_must $ZFS allow $STAFF1 @set $ROOT_TESTFS +log_must verify_perm $ROOT_TESTFS $perms1 $STAFF1 +for fs in $childfs $grandchild ; do + log_must verify_noperm $childfs $perms1 $STAFF1 + log_must verify_perm $childfs $perms2 $STAFF1 +done + +# Remove the mask, $perms1 will be allowed to its descendent datasets +log_must $ZFS unallow -s @set $childfs +for fs in $childfs $grandchild ; do + log_must verify_noperm $childfs $perms2 $STAFF1 + log_must verify_perm $childfs $perms1 $STAFF1 +done + +log_pass "Verify permission set can be masked on descendetn dataset pass." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_008_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_008_pos.ksh new file mode 100644 index 00000000000..75897ed9379 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_008_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_008_pos.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_008_pos +# +# DESCRIPTION: +# non-root user can allow any permissions which he is holding to +# other else user when it get 'allow' permission. +# +# STRATEGY: +# 1. Set two set permissions to two datasets locally. +# 2. Verify the non-root user can allow permission if he has allow +# permission. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify non-root user can allow permissions." +log_onexit restore_root_datasets + +perms1="snapshot,reservation" +perms2="send,compression,checksum,userprop" +childfs=$ROOT_TESTFS/childfs + +log_must $ZFS create $childfs + +for dtst in $DATASETS ; do + # Delegate local permission to $STAFF1 + log_must $ZFS allow -l $STAFF1 $perms1 $dtst + log_must $ZFS allow -l $STAFF1 allow $dtst + + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must $ZFS allow -l $STAFF1 $perms2 $childfs + # $perms1 is local permission in $ROOT_TESTFS + log_mustnot user_run $STAFF1 $ZFS allow $OTHER1 $perms1 $childfs + log_must verify_noperm $childfs $perms1 $OTHER1 + fi + + # Verify 'allow' give non-privilege user delegated permission. + log_must user_run $STAFF1 $ZFS allow -l $OTHER1 $perms1 $dtst + log_must verify_perm $dtst $perms1 $OTHER1 + + # $perms2 was not allow to $STAFF1, so he have no permission to + # delegate permission to other else. + log_mustnot user_run $STAFF1 $ZFS allow $OTHER1 $perms2 $dtst + log_must verify_noperm $dtst $perms2 $OTHER1 +done + +log_pass "Verify non-root user can allow permissions passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_009_neg.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_009_neg.ksh new file mode 100644 index 00000000000..96ba0bfede5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_009_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_009_neg.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_009_neg +# +# DESCRIPTION: +# zfs allow can deal with invalid arguments.(Invalid options or combination) +# +# STRATEGY: +# 1. Verify invalid argumets will cause error. +# 2. Verify non-optional argument was missing will cause error. +# 3. Verify invalid options cause error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify invalid arguments are handled correctly." +log_onexit restore_root_datasets + +# Permission sets are limited to 64 characters in length. +longset="set123456789012345678901234567890123456789012345678901234567890123" +for dtst in $DATASETS ; do + log_mustnot eval "$ZFS allow -s @$longset $dtst" + # Create non-existent permission set + typeset timestamp=$($DATE +'%F-%R:%S') + log_mustnot $ZFS allow -s @non-existent $dtst + log_mustnot $ZFS allow $STAFF "atime,created,mounted" $dtst + log_mustnot $ZFS allow $dtst $TESTPOOL + log_mustnot $ZFS allow -c $dtst + log_mustnot $ZFS allow -u $STAFF1 $dtst + log_mustnot $ZFS allow -u $STAFF1 -g $STAFF_GROUP "create,destroy" $dtst + log_mustnot $ZFS allow -u $STAFF1 -e "mountpoint" $dtst +done + +log_pass "Invalid arguments are handled correctly." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_010_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_010_pos.ksh new file mode 100644 index 00000000000..f03e559bc6d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_010_pos.ksh @@ -0,0 +1,128 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_010_pos.ksh 1.3 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_010_pos +# +# DESCRIPTION: +# Scan the following permissions one by one to verify privileged user +# has correct permission delegation in datasets. +# +# STRATEGY: +# 1. Delegate all the permission one by one to user on dataset. +# 2. Verify privileged user has correct permission without any other +# permissions allowed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-11-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify privileged user has correct permissions once which was "\ + "delegated to him in datasets" +log_onexit restore_root_datasets + +# +# Results in Results in +# Permission Filesystem Volume +# +set -A perms create true false \ + snapshot true true \ + mount true false \ + send true true \ + allow true true \ + quota true false \ + reservation true true \ + recordsize true false \ + mountpoint true false \ + checksum true true \ + compression true true \ + canmount true false \ + atime true false \ + devices true false \ + exec true false \ + volsize false true \ + setuid true false \ + readonly true true \ + snapdir true false \ + userprop true true \ + aclmode true false \ + aclinherit true false \ + rollback true true \ + clone true true \ + rename true true \ + promote true true \ + zoned true false \ + shareiscsi true true \ + xattr true false \ + receive true false \ + destroy true true +if is_global_zone; then + typeset -i n=${#perms[@]} + perms[((n))]="sharenfs"; perms[((n+1))]="true"; perms[((n+2))]="false" + perms[((n+3))]="share"; perms[((n+4))]="true"; perms[((n+5))]="false" +fi + +for dtst in $DATASETS; do + typeset -i k=1 + typeset type=$(get_prop type $dtst) + [[ $type == "volume" ]] && k=2 + + typeset -i i=0 + while (( i < ${#perms[@]} )); do + log_must $ZFS allow $STAFF1 ${perms[$i]} $dtst + + if [[ ${perms[((i+k))]} == "true" ]]; then + log_must verify_perm $dtst ${perms[$i]} $STAFF1 + else + log_must verify_noperm $dtst ${perms[$i]} $STAFF1 + fi + + log_must restore_root_datasets + + ((i += 3)) + done +done + +log_pass "Verify privileged user has correct permissions " \ + "in datasets passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_011_neg.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_011_neg.ksh new file mode 100644 index 00000000000..d1d4539f152 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_011_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_011_neg.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_011_neg +# +# DESCRIPTION: +# Verify zpool subcmds and system readonly properties can't be delegated. +# +# STRATEGY: +# 1. Loop all the zpool subcmds and readonly properties, except permission +# 'create' & 'destroy'. +# 2. Verify those subcmd or properties can't be delegated. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify zpool subcmds and system readonly properties can't be " \ + "delegated." +log_onexit restore_root_datasets + +set -A invalid_perms \ + add remove list iostat \ + status offline online clear \ + attach detach replace scrub \ + export import upgrade \ + type creation used available \ + referenced compressratio mounted + +for dtst in $DATASETS ; do + typeset -i i=0 + + while ((i < ${#invalid_perms[@]})); do + log_mustnot $ZFS allow $STAFF1 ${invalid_perms[$i]} $dtst + + ((i += 1)) + done +done + +log_pass "Verify zpool subcmds and system readonly properties passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_012_neg.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_012_neg.ksh new file mode 100644 index 00000000000..6a25ab10529 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_012_neg.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_allow_012_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_allow_012_neg +# +# DESCRIPTION: +# Scan all permissions one by one to verify privileged user +# can not use permissions properly when delegation property is set off +# +# STRATEGY: +# 1. Delegate all the permission one by one to user on dataset. +# 2. Verify privileged user can not use permissions properly when +# delegation property is off +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + log_must $ZPOOL set delegation=on $TESTPOOL + log_must restore_root_datasets +} + +log_assert "Verify privileged user can not use permissions properly when " \ + "delegation property is set off" +log_onexit cleanup + + +set -A perms create snapshot mount send allow quota reservation \ + recordsize mountpoint checksum compression canmount atime \ + devices exec volsize setuid readonly snapdir userprop \ + aclmode aclinherit rollback clone rename promote \ + zoned shareiscsi xattr receive destroy sharenfs share + +log_must $ZPOOL set delegation=off $TESTPOOL + +for dtst in $DATASETS; do + typeset -i i=0 + while (( i < ${#perms[@]} )); do + + log_must $ZFS allow $STAFF1 ${perms[$i]} $dtst + log_must verify_noperm $dtst ${perms[$i]} $STAFF1 + + log_must restore_root_datasets + ((i += 1)) + done +done + +log_pass "Verify privileged user can not use permissions properly when " \ + "delegation property is set off" diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_allow_test.sh b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_test.sh new file mode 100755 index 00000000000..d30eaa73ae3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_allow_test.sh @@ -0,0 +1,356 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_allow_001_pos cleanup +zfs_allow_001_pos_head() +{ + atf_set "descr" "everyone' is interpreted as a keyword even if a useror group named 'everyone' exists." + atf_set "require.progs" zfs svcs +} +zfs_allow_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_002_pos cleanup +zfs_allow_002_pos_head() +{ + atf_set "descr" " is interpreted as user if possible, then as group." + atf_set "require.progs" zfs svcs +} +zfs_allow_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_003_pos cleanup +zfs_allow_003_pos_head() +{ + atf_set "descr" "Verify option '-l' only allow permission to the dataset itself." + atf_set "require.progs" zfs svcs +} +zfs_allow_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_004_pos cleanup +zfs_allow_004_pos_head() +{ + atf_set "descr" "Verify option '-d' allow permission to the descendent datasets." + atf_set "require.progs" zfs svcs +} +zfs_allow_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_005_pos cleanup +zfs_allow_005_pos_head() +{ + atf_set "descr" "Verify option '-c' will be granted locally to the creator." + atf_set "require.progs" zfs svcs runwattr +} +zfs_allow_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_006_pos cleanup +zfs_allow_006_pos_head() +{ + atf_set "descr" "Changing permissions in a set will change what is allowedwherever the set is used." + atf_set "require.progs" zfs svcs +} +zfs_allow_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_007_pos cleanup +zfs_allow_007_pos_head() +{ + atf_set "descr" "Verify permission set can be masked on descendent dataset." + atf_set "require.progs" zfs svcs +} +zfs_allow_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_007_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_008_pos cleanup +zfs_allow_008_pos_head() +{ + atf_set "descr" "Verify non-root user can allow permissions." + atf_set "require.progs" zfs svcs runwattr +} +zfs_allow_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_008_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_009_neg cleanup +zfs_allow_009_neg_head() +{ + atf_set "descr" "Verify invalid arguments are handled correctly." + atf_set "require.progs" zfs svcs +} +zfs_allow_009_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_009_neg.ksh || atf_fail "Testcase failed" +} +zfs_allow_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_010_pos cleanup +zfs_allow_010_pos_head() +{ + atf_set "descr" "Verify privileged user has correct permissions once which wasdelegated to him in datasets" + atf_set "require.progs" zfs svcs +} +zfs_allow_010_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_010_pos.ksh || atf_fail "Testcase failed" +} +zfs_allow_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_011_neg cleanup +zfs_allow_011_neg_head() +{ + atf_set "descr" "Verify zpool subcmds and system readonly properties can't bedelegated." + atf_set "require.progs" zfs svcs +} +zfs_allow_011_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_011_neg.ksh || atf_fail "Testcase failed" +} +zfs_allow_011_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_allow_012_neg cleanup +zfs_allow_012_neg_head() +{ + atf_set "descr" "Verify privileged user can not use permissions properly whendelegation property is set off" + atf_set "require.progs" zfs zpool svcs +} +zfs_allow_012_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_allow_012_neg.ksh || atf_fail "Testcase failed" +} +zfs_allow_012_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_allow_001_pos + atf_add_test_case zfs_allow_002_pos + atf_add_test_case zfs_allow_003_pos + atf_add_test_case zfs_allow_004_pos + atf_add_test_case zfs_allow_005_pos + atf_add_test_case zfs_allow_006_pos + atf_add_test_case zfs_allow_007_pos + atf_add_test_case zfs_allow_008_pos + atf_add_test_case zfs_allow_009_neg + atf_add_test_case zfs_allow_010_pos + atf_add_test_case zfs_allow_011_neg + atf_add_test_case zfs_allow_012_neg +} diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_001_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_001_pos.ksh new file mode 100644 index 00000000000..5e68c7cfbea --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_001_pos.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_001_pos.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_001_pos +# +# DESCRIPTION: +# Verify '-l' only removed the local permissions. +# +# STRATEGY: +# 1. Set up unallow test model. +# 2. Implement unallow -l to $ROOT_TESTFS or $TESTVOL +# 3. Verify '-l' only remove the local permissions. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify '-l' only removed the local permissions." +log_onexit restore_root_datasets + +log_must setup_unallow_testenv + +for dtst in $DATASETS ; do + log_must $ZFS unallow -l $STAFF1 $dtst + log_must verify_noperm $dtst $LOCAL_SET $STAFF1 + + log_must $ZFS unallow -l $OTHER1 $dtst + log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1 + + log_must verify_perm $dtst $LOCAL_DESC_SET $OTHER2 + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER1 $OTHER2 + log_must verify_perm $SUBFS $DESC_SET $STAFF2 + fi +done + +log_pass "Verify '-l' only removed the local permissions passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_002_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_002_pos.ksh new file mode 100644 index 00000000000..4cd5c67273e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_002_pos.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_002_pos.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_002_pos +# +# DESCRIPTION: +# Verify '-d' only remove the permissions on descendent filesystem. + +# STRATEGY: +# 1. Set up unallow test model. +# 2. Implement unallow -d to $ROOT_TESTFS +# 3. Verify '-d' only remove the permissions on descendent filesystem. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify '-d' only removed the descendent permissions." +log_onexit restore_root_datasets + +log_must setup_unallow_testenv + +log_must $ZFS unallow -d $STAFF2 $ROOT_TESTFS +log_must verify_noperm $SUBFS $DESC_SET $STAFF2 + +log_must $ZFS unallow -d $OTHER1 $ROOT_TESTFS +log_must verify_noperm $SUBFS $LOCAL_DESC_SET $OTHER1 +log_must verify_perm $ROOT_TESTFS $LOCAL_DESC_SET $OTHER1 + +log_must verify_perm $ROOT_TESTFS $LOCAL_DESC_SET $OTHER2 +log_must verify_perm $SUBFS $LOCAL_DESC_SET $OTHER2 + +log_pass "Verify '-d' only removed the descendent permissions passed" diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_003_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_003_pos.ksh new file mode 100644 index 00000000000..6af70a2ccb1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_003_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_003_pos.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_003_pos +# +# DESCRIPTION: +# Verify options '-r' or '-l' + '-d' will unallow permission to this +# dataset and the descendent datasets. +# +# STRATEGY: +# 1. Set up unallow test model. +# 2. Implement unallow -l -d to $ROOT_TESTFS or $ROOT_TESTVOL without +# options. +# 3. Verify '-l' + '-d' will unallow local + descendent permission. +# 4. Verify '-r' will unallow local + descendent permission. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify options '-r' and '-l'+'-d' will unallow permission to " \ + "this dataset and the descendent datasets." +log_onexit restore_root_datasets + +log_must setup_unallow_testenv + +for dtst in $DATASETS ; do + log_must $ZFS unallow $STAFF1 $dtst + log_must $ZFS unallow -l -d $STAFF2 $dtst + log_must verify_noperm $dtst $LOCAL_SET $STAFF1 + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must verify_noperm $SUBFS $DESC_SET $STAFF2 + fi + + log_must $ZFS unallow -l -d $OTHER1 $dtst + log_must $ZFS unallow -r $OTHER2 $dtst + log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1 $OTHER2 + if [[ $dtst == $ROOT_TESTFS ]]; then + log_must verify_noperm $SUBFS $LOCAL_DESC_SET $OTHER1 $OTHER2 + fi +done + +log_pass "Verify options '-r' and '-l'+'-d' function passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_004_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_004_pos.ksh new file mode 100644 index 00000000000..944cfc5c5d7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_004_pos.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_004_pos.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_004_pos +# +# DESCRIPTION: +# Verify '-s' will remove permissions from the named set. +# +# STRATEGY: +# 1. Set @basic set to $ROOT_TESTFS or $ROOT_TESTVOL and allow @basic +# to $STAFF1 +# 2. Verify $STAFF1 have @basic permissions. +# 3. Verify '-s' will remove permission from the named set. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify '-s' will remove permissions from the named set." +log_onexit restore_root_datasets + +for dtst in $DATASETS ; do + log_must $ZFS allow -s @basic $LOCAL_DESC_SET $dtst + log_must $ZFS allow -u $STAFF1 @basic $dtst + + log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1 + log_must $ZFS unallow -s @basic $LOCAL_DESC_SET $dtst + log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF1 +done + +log_pass "Verify '-s' will remove permissions from the named set passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_005_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_005_pos.ksh new file mode 100644 index 00000000000..82dbe2553d3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_005_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_005_pos.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_005_pos +# +# DESCRIPTION: +# Verify option '-c' will remove the created permission set. +# +# STRATEGY: +# 1. Set created time set to $ROOT_TESTFS. +# 2. Allow permission create to $STAFF1 on $ROOT_TESTFS. +# 3. Create $SUBFS and verify $STAFF1 have created time permissions. +# 4. Verify $STAFF1 has created time permission. +# 5. Unallow created time permission with option '-c'. +# 6. Created $SUBFS and verify $STAFF1 have not created time permissions. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify option '-c' will remove the created permission set." +log_onexit restore_root_datasets + +log_must $ZFS allow -c $LOCAL_SET $ROOT_TESTFS +log_must $ZFS allow -l $STAFF1 create,mount $ROOT_TESTFS + +# Create $SUBFS and verify $SUBFS has created time permissions. +user_run $STAFF1 $ZFS create $SUBFS +if ! datasetexists $SUBFS ; then + log_fail "ERROR: ($STAFF1): $ZFS create $SUBFS" +fi +log_must verify_perm $SUBFS $LOCAL_SET $STAFF1 + +# +# After unallow -c, create $SUBFS2 and verify $SUBFS2 has not created time +# permissions any more. +# +log_must $ZFS unallow -c $LOCAL_SET $ROOT_TESTFS +user_run $STAFF1 $ZFS create $SUBFS2 +if ! datasetexists $SUBFS2 ; then + log_fail "ERROR: ($STAFF1): $ZFS create $SUBFS2" +fi +log_must verify_noperm $SUBFS2 $LOCAL_SET $STAFF1 + +log_pass "Verify option '-c' will remove the created permission set passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_006_pos.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_006_pos.ksh new file mode 100644 index 00000000000..ed83f31d5bb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_006_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_006_pos.ksh 1.2 07/07/31 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_006_pos +# +# DESCRIPTION: +# Verify option '-u', '-g' and '-e' only removed the specified type +# permissions set. +# +# STRATEGY: +# 1. Allow '-u' '-g' & '-e' to $STAFF1 on ROOT_TESTFS or $ROOT_TESTVOL. +# 2. Unallow '-u' '-g' & '-e' on $ROOT_TESTFS or $ROOT_TESTVOL separately. +# 3. Verify permissions on $ROOT_TESTFS or $ROOT_TESTVOL separately. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify option '-u', '-g' and '-e' only removed the specified type "\ + "permissions set." +log_onexit restore_root_datasets + +for dtst in $DATASETS ; do + log_must $ZFS allow -u $STAFF1 $LOCAL_DESC_SET $dtst + log_must $ZFS allow -g $STAFF_GROUP $LOCAL_DESC_SET $dtst + log_must $ZFS allow -e $LOCAL_DESC_SET $dtst + + log_must verify_perm $dtst $LOCAL_DESC_SET \ + $STAFF1 $STAFF2 $OTHER1 $OTHER2 + + log_must $ZFS unallow -e $dtst + log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1 $STAFF2 + log_must verify_noperm $dtst $LOCAL_DESC_SET $OTHER1 $OTHER2 + + log_must $ZFS unallow -g $STAFF_GROUP $dtst + log_must verify_perm $dtst $LOCAL_DESC_SET $STAFF1 + log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF2 + + log_must $ZFS unallow -u $STAFF1 $dtst + log_must verify_noperm $dtst $LOCAL_DESC_SET $STAFF1 +done + +log_pass "Verify option '-u', '-g' and '-e' passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_007_neg.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_007_neg.ksh new file mode 100644 index 00000000000..cf5d132687c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_007_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_007_neg.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_007_neg +# +# DESCRIPTION: +# zfs unallow will not remove those permissions which inherited from +# its parent filesystem. +# +# STRATEGY: +# 1. Assign perm1 to $ROOT_TESTFS +# 2. Create $SUBFS and assign perm2 to it. +# 3. Verify unallow can not affect perm1 on $SUBFS +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs unallow won't remove those permissions which inherited from " \ + "its parent dataset." +log_onexit restore_root_datasets + +perm1="atime,devices"; perm2="compression,checksum" +log_must $ZFS create $SUBFS +log_must $ZFS allow $STAFF1 $perm1 $ROOT_TESTFS +log_must $ZFS allow $STAFF1 $perm2 $SUBFS + +log_must verify_perm $SUBFS ${perm1},${perm2} $STAFF1 +# +# Athrough unallow the permissions which don't exists on the specific dataset +# return 0, the inherited permissions can't be removed in fact. +# +log_must $ZFS unallow -u $STAFF1 $perm1 $SUBFS +log_must verify_perm $SUBFS ${perm1},${perm2} $STAFF1 + +log_pass "Verify zfs unallow won't remove inherited permissions passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_008_neg.ksh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_008_neg.ksh new file mode 100644 index 00000000000..f0d5030f125 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_008_neg.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfs_unallow_008_neg.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/tests/delegate/delegate_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zfs_unallow_008_neg +# +# DESCRIPTION: +# zfs unallow can handle invalid arguments. +# +# STRATEGY: +# 1. Set up basic test environment. +# 2. Verify zfs unallow handle invalid arguments correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs unallow can handle invalid arguments." +log_onexit restore_root_datasets + +function neg_test +{ + log_mustnot eval "$@ > /dev/null 2>&1" +} + +set -A badopts "everyone -e" "everyone -u $STAFF1" "everyone everyone" \ + "-c -l" "-c -d" "-c -e" "-c -s" "-r" \ + "-u -e" "-s -e" "-s -l -d" "-s @non-exist-set -l" \ + "-s @non-existen-set -d" "-s @non-existen-set -e" \ + "-r -u $STAFF1 $STAFF1" "-u $STAFF1 -g $STAFF_GROUP" \ + "-u $STAFF1 -e" + +log_must setup_unallow_testenv + +for dtst in $DATASETS ; do + log_must $ZFS allow -c create $dtst + + typeset -i i=0 + while ((i < ${#badopts[@]})); do + neg_test $ZFS unallow ${badopts[$i]} $dtst + ((i += 1)) + done + + neg_test user_run $STAFF1 $ZFS unallow $dtst +done + +log_pass "zfs unallow can handle invalid arguments passed." diff --git a/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_test.sh b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_test.sh new file mode 100755 index 00000000000..5de6a9ad47a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/delegate/zfs_unallow_test.sh @@ -0,0 +1,248 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfs_unallow_001_pos cleanup +zfs_unallow_001_pos_head() +{ + atf_set "descr" "Verify '-l' only removed the local permissions." + atf_set "require.progs" zfs svcs +} +zfs_unallow_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_001_pos.ksh || atf_fail "Testcase failed" +} +zfs_unallow_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_002_pos cleanup +zfs_unallow_002_pos_head() +{ + atf_set "descr" "Verify '-d' only removed the descendent permissions." + atf_set "require.progs" zfs svcs +} +zfs_unallow_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_002_pos.ksh || atf_fail "Testcase failed" +} +zfs_unallow_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_003_pos cleanup +zfs_unallow_003_pos_head() +{ + atf_set "descr" "Verify options '-r' and '-l'+'-d' will unallow permission tothis dataset and the descendent datasets." + atf_set "require.progs" zfs svcs +} +zfs_unallow_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_003_pos.ksh || atf_fail "Testcase failed" +} +zfs_unallow_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_004_pos cleanup +zfs_unallow_004_pos_head() +{ + atf_set "descr" "Verify '-s' will remove permissions from the named set." + atf_set "require.progs" zfs svcs +} +zfs_unallow_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_004_pos.ksh || atf_fail "Testcase failed" +} +zfs_unallow_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_005_pos cleanup +zfs_unallow_005_pos_head() +{ + atf_set "descr" "Verify option '-c' will remove the created permission set." + atf_set "require.progs" zfs svcs runwattr +} +zfs_unallow_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_005_pos.ksh || atf_fail "Testcase failed" +} +zfs_unallow_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_006_pos cleanup +zfs_unallow_006_pos_head() +{ + atf_set "descr" "Verify option '-u', '-g' and '-e' only removed the specified typepermissions set." + atf_set "require.progs" zfs svcs +} +zfs_unallow_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_006_pos.ksh || atf_fail "Testcase failed" +} +zfs_unallow_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_007_neg cleanup +zfs_unallow_007_neg_head() +{ + atf_set "descr" "zfs unallow won't remove those permissions which inherited fromits parent dataset." + atf_set "require.progs" zfs svcs +} +zfs_unallow_007_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_007_neg.ksh || atf_fail "Testcase failed" +} +zfs_unallow_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfs_unallow_008_neg cleanup +zfs_unallow_008_neg_head() +{ + atf_set "descr" "zfs unallow can handle invalid arguments." + atf_set "require.progs" zfs svcs runwattr +} +zfs_unallow_008_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfs_unallow_008_neg.ksh || atf_fail "Testcase failed" +} +zfs_unallow_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/delegate_common.kshlib + . $(atf_get_srcdir)/delegate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zfs_unallow_001_pos + atf_add_test_case zfs_unallow_002_pos + atf_add_test_case zfs_unallow_003_pos + atf_add_test_case zfs_unallow_004_pos + atf_add_test_case zfs_unallow_005_pos + atf_add_test_case zfs_unallow_006_pos + atf_add_test_case zfs_unallow_007_neg + atf_add_test_case zfs_unallow_008_neg +} diff --git a/tests/sys/cddl/zfs/tests/devices/Makefile b/tests/sys/cddl/zfs/tests/devices/Makefile new file mode 100644 index 00000000000..da4f63bd119 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/devices +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= devices_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= devices_common.kshlib +${PACKAGE}FILES+= devices_002_neg.ksh +${PACKAGE}FILES+= devices_test.sh +${PACKAGE}FILES+= devices_003_pos.ksh +${PACKAGE}FILES+= devices.cfg +${PACKAGE}FILES+= devices_001_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/devices/cleanup.ksh b/tests/sys/cddl/zfs/tests/devices/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/devices/devices.cfg b/tests/sys/cddl/zfs/tests/devices/devices.cfg new file mode 100644 index 00000000000..66ca60eaaa8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/devices.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)devices.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE1=testfile1${TESTCASE_ID} +export TESTFILE2=testfile2${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/devices/devices_001_pos.ksh b/tests/sys/cddl/zfs/tests/devices/devices_001_pos.ksh new file mode 100644 index 00000000000..df4f0372bd9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/devices_001_pos.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)devices_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/devices/devices_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: devices_001_pos +# +# DESCRIPTION: +# When set property devices=on on file system, devices files can be used in +# this file system. +# +# STRATEGY: +# 1. Create pool and file system. +# 2. Set devices=on on this file system. +# 3. Separately create block device file and character file. +# 4. Separately read from those two device files. +# 5. Check the return value, and make sure it succeeds. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Setting devices=on on file system, the devices files in this file" \ + "system can be used." +log_onexit cleanup + +log_must $ZFS set devices=on $TESTPOOL/$TESTFS + +# +# Separately create block device file and character device file, then try to +# open them and make sure it succeed. +# +create_dev_file b $TESTDIR/$TESTFILE1 +log_must $DD if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1 +create_dev_file c $TESTDIR/$TESTFILE2 +log_must $DD if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1 + +log_pass "Setting devices=on on file system and testing it pass." diff --git a/tests/sys/cddl/zfs/tests/devices/devices_002_neg.ksh b/tests/sys/cddl/zfs/tests/devices/devices_002_neg.ksh new file mode 100644 index 00000000000..3f2c932dc81 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/devices_002_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)devices_002_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/devices/devices_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: devices_002_neg +# +# DESCRIPTION: +# When set property devices=off on file system, device files cannot be used +# in this file system. +# +# STRATEGY: +# 1. Create pool and file system. +# 2. Set devices=off on this file system. +# 3. Separately create block device file and character file. +# 4. Separately read from those two device files. +# 5. Check the return value, and make sure it failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Setting devices=off on file system, the devices files in this file"\ + "system can not be used." +log_onexit cleanup + +log_must $ZFS set devices=off $TESTPOOL/$TESTFS + +# +# Separately create block device file and character device file, then try to +# open them and make sure it failed. +# +create_dev_file b $TESTDIR/$TESTFILE1 +log_mustnot $DD if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1 +create_dev_file c $TESTDIR/$TESTFILE2 +log_mustnot $DD if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1 + +log_pass "Setting devices=off on file system and testing it pass." diff --git a/tests/sys/cddl/zfs/tests/devices/devices_003_pos.ksh b/tests/sys/cddl/zfs/tests/devices/devices_003_pos.ksh new file mode 100644 index 00000000000..8fe11406870 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/devices_003_pos.ksh @@ -0,0 +1,63 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)devices_003_pos.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: devices_003_pos +# +# DESCRIPTION: +# +# Writing random data into /dev/zfs should do no harm. +# +# STRATEGY: +# 1. Write some random data into /dev/zfs +# 2. Verify that this should fail. +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-04-24) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "Writing random data into /dev/zfs should do no harm." + +log_mustnot $DD if=/dev/urandom of=/dev/zfs count=1024 + +log_pass "Writing random data into /dev/zfs should do no harm." diff --git a/tests/sys/cddl/zfs/tests/devices/devices_common.kshlib b/tests/sys/cddl/zfs/tests/devices/devices_common.kshlib new file mode 100644 index 00000000000..b4ca65e03cf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/devices_common.kshlib @@ -0,0 +1,120 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)devices_common.kshlib 1.3 07/03/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Create block file or charactor file according to parameter. +# +# $1 device file type +# $2 file name +# +function create_dev_file +{ + typeset filetype=$1 + typeset filename=$2 + + case $filetype in + b) + devtype=$($DF -T / | $AWK '{print $2}') + case $devtype in + zfs) + rootpool=$($DF / | \ + $AWK '{print $2}') + rootpool=${rootpool#\(} + rootpool=${rootpool%%/*} + + devstr=$(get_disklist $rootpool) + devstr=$($ECHO "$devstr" | \ + $AWK '{print $1}') + [[ -z $devstr ]] && \ + log_fail "Can not get block device file." + devstr=/dev/dsk/${devstr} + ;; + ufs) + # + # Get the existing block device file in current system. + # And bring out the first one. + # + devstr=$($DF -lht ufs | \ + $GREP "^/dev/dsk" | \ + $AWK '{print $1}') + devstr=$($ECHO "$devstr" | \ + $AWK '{print $1}') + [[ -z $devstr ]] && \ + log_fail "Can not get block device file." + ;; + *) + log_unsupported "Unsupported fstype " \ + "for / ($devtype)," \ + "only ufs|zfs is supported." + ;; + esac + + # + # Get the device file information. i.e: + # /dev/dsk/c0t0d0s0: block special (28/768) + # + devstr=$($FILE $devstr) + + # + # Bring out major and minor number. + # + major=${devstr##*\(} + major=${major%%/*} + minor=${devstr##*/} + minor=${minor%\)} + + log_must $MKNOD $filename b $major $minor + ;; + c) + # + # Create device file '/dev/null' + # + log_must $MKNOD $filename c 13 2 + ;; + *) + log_fail "'$filetype' is wrong." + ;; + esac + + return 0 +} + +function cleanup +{ + log_must $ZFS set devices=on $TESTPOOL/$TESTFS + log_must $RM -f $TESTDIR/$TESTFILE1 + log_must $RM -f $TESTDIR/$TESTFILE2 + log_must $RM -f $TESTDIR/$TESTFILE1.out + log_must $RM -f $TESTDIR/$TESTFILE2.out +} + diff --git a/tests/sys/cddl/zfs/tests/devices/devices_test.sh b/tests/sys/cddl/zfs/tests/devices/devices_test.sh new file mode 100755 index 00000000000..2ceda509960 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/devices_test.sh @@ -0,0 +1,112 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case devices_001_pos cleanup +devices_001_pos_head() +{ + atf_set "descr" "Setting devices=on on file system, the devices files in this filesystem can be used." + atf_set "require.progs" zfs +} +devices_001_pos_body() +{ + atf_expect_fail "The devices property is not yet supported on FreeBSD" + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/devices_common.kshlib + . $(atf_get_srcdir)/devices.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/devices_001_pos.ksh || atf_fail "Testcase failed" +} +devices_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/devices_common.kshlib + . $(atf_get_srcdir)/devices.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case devices_002_neg cleanup +devices_002_neg_head() +{ + atf_set "descr" "Setting devices=off on file system, the devices files in this filesystem can not be used." + atf_set "require.progs" zfs +} +devices_002_neg_body() +{ + atf_expect_fail "The devices property is not yet supported on FreeBSD" + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/devices_common.kshlib + . $(atf_get_srcdir)/devices.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/devices_002_neg.ksh || atf_fail "Testcase failed" +} +devices_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/devices_common.kshlib + . $(atf_get_srcdir)/devices.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case devices_003_pos cleanup +devices_003_pos_head() +{ + atf_set "descr" "Writing random data into /dev/zfs should do no harm." +} +devices_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/devices_common.kshlib + . $(atf_get_srcdir)/devices.cfg + + ksh93 $(atf_get_srcdir)/devices_003_pos.ksh || atf_fail "Testcase failed" +} +devices_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/devices_common.kshlib + . $(atf_get_srcdir)/devices.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case devices_001_pos + atf_add_test_case devices_002_neg + atf_add_test_case devices_003_pos +} diff --git a/tests/sys/cddl/zfs/tests/devices/setup.ksh b/tests/sys/cddl/zfs/tests/devices/setup.ksh new file mode 100644 index 00000000000..5ed779163f4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/devices/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/exec/Makefile b/tests/sys/cddl/zfs/tests/exec/Makefile new file mode 100644 index 00000000000..2d0c2782a57 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/exec/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/exec/ +FILESDIR=${TESTSDIR} +BINDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= exec_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= exec_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= exec_002_neg.ksh +PROG= mmap_exec +MAN= + +.include diff --git a/tests/sys/cddl/zfs/tests/exec/cleanup.ksh b/tests/sys/cddl/zfs/tests/exec/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/exec/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/exec/exec_001_pos.ksh b/tests/sys/cddl/zfs/tests/exec/exec_001_pos.ksh new file mode 100644 index 00000000000..2c2f9013af7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/exec/exec_001_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)exec_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: exec_001_pos +# +# DESCRIPTION: +# When set property exec=on on a filesystem, processes can be executed from +# this filesystem. +# +# STRATEGY: +# 1. Create pool and file system. +# 2. Copy '/bin/ls' to the ZFS file system. +# 3. Setting exec=on on this file system. +# 4. Make sure '/bin/ls' can work in this ZFS file system. +# 5. Make sure mmap which is using the PROT_EXEC calls succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $RM $TESTDIR/myls +} + +log_assert "Setting exec=on on a filesystem, processes can be executed from " \ + "this file system." +log_onexit cleanup + +log_must $CP $LS $TESTDIR/myls +log_must $ZFS set exec=on $TESTPOOL/$TESTFS +log_must $TESTDIR/myls +log_must mmap_exec $TESTDIR/myls + +log_pass "Setting exec=on on filesystem testing passed." diff --git a/tests/sys/cddl/zfs/tests/exec/exec_002_neg.ksh b/tests/sys/cddl/zfs/tests/exec/exec_002_neg.ksh new file mode 100644 index 00000000000..16125a0d84f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/exec/exec_002_neg.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)exec_002_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: exec_002_neg +# +# DESCRIPTION: +# When set property exec=off on a filesystem, processes can not be executed from +# this filesystem. +# +# STRATEGY: +# 1. Create pool and file system. +# 2. Copy '/bin/ls' to the ZFS file system. +# 3. Setting exec=off on this file system. +# 4. Make sure '/bin/ls' can not work in this ZFS file system. +# 5. Make sure mmap which is using the PROT_EXEC calls failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $RM $TESTDIR/myls +} + +# +# Execute and check if the return value is equal to expected. +# +# $1 expected value +# $2..$n executed item +# +function exec_n_check +{ + typeset expect_value=$1 + + shift + $@ + ret=$? + if [[ $ret != $expect_value ]]; then + log_fail "Unexpected return code: '$ret'" + fi + + return 0 +} + +log_assert "Setting exec=off on a filesystem, processes can not be executed " \ + "from this file system." +log_onexit cleanup + +log_must $CP $LS $TESTDIR/myls +log_must $ZFS set exec=off $TESTPOOL/$TESTFS + +log_must exec_n_check 126 $TESTDIR/myls +log_must exec_n_check 13 mmap_exec $TESTDIR/myls + +log_pass "Setting exec=off on filesystem testing passed." diff --git a/tests/sys/cddl/zfs/tests/exec/exec_test.sh b/tests/sys/cddl/zfs/tests/exec/exec_test.sh new file mode 100755 index 00000000000..b71978e4518 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/exec/exec_test.sh @@ -0,0 +1,80 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case exec_001_pos cleanup +exec_001_pos_head() +{ + atf_set "descr" "Setting exec=on on a filesystem, processes can be executed fromthis file system." + atf_set "require.progs" zfs +} +exec_001_pos_body() +{ + export PATH=$(atf_get_srcdir):$PATH + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/exec_001_pos.ksh || atf_fail "Testcase failed" +} +exec_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case exec_002_neg cleanup +exec_002_neg_head() +{ + atf_set "descr" "Setting exec=off on a filesystem, processes can not be executedfrom this file system." + atf_set "require.progs" zfs +} +exec_002_neg_body() +{ + PATH=$(atf_get_srcdir):$PATH + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/exec_002_neg.ksh || atf_fail "Testcase failed" +} +exec_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case exec_001_pos + atf_add_test_case exec_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/exec/mmap_exec.c b/tests/sys/cddl/zfs/tests/exec/mmap_exec.c new file mode 100644 index 00000000000..409bf2ffca1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/exec/mmap_exec.c @@ -0,0 +1,70 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)mmap_exec.c 1.3 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include + +extern int errno; + +int +main(int argc, char *argv[]) +{ + int fd; + struct stat statbuf; + + if (argc != 2) { + (void) printf("Error: missing binary name.\n"); + (void) printf("Usage:\n\t%s \n", + argv[0]); + return (1); + } + + errno = 0; + + if ((fd = open(argv[1], O_RDONLY)) < 0) { + perror("open"); + return (errno); + } + if (fstat(fd, &statbuf) < 0) { + perror("fstat"); + return (errno); + } + + if (mmap(0, statbuf.st_size, + PROT_EXEC, MAP_SHARED, fd, 0) == MAP_FAILED) { + perror("mmap"); + return (errno); + } + + return (0); +} diff --git a/tests/sys/cddl/zfs/tests/exec/setup.ksh b/tests/sys/cddl/zfs/tests/exec/setup.ksh new file mode 100644 index 00000000000..5ed779163f4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/exec/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/grow_pool/Makefile b/tests/sys/cddl/zfs/tests/grow_pool/Makefile new file mode 100644 index 00000000000..efbfcd06cd3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_pool/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/grow_pool +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= grow_pool_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= grow_pool_001_pos.ksh +${PACKAGE}FILES+= grow_pool.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/grow_pool/cleanup.ksh b/tests/sys/cddl/zfs/tests/grow_pool/cleanup.ksh new file mode 100644 index 00000000000..ba85502f7a0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_pool/cleanup.ksh @@ -0,0 +1,46 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +ismounted $TESTFS && \ + log_must $ZFS umount $TESTDIR +destroy_pool "$TESTPOOL" + +if [[ -z $DISK ]]; then + cleanup_devices "$DISK0 $DISK1" +else + cleanup_devices "$DISK" +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/grow_pool/grow_pool.cfg b/tests/sys/cddl/zfs/tests/grow_pool/grow_pool.cfg new file mode 100644 index 00000000000..ffb12ef1ea3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_pool/grow_pool.cfg @@ -0,0 +1,46 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)grow_pool.cfg 1.3 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +export DISK_ARRAY_LIMIT=2 +export BLOCK_SIZE=8192 +set_disks +# +# Do not make SIZE too large as the three slices may exceed +# the size of the disk, and also slow down the test +# which involves filling until ENOSPC +# +export SIZE="100mb" +export PARTITION=1 +export SMALL_WRITE_COUNT=100 +export TESTFILE1=file${TESTCASE_ID}.1 +export WRITE_COUNT=65536000 diff --git a/tests/sys/cddl/zfs/tests/grow_pool/grow_pool_001_pos.ksh b/tests/sys/cddl/zfs/tests/grow_pool/grow_pool_001_pos.ksh new file mode 100644 index 00000000000..c64cd2c61b1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_pool/grow_pool_001_pos.ksh @@ -0,0 +1,87 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)grow_pool_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: grow_pool_001_pos +# +# DESCRIPTION: +# A ZFS file system is limited by the amount of disk space +# available to the pool. Growing the pool by adding a disk +# increases the amount of space. +# +# STRATEGY: +# 1) Fill a ZFS filesystem until ENOSPC by creating a large file +# 2) Grow the pool by adding a disk +# 3) Verify that more data can now be written to the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A zpool may be increased in capacity by adding a disk" + +log_must $ZFS set compression=off $TESTPOOL/$TESTFS +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 \ + -b $BLOCK_SIZE -c $WRITE_COUNT -d 0 +typeset -i zret=$? +readonly ENOSPC=28 +if [[ $zret -ne $ENOSPC ]]; then + log_fail "file_write completed w/o ENOSPC, aborting!!!" +fi + +if [[ ! -s $TESTDIR/$TESTFILE1 ]]; then + log_fail "$TESTDIR/$TESTFILE1 was not created" +fi + +if [[ -n $DISK ]]; then + log_must $ZPOOL add $TESTPOOL ${DISK}p2 +else + log_must $ZPOOL add $TESTPOOL $DISK1 +fi + +log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE1 \ + -b $BLOCK_SIZE -c $SMALL_WRITE_COUNT -d 0 + +log_must $ZFS inherit compression $TESTPOOL/$TESTFS +log_pass "TESTPOOL successfully grown" diff --git a/tests/sys/cddl/zfs/tests/grow_pool/grow_pool_test.sh b/tests/sys/cddl/zfs/tests/grow_pool/grow_pool_test.sh new file mode 100755 index 00000000000..93d223f90cf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_pool/grow_pool_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case grow_pool_001_pos cleanup +grow_pool_001_pos_head() +{ + atf_set "descr" "A zpool may be increased in capacity by adding a disk" + atf_set "require.progs" zfs zpool +} +grow_pool_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/grow_pool.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/grow_pool_001_pos.ksh || atf_fail "Testcase failed" +} +grow_pool_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/grow_pool.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case grow_pool_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/grow_pool/setup.ksh b/tests/sys/cddl/zfs/tests/grow_pool/setup.ksh new file mode 100644 index 00000000000..96f3502c74b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_pool/setup.ksh @@ -0,0 +1,47 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if [[ -n $DISK ]]; then + log_note "No spare disks available. Using slices on $DISK" + log_must partition_disk $SIZE $DISK 2 + tmp=${DISK}p1 +else + wipe_partition_table $DISK0 $DISK1 + log_must set_partition $PARTITION "" $SIZE $DISK0 + log_must set_partition $PARTITION "" $SIZE $DISK1 + tmp=$DISK0"p"$PARTITION +fi + +default_setup $tmp diff --git a/tests/sys/cddl/zfs/tests/grow_replicas/Makefile b/tests/sys/cddl/zfs/tests/grow_replicas/Makefile new file mode 100644 index 00000000000..bd5c448129e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_replicas/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/grow_replicas +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= grow_replicas_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= grow_replicas.cfg +${PACKAGE}FILES+= grow_replicas_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/grow_replicas/cleanup.ksh b/tests/sys/cddl/zfs/tests/grow_replicas/cleanup.ksh new file mode 100644 index 00000000000..a60c3d9fc66 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_replicas/cleanup.ksh @@ -0,0 +1,42 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +ismounted $TESTFS && \ + log_must $ZFS umount $TESTDIR +destroy_pool "$TESTPOOL" + +cleanup_devices $DISKS + +log_pass diff --git a/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas.cfg b/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas.cfg new file mode 100644 index 00000000000..c76f97b6271 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas.cfg @@ -0,0 +1,74 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)grow_replicas.cfg 1.4 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +function set_disks +{ + set -A disk_array $(find_disks $DISKS) + typeset -i i=0 + typeset -i limit=4 + while (( i < limit )); do + if [[ -n ${disk_array[$i]} ]]; then + export DISK${i}="${disk_array[$i]}" + else + export DISK=${DISKS%% *} + return + fi + ((i = i + 1)) + done + export DISK="" +} + +typeset -i index=`expr $RANDOM % 2` +if (( $index == 0 )); then + POOLTYPE="mirror" +else + POOLTYPE="raidz" +fi +export POOLTYPE + +export BLOCK_SIZE=8192 +set_disks +# +# Do not make SIZE too large as the three slices may exceed +# the size of the disk, and also slow down the test +# which involves filling until ENOSPC +# +export SIZE="100mb" +if [[ $WRAPPER != *"smi"* ]]; then + export PARTITION=1 +else + export PARTITION=2 +fi +export SMALL_WRITE_COUNT=100 +export TESTFILE1=file${TESTCASE_ID}.1 +export WRITE_COUNT=65536000 diff --git a/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas_001_pos.ksh b/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas_001_pos.ksh new file mode 100644 index 00000000000..3727002b8ba --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas_001_pos.ksh @@ -0,0 +1,96 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)grow_replicas_001_pos.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: grow_replicas_001_pos +# +# DESCRIPTION: +# A ZFS file system is limited by the amount of disk space +# available to the pool. Growing the pool by adding a disk +# increases the amount of space. +# +# STRATEGY: +# 1) Fill a ZFS filesystem mirror/raidz until ENOSPC by creating lots +# of files +# 2) Grow the mirror/raidz by adding a disk +# 3) Verify that more data can now be written to the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A zpool mirror/raidz may be increased in capacity by adding a disk." + +log_must $ZFS set compression=off $TESTPOOL/$TESTFS +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 \ + -b $BLOCK_SIZE -c $WRITE_COUNT -d 0 + +typeset -i zret=$? +readonly ENOSPC=28 +if [[ $zret -ne $ENOSPC ]]; then + log_fail "file_write completed w/o ENOSPC, aborting!!!" +fi + +if [[ ! -s $TESTDIR/$TESTFILE1 ]]; then + log_fail "$TESTDIR/$TESTFILE1 was not created" +fi + +# +# $DISK will be set if we're using slices on one disk +# +if [[ -n $DISK ]]; then + log_must $ZPOOL add $TESTPOOL $POOLTYPE ${DISK}p3 \ + ${DISK}p4 +else + [[ -z $DISK2 || -z $DISK3 ]] && \ + log_unsupported "No spare disks available." + log_must $ZPOOL add -f $TESTPOOL $POOLTYPE ${DISK2}p${PARTITION} \ + ${DISK3}p${PARTITION} +fi + +log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE1 \ + -b $BLOCK_SIZE -c $SMALL_WRITE_COUNT -d 0 + +log_must $ZFS inherit compression $TESTPOOL/$TESTFS +log_pass "TESTPOOL mirror/raidz successfully grown" diff --git a/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas_test.sh b/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas_test.sh new file mode 100755 index 00000000000..435446a9fff --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_replicas/grow_replicas_test.sh @@ -0,0 +1,58 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case grow_replicas_001_pos cleanup +grow_replicas_001_pos_head() +{ + atf_set "descr" "A zpool mirror/raidz may be increased in capacity by adding a disk." + atf_set "require.progs" zfs zpool +} +grow_replicas_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/grow_replicas.cfg + + + verify_disk_count "$DISKS" 4 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/grow_replicas_001_pos.ksh || atf_fail "Testcase failed" +} +grow_replicas_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/grow_replicas.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case grow_replicas_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/grow_replicas/setup.ksh b/tests/sys/cddl/zfs/tests/grow_replicas/setup.ksh new file mode 100644 index 00000000000..86ba5b2a64b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/grow_replicas/setup.ksh @@ -0,0 +1,59 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.5 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +log_note "Creating pool type: $POOLTYPE" + +if [[ -n $DISK ]]; then + log_note "No spare disks available. Using slices on $DISK" + partition_disk $SIZE $DISK 4 + create_pool $TESTPOOL $POOLTYPE ${DISK}p1 \ + ${DISK}p2 +else + wipe_partition_table $DISK0 $DISK1 $DISK2 $DISK3 + log_must set_partition $PARTITION "" $SIZE $DISK0 + log_must set_partition $PARTITION "" $SIZE $DISK1 + log_must set_partition $PARTITION "" $SIZE $DISK2 + log_must set_partition $PARTITION "" $SIZE $DISK3 + create_pool $TESTPOOL $POOLTYPE ${DISK0}p${PARTITION} \ + ${DISK1}p${PARTITION} +fi + +$RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR +$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR + +log_must $ZFS create $TESTPOOL/$TESTFS +log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +log_pass diff --git a/tests/sys/cddl/zfs/tests/history/Makefile b/tests/sys/cddl/zfs/tests/history/Makefile new file mode 100644 index 00000000000..bd6fa3b1581 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/Makefile @@ -0,0 +1,33 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/history/ +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= history_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= history_005_neg.ksh +${PACKAGE}FILES+= history_004_pos.ksh +${PACKAGE}FILES+= history_008_pos.ksh +${PACKAGE}FILES+= i386.orig_history.txt +${PACKAGE}FILES+= sparc.orig_history.txt +${PACKAGE}FILES+= history_common.kshlib +${PACKAGE}FILES+= history.cfg +${PACKAGE}FILES+= sparc.migratedpool.DAT.Z +${PACKAGE}FILES+= history_010_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfs-pool-v4.dat.Z +${PACKAGE}FILES+= history_009_pos.ksh +${PACKAGE}FILES+= history_001_pos.ksh +${PACKAGE}FILES+= history_006_neg.ksh +${PACKAGE}FILES+= i386.migratedpool.DAT.Z +${PACKAGE}FILES+= history_003_pos.ksh +${PACKAGE}FILES+= history_007_pos.ksh +${PACKAGE}FILES+= history_002_pos.ksh +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/history/cleanup.ksh b/tests/sys/cddl/zfs/tests/history/cleanup.ksh new file mode 100644 index 00000000000..a29e4b0539c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +$ZPOOL history > /dev/null 2>&1 +(($? != 0)) && log_unsupported + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/history/history.cfg b/tests/sys/cddl/zfs/tests/history/history.cfg new file mode 100644 index 00000000000..8fcd1f8b9cb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history.cfg @@ -0,0 +1,48 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history.cfg 1.5 08/08/15 SMI" +# + +export ZFSROOT= + +export MPOOL=mpool.${TESTCASE_ID} + +export EXPECT_HISTORY=$TMPDIR/exp_history.${TESTCASE_ID} +export REAL_HISTORY=$TMPDIR/real_history.${TESTCASE_ID} +export ADD_HISTORY=$TMPDIR/add_history.${TESTCASE_ID} + +export MIGRATEDPOOLNAME=${MIGRATEDPOOLNAME:-history_pool} +export TIMEZONE=${TIMEZONE:-US/Mountain} + +export STF_TIMEOUT=1800 + +export HIST_USER="huser" +export HIST_GROUP="hgroup" + +export TESTVOL=testvol.${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/history/history_001_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_001_pos.ksh new file mode 100644 index 00000000000..38a7a5d09f7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_001_pos.ksh @@ -0,0 +1,121 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_001_pos.ksh 1.3 07/05/25 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_001_pos +# +# DESCRIPTION: +# Create a scenario to verify the following zpool subcommands are logged. +# create, destroy, add, remove, offline, online, attach, detach, replace, +# scrub, export, import, clear, upgrade. +# +# STRATEGY: +# 1. Create three virtual disk files. +# 2. Create a three-way mirror. +# 3. Invoke every sub-commands to this mirror, except upgrade. +# 4. Compare 'zpool history' log with expected log. +# 5. Imported specified pool and upgrade it, verify 'upgrade' was logged. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + destroy_pool $MPOOL + destroy_pool $upgrade_pool + + [[ -d $import_dir ]] && $RM -rf $import_dir + for file in $REAL_HISTORY $EXPECT_HISTORY \ + $VDEV1 $VDEV2 $VDEV3 $VDEV4 + do + [[ -f $file ]] && $RM -f $file + done +} + +log_assert "Verify zpool sub-commands which modify state are logged." +log_onexit cleanup + +(( $? != 0)) && log_fail "get_prop($TESTPOOL mountpoint)" +VDEV1=$TMPDIR/vdev1; VDEV2=$TMPDIR/vdev2; +VDEV3=$TMPDIR/vdev3; VDEV4=$TMPDIR/vdev4; + +log_must create_vdevs $VDEV1 $VDEV2 $VDEV3 $VDEV4 +$CAT /dev/null > $EXPECT_HISTORY + +exec_record $ZPOOL create $MPOOL mirror $VDEV1 $VDEV2 +exec_record $ZPOOL add -f $MPOOL spare $VDEV3 +exec_record $ZPOOL remove $MPOOL $VDEV3 +exec_record $ZPOOL offline $MPOOL $VDEV1 +exec_record $ZPOOL online $MPOOL $VDEV1 +exec_record $ZPOOL attach $MPOOL $VDEV1 $VDEV4 +exec_record $ZPOOL detach $MPOOL $VDEV4 +exec_record $ZPOOL replace -f $MPOOL $VDEV1 $VDEV4 +exec_record $ZPOOL export $MPOOL +exec_record $ZPOOL import -d $TMPDIR $MPOOL +exec_record $ZPOOL destroy $MPOOL +exec_record $ZPOOL import -D -f -d $TMPDIR $MPOOL +exec_record $ZPOOL clear $MPOOL + +format_history $MPOOL $REAL_HISTORY +log_must $DIFF $REAL_HISTORY $EXPECT_HISTORY + +import_dir=$TMPDIR/import_dir.${TESTCASE_ID} +log_must $MKDIR $import_dir +log_must $CP $STF_SUITE/tests/history/zfs-pool-v4.dat.Z $import_dir +log_must $UNCOMPRESS $import_dir/zfs-pool-v4.dat.Z + +# Truncate $EXPECT_HISTORY file +log_must eval "$CAT /dev/null > $EXPECT_HISTORY" + +upgrade_pool=$($ZPOOL import -d $import_dir | $GREP "pool:" | $AWK '{print $2}') +exec_record $ZPOOL import -d $import_dir $upgrade_pool +# Get existing history +format_history $upgrade_pool $EXPECT_HISTORY +exec_record $ZPOOL upgrade $upgrade_pool + +format_history $upgrade_pool $REAL_HISTORY +log_must $DIFF $REAL_HISTORY $EXPECT_HISTORY + +log_pass "zpool sub-commands which modify state are logged passed. " diff --git a/tests/sys/cddl/zfs/tests/history/history_002_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_002_pos.ksh new file mode 100644 index 00000000000..614c807cfba --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_002_pos.ksh @@ -0,0 +1,177 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_002_pos.ksh 1.5 09/01/12 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_002_pos +# +# DESCRIPTION: +# Create a scenario to verify the following zfs subcommands are logged. +# create, destroy, clone, rename, snapshot, rollback, +# set, inherit, receive, promote. +# +# STRATEGY: +# 1. Format zpool history to file $EXPECT_HISTORY. +# 2. Invoke every sub-commands to this mirror. +# 3. Compare 'zpool history' log with expected log. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + for FileToRm in $EXPECT_HISTORY $REAL_HISTORY $tmpfile $tmpfile2; do + [[ -f $FileToRm ]] && log_must $RM -f $FileToRm + done + for dataset in $fs $newfs $fsclone $vol $newvol $volclone; do + datasetexists $dataset && $ZFS destroy -Rf $dataset + done + log_must $RM -rf /history.${TESTCASE_ID} +} + +log_assert "Verify zfs sub-commands which modify state are logged." +log_onexit cleanup + +format_history $TESTPOOL $EXPECT_HISTORY + +fs=$TESTPOOL/$TESTFS1; newfs=$TESTPOOL/newfs; fsclone=$TESTPOOL/clone +vol=$TESTPOOL/$TESTVOL ; newvol=$TESTPOOL/newvol; volclone=$TESTPOOL/volclone +fssnap=$fs@fssnap; fssnap2=$fs@fssnap2 +volsnap=$vol@volsnap; volsnap2=$vol@volsnap2 + +# property value property value +# +set -A props \ + quota 64M recordsize 512 \ + reservation 32M reservation none \ + mountpoint /history.${TESTCASE_ID} mountpoint legacy \ + mountpoint none sharenfs on \ + sharenfs off \ + compression on compression off \ + compression lzjb aclmode discard \ + aclmode groupmask aclmode passthrough \ + atime on atime off \ + exec on exec off \ + setuid on setuid off \ + readonly on readonly off \ + snapdir hidden snapdir visible \ + aclinherit discard aclinherit noallow \ + aclinherit secure aclinherit passthrough \ + canmount off canmount on \ + compression gzip compression gzip-$((RANDOM%9 + 1)) \ + copies $((RANDOM%3 +1)) + +# Add a few extra properties not supported on FreeBSD, if applicable. The +# currently unsupported list is in the source in libzfs_dataset.c. +if [[ $os_name != "FreeBSD" ]]; then + set +A props \ + devices on devices off \ + zoned on zoned off \ + shareiscsi on shareiscsi off \ + xattr on xattr off +fi + +tmpfile=$TMPDIR/tmpfile.${TESTCASE_ID} ; tmpfile2=$TMPDIR/tmpfile2.${TESTCASE_ID} + +exec_record $ZFS create $fs + +typeset enc="" +enc=$(get_prop encryption $fs) +if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || [[ "$enc" == "off" ]]; then + typeset -i n=${#props[@]} + + props[$n]=checksum ; props[((n+1))]="on" + props[((n+2))]=checksum ; props[((n+3))]="off" + props[((n+4))]=checksum ; props[((n+5))]="fletcher2" + props[((n+6))]=checksum ; props[((n+7))]="fletcher4" + props[((n+8))]=checksum ; props[((n+9))]="sha256" +fi + +# Set all the property for filesystem +typeset -i i=0 +while ((i < ${#props[@]})) ; do + exec_record $ZFS set ${props[$i]}=${props[((i+1))]} $fs + + # quota, reservation, canmount can not be inherited. + # + if [[ ${props[$i]} != "quota" && \ + ${props[$i]} != "reservation" && \ + ${props[$i]} != "canmount" ]]; + then + exec_record $ZFS inherit ${props[$i]} $fs + fi + + ((i += 2)) +done +exec_record $ZFS create -V 64M $vol +exec_record $ZFS set volsize=32M $vol +exec_record $ZFS snapshot $fssnap +exec_record $ZFS snapshot $volsnap +exec_record $ZFS snapshot $fssnap2 +exec_record $ZFS snapshot $volsnap2 +log_must eval "$ZFS send -i $fssnap $fssnap2 > $tmpfile" +log_must eval "$ZFS send -i $volsnap $volsnap2 > $tmpfile2" +exec_record $ZFS destroy $fssnap2 +exec_record $ZFS destroy $volsnap2 +exec_record eval "$ZFS receive $fs < $tmpfile" +exec_record eval "$ZFS receive $vol < $tmpfile2" +exec_record $ZFS rollback -r $fssnap +exec_record $ZFS rollback -r $volsnap +exec_record $ZFS clone $fssnap $fsclone +exec_record $ZFS clone $volsnap $volclone +exec_record $ZFS rename $fs $newfs +exec_record $ZFS rename $vol $newvol +exec_record $ZFS promote $fsclone +exec_record $ZFS promote $volclone +exec_record $ZFS destroy $newfs +exec_record $ZFS destroy $newvol +exec_record $ZFS destroy -rf $fsclone +exec_record $ZFS destroy -rf $volclone + +format_history $TESTPOOL $REAL_HISTORY + +log_must $DIFF $REAL_HISTORY $EXPECT_HISTORY + +log_pass "zfs sub-commands which modify state are logged passed." diff --git a/tests/sys/cddl/zfs/tests/history/history_003_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_003_pos.ksh new file mode 100644 index 00000000000..1f4ea1990c3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_003_pos.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_003_pos +# +# DESCRIPTION: +# zpool history can record and output huge log. +# +# STRATEGY: +# 1. Create two 100M virtual disk files. +# 2. Create test pool using the two virtual files. +# 3. Loop N times to set compression to test pool. +# 4. Make sure 'zpool history' output correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "zpool history limitation test." + +typeset -i expect_count=300 +typeset -i orig_count=$($ZPOOL history $TESTPOOL | $WC -l | $AWK '{print $1}') + +typeset -i i=0 +typeset -i num_iters=0 +((num_iters = expect_count / 5)) +while ((i < num_iters)); do + $ZFS set compression=off $TESTPOOL/$TESTFS + $ZFS set compression=on $TESTPOOL/$TESTFS + $ZFS set compression=off $TESTPOOL/$TESTFS + $ZFS set compression=on $TESTPOOL/$TESTFS + $ZFS set compression=off $TESTPOOL/$TESTFS + + ((i += 1)) +done + +typeset -i entry_count=$($ZPOOL history $TESTPOOL | $WC -l | $AWK '{print $1}') + +typeset -i count_diff=0 +((count_diff = entry_count - orig_count)) +if ((count_diff != expect_count)); then + echo "Zpool history is as follows:" + log_must $ZPOOL history $TESTPOOL + log_fail "Expected $expect_count new entries, got $count_diff" +fi + +log_pass "zpool history limitation test passed." diff --git a/tests/sys/cddl/zfs/tests/history/history_004_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_004_pos.ksh new file mode 100644 index 00000000000..759aa2190db --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_004_pos.ksh @@ -0,0 +1,114 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_004_pos +# +# DESCRIPTION: +# 'zpool history' can copes with many simultaneous command. +# +# STRATEGY: +# 1. Create test pool and test fs. +# 2. Loop 100 times, set properties to test fs simultaneously. +# 3. Wait for all the command execution complete. +# 4. Make sure all the commands was logged by 'zpool history'. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "'zpool history' can copes with many simultaneous command." + +typeset -i orig_count=$($ZPOOL history $TESTPOOL | $WC -l | $AWK '{print $1}') + +typeset -i i=0 +while ((i < 10)); do + $ZFS set compression=off $TESTPOOL/$TESTFS & + $ZFS set atime=off $TESTPOOL/$TESTFS & + $ZFS create $TESTPOOL/$TESTFS1 & + $ZFS create $TESTPOOL/$TESTFS2 & + $ZFS create $TESTPOOL/$TESTFS3 & + + wait + + $ZFS snapshot $TESTPOOL/$TESTFS1@snap & + $ZFS snapshot $TESTPOOL/$TESTFS2@snap & + $ZFS snapshot $TESTPOOL/$TESTFS3@snap & + + wait + + $ZFS clone $TESTPOOL/$TESTFS1@snap $TESTPOOL/clone1 & + $ZFS clone $TESTPOOL/$TESTFS2@snap $TESTPOOL/clone2 & + $ZFS clone $TESTPOOL/$TESTFS3@snap $TESTPOOL/clone3 & + + wait + + $ZFS promote $TESTPOOL/clone1 & + $ZFS promote $TESTPOOL/clone2 & + $ZFS promote $TESTPOOL/clone3 & + + wait + + $ZFS destroy $TESTPOOL/$TESTFS1 & + $ZFS destroy $TESTPOOL/$TESTFS2 & + $ZFS destroy $TESTPOOL/$TESTFS3 & + + wait + + $ZFS destroy -Rf $TESTPOOL/clone1 & + $ZFS destroy -Rf $TESTPOOL/clone2 & + $ZFS destroy -Rf $TESTPOOL/clone3 & + + wait + ((i += 1)) +done + +typeset -i count=$($ZPOOL history $TESTPOOL | $WC -l | $AWK '{print $1}') + +if ((count - orig_count != 200)); then + $ZPOOL history $spool + log_fail "Expected 200 more than $orig_count entries, but got $count" +fi + +log_pass "zpool history copes with simultaneous commands passed." diff --git a/tests/sys/cddl/zfs/tests/history/history_005_neg.ksh b/tests/sys/cddl/zfs/tests/history/history_005_neg.ksh new file mode 100644 index 00000000000..787ac6badda --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_005_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_005_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_005_neg +# +# DESCRIPTION: +# Verify the following zpool subcommands are not logged. +# zpool list +# zpool status +# zpool iostat +# +# STRATEGY: +# 1. Create a test pool. +# 2. Separately invoke zpool list|status|iostat +# 3. Verify they was not recored in pool history. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + [[ -f $EXPECT_HISTORY ]] && $RM -f $EXPECT_HISTORY + [[ -f $REAL_HISTORY ]] && $RM -f $REAL_HISTORY +} + +log_assert "Verify 'zpool list|status|iostat' will not be logged." +log_onexit cleanup + +# Save initial TESTPOOL history +log_must eval "$ZPOOL history $TESTPOOL > $EXPECT_HISTORY" + +log_must $ZPOOL list $TESTPOOL > /dev/null +log_must $ZPOOL status $TESTPOOL > /dev/null +log_must $ZPOOL iostat $TESTPOOL > /dev/null + +log_must eval "$ZPOOL history $TESTPOOL > $REAL_HISTORY" +log_must $DIFF $EXPECT_HISTORY $REAL_HISTORY + +log_pass "Verify 'zpool list|status|iostat' passed." diff --git a/tests/sys/cddl/zfs/tests/history/history_006_neg.ksh b/tests/sys/cddl/zfs/tests/history/history_006_neg.ksh new file mode 100644 index 00000000000..7acb93b7d8d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_006_neg.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_006_neg.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_006_neg +# +# DESCRIPTION: +# Verify the following zfs subcommands are not logged. +# list, get, mount, unmount, share, unshare, send +# +# STRATEGY: +# 1. Create a test pool. +# 2. Separately invoke zfs list|get|mount|unmount|share|unshare|send +# 3. Verify they was not recored in pool history. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + [[ -f $EXPECT_HISTORY ]] && $RM -f $EXPECT_HISTORY + [[ -f $REAL_HISTORY ]] && $RM -f $REAL_HISTORY + if datasetexists $fs ; then + log_must $ZFS destroy -rf $fs + fi + log_must $ZFS create $fs +} + +log_assert "Verify 'zfs list|get|mount|unmount|share|unshare|send' will not " \ + "be logged." +log_onexit cleanup + +# Create initial test environment +fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2 +log_must $ZFS set sharenfs=on $fs +log_must $ZFS snapshot $snap1 +log_must $ZFS snapshot $snap2 + +# Save initial TESTPOOL history +log_must eval "$ZPOOL history $TESTPOOL > $EXPECT_HISTORY" + +log_must $ZFS list $fs > /dev/null +log_must $ZFS get mountpoint $fs > /dev/null +log_must $ZFS unmount $fs +log_must $ZFS mount $fs +log_must $ZFS share $fs +log_must $ZFS unshare $fs +log_must $ZFS send -i $snap1 $snap2 > /dev/null + +log_must eval "$ZPOOL history $TESTPOOL > $REAL_HISTORY" +log_must $DIFF $EXPECT_HISTORY $REAL_HISTORY + +log_pass "Verify 'zfs list|get|mount|unmount|share|unshare|send' passed." diff --git a/tests/sys/cddl/zfs/tests/history/history_007_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_007_pos.ksh new file mode 100644 index 00000000000..316b92ec822 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_007_pos.ksh @@ -0,0 +1,129 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_007_pos.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_007_pos +# +# DESCRIPTION: +# Verify command history moves with pool while pool being migrated +# +# STRATEGY: +# 1. Import uniform platform and cross platform pools +# 2. Contract the command history of the imported pool +# 3. Compare imported history log with the previous log. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $migratedpoolname && \ + log_must $ZPOOL destroy -f $migratedpoolname + + [[ -d $import_dir ]] && $RM -rf $import_dir +} + +log_assert "Verify command history moves with pool while migrating." +log_onexit cleanup + +# The *.orig_history.txt files were made using the America/Denver timezone, +# and since "zpool history" outputs timestamps in localtime, the test must +# be run in that same timezone +export TZ="America/Denver" + +tst_dir=$STF_SUITE/tests/history +import_dir=$TESTDIR/importdir.${TESTCASE_ID} +migrated_cmds_f=$import_dir/migrated_history.${TESTCASE_ID} +migratedpoolname=$MIGRATEDPOOLNAME +typeset -i RET=1 +typeset -i linenum=0 + +[[ ! -d $import_dir ]] && log_must $MKDIR $import_dir + +# We test the migrations on both uniform platform and cross platform +for arch in "i386" "sparc"; do + log_must $CP $tst_dir/${arch}.orig_history.txt $import_dir + orig_cmds_f=$import_dir/${arch}.orig_history.txt + #remove blank line + orig_cmds_f1=$import_dir/${arch}.orig_history_1.txt + $CAT $orig_cmds_f | $GREP -v "^$" > $orig_cmds_f1 + + log_must $CP $tst_dir/${arch}.migratedpool.DAT.Z $import_dir + log_must $UNCOMPRESS $import_dir/${arch}.migratedpool.DAT.Z + + #destroy the pool with same name, so that import operation could succeed. + poolexists $migratedpoolname && \ + log_must $ZPOOL destroy -f $migratedpoolname + + log_must $ZPOOL import -d $import_dir $migratedpoolname + $ZPOOL history $migratedpoolname | $GREP -v "^$" >$migrated_cmds_f + RET=$? + (( $RET != 0 )) && log_fail "$ZPOOL histroy $migratedpoolname fails." + + # The migrated history file should differ with original history file on + # two commands -- 'export' and 'import', which are included in migrated + # history file but not in original history file. so, check the two commands + # firstly in migrated history file and then delete them, and then compare + # this filtered file with the original history file. They should be identical + # at this time. + for subcmd in "export" "import"; do + $GREP "$subcmd" $migrated_cmds_f >/dev/null 2>&1 + RET=$? + (( $RET != 0 )) && log_fail "zpool $subcmd is not logged for" \ + "the imported pool $migratedpoolname." + done + + tmpfile=$import_dir/cmds_tmp.${TESTCASE_ID} + linenum=`$CAT $migrated_cmds_f | $WC -l` + (( linenum = linenum - 2 )) + $HEAD -n $linenum $migrated_cmds_f > $tmpfile + log_must $DIFF $tmpfile $orig_cmds_f1 + + #cleanup for next loop testing + log_must $ZPOOL destroy -f $migratedpoolname + log_must $RM -f `$LS $import_dir` +done + +log_pass "Command history moves with pool as expected while pool being migrated. " diff --git a/tests/sys/cddl/zfs/tests/history/history_008_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_008_pos.ksh new file mode 100644 index 00000000000..59fadcfd795 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_008_pos.ksh @@ -0,0 +1,147 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_008_pos.ksh 1.3 09/01/12 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_008_pos +# +# DESCRIPTION: +# Internal journal records all the recursively operations. +# +# STRATEGY: +# 1. Create a filesystem and several sub-filesystems in it. +# 2. Make recursively snapshot. +# 3. Verify internal journal records all the recursively operations. +# 4. Do the same verification to inherit, rollback and destroy. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-22) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +$ZFS 2>&1 | $GREP "allow" > /dev/null +(($? != 0)) && log_unsupported + +function cleanup +{ + [[ -f $REAL_HISTORY ]] && $RM -f $REAL_HISTORY + [[ -f $ADD_HISTORY ]] && $RM -f $ADD_HISTORY + if datasetexists $root_testfs; then + log_must $ZFS destroy -rf $root_testfs + fi + log_must $ZFS create $root_testfs +} + +log_assert "Internal journal records all the recursively operations." +log_onexit cleanup + +root_testfs=$TESTPOOL/$TESTFS +fs1=$root_testfs/fs1; fs2=$root_testfs/fs2; fs3=$root_testfs/fs3 +for fs in $fs1 $fs2 $fs3; do + log_must $ZFS create $fs +done + +# +# Verify 'zfs snapshot -r' +# +format_history $TESTPOOL $REAL_HISTORY -i +log_must $ZFS snapshot -r ${root_testfs}@snap +additional_history $TESTPOOL $ADD_HISTORY -i +for ds in $fs1 $fs2 $fs3 ; do + log_must verify_history $ADD_HISTORY "snapshot" ${ds}@snap +done + +log_must $ZFS snapshot ${root_testfs}@snap2 +log_must $ZFS snapshot ${root_testfs}@snap3 +typeset snap2_id=$(get_dataset_id ${root_testfs}@snap2) +typeset snap3_id=$(get_dataset_id ${root_testfs}@snap3) + +# +# Verify 'zfs rollback -r' +# +format_history $TESTPOOL $REAL_HISTORY -i +log_must $ZFS rollback -r ${root_testfs}@snap +additional_history $TESTPOOL $ADD_HISTORY -i + +cat $ADD_HISTORY +for ds_id in ${snap2_id} ${snap3_id}; do + log_must verify_destroyed $ADD_HISTORY $ds_id +done +log_must verify_direct_history $ADD_HISTORY "rollback -r" $root_testfs + +# +# Verify 'zfs inherit -r' +# +format_history $TESTPOOL $REAL_HISTORY -i +log_must $ZFS inherit -r mountpoint $root_testfs +additional_history $TESTPOOL $ADD_HISTORY -i +cat $ADD_HISTORY +for ds in $fs1 $fs2 $fs3 $root_testfs; do + log_must verify_history $ADD_HISTORY "inherit" $ds +done +log_must verify_direct_history $ADD_HISTORY "inherit -r mountpoint" $root_testfs + +# Initial original $REAL_HISTORY +format_history $TESTPOOL $REAL_HISTORY -i + +fs1_id=$(get_dataset_id $fs1) +fs2_id=$(get_dataset_id $fs2) +fs3_id=$(get_dataset_id $fs3) +root_id=$(get_dataset_id $root_testfs) +fs1_snap_id=$(get_dataset_id ${fs1}@snap) +fs2_snap_id=$(get_dataset_id ${fs2}@snap) +fs3_snap_id=$(get_dataset_id ${fs3}@snap) +root_snap_id=$(get_dataset_id ${root_testfs}@snap) + +# +# Verify 'zfs destroy -r' +# +log_must $ZFS destroy -r $root_testfs +additional_history $TESTPOOL $ADD_HISTORY -i +cat $ADD_HISTORY +for ds_id in ${fs1_id} ${fs2_id} ${fs3_id} ${root_id} ${fs1_snap_id} ${fs2_snap_id} ${fs3_snap_id} ${root_snap_id}; do + log_must verify_destroyed $ADD_HISTORY $ds_id +done +log_must verify_direct_history $ADD_HISTORY "destroy -r" $root_testfs + +log_pass "Internal journal records all the recursively operations passed." diff --git a/tests/sys/cddl/zfs/tests/history/history_009_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_009_pos.ksh new file mode 100644 index 00000000000..e177b629393 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_009_pos.ksh @@ -0,0 +1,180 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_009_pos.ksh 1.4 09/01/12 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_009_pos +# +# DESCRIPTION: +# Verify the delegation internal history are correctly. +# +# ul$ identifies permssions granted locally for this userid. +# ud$ identifies permissions granted on descendent datasets for +# this userid. +# +# Ul$ identifies permission sets granted locally for this userid. +# Ud$ identifies permission sets granted on descendent datasets for +# this userid. +# +# gl$ identifies permissions granted locally for this groupid. +# gd$ identifies permissions granted on descendent datasets for +# this groupid. +# +# Gl$ identifies permission sets granted locally for this groupid. +# Gd$ identifies permission sets granted on descendent datasets for +# this groupid. +# +# el$ identifies permissions granted locally for everyone. +# ed$ identifies permissions granted on descendent datasets for +# everyone. +# +# El$ identifies permission sets granted locally for everyone. +# Ed$ identifies permission sets granted to descendent datasets +# for everyone. +# +# c-$ identifies permission to create at dataset creation time. +# C-$ identifies permission sets to grant locally at dataset +# creation time. +# +# s-$@ permissions defined in specified set @ +# S-$@ Sets defined in named set @ +# +# STRATEGY: +# 1. Create test group and user. +# 2. Define permission sets and verify the internal history correctly. +# 3. Separately verify the internal history above is correct. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +$ZFS 2>&1 | $GREP "allow" > /dev/null +(($? != 0)) && log_unsupported + +function cleanup +{ + if [[ -f $REAL_HISTORY ]]; then + log_must $RM -f $REAL_HISTORY + fi + if [[ -f $ADD_HISTORY ]]; then + log_must $RM -f $ADD_HISTORY + fi + del_user $HIST_USER + del_group $HIST_GROUP +} + +log_assert "Verify the delegation internal history are correctly." +log_onexit cleanup + +testfs=$TESTPOOL/$TESTFS +# Create history test group and user and get user id and group id +add_group $HIST_GROUP +add_user $HIST_GROUP $HIST_USER + +uid=$($ID $HIST_USER | $AWK -F= '{print $2}'| $AWK -F"(" '{print $1}' ) +gid=$($ID $HIST_USER | $AWK -F= '{print $3}'| $AWK -F"(" '{print $1}' ) + +# Initial original $REAL_HISTORY +format_history $TESTPOOL $REAL_HISTORY -i + +# +# Keyword subcmd operating allow_options +# +set -A array \ + "s-\$@basic" "allow" "-s @basic snapshot" \ + "S-\$@set" "allow" "-s @set @basic" \ + "c-\\$" "allow" "-c create" \ + "c-\\$" "unallow" "-c create" \ + "C-\\$ @set" "allow" "-c @set" \ + "C-\\$ @set" "unallow" "-c @set" \ + "ul\$$uid" "allow" "-l -u $HIST_USER snapshot" \ + "ul\$$uid" "allow" "-u $HIST_USER snapshot" \ + "ul\$$uid" "unallow" "-u $HIST_USER snapshot" \ + "Ul\$$uid" "allow" "-l -u $HIST_USER @set" \ + "Ul\$$uid" "allow" "-u $HIST_USER @set" \ + "Ul\$$uid" "unallow" "-u $HIST_USER @set" \ + "ud\$$uid" "allow" "-d -u $HIST_USER snapshot" \ + "ud\$$uid" "allow" "-u $HIST_USER snapshot" \ + "ud\$$uid" "unallow" "-u $HIST_USER snapshot" \ + "Ud\$$uid" "allow" "-d -u $HIST_USER @set" \ + "Ud\$$uid" "allow" "-u $HIST_USER @set" \ + "Ud\$$uid" "unallow" "-u $HIST_USER @set" \ + "gl\$$gid" "allow" "-l -g $HIST_GROUP snapshot" \ + "gl\$$gid" "allow" "-g $HIST_GROUP snapshot" \ + "gl\$$gid" "unallow" "-g $HIST_GROUP snapshot" \ + "Gl\$$gid" "allow" "-l -g $HIST_GROUP @set" \ + "Gl\$$gid" "allow" "-g $HIST_GROUP @set" \ + "Gl\$$gid" "unallow" "-g $HIST_GROUP @set" \ + "gd\$$gid" "allow" "-d -g $HIST_GROUP snapshot" \ + "gd\$$gid" "allow" "-g $HIST_GROUP snapshot" \ + "gd\$$gid" "unallow" "-g $HIST_GROUP snapshot" \ + "Gd\$$gid" "allow" "-d -g $HIST_GROUP @set" \ + "Gd\$$gid" "allow" "-g $HIST_GROUP @set" \ + "Gd\$$gid" "unallow" "-g $HIST_GROUP @set" \ + "el\\$" "allow" "-l -e snapshot" \ + "el\\$" "allow" "-e snapshot" \ + "el\\$" "unallow" "-e snapshot" \ + "El\\$" "allow" "-l -e @set" \ + "El\\$" "allow" "-e @set" \ + "El\\$" "unallow" "-e @set" \ + "ed\\$" "allow" "-d -e snapshot" \ + "ed\\$" "allow" "-e snapshot" \ + "ed\\$" "unallow" "-e snapshot" \ + "Ed\\$" "allow" "-d -e @set" \ + "Ed\\$" "allow" "-e @set" \ + "Ed\\$" "unallow" "-e @set" + +typeset -i i=0 +while ((i < ${#array[@]})); do + keyword=${array[$i]} + subcmd=${array[((i+1))]} + options=${array[((i+2))]} + + log_must $ZFS $subcmd $options $testfs + additional_history $TESTPOOL $ADD_HISTORY -i + log_must verify_history $ADD_HISTORY $subcmd $testfs $keyword + + ((i += 3)) +done + +log_pass "Verify the delegation internal history are correctly." diff --git a/tests/sys/cddl/zfs/tests/history/history_010_pos.ksh b/tests/sys/cddl/zfs/tests/history/history_010_pos.ksh new file mode 100644 index 00000000000..323ce1d45d9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_010_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_010_pos.ksh 1.4 09/01/12 SMI" +# + +. $STF_SUITE/tests/history/history_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: history_010_pos +# +# DESCRIPTION: +# Verify internal long history information are correct. +# +# STRATEGY: +# 1. Create non-root test user and group. +# 2. Do some zfs operation test by root and non-root user. +# 3. Verify the long history information are correct. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +$ZFS 2>&1 | $GREP "allow" > /dev/null +(($? != 0)) && log_unsupported + +function cleanup +{ + [[ -f $REAL_HISTORY ]] && $RM -f $REAL_HISTORY + [[ -f $EXPECT_HISTORY ]] && $RM -f $EXPECT_HISTORY + + del_user $HIST_USER + del_group $HIST_GROUP + + datasetexists $root_testfs && log_must $ZFS destroy -rf $root_testfs +} + +log_assert "Verify internal long history information are correct." +log_onexit cleanup + +root_testfs=$TESTPOOL/$TESTFS1 + +# Create history test group and user and get user id and group id +add_group $HIST_GROUP +add_user $HIST_GROUP $HIST_USER +uid=$($ID $HIST_USER | $AWK -F= '{print $2}'| $AWK -F"(" '{print $1}' ) +gid=$($ID $HIST_USER | $AWK -F= '{print $3}'| $AWK -F"(" '{print $1}' ) + +# Get original long history +format_history $TESTPOOL $EXPECT_HISTORY "-l" + +exec_record -l $ZFS create $root_testfs +exec_record -l $ZFS allow $HIST_GROUP snapshot,mount $root_testfs +exec_record -l $ZFS allow $HIST_USER destroy,mount $root_testfs +exec_record -l $ZFS allow $HIST_USER reservation $root_testfs +exec_record -l $ZFS allow $HIST_USER allow $root_testfs + +exec_record -l -u $HIST_USER "$ZFS snapshot $root_testfs@snap" +exec_record -l -u $HIST_USER "$ZFS destroy $root_testfs@snap" +exec_record -l -u $HIST_USER "$ZFS reservation=64M $root_testfs" +exec_record -l -u $HIST_USER "$ZFS allow $HIST_USER reservation $root_testfs" +exec_record -l $ZFS unallow $HIST_USER create $root_testfs +exec_record -l $ZFS unallow $HIST_GROUP snapshot $root_testfs +exec_record -l $ZFS destroy -r $root_testfs + +format_history $TESTPOOL $REAL_HISTORY "-l" +log_must $DIFF $REAL_HISTORY $EXPECT_HISTORY + +del_user $HIST_USER +del_group $HIST_GROUP + +log_pass "Verify internal long history information pass." diff --git a/tests/sys/cddl/zfs/tests/history/history_common.kshlib b/tests/sys/cddl/zfs/tests/history/history_common.kshlib new file mode 100644 index 00000000000..897311afb02 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_common.kshlib @@ -0,0 +1,268 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)history_common.kshlib 1.3 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Execute arguments and record them to the log file. +# Notice: EXPECT_HISTORY need be defined. +# +# $1-n arguments for execution. +# +function exec_record +{ + [[ -z $EXPECT_HISTORY ]] && log_fail "EXPECT_HISTORY is undefined." + + typeset long_hist + typeset user='root' + typeset opt + while getopts ":lu:" opt; do + case $opt in + l) long_hist=1;; + u) user=$OPTARG ;; + esac + done + shift $(($OPTIND -1)) + + if [[ $user == 'root' ]]; then + log_must "$@" + else + log_must $SU $user -c "$@" + fi + user_id=$(id -u $user) + + typeset cmdline="$@" + # Remove "eval" ">*" & "<*" for 'zfs send' and 'zfs receive'. + cmdline=${cmdline#eval} + cmdline=${cmdline%%\>*} + cmdline=${cmdline%%\<*} + + # Remove additional blank + cmdline=${cmdline## } + cmdline=${cmdline%% } + + # Get the basename of command. i.e: /usr/sbin/zpool -> zpool + typeset cmd=$($ECHO $cmdline | $AWK '{print $1}') + eval cmdline=\${cmdline#$cmd} + cmd=${cmd##*/} + + # Write basic history to file + print -n $cmd $cmdline >> $EXPECT_HISTORY + if [[ -n $long_hist ]]; then + # Write long history to file + hn=$($HOSTNAME) + zn=$($ZONENAME) + [ "$zn" = "global" ] && zn="" + [ -n "$zn" ] && zn=":$zn" + print -n " [user $user_id ($user) on $hn$zn]" >> $EXPECT_HISTORY + fi + # Plus enter in the end of line + print >> $EXPECT_HISTORY +} + +# +# Format 'zpool history' output to specified file. +# +# $1 pool name +# $2 output file. +# $3 option +# +function format_history +{ + typeset pool=$1 + typeset outfile=$2 + typeset option=$3 + + [[ -z $pool || -z $outfile ]] && \ + log_fail "Usage: format_history [option]" + + typeset temp_history=$TMPDIR/temp_history.format_history.${TESTCASE_ID} + $ZPOOL history $option $pool > $temp_history + + # Truncate output file + $CAT /dev/null > $outfile + + typeset line + typeset -i n=0 + while read line; do + # Ignore the first line and empty line + if [[ $n -eq 0 || -z $line ]]; then + n=1; continue + fi + $ECHO ${line#* } >> $outfile + done < $temp_history + + $RM -f $temp_history +} + +# +# Get the additional pool history. +# +# $1 pool name +# $2 additional history file +# $3 option +# +function additional_history +{ + typeset pool=$1 + typeset add_his_file=$2 + typeset option=$3 + + if [[ -z $pool || -z $add_his_file ]]; then + log_fail "Usage: additional_history " \ + " [option]" + fi + + typeset temp_history=$TMPDIR/temp_history.additional_history.${TESTCASE_ID} + # Current current history + format_history $pool $temp_history $option + # Figure out new history + $DIFF $temp_history $REAL_HISTORY | $GREP "^<" | $SED 's/^<[ ]*//' > \ + $add_his_file + + $CP $temp_history $REAL_HISTORY + $RM -f $temp_history +} + +# +# Get given dataset id +# +# $1 dataset name +# +function get_dataset_id +{ + typeset ds=$1 + + # + # The zdb information looks like: + # + # Dataset pool/fs [ZPL], ID 21, cr_txg 6, 18.0K, 4 objects + # + typeset dst_id=$($ZDB $ds | $GREP "^Dataset $ds " | \ + $AWK -F\, '{print $2}' | $AWK '{print $2}') + + $ECHO $dst_id +} + +# +# Special case of verify_history, but only for destroyed datasets. This is +# needed because get_dataset_id depends on still having the original dataset +# in order to obtain its dataset id. +# +function verify_destroyed # +{ + typeset his_file=$1 + typeset ds_id=$2 + + $GREP -E "\[txg:[0-9]+\] destroy [^ ]+ \($ds_id\)" $his_file \ + > /dev/null 2>&1 + (($? == 0)) && return 0 + return 1 +} + +# +# Verify directly executed commands in a history file. This differs from +# verify_history in that it checks for explicit commands as opposed to +# internally generated commands. +# +function verify_direct_history # +{ + typeset his_file=$1 + typeset subcmd=$2 + typeset ds=$3 + + $GREP "zfs ${subcmd} ${ds}" ${his_file} > /dev/null 2>&1 + (($? == 0)) && return 0 + return 1 +} + +# This function mostly just helps to collapse the case statement +# in verify_history. It returns whether the line matches (1==true). +function verify_history_line +{ + typeset line=$1 + typeset subcmd=$2 + typeset ds=$3 + typeset keyword=$4 + + typeset dst_id=$(get_dataset_id $ds) + log_note "Line: '$line'" + log_note "Checking cmd($subcmd) for $ds, keyword='$keyword'" + $ECHO $line | $GREP -E "\[txg:[0-9]+\] $subcmd $ds \($dst_id\)" | \ + $GREP $keyword >/dev/null 2>&1 + [[ $? == 0 ]] && return 1 + return 0 +} + +# +# Scan history file and check if it include expected internal history +# information +# +# $1 history file +# $2 subcmd +# $3 dataset +# $4 keyword +# +function verify_history # [keyword] +{ + typeset his_file=$1 + typeset subcmd=$2 + typeset ds=$3 + typeset keyword=$4 + + typeset line found=0 + log_note "Test1" + while read line; do + case $subcmd in + snapshot|rollback|inherit) + # [txg:12] snapshot system/foo@0 (46) + keyword="$subcmd" + verify_history_line "$line" $subcmd $ds $keyword + [[ $? == 0 ]] && return 0 + ;; + allow) + # [txg:10] permission update testpool.1477/testfs.1477 (40) s-$@basic snapshot + _subcmd="permission update" + verify_history_line "$line" "$_subcmd" $ds "$keyword" + [[ $? == 0 ]] && return 0 + ;; + unallow) + # [txg:174] permission remove testpool.1477/testfs.1477 (40) El$ @set + _subcmd="permission remove" + verify_history_line "$line" "$_subcmd" $ds "$keyword" + [[ $? == 0 ]] && return 0 + ;; + *) + ;; + esac + done < $his_file + return 1 +} diff --git a/tests/sys/cddl/zfs/tests/history/history_test.sh b/tests/sys/cddl/zfs/tests/history/history_test.sh new file mode 100755 index 00000000000..51c3ce75ccd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/history_test.sh @@ -0,0 +1,301 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case history_001_pos +history_001_pos_head() +{ + atf_set "descr" "Verify zpool sub-commands which modify state are logged." + atf_set "require.progs" zpool nawk + atf_set "timeout" 1800 +} +history_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/history_001_pos.ksh || atf_fail "Testcase failed" +} + +atf_test_case history_002_pos cleanup +history_002_pos_head() +{ + atf_set "descr" "Verify zfs sub-commands which modify state are logged." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +history_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_002_pos.ksh || atf_fail "Testcase failed" +} +history_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_003_pos cleanup +history_003_pos_head() +{ + atf_set "descr" "zpool history limitation test." + atf_set "require.progs" zpool zfs + atf_set "timeout" 1800 +} +history_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_003_pos.ksh || atf_fail "Testcase failed" +} +history_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_004_pos cleanup +history_004_pos_head() +{ + atf_set "descr" "'zpool history' can copes with many simultaneous command." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +history_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_004_pos.ksh || atf_fail "Testcase failed" +} +history_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_005_neg cleanup +history_005_neg_head() +{ + atf_set "descr" "Verify 'zpool list|status|iostat' will not be logged." + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +history_005_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_005_neg.ksh || atf_fail "Testcase failed" +} +history_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_006_neg cleanup +history_006_neg_head() +{ + atf_set "descr" "Verify 'zfs list|get|mount|unmount|share|unshare|send' will notbe logged." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +history_006_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_006_neg.ksh || atf_fail "Testcase failed" +} +history_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_007_pos cleanup +history_007_pos_head() +{ + atf_set "descr" "Verify command history moves with pool while migrating." + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +history_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_007_pos.ksh || atf_fail "Testcase failed" +} +history_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_008_pos cleanup +history_008_pos_head() +{ + atf_set "descr" "Internal journal records all the recursively operations." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +history_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_008_pos.ksh || atf_fail "Testcase failed" +} +history_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_009_pos cleanup +history_009_pos_head() +{ + atf_set "descr" "Verify the delegation internal history are correctly." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +history_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_009_pos.ksh || atf_fail "Testcase failed" +} +history_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case history_010_pos cleanup +history_010_pos_head() +{ + atf_set "descr" "Verify internal long history information are correct." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +history_010_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/history_010_pos.ksh || atf_fail "Testcase failed" +} +history_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/history_common.kshlib + . $(atf_get_srcdir)/history.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case history_001_pos + atf_add_test_case history_002_pos + atf_add_test_case history_003_pos + atf_add_test_case history_004_pos + atf_add_test_case history_005_neg + atf_add_test_case history_006_neg + atf_add_test_case history_007_pos + atf_add_test_case history_008_pos + atf_add_test_case history_009_pos + atf_add_test_case history_010_pos +} diff --git a/tests/sys/cddl/zfs/tests/history/i386.migratedpool.DAT.Z b/tests/sys/cddl/zfs/tests/history/i386.migratedpool.DAT.Z new file mode 100644 index 00000000000..21cd7fcf583 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/history/i386.migratedpool.DAT.Z differ diff --git a/tests/sys/cddl/zfs/tests/history/i386.orig_history.txt b/tests/sys/cddl/zfs/tests/history/i386.orig_history.txt new file mode 100644 index 00000000000..02e279eec52 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/i386.orig_history.txt @@ -0,0 +1,13 @@ +History for 'history_pool': +2006-10-20.13:18:37 zpool create history_pool /var/tmp/i386.migratedpool.DAT +2006-10-20.13:18:37 zfs create history_pool/fs +2006-10-20.13:18:37 zfs set compression=on history_pool/fs +2006-10-20.13:18:37 zfs set checksum=on history_pool +2006-10-20.13:18:37 zfs snapshot history_pool/fs@snap +2006-10-20.13:18:37 zfs clone history_pool/fs@snap history_pool/clone +2006-10-20.13:18:37 zfs promote history_pool/clone +2006-10-20.13:18:37 zfs promote history_pool/fs +2006-10-20.13:18:37 zfs destroy -r -R history_pool/fs +2006-10-20.13:18:37 zpool export history_pool +2007-04-05.00:05:38 zpool upgrade history_pool + diff --git a/tests/sys/cddl/zfs/tests/history/setup.ksh b/tests/sys/cddl/zfs/tests/history/setup.ksh new file mode 100644 index 00000000000..2d9ec813854 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/setup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +$ZPOOL history > /dev/null 2>&1 +(($? != 0)) && log_unsupported + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/history/sparc.migratedpool.DAT.Z b/tests/sys/cddl/zfs/tests/history/sparc.migratedpool.DAT.Z new file mode 100644 index 00000000000..47a61ffd51a Binary files /dev/null and b/tests/sys/cddl/zfs/tests/history/sparc.migratedpool.DAT.Z differ diff --git a/tests/sys/cddl/zfs/tests/history/sparc.orig_history.txt b/tests/sys/cddl/zfs/tests/history/sparc.orig_history.txt new file mode 100644 index 00000000000..6ae7168bbba --- /dev/null +++ b/tests/sys/cddl/zfs/tests/history/sparc.orig_history.txt @@ -0,0 +1,13 @@ +History for 'history_pool': +2006-10-27.03:13:47 zpool create history_pool /var/tmp/sparc.migratedpool.DAT +2006-10-27.03:13:48 zfs create history_pool/fs +2006-10-27.03:13:48 zfs set compression=on history_pool/fs +2006-10-27.03:13:48 zfs set checksum=on history_pool +2006-10-27.03:13:48 zfs snapshot history_pool/fs@snap +2006-10-27.03:13:48 zfs clone history_pool/fs@snap history_pool/clone +2006-10-27.03:13:49 zfs promote history_pool/clone +2006-10-27.03:13:49 zfs promote history_pool/fs +2006-10-27.03:13:49 zfs destroy -r -R history_pool/fs +2006-10-27.03:13:49 zpool export history_pool +2007-04-05.00:41:55 zpool upgrade history_pool + diff --git a/tests/sys/cddl/zfs/tests/history/zfs-pool-v4.dat.Z b/tests/sys/cddl/zfs/tests/history/zfs-pool-v4.dat.Z new file mode 100644 index 00000000000..bc32472f008 Binary files /dev/null and b/tests/sys/cddl/zfs/tests/history/zfs-pool-v4.dat.Z differ diff --git a/tests/sys/cddl/zfs/tests/hotplug/Makefile b/tests/sys/cddl/zfs/tests/hotplug/Makefile new file mode 100644 index 00000000000..09299869a48 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/Makefile @@ -0,0 +1,21 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/hotplug +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= hotplug_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= hotplug.cfg +${PACKAGE}FILES+= hotplug.kshlib +${PACKAGE}FILES+= hotplug_001_pos.ksh +${PACKAGE}FILES+= hotplug_008_pos.ksh +${PACKAGE}FILES+= hotplug_011_pos.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/hotplug/cleanup.ksh b/tests/sys/cddl/zfs/tests/hotplug/cleanup.ksh new file mode 100644 index 00000000000..2639f0c471a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/cleanup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/tests/hotplug/hotplug.kshlib + +cleanup_testenv $TESTPOOL +destroy_gnops $ALL_DISKS diff --git a/tests/sys/cddl/zfs/tests/hotplug/hotplug.cfg b/tests/sys/cddl/zfs/tests/hotplug/hotplug.cfg new file mode 100644 index 00000000000..84caf18271c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/hotplug.cfg @@ -0,0 +1,36 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotplug.cfg 1.3 08/08/15 SMI" +# + +export DEV_DISKS="$DISK0 $DISK1 $DISK2" +export SPARE_DISKS="$DISK3" +export ALL_DISKS="$DEV_DISKS $SPARE_DISKS" + +set_disks diff --git a/tests/sys/cddl/zfs/tests/hotplug/hotplug.kshlib b/tests/sys/cddl/zfs/tests/hotplug/hotplug.kshlib new file mode 100644 index 00000000000..5cf8a67ea8d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/hotplug.kshlib @@ -0,0 +1,463 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotplug.kshlib 1.4 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/include/libgnop.kshlib +. $STF_SUITE/tests/hotplug/hotplug.cfg + +# +# create lofi devices +# +# $1-n files +# +function create_lofi_device +{ + typeset lofi_files="$@" + + typeset file + for file in $lofi_files ; do + if ! $LOFIADM $file > /dev/null 2>&1 ; then + insert_device $file + if (($? != 0)); then + return 1 + fi + fi + + shift + done + + return 0 +} + +# +# Check and destroy lofi devices +# +# $1-n lofi files or deviece +# +function destroy_lofi_device +{ + typeset -i ret=0 + typeset dev_file="$@" + + typeset file + for file in $dev_file ; do + if $LOFIADM $file > /dev/null 2>&1; then + $LOFIADM -d $file -f + if (($? != 0)); then + ((ret += 1)) + fi + fi + done + + return $ret +} + +# +# Setup test environment using DISKS[1-4] +# +# $1 pool type +# +function setup_testenv +{ + typeset type=$1 + + if [[ -z $type ]]; then + log_fail "Usage: setup_testenv " + fi + + log_must $ZPOOL create -f \ + $TESTPOOL $type ${DISK0}.nop ${DISK1}.nop ${DISK2}.nop ${DISK3}.nop +} + +# +# Cleanup test envirnment according to pool name +# +# $1 pool +# +function cleanup_testenv +{ + destroy_pool $TESTPOOL +} + + +# +# Start a background process to write file on given pool. +# +# $1 pool +# +function start_bg_write +{ + typeset pool=$1 + + if datasetnonexists $pool; then + return 1 + fi + + typeset mntpnt=$(get_prop mountpoint $pool) + + while true; do + $DD if=/dev/random of=$mntpnt/foo count=10 + $SYNC + $SLEEP 1 + done & + BG_PID=$! + + return 0 +} + +# +# Kill the background write process. +# +function kill_bg_write +{ + typeset -i ret=0 + + if [[ -n $BG_PID ]]; then + kill -9 $BG_PID + ret=$? + + if ((ret == 0)); then + BG_PID='' + fi + fi + + $SLEEP 10 + return $ret +} + +# +# Insert a given file into a given device slot +# +# $1 file +# $2 device +# +function insert_device +{ + typeset file=$1 + typeset device=$2 + + if [[ -z $file ]]; then + return 1 + fi + + # + # Make sure insert device succeed within 60 seconds + # + typeset -i i=0 + while ((i < 6)); do + $SLEEP 10 + + $LOFIADM -a $file $device -f > /dev/null 2>&1 + if (($? == 0)); then + return 0 + fi + + ((i += 1)) + done + + return 1 +} + +# +# Remove the given lofi device +# +# $1 device or file +# +function remove_device +{ + typeset devfile=$1 + + if [[ -z $devfile ]]; then + return 1 + fi + + # + # Make sure remove device succeed within 60 seconds + # + typeset -i i=0 + while ((i < 6)); do + $SLEEP 10 + $LOFIADM -d $devfile -f + if (($? == 0)); then + return 0 + fi + + ((i += 1)) + done + + return 1 +} + +# +# Verify the given devices have expected status in pool +# +# $1 pool +# $2 device +# $3 expected status +# +function verify_device_status +{ + typeset pool=$1 + typeset device=$2 + typeset expect_stat=$3 + + if [[ -z $pool || -z $expect_stat || -z $device ]]; then + log_note "Usage: verify_device_status " + return 1 + fi + + # + # 1.5 minute disk status checking, make sure zpool sync disk status. + # + typeset -i i=0 + while ((i < 9)); do + $SLEEP 10 + + typeset str=$($ZPOOL status $pool | $GREP "lofi" | \ + $AWK '{print $1 " " $2}') + typeset real_stat=${str##*$device } + real_stat=$($ECHO $real_stat | $AWK '{print $1}') + + if [[ "$expect_stat" == "$real_stat" ]]; then + return 0 + fi + + ((i += 1)) + done + + log_note "Expected status($expect_stat), " \ + "see status($real_stat) for $device" + $ZPOOL status -v $pool + + return 1 +} + +# +# Output fma event id to given file, the default output file is $FILE_EVENT_ID +# +function getfmri +{ + eval typeset output_file=${1:-$FILE_EVENT_ID} +# +# fmadm faulty output include several sections below +# + +# --------------- ------------------------------------ -------------- --------- +# TIME EVENT-ID MSG-ID SEVERITY +# --------------- ------------------------------------ -------------- --------- +# Aug 31 22:34:19 ec648a9e-0c9f-c495-e176-e38ba212e278 ZFS-8000-D3 Major +# Aug 31 19:44:59 d69cdd12-b0cf-62ea-d0a3-8d2e9ebfeb50 ZFS-8000-D3 +# Aug 31 19:35:16 7213f0d5-00d4-ea32-ddfc-98cdd683c27e ZFS-8000-D3 +# Aug 31 19:29:11 33424bef-a973-4dae-94ef-cb97f2cb0759 ZFS-8000-D3 +# Aug 31 17:07:26 74219b66-ead4-6d2b-bbad-bc40547ca02e ZFS-8000-GH +# +# Fault class : fault.fs.zfs.device +# +# Description : A ZFS device failed. Refer to http://sun.com/msg/ZFS-8000-D3 for +# more information. +# +# Response : No automated response will occur. +# +# Impact : Fault tolerance of the pool may be compromised. +# +# Action : Run 'zpool status -x' and replace the bad device. +# + $FMADM faulty | $NAWK ' + BEGIN { + start = 0 + } + /^---/ && /---$/ { + if (start == 0) { + start = 1 + } + } + /^TIME/ && /SEVERITY$/ { + if (start == 1) { + start = 2 + } + } + /^---/ && /---$/ { + if (start == 2) { + start = 3 + continue + } + } + /^$/ { + start = 0 + } + (start == 3) {print $4}' > $output_file +} + +# +# Verify if ZFS FMA faulty error message are generated. +# +# $1 TRUE or FALSE +# +function fma_faulty +{ + # + # 1.5 minute for FMA faulty checking, make sure FMA sync with ZFS status + # + typeset expect=${1:-TRUE} + + typeset -i fsize + typeset -i i=0 + while ((i < 9)); do + $SLEEP 10 + + # + # try to get fma faulty + # + getfmri $FILE_EVENT_ID + fsize=$($LS -ld $FILE_EVENT_ID | $AWK '{print $5}') + + case $expect in + TRUE) + if (( fsize != 0 )); then + return 0 + fi + ;; + FALSE) + if (( fsize == 0 )); then + return 0 + fi + ;; + *) + return 1 + esac + + ((i += 1)) + done + + return 1 +} + +# +# Create fresh file +# +# $1 file size +# $2 file name +# +function create_file +{ + typeset size=$1 + typeset file=$2 + + if [[ -z $size || -z $file ]]; then + log_note "Usage: create_file " + return 1 + fi + if [[ -f $file ]]; then + $RM -f $file + fi + $MKFILE $size $file + return $? +} + +# +# Unmount all filesystem, and disable syseventd and fmd piror to +# unloading ZFS module +# +function unload_zfs +{ + # destroy /dev/zvol link + log_must $ZFS volfini + + log_must $ZFS unmount -f -a + log_must $SVCADM disable -t sysevent fmd + $SLEEP 10 + + # + # 1 minute for ZFS module unload checking + # + # For example: + # + # 192 fffffffff7c92000 99858 182 1 zfs (ZFS storage pool version 6) + # + typeset -i i=0 + while ((i < 10)); do + typeset id=$($MODINFO | $GREP "ZFS storage" | $AWK '{print $1}') + + if [[ -n $id ]]; then + $MODUNLOAD -i $id + if (($? == 0)) ; then + return 0 + fi + else + return 0 + fi + + $SLEEP 6 + ((i += 1)) + done + + return 1 +} + +# +# Load ZFS module and remount all filesystem +# +function load_zfs +{ + typeset -i ret=0 + $SVCADM enable sysevent fmd + ((ret |= $?)) + + $SLEEP 10 + + $ZFS mount -a + ((ret |= $?)) + + # create /dev/zvol link + $ZFS volinit + ((ret |= $?)) + + return $ret +} + +# +# Convert file name to device name or reverse. +# +# $1-n lofi files or devices +# +function convert_lofi +{ + typeset n list + + for n in "$@"; do + typeset item=$($LOFIADM $n) + list="$list $item" + + shift + done + + $ECHO $list +} diff --git a/tests/sys/cddl/zfs/tests/hotplug/hotplug_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotplug/hotplug_001_pos.ksh new file mode 100644 index 00000000000..4dd344ff759 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/hotplug_001_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotplug_001_pos.ksh 1.2 08/02/27 SMI" +# + +. $STF_SUITE/tests/hotplug/hotplug.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: hotplug_001_pos +# +# DESCRIPTION: +# When removing a device from a redundant pool, the device's state will +# be indicated as 'REMOVED'. +# +# STRATEGY: +# 1. Create mirror/raidz/raidz2 pool. +# 2. Synchronise with device in the background. +# 3. Remove one of device of pool. +# 4. Detect removed devices status is 'REMOVED'. +# 5. Detect no FMA faulty message. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-01) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "When removing a device from a redundant pool, the device's " \ + "state will be indicated as 'REMOVED'." + +for type in "mirror" "raidz" "raidz2"; do + log_note "Start $type testing ..." + setup_testenv $type + + log_must destroy_gnop $DISK0 + wait_for 15 1 check_state $TESTPOOL ${DISK0}.nop 'REMOVED' + log_must check_state $TESTPOOL ${DISK0}.nop 'REMOVED' + + log_must create_gnop $DISK0 + cleanup_testenv $TESTPOOL +done + +log_pass "When removing a device from a redundant pool, the device's " \ + "state will be indicated as 'REMOVED'." diff --git a/tests/sys/cddl/zfs/tests/hotplug/hotplug_008_pos.ksh b/tests/sys/cddl/zfs/tests/hotplug/hotplug_008_pos.ksh new file mode 100644 index 00000000000..426030c2450 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/hotplug_008_pos.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotplug_008_pos.ksh 1.3 08/02/27 SMI" +# + +. $STF_SUITE/tests/hotplug/hotplug.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: hotplug_008_pos +# +# DESCRIPTION: +# After hot spare device is revoved, the devices state will be 'REMOVED'. +# No FMA faults was generated. +# +# STRATEGY: +# 1. Create mirror/raidz/raidz2 pool with hot spare device. +# 2. Synchronise with device in the background. +# 3. Remove the hotspare device. +# 4. Verify the device's status is 'REMOVED'. +# 5. Verify no FMA fault was generated. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-01) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "When removing hotspare device, verify device status is 'REMOVED'." + +for type in "mirror" "raidz" "raidz2"; do + log_must $ZPOOL create -f $TESTPOOL $type $DISK0.nop $DISK1.nop $DISK2.nop spare $DISK3.nop + + log_must destroy_gnop $DISK3 + wait_for 15 1 check_state $TESTPOOL $DISK3.nop 'REMOVED' + log_must check_state $TESTPOOL $DISK3.nop 'REMOVED' + + log_must create_gnop $DISK3 + cleanup_testenv $TESTPOOL +done + +log_pass "When removing hotspare device, verify device status is 'REMOVED'." diff --git a/tests/sys/cddl/zfs/tests/hotplug/hotplug_011_pos.ksh b/tests/sys/cddl/zfs/tests/hotplug/hotplug_011_pos.ksh new file mode 100644 index 00000000000..8dcc0344511 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/hotplug_011_pos.ksh @@ -0,0 +1,84 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotplug_011_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/hotplug/hotplug.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: hotplug_011_pos +# +# DESCRIPTION: +# Removing device offlined, verify device status is UNAVAIL, when the +# system is onlined. +# +# STRATEGY: +# 1. Create mirror/raidz/raidz2 pool w/a hot spare device. +# 2. Synchronise with device in the background. +# 3. Set or unset autoreplace +# 4. Unmount all filesystems and disable syseventd and fmd. +# 5. Unload ZFS module and remove devices. +# 6. Load ZFS module and verify device the device's status is 'UNAVAIL'. +# 7. Verify no FMA fault was generated. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-01) +# +# __stc_assertion_end +# +################################################################################ + +log_assert "If a vdev is missing when a pool is imported, its status will be " \ + "UNAVAIL" + +for type in "mirror" "raidz" "raidz2"; do + setup_testenv $type + + log_must $ZPOOL export $TESTPOOL + + # Random remove one of devices + log_must destroy_gnop $DISK0 + + # reimport the pool + log_must $ZPOOL import $TESTPOOL + + log_must check_state $TESTPOOL $DISK0.nop 'UNAVAIL' + + log_must create_gnop $DISK0 + cleanup_testenv $TESTPOOL +done + +log_pass "If a vdev is missing when a pool is imported, its status will be " \ + "UNAVAIL" diff --git a/tests/sys/cddl/zfs/tests/hotplug/hotplug_test.sh b/tests/sys/cddl/zfs/tests/hotplug/hotplug_test.sh new file mode 100755 index 00000000000..6eb5f6875fa --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/hotplug_test.sh @@ -0,0 +1,111 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case hotplug_001_pos cleanup +hotplug_001_pos_head() +{ + atf_set "descr" "When removing a device from a redundant pool, the device'sstate will be indicated as 'REMOVED'." + atf_set "require.progs" zpool gnop +} +hotplug_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotplug.kshlib + . $(atf_get_srcdir)/hotplug.cfg + + verify_disk_count "$DISKS" 4 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotplug_001_pos.ksh || atf_fail "Testcase failed" +} +hotplug_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotplug.kshlib + . $(atf_get_srcdir)/hotplug.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case hotplug_008_pos cleanup +hotplug_008_pos_head() +{ + atf_set "descr" "When removing hotspare device, verify device status is 'REMOVED'." + atf_set "require.progs" zpool gnop +} +hotplug_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotplug.kshlib + . $(atf_get_srcdir)/hotplug.cfg + + verify_disk_count "$DISKS" 4 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotplug_008_pos.ksh || atf_fail "Testcase failed" +} +hotplug_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotplug.kshlib + . $(atf_get_srcdir)/hotplug.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case hotplug_011_pos cleanup +hotplug_011_pos_head() +{ + atf_set "descr" "Removing device offlined, verify device status is UNAVAIL,when the system is onlined." + atf_set "require.progs" zpool gnop +} +hotplug_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotplug.kshlib + . $(atf_get_srcdir)/hotplug.cfg + + verify_disk_count "$DISKS" 4 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotplug_011_pos.ksh || atf_fail "Testcase failed" +} +hotplug_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotplug.kshlib + . $(atf_get_srcdir)/hotplug.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case hotplug_001_pos + atf_add_test_case hotplug_008_pos + atf_add_test_case hotplug_011_pos +} diff --git a/tests/sys/cddl/zfs/tests/hotplug/setup.ksh b/tests/sys/cddl/zfs/tests/hotplug/setup.ksh new file mode 100644 index 00000000000..798798875de --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotplug/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/tests/hotplug/hotplug.kshlib + +log_must create_gnops $ALL_DISKS +log_pass diff --git a/tests/sys/cddl/zfs/tests/hotspare/Makefile b/tests/sys/cddl/zfs/tests/hotspare/Makefile new file mode 100644 index 00000000000..a7d4b088d20 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/Makefile @@ -0,0 +1,45 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/hotspare +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= hotspare_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= hotspare_create_001_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= hotspare_add_004_neg.ksh +${PACKAGE}FILES+= hotspare_scrub_002_pos.ksh +${PACKAGE}FILES+= hotspare_detach_002_pos.ksh +${PACKAGE}FILES+= hotspare_remove_001_pos.ksh +${PACKAGE}FILES+= hotspare_add_001_pos.ksh +${PACKAGE}FILES+= hotspare_import_001_pos.ksh +${PACKAGE}FILES+= hotspare_replace_002_neg.ksh +${PACKAGE}FILES+= hotspare_clone_002_pos.ksh +${PACKAGE}FILES+= hotspare_export_001_neg.ksh +${PACKAGE}FILES+= hotspare_snapshot_001_pos.ksh +${PACKAGE}FILES+= hotspare_remove_004_pos.ksh +${PACKAGE}FILES+= hotspare_detach_003_pos.ksh +${PACKAGE}FILES+= hotspare_onoffline_004_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= hotspare_replace_001_neg.ksh +${PACKAGE}FILES+= hotspare_scrub_001_pos.ksh +${PACKAGE}FILES+= hotspare_detach_001_pos.ksh +${PACKAGE}FILES+= hotspare_add_003_neg.ksh +${PACKAGE}FILES+= hotspare_remove_003_neg.ksh +${PACKAGE}FILES+= hotspare_add_002_pos.ksh +${PACKAGE}FILES+= hotspare_detach_004_pos.ksh +${PACKAGE}FILES+= hotspare_snapshot_002_pos.ksh +${PACKAGE}FILES+= hotspare.kshlib +${PACKAGE}FILES+= hotspare_detach_005_neg.ksh +${PACKAGE}FILES+= hotspare_remove_002_neg.ksh +${PACKAGE}FILES+= hotspare_onoffline_003_neg.ksh +${PACKAGE}FILES+= hotspare_shared_001_pos.ksh +${PACKAGE}FILES+= hotspare.cfg +${PACKAGE}FILES+= hotspare_clone_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/hotspare/cleanup.ksh b/tests/sys/cddl/zfs/tests/hotspare/cleanup.ksh new file mode 100644 index 00000000000..1d3a7d47cd8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/cleanup.ksh @@ -0,0 +1,41 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +verify_runnable "global" + +log_must cleanup_devices_all + +restart_zfsd + +log_pass diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare.cfg b/tests/sys/cddl/zfs/tests/hotspare/hotspare.cfg new file mode 100644 index 00000000000..8d8035ed5fa --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare.cfg @@ -0,0 +1,60 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare.cfg 1.4 08/02/27 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +. $STF_SUITE/include/libtest.kshlib + +export DISK_ARRAY_NUM=0 +export DISKSARRAY="" + +# +# Variables for hotspare_detach_001 +# +export STF_TIMEOUT=3600 + +set_disks + +export FILESIZE="100m" +export FILESIZE1="150m" +export SIZE="100m" +export SIZE1="80m" +export N_DEVARRAY_FILES=8 + +export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb +export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"} +export HOLES_SEED=${HOLES_SEED-""} +export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""} +export HOLES_COUNT=${HOLES_COUNT-"16384"} # FILESIZE/BLKSIZE/8 +export HOLES_VERBOSE=${HOLES_VERBOSE-""} + +export MYTESTFILE=$STF_SUITE/include/default.cfg +export TESTFILE=testfile.${TESTCASE_ID} +export HOTSPARE_TMPDIR="$TMPDIR/hotspare_tmpdir" diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare.kshlib b/tests/sys/cddl/zfs/tests/hotspare/hotspare.kshlib new file mode 100644 index 00000000000..897a7d5a535 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare.kshlib @@ -0,0 +1,126 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare.kshlib 1.6 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zpool_add/zpool_add.kshlib + + +function cleanup_devices_all +{ + $RM -f ${devarray[*]} + [ -d "$HOTSPARE_TMPDIR" ] && rmdir $HOTSPARE_TMPDIR + + return 0 +} + +typeset -a pooldevs +typeset -a sparedevs +typeset -a logdevs +typeset -a keywords=("" "mirror" "raidz" "raidz2") +typeset -a devarray + +function set_devs +{ + mkdir $HOTSPARE_TMPDIR + typeset -i i=0 + while (( i < $N_DEVARRAY_FILES )) ; do + eval devarray[$i]=$HOTSPARE_TMPDIR/file.$i + log_must create_vdevs ${devarray[$i]} + (( i = i + 1 )) + done + + sparedevs=("${devarray[0]}" "${devarray[1]}") + + pooldevs=("${devarray[3]}" "${devarray[4]}" "${devarray[5]}") + + logdevs="${devarray[7]}" + +} + +function partition_cleanup +{ + cleanup_devices_all + return 0 +} + +# +# $1: keyword, should be "" "mirror" "raidz" "raidz2" +# $2: hotspare list, default as $sparedevs +# +function setup_hotspares # keyword, spares +{ + typeset keyword=$1 + shift + typeset spares=${@:-${sparedevs[@]}} + + create_pool "$TESTPOOL" "$keyword" \ + ${pooldevs[@]} + log_must poolexists "$TESTPOOL" + log_must $ZPOOL set autoreplace=on "$TESTPOOL" + log_must $ZPOOL add -f "$TESTPOOL" spare $spares + log_must iscontained "$TESTPOOL" "$spares" + + if [[ -n ${logdevs[@]} ]] ; then + log_must $ZPOOL add -f "$TESTPOOL" log ${logdevs[@]} + log_must iscontained "$TESTPOOL" "${logdevs[@]}" + fi +} + +# +# $1: the function name that run for all hotspares +# $2: hotspare list, default as $sparedevs +# +function iterate_over_hotspares # function, spares +{ + typeset function=$1 + typeset spares=${2:-${sparedevs[@]}} + + for spare in $spares + do + $function $spare + done +} + +wait_until_resilvered() { +typeset -i i=0 +typeset -i timeout=60 +while [[ $i -lt $timeout ]]; do + if is_pool_resilvered $TESTPOOL; then + break + fi + (( i += 1 )) + if [[ $i == $timeout ]]; then + $ZPOOL status $TESTPOOL + log_fail "Pool didn't resilver in ${timeout} seconds" + fi + $SLEEP 1 +done +} diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_001_pos.ksh new file mode 100644 index 00000000000..caff15f54d5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_001_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_add_001_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_add_001_pos +# +# DESCRIPTION: +# 'zpool add spare ...' can successfully add the specified +# devices to the hot spares list of the given pool +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 3. Verify the devices are added to the spare list +# of the given pool successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" +} + +log_assert "'zpool add spare ...' can add devices to the pool." + +log_onexit cleanup + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool add spare ...' executes successfully" diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_002_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_002_pos.ksh new file mode 100644 index 00000000000..522504cec9a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_002_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_add_002_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_add_002_pos +# +# DESCRIPTION: +# 'zpool add spare ...' can successfully add the specified +# devices to the available list of the given pool while +# there has activated hotspare already. +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 3. Activate some of the hot spares. +# 3. Verify the following devices could add to the spare list +# of the given pool successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" + log_must $ZPOOL replace $TESTPOOL ${pooldevs[0]} $dev + + cleanup_devices $ndev + + log_must $ZPOOL add "$TESTPOOL" spare $ndev + log_must $ZPOOL remove "$TESTPOOL" $ndev + + cleanup_devices $ndev + + log_must $ZPOOL add -f "$TESTPOOL" spare $ndev + log_must $ZPOOL remove "$TESTPOOL" $ndev + + log_must $ZPOOL detach $TESTPOOL $dev +} + +log_assert "'zpool add spare ...' can add devices to the pool while it has spare-in device." + +log_onexit cleanup + +set_devs +typeset ndev=${devarray[2]} + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool add spare ...' executes successfully while it has spare-in device" diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_003_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_003_neg.ksh new file mode 100644 index 00000000000..d6c26a9ae36 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_003_neg.ksh @@ -0,0 +1,144 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_add_003_neg.ksh 1.7 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_add_003_neg +# +# DESCRIPTION: +# 'zpool add' with hot spares will fail +# while the hot spares belong to the following cases: +# - nonexist device, +# - part of an active pool, +# - currently mounted, +# - devices in /etc/vfstab, +# - specified as the dedicated dump device, +# - identical with the basic or spares vdev within the pool, +# - belong to a exported or potentially active ZFS pool, +# - a volume device that belong to the given pool, +# +# STRATEGY: +# 1. Create case scenarios +# 2. For each scenario, try to add [-f] the device to the pool +# 3. Verify the add operation failes as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists "$TESTPOOL" && \ + destroy_pool "$TESTPOOL" + poolexists "$TESTPOOL1" && \ + destroy_pool "$TESTPOOL1" + + if [[ -n $saved_dump_dev ]]; then + if [[ -n $DUMPADM ]]; then + log_must $DUMPADM -u -d $saved_dump_dev + fi + fi + + if [[ -n $DUMPADM ]]; then + cleanup_devices $dump_dev + fi + + partition_cleanup +} + +log_assert "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." + +log_onexit cleanup + +set_devs + +mnttab_dev=$(find_mnttab_dev) +vfstab_dev=$(find_vfstab_dev) +saved_dump_dev=$(save_dump_dev) +dump_dev=${disk}s0 +nonexist_dev=${disk}sbad_slice_num + +create_pool "$TESTPOOL" "${pooldevs[0]}" +log_must poolexists "$TESTPOOL" + +create_pool "$TESTPOOL1" "${pooldevs[1]}" +log_must poolexists "$TESTPOOL1" + +[[ -n $mnttab_dev ]] || log_note "No mnttab devices found" +[[ -n $vfstab_dev ]] || log_note "No vfstab devices found" +# - nonexist device, +# - part of an active pool, +# - currently mounted, +# - devices in /etc/vfstab, +# - identical with the basic or spares vdev within the pool, + +set -A arg "$nonexist_dev" \ + "${pooldevs[0]}" \ + "${pooldevs[1]}" \ + "$mnttab_dev" \ + "$vfstab_dev" + +typeset -i i=0 +while (( i < ${#arg[*]} )); do + if [[ -n "${arg[i]}" ]]; then + log_mustnot $ZPOOL add $TESTPOOL spare ${arg[i]} + log_mustnot $ZPOOL add -f $TESTPOOL spare ${arg[i]} + fi + (( i = i + 1 )) +done + +# - specified as the dedicated dump device, +# This part of the test can only be run on platforms for which DUMPADM is +# defined; ie Solaris +if [[ -n $DUMPADM ]]; then + log_must $DUMPADM -u -d /dev/dsk/$dump_dev + log_mustnot $ZPOOL add "$TESTPOOL" spare $dump_dev + log_mustnot $ZPOOL add -f "$TESTPOOL" spare $dump_dev +fi + +# - belong to a exported or potentially active ZFS pool, + +log_must $ZPOOL export $TESTPOOL1 +log_mustnot $ZPOOL add "$TESTPOOL" spare ${pooldevs[1]} +log_must $ZPOOL import -d $HOTSPARE_TMPDIR $TESTPOOL1 + +log_pass "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_004_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_004_neg.ksh new file mode 100644 index 00000000000..62f02cb8d7e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_add_004_neg.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_add_004_neg.ksh 1.7 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_add_004_neg +# +# DESCRIPTION: +# 'zpool add' will not allow a swap device to be used as a hotspare +# +# STRATEGY: +# 1. Create pools +# 2. Create a swap device +# 3. Try to add [-f] the swap device to the pool +# 4. Verify the add operation failes as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2013-02-15) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists "$TESTPOOL" && \ + destroy_pool "$TESTPOOL" + + if $SWAPCTL -l | grep -q $SWAPDEV; then + log_must $SWAPOFF $SWAPDEV + fi + + partition_cleanup +} + +log_assert "'zpool add [-f]' will not allow a swap device to be used as a hotspare'" + +log_onexit cleanup + +set_devs + +SWAPDEV="$DISK1" + +if $SWAPON $SWAPDEV; then + true +else + log_unsupported "Cannot activate $SWAPDEV as a swap device" +fi + +create_pool "$TESTPOOL" "$DISK0" +log_must poolexists "$TESTPOOL" + +log_mustnot "$ZPOOL" add "$TESTPOOL" spare "$SWAPDEV" +log_mustnot "$ZPOOL" add -f "$TESTPOOL" spare "$SWAPDEV" + +log_pass "'zpool add [-f]' will not allow a swap device to be used as a hotspare'" diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_clone_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_clone_001_pos.ksh new file mode 100644 index 00000000000..88dc48e4539 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_clone_001_pos.ksh @@ -0,0 +1,128 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_clone_001_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_clone_001_pos +# +# DESCRIPTION: +# If a storage pool has activated hot spares, +# create clone and remove the hot spare, +# the data in clone should keep integrity. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Create some files, create a snapshot & clone upon filesystem +# 3. Activate a spare device to the pool +# 4. Create some files, create an new snapshot & clone upon filesystem +# 5. Do 'zpool detach' with the spare in device +# 6. Verify the 2 clones are all kept, and verify the data integrity within them. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 + log_must $ZFS snapshot $TESTPOOL@snap.0 + log_must $ZFS clone $TESTPOOL@snap.0 \ + $TESTPOOL/clone.0 + + log_must $ZPOOL replace $TESTPOOL $odev $dev + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE1 + log_must $ZFS snapshot $TESTPOOL@snap.1 + log_must $ZFS clone $TESTPOOL@snap.1 \ + $TESTPOOL/clone.1 + + log_must $SYNC + + log_must $ZPOOL detach $TESTPOOL $dev + + for file in "$mtpt/clone.0/$TESTFILE0" \ + "$mtpt/clone.1/$TESTFILE1" ; do + [[ ! -e $file ]] && \ + log_fail "$file missing after detach hotspare." + checksum2=$($SUM $file | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2" + done + + log_must $RM -rf $mtpt/clone.0/* + log_must $RM -rf $mtpt/clone.1/* + log_must $ZFS destroy -Rf $TESTPOOL@snap.1 + log_must $ZFS destroy -Rf $TESTPOOL@snap.0 +} + +log_assert "'zpool detach ...' against hotspare should do no harm to clone." + +log_onexit cleanup + +typeset mtpt="" + +set_devs + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + mtpt=$(get_prop mountpoint $TESTPOOL) + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool detach ...' against hotspare should do no harm to clone." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_clone_002_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_clone_002_pos.ksh new file mode 100644 index 00000000000..6927394ec62 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_clone_002_pos.ksh @@ -0,0 +1,136 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_clone_002_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_clone_002_pos +# +# DESCRIPTION: +# If a storage pool has activated hot spares, +# create clone and then invoke "zpool detach" with the original device, +# the data in clone should keep integrity. +# +# STRATEGY: +# 1. Create a storage pool with hot spares activated. +# 2. Create some files, create a snapshot & clone upon filesystem +# 3. Activate a spare device to the pool +# 4. Create some files, create an new snapshot & clone upon filesystem +# 5. Do 'zpool detach' with the original device +# 6. Verify the 2 clones are all kept, and verify the data integrity within them. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 + log_must $ZFS snapshot $TESTPOOL@snap.0 + log_must $ZFS clone $TESTPOOL@snap.0 \ + $TESTPOOL/clone.0 + + log_must $ZPOOL replace $TESTPOOL $odev $dev + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE1 + log_must $ZFS snapshot $TESTPOOL@snap.1 + log_must $ZFS clone $TESTPOOL@snap.1 \ + $TESTPOOL/clone.1 + + log_must $SYNC + + log_must $ZPOOL detach $TESTPOOL $odev + + for file in "$mtpt/clone.0/$TESTFILE0" \ + "$mtpt/clone.1/$TESTFILE1" ; do + [[ ! -e $file ]] && \ + log_fail "$file missing after detach hotspare." + checksum2=$($SUM $file | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2)" + done + + log_must $RM -rf $mtpt/clone.0/* + log_must $RM -rf $mtpt/clone.1/* + log_must $ZFS destroy -Rf $TESTPOOL@snap.1 + log_must $ZFS destroy -Rf $TESTPOOL@snap.0 + + log_must $RM -f $mtpt/* + + log_must $ZPOOL add -f "$TESTPOOL" spare $odev + log_must $ZPOOL replace "$TESTPOOL" $dev $odev + log_must $SYNC + log_must $ZPOOL detach "$TESTPOOL" $dev + log_must $ZPOOL add -f "$TESTPOOL" spare $dev +} + +log_assert "'zpool detach ...' against basic vdev should do no harm to clone." + +log_onexit cleanup + +typeset mtpt="" + +set_devs + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + mtpt=$(get_prop mountpoint $TESTPOOL) + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool detach ...' against basic vdev should do no harm to clone." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_create_001_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_create_001_neg.ksh new file mode 100644 index 00000000000..6d2bca5d6f5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_create_001_neg.ksh @@ -0,0 +1,139 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_create_001_neg.ksh 1.5 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_create_001_neg +# +# DESCRIPTION: +# 'zpool create [-f]' with hot spares will fail +# while the hot spares belong to the following cases: +# - existing pool +# - nonexist device, +# - part of an active pool, +# - currently mounted, +# - devices in /etc/vfstab, +# - specified as the dedicated dump device, +# - identical with the basic vdev within the pool, +# +# STRATEGY: +# 1. Create case scenarios +# 2. For each scenario, try to create a new pool with hot spares +# of the virtual devices +# 3. Verify the creation is failed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + for pool in $TESTPOOL $TESTPOOL1 + do + destroy_pool $pool + done + + if [[ -n $saved_dump_dev ]]; then + if [[ -n $DUMPADM ]]; then + log_must $DUMPADM -u -d $saved_dump_dev + fi + fi + + partition_cleanup +} + +log_assert "'zpool create [-f]' with hot spares should be failed " \ + "with inapplicable scenarios." +log_onexit cleanup + +set_devs + +mnttab_dev=$(find_mnttab_dev) +vfstab_dev=$(find_vfstab_dev) +saved_dump_dev=$(save_dump_dev) +dump_dev=${disk}s0 +nonexist_dev=${disk}sbad_slice_num + +create_pool "$TESTPOOL" ${pooldevs[0]} + +# +# Set up the testing scenarios parameters +# - existing pool +# - nonexist device, +# - part of an active pool, +# - currently mounted, +# - devices in /etc/vfstab, +# - identical with the basic vdev within the pool, + +set -A arg "$TESTPOOL ${pooldevs[1]} spare ${pooldevs[2]}" \ + "$TESTPOOL1 ${pooldevs[1]} spare $nonexist_dev" \ + "$TESTPOOL1 ${pooldevs[1]} spare ${pooldevs[0]}" \ + "$TESTPOOL1 ${pooldevs[1]} spare $mnttab_dev" \ + "$TESTPOOL1 ${pooldevs[1]} spare $vfstab_dev" \ + "$TESTPOOL1 ${pooldevs[1]} spare ${pooldevs[1]}" + +typeset -i i=0 +while (( i < ${#arg[*]} )); do + log_mustnot $ZPOOL create ${arg[i]} + log_mustnot $ZPOOL create -f ${arg[i]} + (( i = i + 1 )) +done + +# now destroy the pool to be polite +log_must $ZPOOL destroy -f $TESTPOOL + +# +# - specified as the dedicated dump device, +# This part of the test can only be run on platforms for which DUMPADM is +# defined; ie Solaris +# +if [[ -n $DUMPADM ]]; then + # create/destroy a pool as a simple way to set the partitioning + # back to something normal so we can use this $disk as a dump device + cleanup_devices $dump_dev + + log_must $DUMPADM -u -d /dev/dsk/$dump_dev + log_mustnot $ZPOOL create $TESTPOOL1 ${pooldevs[1]} spare "$dump_dev" + log_mustnot $ZPOOL create -f $TESTPOOL1 ${pooldevs[1]} spare "$dump_dev" +fi + +log_pass "'zpool create [-f]' with hot spare is failed as expected with inapplicable scenarios." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_001_pos.ksh new file mode 100644 index 00000000000..082fed8763d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_001_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_detach_001_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_detach_001_pos +# +# DESCRIPTION: +# If a hot spare have been activated, +# and invoke "zpool detach" with this hot spare, +# it will be returned to the set of available spares, +# the original drive will remain in its current position. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Activate a spare device to the pool +# 3. Do 'zpool detach' with the spare in device +# 4. Verify the spare device returned to the set of available spares, +# and the original drive will remain in its current position. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $MKFILE 100m /$TESTPOOL/$TESTFILE1 + log_must $SYNC + log_must $ZPOOL replace $TESTPOOL $odev $dev + + log_must resilver_happened $TESTPOOL + log_must check_hotspare_state "$TESTPOOL" "$dev" "INUSE" + + log_must $ZPOOL detach $TESTPOOL $dev + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" + log_must $RM -f /$TESTPOOL/$TESTFILE1 + log_must $SYNC +} + +log_assert "'zpool detach ...' should deactivate the spared-in hot spare device successfully." + +log_onexit cleanup + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool detach ...' deactivate the spared-in hot spare device successfully." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_002_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_002_pos.ksh new file mode 100644 index 00000000000..1ae6ad23189 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_002_pos.ksh @@ -0,0 +1,114 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_detach_002_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_detach_002_pos +# +# DESCRIPTION: +# If a hot spare have been activated, +# and invoke "zpool detach" with the original device, +# then the hot spare will become a functioning device, +# and automatically be removed from the list of available hot spares +# then the spare is automatically removed once the replace completes. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Activate a spare device to the pool +# 3. Do 'zpool detach' with the original device +# 4. Verify the spare device will become a functioning device, +# be removed from the list of available spares as well, +# and the original drive will removed once replace completes. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $ZPOOL replace $TESTPOOL $odev $dev + while check_state "$TESTPOOL" "replacing" \ + "online" || \ + ! is_pool_resilvered $TESTPOOL ; do + $SLEEP 2 + done + log_must check_hotspare_state "$TESTPOOL" "$dev" "INUSE" + + log_must $ZPOOL detach $TESTPOOL $odev + $SLEEP 5 + log_must $ZPOOL replace $TESTPOOL $dev $odev + + while check_state "$TESTPOOL" "replacing" \ + "online" ; do + $SLEEP 2 + done + + log_must $ZPOOL add -f $TESTPOOL spare $dev + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" +} + +log_assert "'zpool detach ...' against a functioning device that have spared should take the hot spare permanently swapping in successfully." + +log_onexit cleanup + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool detach ...' against a functioning device that have spared take the hot spare permanently swapping in successfully." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_003_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_003_pos.ksh new file mode 100644 index 00000000000..68d7292b80b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_003_pos.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_detach_003_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_detach_003_pos +# +# DESCRIPTION: +# If a hot spare have been activated, +# and invoke "zpool replace" to replace the original device, +# then the spare is automatically removed once the replace completes +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Activate a spare device to the pool +# 3. Do 'zpool replace' with the original device +# 4. Verify the original device will replace by the new device, +# and the spare should return to available once replace completes. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $ZPOOL replace $TESTPOOL $odev $dev + log_must check_hotspare_state "$TESTPOOL" "$dev" "INUSE" + log_must $ZPOOL replace -f $TESTPOOL $odev $ndev + + while check_state $TESTPOOL "replacing" \ + "online"; do + $SLEEP 5 + done + + log_mustnot iscontained "$TESTPOOL" "$odev" + log_must iscontained "$TESTPOOL" "$ndev" + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" + log_must $ZPOOL replace $TESTPOOL $ndev $odev + $SLEEP 5 +} + +log_assert "'zpool replace ' against a functioning device that have spared should complete and the hot spare should return to available." + +log_onexit cleanup + +set_devs +typeset ndev=${devarray[2]} + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool replace ' against a functioning device that have spared successful and the hot spare return to available." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_004_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_004_pos.ksh new file mode 100644 index 00000000000..a1eaaf0fd6d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_004_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_detach_004_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_detach_004_pos +# +# DESCRIPTION: +# If a hot spare is activated, +# and invoke "zpool replace" with this hot spare to another hot spare, +# the operation should run successfully. +# +# STRATEGY: +# 1. Create a storage pool with multiple hot spares +# 2. Activate a hot spare by 'zpool replace' with the basic dev, +# make sure there still have enough hot spare in available list. +# 3. Do 'zpool replace' with the hot spare to another AVAIL hot spare. +# 4. Verify the operation runs successfully. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL; then + if [[ "$STF_EXITCODE" -eq "$STF_FAIL" ]]; then + $ECHO "Testcase failed; dumping pool status:" + $ZPOOL status $TESTPOOL + fi + destroy_pool $TESTPOOL + fi + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $ZPOOL replace $TESTPOOL $odev $dev + log_must check_hotspare_state "$TESTPOOL" "$dev" "INUSE" + wait_for_state_exit "$TESTPOOL" "$dev" "resilvering" + + log_must $ZPOOL replace $TESTPOOL $dev $ndev + wait_for_state_exit "$TESTPOOL" "$dev" "online" + + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" + log_must check_hotspare_state "$TESTPOOL" "$ndev" "INUSE" + log_must $ZPOOL detach $TESTPOOL $ndev +} + +log_assert "'zpool replace ' against a hot spare device that have been activated should successful while the another dev is a available hot spare." + +log_onexit cleanup + +set_devs +typeset ndev=${devarray[2]} + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" "${sparedevs[@]} $ndev" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool replace ' against a hot spare device that have been activated should successful while the another dev is a available hot spare." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_005_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_005_neg.ksh new file mode 100644 index 00000000000..9afc09fa4cd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_detach_005_neg.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_detach_005_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_detach_005_neg +# +# DESCRIPTION: +# If a hot spare is only in the list of available hot spares +# but have NOT been activated, +# invoke "zpool detach" with this hot spare will fail with +# a return code of 255 and issue an error message. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Do 'zpool detach' with the hot spare device +# 4. Verify the operation fail with return code of 255 +# and issue an error message. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + log_mustnot $ZPOOL detach "$TESTPOOL" $dev + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" +} + +log_assert "'zpool detach ' against a hot spare device that NOT activated should fail and issue an error message." + +log_onexit cleanup + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool detach ' against a hot spare device that NOT activated fail as expected." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_export_001_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_export_001_neg.ksh new file mode 100644 index 00000000000..a718f7a0741 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_export_001_neg.ksh @@ -0,0 +1,127 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_export_001_neg.ksh 1.2 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_export_001_neg +# +# DESCRIPTION: +# If 2 storage pools have shared hotspares, if the shared hotspare was used by +# one of the pool, the export of the pool that use hotspare will fail. +# +# STRATEGY: +# 1. Create 2 storage pools with hot spares shared. +# 2. Fail one vdev in one pool to make the hotspare in use. +# 3. Export the pool that currently use the hotspare +# 4. Verify the export will failed with warning message. +# 5. Verify export -f will success. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2008-12-12) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + else + $ZPOOL import -d $HOTSPARE_TMPDIR -f | $GREP \ + "pool: $TESTPOOL">/dev/null 2>&1 + if (( $? == 0 )); then + log_must $ZPOOL import -d $HOTSPARE_TMPDIR -f $TESTPOOL + destroy_pool $TESTPOOL + fi + fi + + poolexists $TESTPOOL1 && \ + destroy_pool $TESTPOOL1 + + partition_cleanup + +} + + +log_onexit cleanup + +function verify_assertion # type, dev +{ + typeset pool_type=$1 + typeset hotspare=$2 + + typeset err_dev=${devarray[3]} + typeset pool_dev="${devarray[6]}" + typeset mntp=$(get_prop mountpoint $TESTPOOL) + + create_pool $TESTPOOL1 $pool_dev spare $hotspare + + zpool replace $TESTPOOL $err_dev $hotspare + log_must check_hotspare_state "$TESTPOOL" "$hotspare" "INUSE" + + log_must $ZPOOL status $TESTPOOL + log_must $ZPOOL status $TESTPOOL1 + + log_mustnot $ZPOOL export $TESTPOOL + log_must $ZPOOL export -f $TESTPOOL + + log_must $ZPOOL import -d $HOTSPARE_TMPDIR -f $TESTPOOL + destroy_pool $TESTPOOL + + destroy_pool $TESTPOOL1 +} + +log_onexit cleanup + +log_assert "export pool that using shared hotspares will fail" + +set_devs + +typeset share_spare="${devarray[0]}" +set -A my_keywords "mirror" "raidz1" "raidz2" + +for keyword in "${my_keywords[@]}" ; do + setup_hotspares $keyword $share_spare + verify_assertion $keyword $share_spare +done + +log_pass "export pool that using shared hotspares will fail" + diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_import_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_import_001_pos.ksh new file mode 100644 index 00000000000..fae2596abde --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_import_001_pos.ksh @@ -0,0 +1,167 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_import_001_pos.ksh 1.4 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_import_001_pos +# +# DESCRIPTION: +# If a storage pool has hot spare, +# regardless it has been activated or NOT, +# invoke "zpool export" then import with this storage pool +# should runs successfully, and the data should keep integrity +# after import. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Do 'zpool export' then 'zpool import' with following scernarios +# - the hotspare is only in available list +# - the hotspare is activated +# - the hotspare is activated but offline +# - the hotspare is activated but the basic vdev is offline +# 3. Verify the export/import runs successfully, +# and the data keep integrity after import +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-14) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_export_import #pool #file #chksum +{ + typeset pool=$1 + typeset file=$2 + typeset checksum1=$3 + typeset -i n=0 + + if ! $ZPOOL export $pool; then + # Rarely, this can fail with EBUSY if the pool's configuration + # has already changed within the same transaction group. In + # that case, it is appropriate to retry. + while ((n < 3)); do + $SYNC + log_note "$ZPOOL busy, retrying export (${n})..." + if ((n == 2)); then + log_must $ZPOOL export $pool + else + $ZPOOL export $pool && break + fi + $SLEEP 1 + n=$((n + 1)) + done + fi + log_must $ZPOOL import -d $HOTSPARE_TMPDIR $pool + + [[ ! -e $file ]] && \ + log_fail "$file missing after detach hotspare." + checksum2=$($SUM $file | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2)" + + return 0 +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + # + # - the hotspare is activated + # + log_must $ZPOOL replace $TESTPOOL $odev $dev + while ! is_pool_resilvered $TESTPOOL ; do + $SLEEP 2 + done + + verify_export_import $TESTPOOL \ + $mtpt/$TESTFILE0 $checksum1 + + # + # - the hotspare is activated + # but the basic vdev is offline + # + log_must $ZPOOL offline $TESTPOOL $odev + verify_export_import $TESTPOOL \ + $mtpt/$TESTFILE0 $checksum1 + + log_must $ZPOOL online $TESTPOOL $odev + + log_must $ZPOOL detach $TESTPOOL $dev +} + +log_assert "'zpool export/import ' should runs successfully regardless the hotspare is only in list, activated, or offline." + +log_onexit cleanup + +typeset mtpt="" + +set_devs + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + mtpt=$(get_prop mountpoint $TESTPOOL) + log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 + + # + # - the hotspare is only in available list + # + verify_export_import $TESTPOOL \ + $mtpt/$TESTFILE0 $checksum1 + + iterate_over_hotspares verify_assertion "${vdev%% *}" + + log_must $RM -f $mtpt/$TESTFILE0 + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool export/import ' should runs successfully regardless the hotspare is only in list, activated, or offline." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_onoffline_003_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_onoffline_003_neg.ksh new file mode 100644 index 00000000000..1face124391 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_onoffline_003_neg.ksh @@ -0,0 +1,99 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_onoffline_003_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_onoffline_003_neg +# +# DESCRIPTION: +# Regardless a hot spare is only in the available hot spare list, +# or have been activated, +# invoke "zpool offline" & "zpool online" with this hot spare +# will fail with a return code of 1 and issue an error message. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Try 'zpool offline' & 'zpool online' with each hot spare +# of following condition +# - only in the list of available hot spares (fail) +# - have been activated (fail) +# 3. Verify offline/online results as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_mustnot $ZPOOL offline $TESTPOOL $dev + log_must check_hotspare_state $TESTPOOL $dev "AVAIL" + + log_mustnot $ZPOOL online $TESTPOOL $dev + log_must check_hotspare_state $TESTPOOL $dev "AVAIL" +} + +log_assert "'zpool offline/online ' should fail on inactive spares" + +log_onexit cleanup + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool offline/online ' against a hot spare works as expected." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_onoffline_004_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_onoffline_004_neg.ksh new file mode 100644 index 00000000000..40aa69ce76f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_onoffline_004_neg.ksh @@ -0,0 +1,167 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_onoffline_004_neg.ksh 1.5 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_onoffline_004_neg +# +# DESCRIPTION: +# If a hot spare has been activated, +# turning that basic vdev offline and back online during I/O completes. +# Make sure the integrity of the file system and the resilvering. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Activate the hot spare +# 3. Start some random I/O +# 4. Try 'zpool offline' & 'zpool online' with the basic vdev +# 5. Verify the integrity of the file system and the resilvering. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + kill_all_wp + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/* + + partition_cleanup +} + +function kill_all_wp +{ + for wait_pid in $child_pids + do + $KILL $wait_pid + $WAIT $wait_pid + done +} + +function start_all_wp +{ + typeset -i i=0 + typeset -i iters=1 + + child_pids="" + while (( i < iters )); do + log_note "Invoking $FILE_TRUNC with: $options_display" + $FILE_TRUNC $options $TESTDIR/$TESTFILE.$i & + typeset pid=$! + + child_pids="$child_pids $pid" + ((i = i + 1)) + done +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset -i i=0 + typeset -i iters=1 + typeset odev=${pooldevs[0]} + + log_must $ZPOOL replace $TESTPOOL $odev $dev + + i=0 + while (( i < iters )); do + start_all_wp + while true; do + if is_pool_resilvered "$TESTPOOL"; then + [ -s "$TESTDIR/$TESTFILE.$i" ] && break + fi + $SLEEP 2 + done + + kill_all_wp + log_must test -s $TESTDIR/$TESTFILE.$i + + log_must $ZPOOL offline $TESTPOOL $odev + log_must check_state $TESTPOOL $odev "offline" + + log_must $ZPOOL online $TESTPOOL $odev + log_must check_state $TESTPOOL $odev "online" + (( i = i + 1 )) + done + + log_must $ZPOOL detach $TESTPOOL $dev +} + +log_assert "'zpool offline/online ' against a spared basic vdev during I/O completes." + +log_onexit cleanup + +set_devs + +options="" +options_display="default options" + +[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " + +[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " + +[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " + +[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " + +[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " + +options="$options -r" + +[[ -n "$options" ]] && options_display=$options + +typeset child_pid="" + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL + + iterate_over_hotspares verify_assertion + + verify_filesys "$TESTPOOL" "$TESTPOOL" "$HOTSPARE_TMPDIR" + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool offline/online ' against a spared basic vdev during I/O completes." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_001_pos.ksh new file mode 100644 index 00000000000..651bf8ae4b3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_001_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_remove_001_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_remove_001_pos +# +# DESCRIPTION: +# 'zpool remove ...' can successfully remove the specified +# devices from the hot spares list of the given pool +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 3. Remove hot spares one by one +# 3. Verify the devices are removed fromo the spare list +# of the given pool successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + log_must $ZPOOL remove $TESTPOOL $dev + log_mustnot iscontained "$TESTPOOL" $dev +} + +log_assert "'zpool remove ...' can remove spare device from the pool." + +log_onexit cleanup + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool remove ...' executes successfully" diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_002_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_002_neg.ksh new file mode 100644 index 00000000000..50364140bcf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_002_neg.ksh @@ -0,0 +1,116 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_remove_002_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_remove_002_neg +# +# DESCRIPTION: +# 'zpool remove ...' should return fail if +# - notexist device +# - not within the hot spares of this pool +# - hot spares that currently spared in +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 3. For each scenario, try to remove the hot spares +# 4. Verify the the remove operation get failed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2005-09-27) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $ZPOOL replace $TESTPOOL $odev $dev + log_mustnot $ZPOOL remove $TESTPOOL $dev + log_must $ZPOOL detach $TESTPOOL $dev +} + +log_assert "'zpool remove ...' should fail with inapplicable scenarios." + +log_onexit cleanup + +typeset dev_nonexist dev_notinlist + +case $DISK_ARRAY_NUM in +0|1) + dev_nonexist=/dev/dsk/${disk}sbad_slice_num + dev_notinlist=${disk} + ;; +2|*) + dev_nonexist=/dev/dsk/${DISK0}sbad_slice_num + dev_notinlist="${DISK0} ${DISK1}" + ;; +esac + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + for dev in $dev_nonexist ; do + log_mustnot $ZPOOL remove $TESTPOOL $dev + done + + for dev in $dev_notinlist ; do + log_mustnot $ZPOOL remove $TESTPOOL $dev + done + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool remove ...' fail with inapplicable scenarios." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_003_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_003_neg.ksh new file mode 100644 index 00000000000..41d239f49c2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_003_neg.ksh @@ -0,0 +1,86 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_remove_003_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_remove_003_neg +# +# DESCRIPTION: +# Executing 'zpool remove' command with bad options fails. +# +# STRATEGY: +# 1. Create an array of badly formed 'zpool remove' options. +# 2. Execute each element of the array. +# 3. Verify an error code is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + + +set -A args "" "-?" "-t fakepool" "-f fakepool" "-ev fakepool" "fakepool" \ + "$TESTPOOL" "fakepool ${devarray[0]}" "fakepool ${devarray[1]}" + +log_assert "Executing 'zpool remove' with bad options fails" +log_onexit cleanup + +set_devs +setup_hotspares + +typeset -i i=0 + +while [[ $i -lt ${#args[*]} ]]; do + + log_mustnot $ZPOOL remove ${args[$i]} + + (( i = i + 1 )) +done + +log_pass "'zpool remove' command with bad options failed as expected." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_004_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_004_pos.ksh new file mode 100644 index 00000000000..44be7f864cf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_remove_004_pos.ksh @@ -0,0 +1,99 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_remove_004_pos.ksh 1.2 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_remove_004_pos +# +# DESCRIPTION: +# 'zpool remove ...' can successfully remove the specified +# devices from the hot spares even it no longer exists. +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 3. Export the pool +# 4. Remove the hotspare +# 5. Import the pool +# 6. Remove hot spares one by one +# 7. Verify the devices are removed from the spare list +# of the given pool successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2008-02-25) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + log_must $ZPOOL export $TESTPOOL + log_must $MV $dev $dev.bak + log_must $ZPOOL import -d $HOTSPARE_TMPDIR $TESTPOOL + log_must $ZPOOL remove $TESTPOOL $dev + log_mustnot iscontained "$TESTPOOL" $dev + log_must $MV $dev.bak $dev +} + +log_assert "'zpool remove ...' can remove spare device from the pool." + +log_onexit cleanup + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool remove ...' executes successfully" diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_replace_001_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_replace_001_neg.ksh new file mode 100644 index 00000000000..78cf9a71478 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_replace_001_neg.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_001_neg.ksh 1.4 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_replace_001_neg +# +# DESCRIPTION: +# 'zpool replace ...' should return fail if +# - try to replace a basic vdev that already has an activated +# hot spare. +# - try to replace log device. +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 3. For each scenario, try to replace the basic vdev with the given hot spares +# 4. Verify the the replace operation get failed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + for odev in ${pooldevs[@]} ; do + log_must $ZPOOL replace $TESTPOOL $odev $dev + log_mustnot $ZPOOL replace $TESTPOOL $odev $availdev + log_must $ZPOOL detach $TESTPOOL $dev + done + + if [[ -n ${logdevs[@]} ]] ; then + for odev in ${logdevs[@]} ; do + log_mustnot $ZPOOL replace $TESTPOOL $odev $dev + done + fi +} + +log_assert "'zpool replace ' should fail with inapplicable scenarios." + +log_onexit cleanup + +set_devs + +typeset dev_nonexist +typeset availdev=${devarray[2]} +dev_nonexist=${disk}sbad_slice_num + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" "${sparedevs[@]} $availdev" + + for odev in ${pooldevs[@]} ; do + for ndev in $dev_nonexist ; do + log_mustnot $ZPOOL replace $TESTPOOL $odev $ndev + done + done + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool replace ' fail with inapplicable scenarios." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_replace_002_neg.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_replace_002_neg.ksh new file mode 100644 index 00000000000..0cdbe57cd0d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_replace_002_neg.ksh @@ -0,0 +1,97 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_002_neg.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_replace_002_neg +# +# DESCRIPTION: +# 'zpool replace ...' should return fail if +# the size of hot spares is smaller than the basic vdev. +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 3. Try to replace the basic vdev with the smaller hot spares +# 4. Verify the the replace operation failes +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + for odev in ${pooldevs[0]} ; do + log_mustnot $ZPOOL replace $TESTPOOL $odev $dev + done +} + +log_assert "'zpool replace ' should fail while the hot spares smaller than the basic vdev." + +log_onexit cleanup + +set_devs + +typeset smalldev="${devarray[6]}" +VDEV_SIZE=$SIZE1 +log_must create_vdevs $smalldev +unset VDEV_SIZE + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" "$smalldev" + + iterate_over_hotspares verify_assertion "$smalldev" + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool replace ' should fail while the hot spares smaller than the basic vdev." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_001_pos.ksh new file mode 100644 index 00000000000..f48291d9373 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_001_pos.ksh @@ -0,0 +1,120 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_scrub_001_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_scrub_001_pos +# +# DESCRIPTION: +# If a storage pool has hot spare, +# regardless it has been activated or NOT, +# invoke "zpool scrub" with this storage pool should successful. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Make the storage pool dirty. +# 3. Do 'zpool scrub' with following scernarios +# - the hotspare is only in available list +# - the hotspare is activated +# 4. Verify the scrub runs successfully. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + # Record status so we can see the current state on failure. + $ZPOOL status + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $MKFILE 100m $mtpt/$TESTFILE0 + log_must $ZPOOL scrub $TESTPOOL + while is_pool_scrubbing $TESTPOOL ; do + $SLEEP 2 + done + + log_must $MKFILE 100m $mtpt/$TESTFILE1 + log_must $ZPOOL replace $TESTPOOL $odev $dev + + while ! is_pool_resilvered $TESTPOOL ; do + $SLEEP 2 + done + + log_must $ZPOOL scrub $TESTPOOL + + while is_pool_scrubbing $TESTPOOL ; do + $SLEEP 2 + done + + log_must $ZPOOL detach $TESTPOOL $dev + log_must $RM -f $mtpt/$TESTFILE0 \ + $mtpt/$TESTFILE1 +} + +log_assert "'zpool scrub ' should runs successfully regardless " \ + "the hotspare is only in list or activated." + +log_onexit cleanup + +typeset mtpt="" + +set_devs + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + mtpt=$(get_prop mountpoint $TESTPOOL) + iterate_over_hotspares verify_assertion "${vdev%% *}" + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool scrub ' runs successfully regardless " \ + "the hotspare is only in list or activated." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh new file mode 100644 index 00000000000..c96bff98c67 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh @@ -0,0 +1,135 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_scrub_002_pos +# +# DESCRIPTION: +# 'zpool scrub will scan spares as well as original devices' +# +# STRATEGY: +# 1. Create a storage pool +# 2. Add hot spare devices to the pool +# 4. Replace one of the original devices with a spare +# 5. Simulate errors on the spare +# 6. Scrub the pool +# 7. Verify that scrub detected the simulated errors +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2013-01-14) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + partition_cleanup +} + +# Returns the number of checksums errors detected on the given vdev +function get_cksum #pool, vdev +{ + typeset pool=$1 + typeset vdev=$2 + $ZPOOL status $pool | awk -v vdev=$vdev '$1~vdev {print $5; exit}' +} + +function verify_assertion # odev +{ + typeset odev=$1 + + log_must $ZPOOL replace $TESTPOOL $odev $sdev + log_must check_state $TESTPOOL "$sdev" "INUSE" + + # corrupt out the $TESTPOOL to make sdev in use + # Skip the first input block so we don't overwrite the vdev label + log_must $DD if=/dev/zero bs=1024k count=63 oseek=1 conv=notrunc of=$sdev + + $SYNC + # The pool may already have started scrubbing, so don't assert this. + # Expected postconditions are checked below anyway. + $ZPOOL scrub $TESTPOOL + while is_pool_scrubbing $TESTPOOL ; do + $SLEEP 2 + done + + # Verify that scrub detected the errors + # Some vdevs (ie raidz1) will display the errors on the spare-0 line + # instead of on the basic vdev line + [[ $(get_cksum $TESTPOOL $sdev) > 0 ]] + sdev_errors=$? + [[ $(get_cksum $TESTPOOL "spare-0") > 0 ]] + spare0_errors=$? + log_must [ $sdev_errors -o $spare0_errors ] + + # Now clear the old errors, remove the original device and scrub again. + # No new errors should be found, because the scrub should've found and + # fixed all errors + log_must $ZPOOL clear $TESTPOOL + log_must $ZPOOL detach $TESTPOOL $odev + $ZPOOL scrub $TESTPOOL + while is_pool_scrubbing $TESTPOOL ; do + $SLEEP 2 + done + if [ $(get_cksum $TESTPOOL $sdev) -ne 0 ]; then + log_fail "ERROR: Scrub missed cksum errors on a spare vdev" + fi +} + +log_assert "'zpool scrub' scans spare vdevs" + +log_onexit cleanup + +set_devs +typeset odev="${devarray[3]}" +typeset sdev="${devarray[0]}" + +# Don't test striped pools because they can't have spares +set -A keywords "mirror" "raidz" "raidz2" +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + iterate_over_hotspares verify_assertion $odev + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool scrub scans spare vdevs'" diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_shared_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_shared_001_pos.ksh new file mode 100644 index 00000000000..e6ba1bb7ede --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_shared_001_pos.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_shared_001_pos.ksh 1.0 08/06/12 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_shared_001_pos +# +# DESCRIPTION: +# It is possible to add the same vdev to multiple pools as a shared spare +# even when that vdev is a disk instead of a file +# +# STRATEGY: +# 1. Create various combinations of two pools +# 2. 'zpool add' a hotspare disk to each of them +# 3. verify that the addition worked +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2012-08-06) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + poolexists $TESTPOOL1 && \ + destroy_pool $TESTPOOL1 + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + + log_must $ZPOOL add $TESTPOOL1 spare $dev + + log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" + log_must check_hotspare_state "$TESTPOOL1" "$dev" "AVAIL" +} + + +log_assert "'zpool add spare ...' can add a disk as a shared spare to multiple pools." + +log_onexit cleanup + +set_devs +typeset sdev=$DISK0 +typeset pool1devs="$DISK1 $DISK2 $DISK3 $DISK4" + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" $sdev + log_must create_pool $TESTPOOL1 $keyword $pool1devs + iterate_over_hotspares verify_assertion $sdev + + destroy_pool "$TESTPOOL" + destroy_pool "$TESTPOOL1" +done diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_snapshot_001_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_snapshot_001_pos.ksh new file mode 100644 index 00000000000..9b1458d84c8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_snapshot_001_pos.ksh @@ -0,0 +1,126 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_snapshot_001_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_snapshot_001_pos +# +# DESCRIPTION: +# If a hot spare have been activated, create snapshot upon filesystem, +# then invoke "zpool detach" with this hot spare, +# the data in snapshot should untouched. +# +# STRATEGY: +# 1. Create a storage pool with hot spares +# 2. Create some files, create a snapshot upon filesystem +# 3. Activate a spare device to the pool +# 4. Create some files, create an new snapshot upon filesystem +# 5. Do 'zpool detach' with the spare in device +# 6. Verify the 2 snapshots are all kept, and verify the data integrity within them. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 + log_must $ZFS snapshot $TESTPOOL@snap.0 + + log_must $ZPOOL replace $TESTPOOL $odev $dev + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE1 + log_must $ZFS snapshot $TESTPOOL@snap.1 + + log_must $SYNC + + log_must $ZPOOL detach $TESTPOOL $dev + + for file in \ + "$snaproot/snap.0/$TESTFILE0" \ + "$snaproot/snap.1/$TESTFILE0" \ + "$snaproot/snap.1/$TESTFILE1" ; do + [[ ! -e $file ]] && \ + log_fail "$file missing after detach hotspare." + checksum2=$($SUM $file | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2)" + done + + log_must $RM -f $mtpt/* + log_must $ZFS destroy $TESTPOOL@snap.1 + log_must $ZFS destroy $TESTPOOL@snap.0 +} + +log_assert "'zpool detach ...' against hotspare should do no harm to snapshot." + +log_onexit cleanup + +typeset mtpt="" snaproot="" + +set_devs + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + mtpt=$(get_prop mountpoint $TESTPOOL) + snaproot="$mtpt/$(get_snapdir_name)" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool detach ...' against hotspare should do no harm to snapshot." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_snapshot_002_pos.ksh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_snapshot_002_pos.ksh new file mode 100644 index 00000000000..f2d979a7811 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_snapshot_002_pos.ksh @@ -0,0 +1,132 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_snapshot_002_pos.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: hotspare_snapshot_002_pos +# +# DESCRIPTION: +# If a storage pool has activated hot spares, +# create snapshot and detach the basic vdev, +# the hot spare should become the functional device, and +# the data in snapshot should keep integrity. +# +# STRATEGY: +# 1. Create a storage pool with hot spares activated. +# 2. Create some files, create a snapshot upon filesystem +# 3. Activate a spare device to the pool +# 4. Create some files, create an new snapshot upon filesystem +# 5. Do 'zpool detach' with the original device +# 6. Verify the 2 snapshots are all kept, and verify the data integrity within them. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2006-06-07) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # dev +{ + typeset dev=$1 + typeset odev=${pooldevs[0]} + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE0 + log_must $ZFS snapshot $TESTPOOL@snap.0 + + log_must $ZPOOL replace $TESTPOOL $odev $dev + + log_must $CP $MYTESTFILE $mtpt/$TESTFILE1 + log_must $ZFS snapshot $TESTPOOL@snap.1 + + log_must $SYNC + + log_must $ZPOOL detach $TESTPOOL $odev + + for file in \ + "$snaproot/snap.0/$TESTFILE0" \ + "$snaproot/snap.1/$TESTFILE0" \ + "$snaproot/snap.1/$TESTFILE1" ; do + [[ ! -e $file ]] && \ + log_fail "$file missing after detach hotspare." + checksum2=$($SUM $file | $AWK '{print $1}') + [[ "$checksum1" != "$checksum2" ]] && \ + log_fail "Checksums differ ($checksum1 != $checksum2)" + done + + log_must $ZFS destroy $TESTPOOL@snap.1 + log_must $ZFS destroy $TESTPOOL@snap.0 + + log_must $ZPOOL add -f "$TESTPOOL" spare $odev + log_must $ZPOOL replace "$TESTPOOL" $dev $odev + log_must $SYNC + log_must $ZPOOL detach "$TESTPOOL" $dev + log_must $ZPOOL add -f "$TESTPOOL" spare $dev +} + +log_assert "'zpool detach ...' against basic vdev do no harm to snapshot." + +log_onexit cleanup + +typeset mtpt="" snaproot="" + +set_devs + +checksum1=$($SUM $MYTESTFILE | $AWK '{print $1}') + +for keyword in "${keywords[@]}" ; do + setup_hotspares "$keyword" + + mtpt=$(get_prop mountpoint $TESTPOOL) + snaproot="$mtpt/$(get_snapdir_name)" + + iterate_over_hotspares verify_assertion + + destroy_pool "$TESTPOOL" +done + +log_pass "'zpool detach ...' against basic vdev should do no harm to snapshot." diff --git a/tests/sys/cddl/zfs/tests/hotspare/hotspare_test.sh b/tests/sys/cddl/zfs/tests/hotspare/hotspare_test.sh new file mode 100755 index 00000000000..f84c2d98652 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/hotspare_test.sh @@ -0,0 +1,760 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case hotspare_add_001_pos cleanup +hotspare_add_001_pos_head() +{ + atf_set "descr" "'zpool add spare ...' can add devices to the pool." + atf_set "timeout" 3600 +} +hotspare_add_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_add_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_add_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_add_002_pos cleanup +hotspare_add_002_pos_head() +{ + atf_set "descr" "'zpool add spare ...' can add devices to the pool while it has spare-in device." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_add_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_add_002_pos.ksh || atf_fail "Testcase failed" +} +hotspare_add_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_add_003_neg cleanup +hotspare_add_003_neg_head() +{ + atf_set "descr" "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_add_003_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_add_003_neg.ksh || atf_fail "Testcase failed" +} +hotspare_add_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_add_004_neg cleanup +hotspare_add_004_neg_head() +{ + atf_set "descr" "'zpool add [-f]' will not allow a swap device to be used as a hotspare'" + atf_set "require.progs" zpool swapon swapoff swapctl +} +hotspare_add_004_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_add_004_neg.ksh || atf_fail "Testcase failed" +} +hotspare_add_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_clone_001_pos cleanup +hotspare_clone_001_pos_head() +{ + atf_set "descr" "'zpool detach ...' against hotspare should do no harm to clone." + atf_set "require.progs" zfs zpool sum + atf_set "timeout" 3600 +} +hotspare_clone_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_clone_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_clone_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_clone_002_pos cleanup +hotspare_clone_002_pos_head() +{ + atf_set "descr" "'zpool detach ...' against basic vdev should do no harm to clone." + atf_set "require.progs" zfs zpool sum + atf_set "timeout" 3600 +} +hotspare_clone_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_clone_002_pos.ksh || atf_fail "Testcase failed" +} +hotspare_clone_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_create_001_neg cleanup +hotspare_create_001_neg_head() +{ + atf_set "descr" "'zpool create [-f]' with hot spares should be failedwith inapplicable scenarios." + atf_set "require.progs" dumpadm zpool + atf_set "timeout" 3600 +} +hotspare_create_001_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_create_001_neg.ksh || atf_fail "Testcase failed" +} +hotspare_create_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_detach_001_pos cleanup +hotspare_detach_001_pos_head() +{ + atf_set "descr" "'zpool detach ...' should deactivate the spared-in hot spare device successfully." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_detach_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_detach_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_detach_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_detach_002_pos cleanup +hotspare_detach_002_pos_head() +{ + atf_set "descr" "'zpool detach ...' against a functioning device that have spared should take the hot spare permanently swapping in successfully." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_detach_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_detach_002_pos.ksh || atf_fail "Testcase failed" +} +hotspare_detach_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_detach_003_pos cleanup +hotspare_detach_003_pos_head() +{ + atf_set "descr" "'zpool replace ' against a functioning device that have spared should complete and the hot spare should return to available." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_detach_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_detach_003_pos.ksh || atf_fail "Testcase failed" +} +hotspare_detach_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_detach_004_pos cleanup +hotspare_detach_004_pos_head() +{ + atf_set "descr" "'zpool replace ' against a hot spare device that have been activated should successful while the another dev is a available hot spare." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_detach_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_detach_004_pos.ksh || atf_fail "Testcase failed" +} +hotspare_detach_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_detach_005_neg cleanup +hotspare_detach_005_neg_head() +{ + atf_set "descr" "'zpool detach ' against a hot spare device that NOT activated should fail and issue an error message." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_detach_005_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_detach_005_neg.ksh || atf_fail "Testcase failed" +} +hotspare_detach_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_export_001_neg cleanup +hotspare_export_001_neg_head() +{ + atf_set "descr" "export pool that using shared hotspares will fail" + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_export_001_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_export_001_neg.ksh || atf_fail "Testcase failed" +} +hotspare_export_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_import_001_pos cleanup +hotspare_import_001_pos_head() +{ + atf_set "descr" "'zpool export/import ' should runs successfully regardless the hotspare is only in list, activated, or offline." + atf_set "require.progs" zpool sum + atf_set "timeout" 3600 +} +hotspare_import_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_import_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_import_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_onoffline_003_neg cleanup +hotspare_onoffline_003_neg_head() +{ + atf_set "descr" "'zpool offline/online ' should fail on inactive spares" + atf_set "require.progs" zpool zdb + atf_set "timeout" 3600 +} +hotspare_onoffline_003_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_onoffline_003_neg.ksh || atf_fail "Testcase failed" +} +hotspare_onoffline_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_onoffline_004_neg cleanup +hotspare_onoffline_004_neg_head() +{ + atf_set "descr" "'zpool offline/online ' against a spared basic vdev during I/O completes." + atf_set "require.progs" zfs zpool zdb + atf_set "timeout" 3600 +} +hotspare_onoffline_004_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_onoffline_004_neg.ksh || atf_fail "Testcase failed" +} +hotspare_onoffline_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_remove_001_pos cleanup +hotspare_remove_001_pos_head() +{ + atf_set "descr" "'zpool remove ...' can remove spare device from the pool." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_remove_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_remove_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_remove_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_remove_002_neg cleanup +hotspare_remove_002_neg_head() +{ + atf_set "descr" "'zpool remove ...' should fail with inapplicable scenarios." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_remove_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_remove_002_neg.ksh || atf_fail "Testcase failed" +} +hotspare_remove_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_remove_003_neg cleanup +hotspare_remove_003_neg_head() +{ + atf_set "descr" "Executing 'zpool remove' with bad options fails" + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_remove_003_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_remove_003_neg.ksh || atf_fail "Testcase failed" +} +hotspare_remove_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_remove_004_pos cleanup +hotspare_remove_004_pos_head() +{ + atf_set "descr" "'zpool remove ...' can remove spare device from the pool." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_remove_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_remove_004_pos.ksh || atf_fail "Testcase failed" +} +hotspare_remove_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_replace_001_neg cleanup +hotspare_replace_001_neg_head() +{ + atf_set "descr" "'zpool replace ' should fail with inapplicable scenarios." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_replace_001_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_replace_001_neg.ksh || atf_fail "Testcase failed" +} +hotspare_replace_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_replace_002_neg cleanup +hotspare_replace_002_neg_head() +{ + atf_set "descr" "'zpool replace ' should fail while the hot spares smaller than the basic vdev." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_replace_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_replace_002_neg.ksh || atf_fail "Testcase failed" +} +hotspare_replace_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_scrub_001_pos cleanup +hotspare_scrub_001_pos_head() +{ + atf_set "descr" "'zpool scrub ' should runs successfully regardlessthe hotspare is only in list or activated." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_scrub_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_scrub_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_scrub_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_scrub_002_pos cleanup +hotspare_scrub_002_pos_head() +{ + atf_set "descr" "'zpool scrub' scans spare vdevs" + atf_set "require.progs" zpool +} +hotspare_scrub_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_scrub_002_pos.ksh || atf_fail "Testcase failed" +} +hotspare_scrub_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_shared_001_pos cleanup +hotspare_shared_001_pos_head() +{ + atf_set "descr" "'zpool add spare ...' can add a disk as a shared spare to multiple pools." + atf_set "require.progs" zpool + atf_set "timeout" 3600 +} +hotspare_shared_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_shared_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_shared_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_snapshot_001_pos cleanup +hotspare_snapshot_001_pos_head() +{ + atf_set "descr" "'zpool detach ...' against hotspare should do no harm to snapshot." + atf_set "require.progs" zfs zpool sum + atf_set "timeout" 3600 +} +hotspare_snapshot_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_snapshot_001_pos.ksh || atf_fail "Testcase failed" +} +hotspare_snapshot_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case hotspare_snapshot_002_pos cleanup +hotspare_snapshot_002_pos_head() +{ + atf_set "descr" "'zpool detach ...' against basic vdev do no harm to snapshot." + atf_set "require.progs" zfs zpool sum + atf_set "timeout" 3600 +} +hotspare_snapshot_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/hotspare_snapshot_002_pos.ksh || atf_fail "Testcase failed" +} +hotspare_snapshot_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/hotspare.kshlib + . $(atf_get_srcdir)/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case hotspare_add_001_pos + atf_add_test_case hotspare_add_002_pos + atf_add_test_case hotspare_add_003_neg + atf_add_test_case hotspare_add_004_neg + atf_add_test_case hotspare_clone_001_pos + atf_add_test_case hotspare_clone_002_pos + atf_add_test_case hotspare_create_001_neg + atf_add_test_case hotspare_detach_001_pos + atf_add_test_case hotspare_detach_002_pos + atf_add_test_case hotspare_detach_003_pos + atf_add_test_case hotspare_detach_004_pos + atf_add_test_case hotspare_detach_005_neg + atf_add_test_case hotspare_export_001_neg + atf_add_test_case hotspare_import_001_pos + atf_add_test_case hotspare_onoffline_003_neg + atf_add_test_case hotspare_onoffline_004_neg + atf_add_test_case hotspare_remove_001_pos + atf_add_test_case hotspare_remove_002_neg + atf_add_test_case hotspare_remove_003_neg + atf_add_test_case hotspare_remove_004_pos + atf_add_test_case hotspare_replace_001_neg + atf_add_test_case hotspare_replace_002_neg + atf_add_test_case hotspare_scrub_001_pos + atf_add_test_case hotspare_scrub_002_pos + atf_add_test_case hotspare_shared_001_pos + atf_add_test_case hotspare_snapshot_001_pos + atf_add_test_case hotspare_snapshot_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/hotspare/setup.ksh b/tests/sys/cddl/zfs/tests/hotspare/setup.ksh new file mode 100644 index 00000000000..f671c637edd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/hotspare/setup.ksh @@ -0,0 +1,43 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +verify_runnable "global" + +log_must cleanup_devices_all + +# Most of the tests in this directory manually activate spares, which is not +# possible while ZFSD is running. +stop_zfsd + +log_pass diff --git a/tests/sys/cddl/zfs/tests/inheritance/Makefile b/tests/sys/cddl/zfs/tests/inheritance/Makefile new file mode 100644 index 00000000000..2724915a08f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/Makefile @@ -0,0 +1,66 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/inheritance +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= inheritance_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= config015.cfg +${PACKAGE}FILES+= config012.cfg +${PACKAGE}FILES+= state007.cfg +${PACKAGE}FILES+= state009.cfg +${PACKAGE}FILES+= config020.cfg +${PACKAGE}FILES+= state024.cfg +${PACKAGE}FILES+= state023.cfg +${PACKAGE}FILES+= state018.cfg +${PACKAGE}FILES+= state016.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= config003.cfg +${PACKAGE}FILES+= state011.cfg +${PACKAGE}FILES+= config004.cfg +${PACKAGE}FILES+= config021.cfg +${PACKAGE}FILES+= state008.cfg +${PACKAGE}FILES+= config013.cfg +${PACKAGE}FILES+= state006.cfg +${PACKAGE}FILES+= config014.cfg +${PACKAGE}FILES+= state001.cfg +${PACKAGE}FILES+= state010.cfg +${PACKAGE}FILES+= config005.cfg +${PACKAGE}FILES+= state017.cfg +${PACKAGE}FILES+= config002.cfg +${PACKAGE}FILES+= state019.cfg +${PACKAGE}FILES+= state022.cfg +${PACKAGE}FILES+= state014.cfg +${PACKAGE}FILES+= config001.cfg +${PACKAGE}FILES+= state013.cfg +${PACKAGE}FILES+= config006.cfg +${PACKAGE}FILES+= config008.cfg +${PACKAGE}FILES+= inherit_001_pos.ksh +${PACKAGE}FILES+= state021.cfg +${PACKAGE}FILES+= config022.cfg +${PACKAGE}FILES+= config019.cfg +${PACKAGE}FILES+= config017.cfg +${PACKAGE}FILES+= state002.cfg +${PACKAGE}FILES+= config010.cfg +${PACKAGE}FILES+= state005.cfg +${PACKAGE}FILES+= state020.cfg +${PACKAGE}FILES+= inherit.kshlib +${PACKAGE}FILES+= config009.cfg +${PACKAGE}FILES+= state012.cfg +${PACKAGE}FILES+= config007.cfg +${PACKAGE}FILES+= state015.cfg +${PACKAGE}FILES+= config011.cfg +${PACKAGE}FILES+= inherit.cfg +${PACKAGE}FILES+= state004.cfg +${PACKAGE}FILES+= config016.cfg +${PACKAGE}FILES+= state003.cfg +${PACKAGE}FILES+= config018.cfg +${PACKAGE}FILES+= config023.cfg +${PACKAGE}FILES+= config024.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/inheritance/README.config b/tests/sys/cddl/zfs/tests/inheritance/README.config new file mode 100644 index 00000000000..221c28abe99 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/README.config @@ -0,0 +1,66 @@ +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)README.config 1.2 07/01/09 SMI" +# +# The configX.cfg files describe both the dataset hierarchy to +# be created but also the initial source values for the datasets +# properties, i.e. whether they should be left with their default values +# or set locally. +# +# Format for this file is as follows: +# +# +# - must be the full dataset name +# +# - recognised types are POOL, CTR and FS +# +# +# - can have one of the following +# values: +# +# default property values are left unchanged +# +# local property values are set locally +# +# - property values are left unchanged (has the +# same effect as 'default' but is used to indicate +# that the property 'source' field may be 'inherited +# from..' depending on the actions further up the +# dataset hierarchy. +# +# +# The configuration below creates a three tier dataset layout, consisting +# of a pool, container and filesystem. +# +# The top tier pool's properties being set locally, and the two +# lower tier properties each inheriting their values from the next tier +# up. +# +TESTPOOL POOL local +TESTPOOL/TESTCTR CTR - +TESTPOOL/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/README.state b/tests/sys/cddl/zfs/tests/inheritance/README.state new file mode 100644 index 00000000000..4773475ef98 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/README.state @@ -0,0 +1,108 @@ +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)README.state 1.2 07/01/09 SMI" +# +# +# For every configX.cfg file there must be a corresponding stateX.cfg +# file. The state file both drives the operations to be performed on the +# dataset hierarchy which has been specified by the corresponding +# configX.cfg file, and also specifies the expected state of the +# properties after the operation has been completed. +# +# The format of the file is: +# : +# +# +# .... .... +# .... .... +# +# - dataset upon which the is to be executed. Can +# be any of the datasets specified in the corresponding +# configX.cfg file. If no command is to be executed +# then must be set to '-' +# +# +# - command to be executed upon the specified dataset. +# Currently the only supported commands are 'inherit' +# or 'inherit -r'. If no command is to be executed, +# then must be set to '-'. +# +# +# - the 'source' (as reported in 'zfs get') for the +# the properties before is executed. This +# can be 'default', 'local' or the name of a dataset +# from which the property is inherited. (The code +# automatically adds in the 'inherited from..' part +# of the string when doing the check. +# +# This field is for informational purposes only, to +# aid the user in seeing how the changes trickle down +# the data hierarchy. +# +# +# - the expected value of the 'source' field after the +# has been executed on the . +# As above can be 'default', 'local', or the dataset +# from which the property is inherited. +# +# Two important things to note: +# 1) there must be a line corresponding to each dataset +# line specified in the configX.cfg file. +# +# +# 2) There can be as many / blocks as desired, but +# there must be at least one, and the effect of each block is cumulative +# (i.e. the properties are not reset back to their default values between +# each block. If that is desired then each block must be placed in its +# own state file with its own corresponding configX.cfg file). +# +# +# Below are two sample / blocks. +# +# The first simply verifies that the properties on the top level dataset +# were set locally, and that the middle and bottom datasets properties +# were inherited from the top level pool (called TESTPOOL). Note the '-:-' +# which means that no command is to be executed, but simply that the +# properties settings are to be verified. +# +-:- +# +local local +TESTPOOL TESTPOOL +TESTPOOL TESTPOOL +# +# +# The block below describes the expected state of the properties after +# an 'inherit -r' command has been run on the top level pool (called +# TESTPOOL). +# +TESTPOOL:inherit -r +# +local default +TESTPOOL default +TESTPOOL default diff --git a/tests/sys/cddl/zfs/tests/inheritance/cleanup.ksh b/tests/sys/cddl/zfs/tests/inheritance/cleanup.ksh new file mode 100644 index 00000000000..26ce7c30a0b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/inheritance/config001.cfg b/tests/sys/cddl/zfs/tests/inheritance/config001.cfg new file mode 100644 index 00000000000..fdb07fa9731 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config001.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config001.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR - +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config002.cfg b/tests/sys/cddl/zfs/tests/inheritance/config002.cfg new file mode 100644 index 00000000000..8bb083a5924 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config002.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config002.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config003.cfg b/tests/sys/cddl/zfs/tests/inheritance/config003.cfg new file mode 100644 index 00000000000..631ea9a5741 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config003.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config003.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR default +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config004.cfg b/tests/sys/cddl/zfs/tests/inheritance/config004.cfg new file mode 100644 index 00000000000..841fa70f256 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config004.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config004.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config005.cfg b/tests/sys/cddl/zfs/tests/inheritance/config005.cfg new file mode 100644 index 00000000000..b06debe943b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config005.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config005.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config006.cfg b/tests/sys/cddl/zfs/tests/inheritance/config006.cfg new file mode 100644 index 00000000000..dcd87f912ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config006.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config006.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR - +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config007.cfg b/tests/sys/cddl/zfs/tests/inheritance/config007.cfg new file mode 100644 index 00000000000..0ea0f849a4b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config007.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config007.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config008.cfg b/tests/sys/cddl/zfs/tests/inheritance/config008.cfg new file mode 100644 index 00000000000..6e9e866777e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config008.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config008.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR default +testpool.inherit/TESTCTR/TESTFS1 FS default diff --git a/tests/sys/cddl/zfs/tests/inheritance/config009.cfg b/tests/sys/cddl/zfs/tests/inheritance/config009.cfg new file mode 100644 index 00000000000..092f79b973e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config009.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config009.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR default +testpool.inherit/TESTCTR/TESTFS1 FS default diff --git a/tests/sys/cddl/zfs/tests/inheritance/config010.cfg b/tests/sys/cddl/zfs/tests/inheritance/config010.cfg new file mode 100644 index 00000000000..8090b6ba7f3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config010.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config010.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR default +testpool.inherit/TESTCTR/TESTFS1 FS default diff --git a/tests/sys/cddl/zfs/tests/inheritance/config011.cfg b/tests/sys/cddl/zfs/tests/inheritance/config011.cfg new file mode 100644 index 00000000000..09187d2614c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config011.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config011.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR default +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config012.cfg b/tests/sys/cddl/zfs/tests/inheritance/config012.cfg new file mode 100644 index 00000000000..8a35c96e125 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config012.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config012.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR default +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config013.cfg b/tests/sys/cddl/zfs/tests/inheritance/config013.cfg new file mode 100644 index 00000000000..41dc8b357b4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config013.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config013.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config014.cfg b/tests/sys/cddl/zfs/tests/inheritance/config014.cfg new file mode 100644 index 00000000000..b3f8739e670 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config014.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config014.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config015.cfg b/tests/sys/cddl/zfs/tests/inheritance/config015.cfg new file mode 100644 index 00000000000..51709ab3323 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config015.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config015.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config016.cfg b/tests/sys/cddl/zfs/tests/inheritance/config016.cfg new file mode 100644 index 00000000000..6b7106c58cc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config016.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config016.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL default +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config017.cfg b/tests/sys/cddl/zfs/tests/inheritance/config017.cfg new file mode 100644 index 00000000000..8623bddcbd4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config017.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config017.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config018.cfg b/tests/sys/cddl/zfs/tests/inheritance/config018.cfg new file mode 100644 index 00000000000..6d7aca4d67d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config018.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config018.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config019.cfg b/tests/sys/cddl/zfs/tests/inheritance/config019.cfg new file mode 100644 index 00000000000..f34d2935590 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config019.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config019.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR - +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config020.cfg b/tests/sys/cddl/zfs/tests/inheritance/config020.cfg new file mode 100644 index 00000000000..da4abdbceec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config020.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config020.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR - +testpool.inherit/TESTCTR/TESTFS1 FS - diff --git a/tests/sys/cddl/zfs/tests/inheritance/config021.cfg b/tests/sys/cddl/zfs/tests/inheritance/config021.cfg new file mode 100644 index 00000000000..dbaca99ee12 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config021.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config021.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR - +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config022.cfg b/tests/sys/cddl/zfs/tests/inheritance/config022.cfg new file mode 100644 index 00000000000..b4b71e2f656 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config022.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config022.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR - +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config023.cfg b/tests/sys/cddl/zfs/tests/inheritance/config023.cfg new file mode 100644 index 00000000000..de6a05a0311 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config023.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config023.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/config024.cfg b/tests/sys/cddl/zfs/tests/inheritance/config024.cfg new file mode 100644 index 00000000000..f1e0b0e846a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/config024.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)config024.cfg 1.2 07/01/09 SMI" +# +testpool.inherit POOL local +testpool.inherit/TESTCTR CTR local +testpool.inherit/TESTCTR/TESTFS1 FS local diff --git a/tests/sys/cddl/zfs/tests/inheritance/inherit.cfg b/tests/sys/cddl/zfs/tests/inheritance/inherit.cfg new file mode 100644 index 00000000000..a485e69fb82 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/inherit.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)inherit.cfg 1.3 08/08/15 SMI" +# + +export ZFSROOT= +export STF_TIMEOUT=2800 diff --git a/tests/sys/cddl/zfs/tests/inheritance/inherit.kshlib b/tests/sys/cddl/zfs/tests/inheritance/inherit.kshlib new file mode 100644 index 00000000000..5a3ce922739 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/inherit.kshlib @@ -0,0 +1,115 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)inherit.kshlib 1.3 09/05/19 SMI" +# + +# +# Simple function to get the source of the specified property. +# If unable to get the property then exits. +# +function get_prop_src # property dataset +{ + typeset prop_val + typeset prop=$1 + typeset dataset=$2 + + prop_val=`$ZFS get -H -o source $prop $dataset` + + if [[ $? -ne 0 ]]; then + log_fail "Unable to determine the source of $prop " \ + "property for dataset $dataset" + else + print $prop_val + fi +} + +# +# Function to check the 'source' of a property. The source can +# either be "default", "local", or "inherited from ". +# +# The 'expected src' argument must be either "default", "local", or +# a dataset name. +# +# Returns 0 on success, 1 on failure. +# +function verify_prop_src # child_dataset property expected_src +{ + typeset target=$1 + typeset prop=$2 + typeset expected=$3 + + prop_src=`get_prop_src $prop $target` + + # + # Rather than just checking if $prop_src == $expected + # we first determine what value $expected should have. + # This allows us to catch the case where a property + # has a source of "local" but we expected it to be + # "default" + # + if [[ $expected == "default" ]]; then + if [[ $prop_src != $expected ]]; then + log_note "Property $prop of $target has source"\ + " $prop_src rather than $expected" + return 1 + fi + elif [[ $expected == "local" ]]; then + if [[ $prop_src != $expected ]]; then + log_note "Property $prop of $target has source"\ + " $prop_src rather than $expected" + return 1 + fi + elif [[ $prop_src != "inherited from $expected" ]]; then + log_note "Property $prop of $expected has source $prop_src"\ + " rather than 'inherited from $expected'" + return 1 + fi + + return 0 +} + +# +# Simple function to set a property to a +# specified value and verify it has changed +# correctly. +# +function set_n_verify_prop #property value dataset +{ + typeset prop=$1 + typeset prop_val=$2 + typeset dataset=$3 + + $ZFS set $prop=$prop_val $dataset + check_val=`get_prop $prop $dataset` + + if [[ $check_val != $prop_val ]]; then + log_fail "Property $prop of $dataset has value $check_val"\ + " rather than $prop_val" + fi +} diff --git a/tests/sys/cddl/zfs/tests/inheritance/inherit_001_pos.ksh b/tests/sys/cddl/zfs/tests/inheritance/inherit_001_pos.ksh new file mode 100644 index 00000000000..8f965d40c49 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/inherit_001_pos.ksh @@ -0,0 +1,440 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)inherit_001_pos.ksh 1.5 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/inheritance/inherit.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: inherit_001_pos +# +# DESCRIPTION: +# Test that properties are correctly inherited using 'zfs set', +# 'zfs inherit' and 'zfs inherit -r'. +# +# STRATEGY: +# 1) Read a configX.cfg file and create the specified datasets +# 2) Read a stateX.cfg file and execute the commands within it +# and verify that the properties have the correct values +# 3) Repeat steps 1-2 for each configX and stateX files found. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Test properties are inherited correctly" + +# +# Simple function to create specified datasets. +# +function create_dataset #name type disks +{ + typeset dataset=$1 + typeset type=$2 + typeset disks=$3 + + if [[ $type == "POOL" ]]; then + create_pool "$dataset" "$disks" + elif [[ $type == "CTR" ]]; then + log_must $ZFS create $dataset + log_must $ZFS set canmount=off $dataset + elif [[ $type == "FS" ]]; then + log_must $ZFS create $dataset + else + log_fail "ERROR: Unrecognised type $type" + fi + + list="$list $dataset" +} + +# +# Function to walk through all the properties in a +# dataset, setting them to a 'local' value if required. +# +function init_props #dataset init_code +{ + typeset dataset=$1 + typeset init_code=$2 + typeset new_val + typeset -i i=0 + + # + # Though the effect of '-' and 'default' is the same we + # call them out via a log_note to aid in debugging the + # config files + # + if [[ $init_code == "-" ]]; then + log_note "Leaving properties for $dataset unchanged." + [[ $def_recordsize == 0 ]] && \ + update_recordsize $dataset $init_code + return; + elif [[ $init_code == "default" ]]; then + log_note "Leaving properties for $dataset at default values." + [[ $def_recordsize == 0 ]] && \ + update_recordsize $dataset $init_code + return; + elif [[ $init_code == "local" ]]; then + log_note "Setting properties for $dataset to local values." + for (( ; i < ${#props[*]}; i += 2 )); do + if [[ ${props[i]} == "recordsize" ]]; then + update_recordsize $dataset $init_code + else + set_n_verify_prop ${props[i]} \ + ${local_val[((i/2))]} $dataset + fi + done + else + log_fail "ERROR: Unrecognised init code $init_code" + fi +} + +# +# We enter this function either to update the recordsize value +# in the default array, or to update the local value array. +# +function update_recordsize { #dataset init_code + typeset dataset=$1 + typeset init_code=$2 + typeset idx=0 + typeset record_val + + # + # First need to find where the recordsize property is + # located in the arrays + # + for (( ; idx < ${#props[*]}; idx += 2 )); do + [[ ${props[idx]} == "recordsize" ]] && \ + break + done + + (( idx = idx / 2 )) + record_val=`get_prop recordsize $dataset` + if [[ $init_code == "-" || \ + $init_code == "default" ]]; then + + def_val[idx]=$record_val + def_recordsize=1 + + elif [[ $init_code == "local" ]]; then + + log_must $ZFS set recordsize=$record_val $dataset + + local_val[idx]=$record_val + fi +} + +# +# The mountpoint property is slightly different from other properties and +# so is handled here. For all other properties if they are set to a specific +# value at a higher level in the data hierarchy (i.e. checksum=on) then that +# value propogates down the hierarchy unchanged, with the source field being +# set to 'inherited from '. +# +# The mountpoint property is different in that while the value propogates +# down the hierarchy, the value at each level is determined by a combination +# of the top-level value and the current level in the hierarchy. +# +# For example consider the case where we have a pool (called pool1), containing +# a dataset (ctr) which in turn contains a filesystem (fs). If we set the +# mountpoint of the pool to '/mnt2' then the mountpoints for the dataset and +# filesystem are '/mnt2/ctr' and /mnt2/ctr/fs' respectively, with the 'source' +# field being set to 'inherited from pool1'. +# +# So at the filesystem level to calculate what our mountpoint property should +# be set to we walk back up the hierarchy sampling the mountpoint property at +# each level and forming up the expected mountpoint value piece by piece until +# we reach the level specified in the 'source' field, which in this example is +# the top-level pool. +# +function get_mntpt_val #dataset src index +{ + typeset dataset=$1 + typeset src=$2 + typeset idx=$3 + typeset new_path="" + typeset dset + typeset mntpt="" + + if [[ $src == "local" ]]; then + mntpt=${local_val[idx]} + elif [[ $src == "default" ]]; then + mntpt="$ZFSROOT/"$dataset + else + # Walk back up the hierarchy building up the + # expected mountpoint property value. + obj_name=${dataset##*/} + + while [[ $src != $dataset ]]; do + dset=${dataset%/*} + + mnt_val=`get_prop mountpoint $dset` + + mod_prop_val=${mnt_val##*/} + new_path="/"$mod_prop_val$new_path + dataset=$dset + done + + mntpt=$new_path"/"$obj_name + fi + print $mntpt +} + +# +# Simple function to verify that a property has the +# expected value. +# +function verify_prop_val #property dataset src index +{ + typeset dataset=$1 + typeset prop=$2 + typeset src=$3 + typeset idx=$4 + typeset new_path="" + typeset dset + typeset exp_val + typeset prop_val + + prop_val=`get_prop $prop $dataset` + + # mountpoint property is handled as a special case + if [[ $prop == "mountpoint" ]]; then + exp_val=`get_mntpt_val $dataset $src $idx` + else + if [[ $src == "local" ]]; then + exp_val=${local_val[idx]} + elif [[ $src == "default" ]]; then + exp_val=${def_val[idx]} + else + # + # We are inheriting the value from somewhere + # up the hierarchy. + # + exp_val=`get_prop $prop $src` + fi + fi + + [ "$prop_val" = "$exp_val" ] && return + + # After putback PSARC/2008/231 Apr,09,2008, the default value of + # aclinherit has changed to be 'restricted' instead of 'secure', + # but the old interface of 'secure' still exist + [ "$prop" = "aclinherit" ] && return + [ "$exp_val" = "secure" ] && return + [ "$prop_val" = "restricted" ] && return + + log_fail "ERROR: Property $prop (source $src index $idx) for $dataset" \ + "was [$prop_val]; expected [$exp_val]" +} + +# +# Function to read the configX.cfg files and create the specified +# dataset hierarchy +# +function scan_config #config-file +{ + typeset config_file=$1 + + DISK=${DISKS%% *} + + list="" + + grep "^[^#]" $config_file | { + while read name type init ; do + create_dataset $name $type $DISK + init_props $name $init + done + } +} + +function check_state +{ + typeset i=$1 + typeset j=$2 + typeset op=$3 + typeset target=$4 + + # + # The user can if they wish specify that no operation be performed + # (by specifying '-' rather than a command). This is not as + # useless as it sounds as it allows us to verify that the dataset + # hierarchy has been set up correctly as specified in the + # configX.cfg file (which includes 'set'ting properties at a higher + # level and checking that they propogate down to the lower levels. + # + # Note in a few places here, we use log_onfail, rather than + # log_must - this substantially reduces journal output. + # + if [[ $op != "-" ]]; then + # Unmount the test datasets if they are still mounted. + # Most often, they won't be, so discard the output + unmount_all_safe > /dev/null 2>&1 + + for p in ${props[i]} ${props[((i+1))]}; do + log_onfail $ZFS $op $p $target + done + fi + for check_obj in $list; do + read init_src final_src + + for p in ${props[i]} ${props[((i+1))]}; do + verify_args="$check_obj $p $final_src" + + log_onfail verify_prop_src $check_obj $p $final_src + log_onfail verify_prop_val $check_obj $p $final_src $j + done + done +} + +# +# Main function. Executes the commands specified in the stateX.cfg +# files and then verifies that all the properties have the correct +# values and 'source' fields. +# +function scan_state #state-file +{ + typeset state_file=$1 + typeset -i i=0 + typeset -i j=0 + + log_note "Reading state from $state_file" + for (( ; i < ${#props[*]}; i += 2, j += 1 )); do + grep "^[^#]" $state_file | { + while IFS=: read target op; do + check_state $i $j "$op" "$target" + done + } + done +} + + +set -A props "checksum" "" \ + "compression" "compress" \ + "atime" "" \ + "exec" "" \ + "setuid" "" \ + "sharenfs" "" \ + "recordsize" "recsize" \ + "mountpoint" "" \ + "snapdir" "" \ + "aclmode" "" \ + "aclinherit" "" \ + "readonly" "rdonly" + +# +# Note except for the mountpoint default value (which is handled in +# the routine itself), each property specified in the 'props' array +# above must have a corresponding entry in the two arrays below. +# +set -A def_val "on" \ + "off" \ + "on" \ + "on" \ + "on" \ + "off" \ + "" \ + "" \ + "hidden" \ + "discard" \ + "secure" \ + "off" + +set -A local_val "off" "on" "off" "off" \ + "off" "on" "" \ + "$TESTDIR" "visible" "groupmask" "discard" \ + "off" + +log_must $ZPOOL create $TESTPOOL ${DISKS%% *} + +# Append the "shareiscsi" property if it is supported +$ZFS get shareiscsi $TESTPOOL > /dev/null 2>&1 +if [[ $? -eq 0 ]]; then + typeset -i i=${#props[*]} + props[i]="shareiscsi" + props[((i+1))]="" + def_val[((i/2))]="off" + local_val[((i/2))]="on" +fi + +# Append the "devices" property if it is settable +$ZFS set devices=off $TESTPOOL +if [[ $? -eq 0 ]]; then + typeset -i i=${#props[*]} + props[i]="devices" + props[((i+1))]="" + def_val[((i/2))]="on" + local_val[((i/2))]="off" +else + log_note "Setting devices=off is not supported on this system" +fi + +log_must $ZPOOL destroy $TESTPOOL + +# +# Global flag indicating whether the default record size had been +# read. +# +typeset def_recordsize=0 + +TDIR=$STF_SUITE/tests/inheritance +set -A config_files $(ls $TDIR/config*[1-9]*.cfg) +set -A state_files $(ls $TDIR/state*.cfg) + +# +# Global list of datasets created. +# +list="" + +if [[ ${#config_files[*]} != ${#state_files[*]} ]]; then + log_fail "ERROR: Must have the same number of config files"\ + "(${#config_files[*]}) and state files ${#state_files[*]}" +fi + +typeset -i fnum=0 +for (( ; fnum < ${#config_files[*]}; fnum += 1 )); do + default_cleanup_noexit + def_recordsize=0 + + log_note "*** Testing configuration ${config_files[fnum]}" + scan_config ${config_files[fnum]} + scan_state ${state_files[fnum]} +done + +log_pass "Properties correctly inherited as expected" diff --git a/tests/sys/cddl/zfs/tests/inheritance/inheritance_test.sh b/tests/sys/cddl/zfs/tests/inheritance/inheritance_test.sh new file mode 100755 index 00000000000..6a0ccbc29df --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/inheritance_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case inherit_001_pos cleanup +inherit_001_pos_head() +{ + atf_set "descr" "Test properties are inherited correctly" + atf_set "timeout" 1800 + atf_set "require.progs" zfs +} +inherit_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/inherit.kshlib + . $(atf_get_srcdir)/inherit.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/inherit_001_pos.ksh || atf_fail "Testcase failed" +} +inherit_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case inherit_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/inheritance/state001.cfg b/tests/sys/cddl/zfs/tests/inheritance/state001.cfg new file mode 100644 index 00000000000..660090ea024 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state001.cfg @@ -0,0 +1,44 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state001.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that the property that was set on the top level pool +# via the 'local' keyword (in the config1.cfg file) has correctly +# propogated down the hierarchy. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +local local +testpool.inherit testpool.inherit +testpool.inherit testpool.inherit diff --git a/tests/sys/cddl/zfs/tests/inheritance/state002.cfg b/tests/sys/cddl/zfs/tests/inheritance/state002.cfg new file mode 100644 index 00000000000..e634e6e99ce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state002.cfg @@ -0,0 +1,45 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state002.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that the property that was set on the middle level +# dataset via the 'local' keyword (in the configX.cfg file) has +# correctly propogated down the hierarchy to the filesystem underneath, +# while leaving the top level pools properties unchanged. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +default default +local local +testpool.inherit/TESTCTR testpool.inherit/TESTCTR diff --git a/tests/sys/cddl/zfs/tests/inheritance/state003.cfg b/tests/sys/cddl/zfs/tests/inheritance/state003.cfg new file mode 100644 index 00000000000..e29ccf9d3fd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state003.cfg @@ -0,0 +1,43 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state003.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that setting the filesystem's properties does not affect +# the properties of datasets above it in the hierarchy. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +default default +default default +local local diff --git a/tests/sys/cddl/zfs/tests/inheritance/state004.cfg b/tests/sys/cddl/zfs/tests/inheritance/state004.cfg new file mode 100644 index 00000000000..0b41f76d165 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state004.cfg @@ -0,0 +1,44 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state004.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that setting a property on a middle level dataset does +# not prevent us from setting a property on the bottom level filesystem, +# and that neither affects the top level pools properties. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +default default +local local +local local diff --git a/tests/sys/cddl/zfs/tests/inheritance/state005.cfg b/tests/sys/cddl/zfs/tests/inheritance/state005.cfg new file mode 100644 index 00000000000..162da273d40 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state005.cfg @@ -0,0 +1,45 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state005.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that when we set a property on a top level pool, followed +# by a middle level dataset, that the bottom level filesystem inherits +# the property from the middle level dataset, and not from the top level +# pool. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +local local +local local +testpool.inherit/TESTCTR testpool.inherit/TESTCTR diff --git a/tests/sys/cddl/zfs/tests/inheritance/state006.cfg b/tests/sys/cddl/zfs/tests/inheritance/state006.cfg new file mode 100644 index 00000000000..21cb96a567b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state006.cfg @@ -0,0 +1,47 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state006.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that when we set a property on a top level pool, followed +# by a bottom level filesystem, that the middle level dataset inherits +# the property from the top level pool, and not from the bottom level +# filesystem. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +# +# +local local +testpool.inherit testpool.inherit +local local diff --git a/tests/sys/cddl/zfs/tests/inheritance/state007.cfg b/tests/sys/cddl/zfs/tests/inheritance/state007.cfg new file mode 100644 index 00000000000..fb93d7c3d9d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state007.cfg @@ -0,0 +1,45 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state007.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that when we can set properties on each level of the +# hierarchy independently. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +# +# +local local +local local +local local diff --git a/tests/sys/cddl/zfs/tests/inheritance/state008.cfg b/tests/sys/cddl/zfs/tests/inheritance/state008.cfg new file mode 100644 index 00000000000..c3ebd9b4afd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state008.cfg @@ -0,0 +1,44 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state008.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# No command is actually run (hence '-:-') but rather this state file is +# used to verify that when we create a dataset hierarchy that the +# properties of each dataset have their default values. +# +# *** ASSERTION DESCRIPTION *** +# +-:- +# +# +default default +default default +default default diff --git a/tests/sys/cddl/zfs/tests/inheritance/state009.cfg b/tests/sys/cddl/zfs/tests/inheritance/state009.cfg new file mode 100644 index 00000000000..6c4e323c2c1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state009.cfg @@ -0,0 +1,57 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state009.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit' at different levels of a +# data hierarchy where the properties of each dataset have their +# default values leaves the values unchanged. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit +# +default default +default default +default default +# +testpool.inherit/TESTCTR:inherit +# +default default +default default +default default +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state010.cfg b/tests/sys/cddl/zfs/tests/inheritance/state010.cfg new file mode 100644 index 00000000000..83f563cf184 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state010.cfg @@ -0,0 +1,56 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state010.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit -r' at different levels of a +# data hierarchy where the properties of each dataset have their +# default values leaves the values unchanged. +# +# *** ASSERTION DESCRIPTION *** +# +testpool.inherit:inherit -r +# +default default +default default +default default +# +testpool.inherit/TESTCTR:inherit -r +# +default default +default default +default default +# +testpool.inherit/TESTCTR/TESTFS1:inherit -r +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state011.cfg b/tests/sys/cddl/zfs/tests/inheritance/state011.cfg new file mode 100644 index 00000000000..b53a9ab7d33 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state011.cfg @@ -0,0 +1,58 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state011.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that running 'zfs inherit' at each level of the data hierarchy +# when the bottom filesystem level properties have been set locally has +# no effect except at the bottom level where the property values are +# inherited from the middle level dataset. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit +# +default default +default default +local local +# +testpool.inherit/TESTCTR:inherit +# +default default +default default +local local +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +local default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state012.cfg b/tests/sys/cddl/zfs/tests/inheritance/state012.cfg new file mode 100644 index 00000000000..1bbde3a5c5a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state012.cfg @@ -0,0 +1,62 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state012.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that running 'zfs inherit -r' at each level of the data hierarchy +# when the bottom filesystem level properties have been set locally results +# in the top level property values being propogated down the data +# hierarchy. +# +# Executing inherit -r at the middle level and bottom levels after +# running it at the top level is somewhat redundant as the top level value +# should propogate down the entire data hierarchy. Done for completeness +# sake. +# +# *** ASSERTION DESCRIPTION *** +# +testpool.inherit:inherit -r +# +default default +default default +local default +# +testpool.inherit/TESTCTR:inherit -r +# +default default +default default +default default +# +testpool.inherit/TESTCTR/TESTFS1:inherit -r +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state013.cfg b/tests/sys/cddl/zfs/tests/inheritance/state013.cfg new file mode 100644 index 00000000000..c0e6cc9185e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state013.cfg @@ -0,0 +1,56 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state013.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit' on each level when the middle +# and bottom levels properties are set locally results in the middle and +# bottom levels inheriting values from the next level up in the hierarchy. +# +# *** ASSERTION DESCRIPTION *** +# +testpool.inherit:inherit +# +default default +local local +local local +# +testpool.inherit/TESTCTR:inherit +# +default default +local default +local local +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +local default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state014.cfg b/tests/sys/cddl/zfs/tests/inheritance/state014.cfg new file mode 100644 index 00000000000..4569a560e7d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state014.cfg @@ -0,0 +1,62 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state014.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that running 'zfs inherit -r' at each level of the data hierarchy +# when the bottom and middle level properties have been set locally results +# in the top level property values being propogated down the data +# hierarchy. +# +# Note : executing inherit -r at the middle level and bottom levels after +# running it at the top level is somewhat redundant as the top level value +# should propogate down the entire data hierarchy. Done for completeness +# sake. +# +# *** ASSERTION DESCRIPTION *** +# +testpool.inherit:inherit -r +# +default default +local default +local default +# +testpool.inherit/TESTCTR:inherit -r +# +default default +default default +default default +# +testpool.inherit/TESTCTR/TESTFS1:inherit -r +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state015.cfg b/tests/sys/cddl/zfs/tests/inheritance/state015.cfg new file mode 100644 index 00000000000..d94aeb2a203 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state015.cfg @@ -0,0 +1,66 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state015.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit' at the top level in the hierarchy +# when the middle level properties are set locally, and the bottom +# level has inherited its value from the middle level, results in no change +# to the top level properties. +# +# Executing 'zfs inherit' at the middle level results in the middle level +# inheriting its value from the top level, and passing the values down to +# the bottom level. +# +# Executing 'zfs inherit' at the bottom level is somewhat redundant but +# is done for completness sake. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit +# +default default +local local +testpool.inherit/TESTCTR testpool.inherit/TESTCTR +# +# +testpool.inherit/TESTCTR:inherit +# +default default +local default +testpool.inherit/TESTCTR default +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +default default diff --git a/tests/sys/cddl/zfs/tests/inheritance/state016.cfg b/tests/sys/cddl/zfs/tests/inheritance/state016.cfg new file mode 100644 index 00000000000..8316c35f936 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state016.cfg @@ -0,0 +1,62 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state016.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit -r' at the top level in the hierarchy +# when the middle level properties are set locally, and the bottom +# level has inherited its value from the middle level, results in no change +# to the top level properties and the middle and bottom properties changing +# to the top level (default) values. +# +# Executing 'zfs inherit -r' at the bottom and middle levels after executing +# at the top level is somewhat redundant but ss done for completness sake. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit -r +# +default default +local default +testpool.inherit default +# +testpool.inherit/TESTCTR:inherit -r +# +default default +default default +default default +# +testpool.inherit/TESTCTR/TESTFS1:inherit -r +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state017.cfg b/tests/sys/cddl/zfs/tests/inheritance/state017.cfg new file mode 100644 index 00000000000..4ca6d89d6c0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state017.cfg @@ -0,0 +1,67 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state017.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit' at the top level in the hierarchy +# when the top level and middle level datasets properties are set locally, +# and the bottom level has inherited its properties from the middle +# level, results in the top level properties reverting back to their +# default values. +# +# Executing 'zfs inherit' at the middle level results in the middle level +# inheriting its value from the top level (which is now default), and passing +# the values down to the bottom level. +# +# Executing 'zfs inherit' at the bottom level is somewhat redundant but +# is done for completness sake. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit +# +local default +local local +testpool.inherit/TESTCTR testpool.inherit/TESTCTR +# +# +testpool.inherit/TESTCTR:inherit +# +default default +local default +testpool.inherit/TESTCTR default +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +default default diff --git a/tests/sys/cddl/zfs/tests/inheritance/state018.cfg b/tests/sys/cddl/zfs/tests/inheritance/state018.cfg new file mode 100644 index 00000000000..01692795179 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state018.cfg @@ -0,0 +1,64 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state018.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit -r' at the top level in the hierarchy +# when the top level and middle level datasets properties are set locally, +# and the bottom level has inherited its properties from the middle +# level, results in the top level properties reverting back to their +# default values and being propogated down to the other datasets in the +# hierarchy. +# +# Executing 'zfs inherit -r' at the middle and bottom levels after executing +# it at the top level is somewhat redundant but is done for completness sake. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit -r +# +local default +local default +testpool.inherit/TESTCTR default +# +# +testpool.inherit/TESTCTR:inherit -r +# +default default +default default +default default +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +default default diff --git a/tests/sys/cddl/zfs/tests/inheritance/state019.cfg b/tests/sys/cddl/zfs/tests/inheritance/state019.cfg new file mode 100644 index 00000000000..aa2f61acc4f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state019.cfg @@ -0,0 +1,63 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state019.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit' at the top level in the hierarchy +# when the top level properties are set locally and the middle and bottom +# datasets have inherited from the top level, results in the top level +# properties reverting back to their default values, the middle and bottom +# levels inheriting the changed values. +# +# Executing 'zfs inherit' at the middle and bottom levels is somewhat +# redundant but is done for completness sake. +# +# *** ASSERTION DESCRIPTION *** +# +testpool.inherit:inherit +# +local default +testpool.inherit default +testpool.inherit default +# +# +testpool.inherit/TESTCTR:inherit +# +default default +default default +default default +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state020.cfg b/tests/sys/cddl/zfs/tests/inheritance/state020.cfg new file mode 100644 index 00000000000..fc0111f12a8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state020.cfg @@ -0,0 +1,64 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state020.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit -r' at the top level in the hierarchy +# when the top level properties are set locally and the middle and bottom +# datasets have inherited from the top level, results in the top level +# properties reverting back to their default values, the middle and bottom +# levels inheriting the changed values. +# +# Executing 'zfs inherit -r' at the middle and bottom levels is somewhat +# redundant but is done for completness sake. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit -r +# +local default +testpool.inherit default +testpool.inherit default +# +# +testpool.inherit/TESTCTR:inherit -r +# +default default +default default +default default +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit -r +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state021.cfg b/tests/sys/cddl/zfs/tests/inheritance/state021.cfg new file mode 100644 index 00000000000..55561af544a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state021.cfg @@ -0,0 +1,64 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state021.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit' at the top level in the hierarchy +# when the top level and bottom level properties are set locally and the +# middle dataset has inherited from the top level, results in the top level +# properties reverting back to their default values, and the middle level +# inheriting the new top level value. +# +# Executing 'zfs inherit' at the bottom level results in it inheriting +# the middle level values. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit +# +local default +testpool.inherit default +local local +# +# +testpool.inherit/TESTCTR:inherit +# +default default +default default +local local +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +local default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state022.cfg b/tests/sys/cddl/zfs/tests/inheritance/state022.cfg new file mode 100644 index 00000000000..b16976ca3a8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state022.cfg @@ -0,0 +1,63 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state022.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit -r' at the top level in the hierarchy +# when the top level and bottom level properties are set locally and the +# middle dataset has inherited from the top level, results in the top level +# properties reverting back to their default values, the middle and bottom +# levels inheriting the changed values. +# +# Executing 'zfs inherit -r' at the middle and bottom levels is somewhat +# redundant but is done for completness sake. +# +# *** ASSERTION DESCRIPTION *** +# +testpool.inherit:inherit -r +# +local default +testpool.inherit default +local default +# +# +testpool.inherit/TESTCTR:inherit -r +# +default default +default default +default default +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit -r +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state023.cfg b/tests/sys/cddl/zfs/tests/inheritance/state023.cfg new file mode 100644 index 00000000000..85ac3f8a870 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state023.cfg @@ -0,0 +1,65 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state023.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit' at the top level in the hierarchy +# when each levels properties are set locally, results in the top level +# properties reverting back to their default values. +# +# Executing 'zfs inherit' at the middle level results in it inheriting +# the top levels (now default) values +# +# Executing 'zfs inherit' at the bottom level results in it inheriting +# the middle levels (now default) values +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit +# +local default +local local +local local +# +# +testpool.inherit/TESTCTR:inherit +# +default default +local default +local local +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +local default +# diff --git a/tests/sys/cddl/zfs/tests/inheritance/state024.cfg b/tests/sys/cddl/zfs/tests/inheritance/state024.cfg new file mode 100644 index 00000000000..ce46e1ec34f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inheritance/state024.cfg @@ -0,0 +1,63 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)state024.cfg 1.2 07/01/09 SMI" +# +# *** ASSERTION DESCRIPTION *** +# +# Verify that executing 'zfs inherit -r' at the top level in the hierarchy +# when each levels properties are set locally, results in the top level +# properties reverting back to their default values, and the changed +# values being propogated down the hierarchy. +# +# Executing 'zfs inherit -r' at the middle and bottom levels after doing so +# at the top level is somewhat redundant but is done for completeness. +# +# *** ASSERTION DESCRIPTION *** +# +# +testpool.inherit:inherit -r +# +local default +local default +local default +# +# +testpool.inherit/TESTCTR:inherit +# +default default +default default +default default +# +# +testpool.inherit/TESTCTR/TESTFS1:inherit +# +default default +default default +default default +# diff --git a/tests/sys/cddl/zfs/tests/interop/Makefile b/tests/sys/cddl/zfs/tests/interop/Makefile new file mode 100644 index 00000000000..40ca9683a83 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/interop/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/interop +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= interop_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= interop_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= interop.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/interop/cleanup.ksh b/tests/sys/cddl/zfs/tests/interop/cleanup.ksh new file mode 100644 index 00000000000..64337c28743 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/interop/cleanup.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +ismounted $TESTPOOL/$TESTFS +(( $? == 0 )) && log_must $ZFS umount -f $TESTDIR +destroy_pool $TESTPOOL + +$METASTAT $META_DEVICE_ID > /dev/null 2>&1 +if (( $? == 0 )); then + log_note "Clearing meta device ($META_DEVICE_ID)" + $METACLEAR -f $META_DEVICE_ID > /dev/null 2>&1 +fi + +typeset metadb="" +typeset i="" + +metadb=`$METADB | $CUT -f6 | $GREP dev | $UNIQ` +for i in $metadb; do + log_note "Clearing meta db ($i)" + $METADB -fd $i > /dev/null 2>&1 +done + +# recreate and destroy a zpool over the disks to restore the partitions to +# normal +case $DISK_COUNT in +0) + log_note "No disk devices to restore" + ;; +1) + log_must cleanup_devices $ZFS_DISK2 + ;; +2) + log_must cleanup_devices $META_DISK0 $ZFS_DISK2 + ;; +*) + log_must cleanup_devices $META_DISK0 $META_DISK1 $ZFS_DISK2 + ;; +esac + +log_pass "Cleanup has been successful" diff --git a/tests/sys/cddl/zfs/tests/interop/interop.cfg b/tests/sys/cddl/zfs/tests/interop/interop.cfg new file mode 100644 index 00000000000..4886c41de16 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/interop/interop.cfg @@ -0,0 +1,82 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)interop.cfg 1.3 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +set -A disk_array $(find_disks $DISKS) +case "${#disk_array[*]}" in +0) + DISK_COUNT=0 + ;; +1) + # We need to repartition the single disk to two slices + DISK_COUNT=1 + META_DISK0=${disk_array[0]} + SINGLE_DISK=$META_DISK0 + META_DISK1=$META_DISK0 + ZFS_DISK2=$META_DISK0 + META_SIDE0=${SINGLE_DISK}s0 + META_SIDE1=${SINGLE_DISK}s1 + ZFS_SIDE2=${SINGLE_DISK}s3 + ;; +2) + # We need to repartition the single disk to two slices and allocate + # the 2nd disk to ZFS + DISK_COUNT=2 + META_DISK0=${disk_array[0]} + SINGLE_DISK=$META_DISK0 + META_DISK1=$META_DISK0 + ZFS_DISK2=${disk_array[1]} + META_SIDE0=${SINGLE_DISK}s0 + META_SIDE1=${SINGLE_DISK}s1 + ZFS_SIDE2=${ZFS_DISK2}s0 + ;; +*) + # In this case there are at least enough disks to use. + DISK_COUNT=3 + META_DISK0=${disk_array[0]} + META_DISK1=${disk_array[1]} + ZFS_DISK2=${disk_array[2]} + META_SIDE0=${META_DISK0}s0 + META_SIDE1=${META_DISK1}s0 + ZFS_SIDE2=${ZFS_DISK2}s0 + ;; +esac + +export DISK_COUNT META_DISK0 META_DISK1 ZFS_DISK2 +export META_SIDE0 META_SIDE1 ZFS_SIDE2 SINGLE_DISK + +export TESTFILE=testfile +export FS_SIZE=500m +export META_DEVICE_ID=d99 +export META_DEVICE_PATH=/dev/md/dsk/$META_DEVICE_ID +export FILE_COUNT=20 +export FILE_SIZE=$(( 1024 * 1024 )) diff --git a/tests/sys/cddl/zfs/tests/interop/interop_001_pos.ksh b/tests/sys/cddl/zfs/tests/interop/interop_001_pos.ksh new file mode 100644 index 00000000000..be6527955ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/interop/interop_001_pos.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)interop_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: interop_001_pos +# +# DESCRIPTION: +# Create a SVM device and add this to an existing ZFS pool +# +# STRATEGY: +# 1. Create a SVM metadevice +# 2. Create a ZFS file system +# 3. Add SVM metadevice to the ZFS pool +# 4. Create files and fill the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + + +function cleanup +{ + $RM -rf $TESTDIR/* +} + +log_assert "Create a SVM device and add this to an existing ZFS pool" + +log_onexit cleanup + +# the current size of the test pool +typeset -i oldsize=`$ZFS get -pH -o value available $TESTPOOL` + +log_must $ZPOOL add $TESTPOOL $META_DEVICE_PATH +log_must $ZPOOL iostat -v | $GREP $META_DEVICE_ID + +# the size of the test pool after adding the extra device +typeset -i newsize=`$ZFS get -pH -o value available $TESTPOOL` + +(( $oldsize >= $newsize )) && \ + log_fail "Pool space available ($oldsize) before adding a new device was "\ + "larger than the space available ($newsize) afterwards." + +log_note "Pool space available was ($oldsize), it's now ($newsize)" + +typeset -i odirnum=1 +typeset -i idirnum=0 +typeset -i filenum=0 +typeset -i retval=0 +typeset bg=$TESTDIR/bigdirectory + +fill_fs $bg 20 25 $FILE_SIZE $FILE_COUNT +retval=$? + +afterwritepoolavail=`$ZFS get -pH -o value available $TESTPOOL` +readonly ENOSPC=28 + +(( $retval == $ENOSPC && $afterwritepoolavail < $oldsize)) && \ + log_pass "Successfully used ($(( $newsize - $oldsize )) bytes) in "\ + "pool provided by SVM metadevice" + +log_fail "Failed to use space in pool ($(( $newsize - $oldsize ))bytes) "\ + "provided by SVM metadevice" diff --git a/tests/sys/cddl/zfs/tests/interop/interop_test.sh b/tests/sys/cddl/zfs/tests/interop/interop_test.sh new file mode 100755 index 00000000000..d853e6078e4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/interop/interop_test.sh @@ -0,0 +1,56 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case interop_001_pos cleanup +interop_001_pos_head() +{ + atf_set "descr" "Create a SVM device and add this to an existing ZFS pool" + atf_set "require.progs" metadb zfs metaclear metastat metainit zpool +} +interop_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/interop.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/interop_001_pos.ksh || atf_fail "Testcase failed" +} +interop_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/interop.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case interop_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/interop/setup.ksh b/tests/sys/cddl/zfs/tests/interop/setup.ksh new file mode 100644 index 00000000000..48b7054d50c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/interop/setup.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.5 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +case $DISK_COUNT in +0) + log_untested "Need at least 1 disk device for test" + ;; +1) + log_note "Partitioning a single disk ($SINGLE_DISK)" + ;; +2) + log_note "Partitioning a disks ($SINGLE_DISK) and ($ZFS_DISK2)" + ;; +3) + log_note "Partitioning disks ($META_DISK0 $META_DISK1 $ZFS_DISK2)" + ;; +esac + +wipe_partition_table $META_DISK0 +log_must set_partition ${META_SIDE0##*s} "" $FS_SIZE $META_DISK0 +if [[ $WRAPPER == *"smi"* && $META_DISK1 == $META_DISK0 ]]; then + typeset i=${META_SIDE0##*s} + typeset cyl=$(get_endslice $META_DISK0 $i) + log_must set_partition ${META_SIDE1##*s} "$cyl" $FS_SIZE $META_DISK1 +else + log_must set_partition ${META_SIDE1##*s} "" $FS_SIZE $META_DISK1 +fi +if [[ $WRAPPER == *"smi"* && $ZFS_DISK2 == $META_DISK1 ]]; then + typeset i=${META_SIDE1##*s} + typeset cyl=$(get_endslice $META_DISK1 $i) + log_must set_partition ${ZFS_SIDE2##*s} "$cyl" $FS_SIZE $ZFS_DISK2 +else + log_must set_partition ${ZFS_SIDE2##*s} "" $FS_SIZE $ZFS_DISK2 +fi + +create_pool $TESTPOOL $ZFS_SIDE2 + +$RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR +$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR + +log_must $ZFS create $TESTPOOL/$TESTFS +log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +log_must $ZFS set compression=off $TESTPOOL/$TESTFS + +log_note "Configuring metadb with $META_SIDE1" +log_must $METADB -a -f -c 3 $META_SIDE1 + +log_note "Configure $META_DEVICE_ID with $META_SIDE0" +log_must $METAINIT $META_DEVICE_ID 1 1 $META_SIDE0 + +log_pass diff --git a/tests/sys/cddl/zfs/tests/inuse/Makefile b/tests/sys/cddl/zfs/tests/inuse/Makefile new file mode 100644 index 00000000000..f6ae6d27975 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inuse/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/inuse +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= inuse_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= inuse.cfg +${PACKAGE}FILES+= inuse_005_pos.ksh +${PACKAGE}FILES+= inuse_010_neg.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/inuse/inuse.cfg b/tests/sys/cddl/zfs/tests/inuse/inuse.cfg new file mode 100644 index 00000000000..96d54687ca1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inuse/inuse.cfg @@ -0,0 +1,126 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)inuse.cfg 1.7 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_disk_count "$DISKS" 2 +set -A disk_array $(find_disks $DISKS) +case "${#disk_array[@]}" in +2) + FS_DISK0=${disk_array[0]} + FS_DISK1=${disk_array[1]} + FS_DISK2=${disk_array[0]} + FS_DISK3=${disk_array[1]} + FS_SIDE0=${FS_DISK0}p1 + FS_SIDE1=${FS_DISK0}p2 + FS_SIDE2=${FS_DISK1}p1 + FS_SIDE3=${FS_DISK1}p2 + disk0="$FS_SIDE0" + disk1="$FS_SIDE1" + disk2="$FS_SIDE2" + disk3="$FS_SIDE3" + disktargets="$disk0 $disk2" + rawdisk0="$FS_SIDE0" + rawdisk1="$FS_SIDE1" + rawdisk2="$FS_SIDE2" + rawdisk3="$FS_SIDE3" + rawtargets="$rawdisk0 $rawdisk2" + vdisks="$FS_DISK0" + sdisks="$FS_DISK1" + vslices="$FS_SIDE0 $FS_SIDE1 $FS_SIDE2" + sslices="$FS_SIDE3" + ;; +3) + FS_DISK0=${disk_array[0]} + FS_DISK1=${disk_array[1]} + FS_DISK2=${disk_array[2]} + FS_DISK3=${disk_array[0]} + FS_SIDE0=${FS_DISK0}p1 + FS_SIDE1=${FS_DISK0}p2 + FS_SIDE2=${FS_DISK1}p1 + FS_SIDE3=${FS_DISK2}p1 + disk0="$FS_SIDE0" + disk1="$FS_SIDE1" + disk2="$FS_SIDE2" + disk3="$FS_SIDE3" + disktargets="$disk0 $disk2 $disk3" + rawdisk0="$FS_SIDE0" + rawdisk1="$FS_SIDE1" + rawdisk2="$FS_SIDE2" + rawdisk3="$FS_SIDE3" + rawtargets="$rawdisk0 $rawdisk2 $rawdisk3" + vdisks="$FS_DISK0 $FS_DISK1" + sdisks="$FS_DISK2" + vslices="$FS_SIDE0 $FS_SIDE2 $FS_SIDE3" + sslices="$FS_SIDE1" + ;; +*) + FS_DISK0=${disk_array[0]} + FS_DISK1=${disk_array[1]} + FS_DISK2=${disk_array[2]} + FS_DISK3=${disk_array[3]} + FS_SIDE0=${FS_DISK0}p1 + FS_SIDE1=${FS_DISK1}p1 + FS_SIDE2=${FS_DISK2}p1 + FS_SIDE3=${FS_DISK3}p1 + disk0="$FS_SIDE0" + disk1="$FS_SIDE1" + disk2="$FS_SIDE2" + disk3="$FS_SIDE3" + disktargets="$disk0 $disk1 $disk2 $disk3" + rawdisk0="$FS_SIDE0" + rawdisk1="$FS_SIDE1" + rawdisk2="$FS_SIDE2" + rawdisk3="$FS_SIDE3" + rawtargets="$rawdisk0 $rawdisk1 $rawdisk2 $rawdisk3" + vdisks="$FS_DISK0 $FS_DISK1 $FS_DISK2" + sdisks="$FS_DISK3" + vslices="$FS_SIDE0 $FS_SIDE1 $FS_SIDE2" + sslices="$FS_SIDE3" + ;; +esac + +export FS_DISK0 FS_DISK1 FS_DISK2 FS_DISK3 SINGLE_DISK +export FS_SIDE0 FS_SIDE1 FS_SIDE2 FS_SIDE3 +export disk0 disk1 disk2 disk3 disktargets +export rawdisk0 rawdisk1 rawdisk2 rawdisk3 rawtargets +export vdisks sdisks vslices sslices + +export UFSMP=$TESTDIR/testinuseufsdump +export FS_SIZE=1g +export PREVDUMPDEV="" +export PIDUFSDUMP="" +export PIDUFSRESTORE="" +# size of block to be written to test file - currently 1mb +export BLOCK_SIZE=$(( 1024 * 1024 )) +# number of blocks to write == size of file +export BLOCK_COUNT=100 +export STF_TIMEOUT=1200 # 20 minutes max. diff --git a/tests/sys/cddl/zfs/tests/inuse/inuse_005_pos.ksh b/tests/sys/cddl/zfs/tests/inuse/inuse_005_pos.ksh new file mode 100644 index 00000000000..89cbabc0ab4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inuse/inuse_005_pos.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)inuse_005_pos.ksh 1.4 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: inuse_005_pos +# +# DESCRIPTION: +# newfs will not interfere with devices and spare devices that are in use +# by active pool. +# +# STRATEGY: +# 1. Create a with the given disk +# 2. Try to newfs against the disk, verify it fails as expect. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-12-30) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" +set_disks + +function cleanup +{ + poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 +} + +log_assert "Verify newfs over active pool fails." + +log_onexit cleanup + +create_pool $TESTPOOL1 $DISK0 +log_mustnot $NEWFS -s 1024 "$DISK0" +destroy_pool $TESTPOOL1 + +log_pass "Newfs over active pool fails." diff --git a/tests/sys/cddl/zfs/tests/inuse/inuse_010_neg.ksh b/tests/sys/cddl/zfs/tests/inuse/inuse_010_neg.ksh new file mode 100644 index 00000000000..cf85a013a3b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inuse/inuse_010_neg.ksh @@ -0,0 +1,52 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2017 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +set_disks + +FSSIZE=1024 #reduce filesystem size, just to speed up newfs +MOUNTPOINT=$TMPDIR/inuse_010_neg_mp + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + $UMOUNT $MOUNTPOINT + cleanup_devices $DISK0 + $RMDIR $MOUNTPOINT +} + +log_onexit cleanup + +log_assert "ZFS shouldn't be able to use a disk with a mounted filesystem" + +log_must $NEWFS -s $FSSIZE $DISK0 +log_must $MKDIR $MOUNTPOINT +log_must $MOUNT $DISK0 $MOUNTPOINT +log_mustnot $ZPOOL create $TESTPOOL $DISK0 + +log_pass "ZFS cannot use a disk with a mounted filesystem" diff --git a/tests/sys/cddl/zfs/tests/inuse/inuse_test.sh b/tests/sys/cddl/zfs/tests/inuse/inuse_test.sh new file mode 100755 index 00000000000..f26567dcc42 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inuse/inuse_test.sh @@ -0,0 +1,66 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case inuse_005_pos +inuse_005_pos_head() +{ + atf_set "descr" "Verify newfs over active pool fails." + atf_set "require.progs" newfs zpool + atf_set "require.user" root +} +inuse_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/inuse.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/inuse_005_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case inuse_010_neg +inuse_010_neg_head() +{ + atf_set "descr" "ZFS shouldn't be able to use a disk with a mounted filesystem" + atf_set "require.progs" newfs zpool + atf_set "require.user" root +} +inuse_010_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/inuse_010_neg.ksh || atf_fail "Testcase failed" +} + + +atf_init_test_cases() +{ + atf_add_test_case inuse_005_pos + atf_add_test_case inuse_010_neg +} diff --git a/tests/sys/cddl/zfs/tests/inuse/setup.ksh b/tests/sys/cddl/zfs/tests/inuse/setup.ksh new file mode 100644 index 00000000000..16fe84f6946 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/inuse/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +log_pass diff --git a/tests/sys/cddl/zfs/tests/iscsi/Makefile b/tests/sys/cddl/zfs/tests/iscsi/Makefile new file mode 100644 index 00000000000..e30fb661f6c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/Makefile @@ -0,0 +1,24 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/iscsi +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= iscsi_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= iscsi_004_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= iscsi_005_pos.ksh +${PACKAGE}FILES+= iscsi_001_pos.ksh +${PACKAGE}FILES+= iscsi_common.kshlib +${PACKAGE}FILES+= iscsi_002_neg.ksh +${PACKAGE}FILES+= iscsi_006_neg.ksh +${PACKAGE}FILES+= iscsi_003_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= iscsi.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/iscsi/cleanup.ksh b/tests/sys/cddl/zfs/tests/iscsi/cleanup.ksh new file mode 100644 index 00000000000..150ed644bde --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/cleanup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +iscsitgt_cleanup + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi.cfg b/tests/sys/cddl/zfs/tests/iscsi/iscsi.cfg new file mode 100644 index 00000000000..044abe74af1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi.cfg @@ -0,0 +1,34 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi.cfg 1.3 08/08/15 SMI" +# + +export TESTVOL=testvol${TESTCASE_ID} +export VOLSIZE=512m +export TESTVOL1=testvol1${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_001_pos.ksh b/tests/sys/cddl/zfs/tests/iscsi/iscsi_001_pos.ksh new file mode 100644 index 00000000000..9152f7488c0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_001_pos.ksh @@ -0,0 +1,99 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi_001_pos.ksh 1.2 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: iscsi_001_pos +# +# DESCRIPTION: +# Verify setting shareiscsi property on volume will make it an iSCSI +# target +# +# STRATEGY: +# 1) Create a volume, turn on shareiscsi directly on the volume +# 2) Check if the target is created or not +# 3) Destroy the volume, then turn on shareiscsi property on parent +# filesystem at first +# 4) Then create the volume, check if the target is created or not +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL && \ + log_must $ZFS destroy $TESTPOOL/$TESTVOL + datasetexists $TESTPOOL/$TESTVOL1 && \ + log_must $ZFS destroy $TESTPOOL/$TESTVOL1 + if [[ "off" != $(get_prop shareiscsi $TESTPOOL) ]]; then + log_must $ZFS set shareiscsi=off $TESTPOOL + fi +} + +log_onexit cleanup + +log_assert "Verify that setting shareiscsi property on volume will make it \ + an iSCSI target as expected." + + +# Check shareiscsi property directly on volume at first +log_must $ZFS set shareiscsi=off $TESTPOOL +log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL +log_must $ZFS set shareiscsi=on $TESTPOOL/$TESTVOL +if ! is_iscsi_target $TESTPOOL/$TESTVOL ; then + log_fail "iscsi target is not created via directly turning on \ + shareiscsi property on volume" +fi + +# Check setting shareiscsi property on parent filesystem also have +# effects on volume +log_must $ZFS set shareiscsi=on $TESTPOOL +log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL1 +if ! is_iscsi_target $TESTPOOL/$TESTVOL1 ; then + log_fail "iscsi target is not created via turning on \ + shareiscsi property on parent filesystem" +fi + +log_pass "Verify that setting shareiscsi property on volume will make it \ + an iSCSI target as expected." diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_002_neg.ksh b/tests/sys/cddl/zfs/tests/iscsi/iscsi_002_neg.ksh new file mode 100644 index 00000000000..440ad74459d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_002_neg.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi_002_neg.ksh 1.2 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# __stc_assertion_start +# +# ID: iscsi_002_neg +# +# DESCRIPTION: +# Verify file systems and snapshots can not be shared via iSCSI +# +# STRATEGY: +# 1) Turn on shareiscsi property directly on the filesystem +# 2) Check if the target is created or not +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if [[ "off" != $(get_prop shareiscsi $TESTPOOL/$TESTFS) ]]; then + log_must $ZFS set shareiscsi=off $TESTPOOL/$TESTFS + fi + datasetexists $TESTPOOL/$TESTFS@snap && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTFS@snap +} + +log_onexit cleanup + +log_assert "Verify file systems and snapshots can not be shared via iSCSI." + +if [[ "off" != $(get_prop shareiscsi $TESTPOOL/$TESTFS) ]]; then + log_fail "The default value of shareiscsi should be off." +fi + +# Check shareiscsi property directly on filesystem at first +log_must $ZFS set shareiscsi=on $TESTPOOL/$TESTFS +if is_iscsi_target $TESTPOOL/$TESTFS ; then + log_fail "shareiscsi property on filesystem makes an iSCSI target \ + unexpectedly." +fi + +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap +if is_iscsi_target $TESTPOOL/$TESTFS@snap ; then + log_fail "shareiscsi property on snapshot makes an iSCSI target \ + unexpectedly." +fi + +log_pass "Verify file systems and snapshots can not be shared via iSCSI." diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_003_neg.ksh b/tests/sys/cddl/zfs/tests/iscsi/iscsi_003_neg.ksh new file mode 100644 index 00000000000..5835d6766b9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_003_neg.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi_003_neg.ksh 1.2 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: iscsi_003_neg +# +# DESCRIPTION: +# Verify invalid value of shareiscsi can not be set +# +# STRATEGY: +# 1) verify a set of invalid value of shareiscsi can not be set +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if [[ "off" != $(get_prop shareiscsi $TESTPOOL/$TESTFS) ]]; then + $ZFS set shareiscsi=off $TESTPOOL/$TESTFS + fi +} + +log_onexit cleanup + +log_assert "Verify invalid value of shareiscsi can not be set" + +set -A inval_str "ON" "oN" "oFF" "Off" "0ff" "disK" "tape" "abc" "??" \ + "type=abc" "type=DISk" "type=type" "TYPE=disk" \ + "type=on" "type=off" "type=123" + +typeset str + +for str in ${inval_str[@]}; do + log_mustnot $ZFS set shareiscsi=$str $TESTPOOL/$TESTFS +done + +log_pass "Verify invalid value of shareiscsi can not be set" diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_004_pos.ksh b/tests/sys/cddl/zfs/tests/iscsi/iscsi_004_pos.ksh new file mode 100644 index 00000000000..0e1ba82db5b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_004_pos.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi_004_pos.ksh 1.2 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: iscsi_004_pos +# +# DESCRIPTION: +# Verify renaming a volume does not change target's iSCSI name +# +# STRATEGY: +# 1) Create a volume, turn on shareiscsi directly on the volume +# 2) Save the target's iSCSI name +# 3) Rename the volume, compare the target's iSCSI name with the original +# one +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL && \ + log_must $ZFS destroy $TESTPOOL/$TESTVOL + datasetexists $TESTPOOL/$TESTVOL1 && \ + log_must $ZFS destroy $TESTPOOL/$TESTVOL1 +} + +log_onexit cleanup + +log_assert "Verify renaming a volume does not change target's iSCSI name." + +log_must $ZFS create -V $VOLSIZE -o shareiscsi=on $TESTPOOL/$TESTVOL + +typeset iname +if ! is_iscsi_target $TESTPOOL/$TESTVOL ; then + log_fail "iscsi target is not created." +fi + +iname=$(iscsi_name $TESTPOOL/$TESTVOL) + +log_must $ZFS rename $TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL1 + +if [[ $iname != $(iscsi_name $TESTPOOL/$TESTVOL1) ]]; then + log_fail "The iSCSI name is changed after renaming the volume." +fi + +log_pass "Verify renaming a volume does not change target's iSCSI name." diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_005_pos.ksh b/tests/sys/cddl/zfs/tests/iscsi/iscsi_005_pos.ksh new file mode 100644 index 00000000000..03091fdbd44 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_005_pos.ksh @@ -0,0 +1,94 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi_005_pos.ksh 1.3 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: iscsi_005_pos +# +# DESCRIPTION: +# Verify export/import pool with iSCSI +# +# STRATEGY: +# 1) Create a volume, turn on shareiscsi directly on the volume +# 2) Export the pool, check the target is gone after the operation +# 3) Import the pool, check the target is back and its scsi name +# not changed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL && \ + log_must $ZFS destroy $TESTPOOL/$TESTVOL +} + +log_onexit cleanup + +log_assert "Verify export/import have right effects on iSCSI targets." + +log_must $ZFS create -V $VOLSIZE -o shareiscsi=on $TESTPOOL/$TESTVOL + +typeset iname +if ! is_iscsi_target $TESTPOOL/$TESTVOL ; then + log_fail "iscsi target is not created." +fi + +iname=$(iscsi_name $TESTPOOL/$TESTVOL) + +log_must $ZPOOL export $TESTPOOL +if is_iscsi_target $TESTPOOL/$TESTVOL ; then + log_fail "iscsi target is not removed after the pool is exported." +fi + +typeset dir=$(get_device_dir $DISKS) +log_must $ZPOOL import -d $dir -f $TESTPOOL +if ! is_iscsi_target $TESTPOOL/$TESTVOL ; then + log_fail "iscsi target is not restored after the pool is imported." +fi +if [[ $iname != $(iscsi_name $TESTPOOL/$TESTVOL) ]]; then + log_fail "The iSCSI name is changed after export/import." +fi + +log_pass "Verify export/import have right effects on iSCSI targets." diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_006_neg.ksh b/tests/sys/cddl/zfs/tests/iscsi/iscsi_006_neg.ksh new file mode 100644 index 00000000000..ad05ff10620 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_006_neg.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi_006_neg.ksh 1.3 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# __stc_assertion_start +# +# ID: iscsi_006_neg +# +# DESCRIPTION: +# Verify iscsioptions can not be changed by zfs command +# +# STRATEGY: +# 1) Save iscsioptions first, then change it on purpose +# 2) Check if the value is really changed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL/$TESTVOL && \ + log_must $ZFS destroy -f $TESTPOOL/$TESTVOL +} + +log_onexit cleanup + +log_assert "Verify iscsioptions can not be changed by zfs command." + +log_must $ZFS create -V $VOLSIZE -o shareiscsi=on $TESTPOOL/$TESTVOL + +typeset ioptions +if ! is_iscsi_target $TESTPOOL/$TESTVOL ; then + log_fail "target is not created." +fi + +# Check iscsioptions can not be seen in the output of 'zfs get all' +$ZFS get all $TESTPOOL/$TESTVOL | $GREP iscsioptions +typeset -i ret=$? +[[ $ret -eq 0 ]] && log_fail "iscsioptions can be seen in ' zfs get all'. " + +ioptions=$(get_prop iscsioptions $TESTPOOL/$TESTVOL) + +$ZFS set iscsioptions="abc" $TESTPOOL/$TESTVOL + +if [[ $ioptions != $(get_prop iscsioptions $TESTPOOL/$TESTVOL) ]]; then + log_fail "iscsioptions property can be changed be $ZFS command." +fi + +log_pass "Verify iscsioptions can not be changed by zfs command." diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_common.kshlib b/tests/sys/cddl/zfs/tests/iscsi/iscsi_common.kshlib new file mode 100644 index 00000000000..204d71566a6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_common.kshlib @@ -0,0 +1,87 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)iscsi_common.kshlib 1.2 07/03/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Check if a volume is a valide iscsi target +# $1 volume name +# return 0 if suceeds, otherwise, return 1 +# +function is_iscsi_target +{ + typeset dataset=$1 + typeset target targets + + [[ -z $dataset ]] && return 1 + + targets=$($ISCSITADM list target | $GREP "Target:" | $AWK '{print $2}') + [[ -z $targets ]] && return 1 + + for target in $targets; do + [[ $dataset == $target ]] && return 0 + done + + return 1 +} + +# +# Get the iSCSI name of a target +# $1 target name +# +function iscsi_name +{ + typeset target=$1 + typeset name + + [[ -z $target ]] && log_fail "No parameter." + + if ! is_iscsi_target $target ; then + log_fail "Not a target." + fi + + name=$($ISCSITADM list target $target | $GREP "iSCSI Name:" \ + | $AWK '{print $2}') + + return $name +} + +# +# Check shareiscsi option is supported or not +# return 0 if it is supported, otherwise return 1 +# +function check_shareiscsi +{ + $ZFS set 2>&1 | $GREP shareiscsi + [[ $? -ne 0 ]] && return 1 + + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/iscsi/iscsi_test.sh b/tests/sys/cddl/zfs/tests/iscsi/iscsi_test.sh new file mode 100755 index 00000000000..cf68dd2b7c9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/iscsi_test.sh @@ -0,0 +1,188 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case iscsi_001_pos cleanup +iscsi_001_pos_head() +{ + atf_set "descr" "Verify that setting shareiscsi property on volume will make itan iSCSI target as expected." + atf_set "require.progs" zfs +} +iscsi_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/iscsi_001_pos.ksh || atf_fail "Testcase failed" +} +iscsi_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case iscsi_002_neg cleanup +iscsi_002_neg_head() +{ + atf_set "descr" "Verify file systems and snapshots can not be shared via iSCSI." + atf_set "require.progs" zfs +} +iscsi_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/iscsi_002_neg.ksh || atf_fail "Testcase failed" +} +iscsi_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case iscsi_003_neg cleanup +iscsi_003_neg_head() +{ + atf_set "descr" "Verify invalid value of shareiscsi can not be set" + atf_set "require.progs" zfs +} +iscsi_003_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/iscsi_003_neg.ksh || atf_fail "Testcase failed" +} +iscsi_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case iscsi_004_pos cleanup +iscsi_004_pos_head() +{ + atf_set "descr" "Verify renaming a volume does not change target's iSCSI name." + atf_set "require.progs" zfs +} +iscsi_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/iscsi_004_pos.ksh || atf_fail "Testcase failed" +} +iscsi_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case iscsi_005_pos cleanup +iscsi_005_pos_head() +{ + atf_set "descr" "Verify export/import have right effects on iSCSI targets." + atf_set "require.progs" zfs zpool +} +iscsi_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/iscsi_005_pos.ksh || atf_fail "Testcase failed" +} +iscsi_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case iscsi_006_neg cleanup +iscsi_006_neg_head() +{ + atf_set "descr" "Verify iscsioptions can not be changed by zfs command." + atf_set "require.progs" zfs +} +iscsi_006_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/iscsi_006_neg.ksh || atf_fail "Testcase failed" +} +iscsi_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/iscsi_common.kshlib + . $(atf_get_srcdir)/iscsi.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case iscsi_001_pos + atf_add_test_case iscsi_002_neg + atf_add_test_case iscsi_003_neg + atf_add_test_case iscsi_004_pos + atf_add_test_case iscsi_005_pos + atf_add_test_case iscsi_006_neg +} diff --git a/tests/sys/cddl/zfs/tests/iscsi/setup.ksh b/tests/sys/cddl/zfs/tests/iscsi/setup.ksh new file mode 100644 index 00000000000..cfd511fa91e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/iscsi/setup.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +iscsitgt_setup + +DISK=${DISKS%% *} + +default_setup "$DISK" diff --git a/tests/sys/cddl/zfs/tests/large_files/Makefile b/tests/sys/cddl/zfs/tests/large_files/Makefile new file mode 100644 index 00000000000..8dc338f9425 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/large_files/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/large_files +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= large_files_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= large_files_001_pos.ksh +${PACKAGE}FILES+= large_files.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/large_files/cleanup.ksh b/tests/sys/cddl/zfs/tests/large_files/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/large_files/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/large_files/large_files.cfg b/tests/sys/cddl/zfs/tests/large_files/large_files.cfg new file mode 100644 index 00000000000..66e70d977a8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/large_files/large_files.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)large_files.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE=testfile${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/large_files/large_files_001_pos.ksh b/tests/sys/cddl/zfs/tests/large_files/large_files_001_pos.ksh new file mode 100644 index 00000000000..338e7b87943 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/large_files/large_files_001_pos.ksh @@ -0,0 +1,67 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)large_files_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: large_files_001_pos +# +# DESCRIPTION: +# Write a file to the allowable ZFS fs size. +# +# STRATEGY: +# 1. largest_file will write to a file and increase its size +# to the maximum allowable. +# 2. The last byte of the file should be accessbile without error. +# 3. Writing beyond the maximum file size generates an 'errno' of +# EFBIG. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Write a file to the allowable ZFS fs size." + +log_note "Invoke 'largest_file' with $TESTDIR/$TESTFILE" +log_must $LARGEST_FILE $TESTDIR/$TESTFILE + +log_pass "Successfully created a file to the maximum allowable size." diff --git a/tests/sys/cddl/zfs/tests/large_files/large_files_test.sh b/tests/sys/cddl/zfs/tests/large_files/large_files_test.sh new file mode 100755 index 00000000000..edf59e97b53 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/large_files/large_files_test.sh @@ -0,0 +1,56 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case large_files_001_pos cleanup +large_files_001_pos_head() +{ + atf_set "descr" "Write a file to the allowable ZFS fs size." +} +large_files_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/large_files.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/large_files_001_pos.ksh || atf_fail "Testcase failed" +} +large_files_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/large_files.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case large_files_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/large_files/setup.ksh b/tests/sys/cddl/zfs/tests/large_files/setup.ksh new file mode 100644 index 00000000000..252b7fd0405 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/large_files/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +disk=${DISKS%% *} + +default_setup $disk diff --git a/tests/sys/cddl/zfs/tests/largest_pool/Makefile b/tests/sys/cddl/zfs/tests/largest_pool/Makefile new file mode 100644 index 00000000000..e5f9d7a64ee --- /dev/null +++ b/tests/sys/cddl/zfs/tests/largest_pool/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/largest_pool +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= largest_pool_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= largest_pool.cfg +${PACKAGE}FILES+= largest_pool_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/largest_pool/largest_pool.cfg b/tests/sys/cddl/zfs/tests/largest_pool/largest_pool.cfg new file mode 100644 index 00000000000..efd13bfa2a9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/largest_pool/largest_pool.cfg @@ -0,0 +1,45 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)largest_pool.cfg 1.3 08/08/15 SMI" +# + +export TESTVOL=testvol${TESTCASE_ID} +export STF_TIMEOUT=1800 +export VOL_PATH=/dev/zvol/dsk/${TESTPOOL2}/$TESTVOL +export VOLSIZES=${VOLSIZES-"2pb 5pb 10pb 2eb 5eb 8eb 9eb"} + +# There're 3 different prompt messages while create +# a volume that great than 1TB on 32-bit +# - volume size exceeds limit for this system. (happy gate) +# - max volume size is 1TB on 32-bit systems (s10u2) +# - value is too large (old) + +export VOL_LIMIT_KEYWORD1="1TB on 32-bit" +export VOL_LIMIT_KEYWORD2="value is too large" +export VOL_LIMIT_KEYWORD3="volume size exceeds limit" diff --git a/tests/sys/cddl/zfs/tests/largest_pool/largest_pool_001_pos.ksh b/tests/sys/cddl/zfs/tests/largest_pool/largest_pool_001_pos.ksh new file mode 100644 index 00000000000..cc215aeff04 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/largest_pool/largest_pool_001_pos.ksh @@ -0,0 +1,168 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)largest_pool_001_pos.ksh 1.6 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +# ########################################################################## +# +# start __stf_assertion__ +# +# ASSERTION: largest_pool_001 +# +# DESCRIPTION: +# The largest pool can be created and a dataset in that +# pool can be created and mounted. +# +# STRATEGY: +# create a pool which will contain a volume device. +# create a volume device of desired sizes. +# create the largest pool allowed using the volume vdev. +# create and mount a dataset in the largest pool. +# create some files in the zfs file system. +# do some zpool list commands and parse the output. +# +# end __stf_assertion__ +# +# ########################################################################## + +verify_runnable "global" + +# +# Parse the results of zpool & zfs creation with specified size +# +# $1: volume size +# +# return value: +# 0 -> success +# 1 -> failure +# +function parse_expected_output +{ + UNITS=`$ECHO $1 | $SED -e 's/^\([0-9].*\)\([a-z].\)/\2/'` + case "$UNITS" in + 'mb') CHKUNIT="M" ;; + 'gb') CHKUNIT="G" ;; + 'tb') CHKUNIT="T" ;; + 'pb') CHKUNIT="P" ;; + 'eb') CHKUNIT="E" ;; + *) CHKUNIT="M" ;; + esac + + log_note "Detect zpool $TESTPOOL in this test machine." + log_must eval "$ZPOOL list $TESTPOOL > $TMPDIR/j.${TESTCASE_ID}" + log_must eval "$GREP $TESTPOOL $TMPDIR/j.${TESTCASE_ID} | \ + $AWK '{print $2}' | $GREP $CHKUNIT" + + log_note "Detect the file system in this test machine." + log_must eval "$DF -t zfs -h > $TMPDIR/j.${TESTCASE_ID}" + log_must eval "$GREP $TESTPOOL $TMPDIR/j.${TESTCASE_ID} | \ + $AWK '{print $2}' | $GREP $CHKUNIT" + + return 0 +} + +# +# Check and destroy zfs, volume & zpool remove the temporary files +# +function cleanup +{ + log_note "Start cleanup the zfs and pool" + + if datasetexists $TESTPOOL/$TESTFS ; then + if ismounted $TESTPOOL/$TESTFS ; then + log_must $ZFS unmount $TESTPOOL/$TESTFS + fi + log_must $ZFS destroy $TESTPOOL/$TESTFS + fi + + destroy_pool $TESTPOOL + + datasetexists $TESTPOOL2/$TESTVOL && \ + log_must $ZFS destroy $TESTPOOL2/$TESTVOL + + destroy_pool $TESTPOOL2 + + $RM -f $TMPDIR/j.* > /dev/null +} + +log_assert "The largest pool can be created and a dataset in that" \ + "pool can be created and mounted." + +# Set trigger. When the test case exit, cleanup is executed. +log_onexit cleanup + +# ----------------------------------------------------------------------- +# volume sizes with unit designations. +# +# Note: specifying the number '1' as size will not give the correct +# units for 'df'. It must be greater than one. +# ----------------------------------------------------------------------- +typeset str +typeset -i ret +for volsize in $VOLSIZES; do + log_note "Create a pool which will contain a volume device" + create_pool $TESTPOOL2 "$DISKS" + + log_note "Create a volume device of desired sizes: $volsize" + str=$($ZFS create -sV $volsize $TESTPOOL2/$TESTVOL 2>&1) + ret=$? + if (( ret != 0 )); then + if [[ $($ISAINFO -b) == 32 && \ + $str == *${VOL_LIMIT_KEYWORD1}* || \ + $str == *${VOL_LIMIT_KEYWORD2}* || \ + $str == *${VOL_LIMIT_KEYWORD3}* ]] + then + log_unsupported \ + "Max volume size is 1TB on 32-bit systems." + else + log_fail "$ZFS create -sV $volsize $TESTPOOL2/$TESTVOL" + fi + fi + + log_note "Create the largest pool allowed using the volume vdev" + create_pool $TESTPOOL "$VOL_PATH" + + log_note "Create a zfs file system in the largest pool" + log_must $ZFS create $TESTPOOL/$TESTFS + + log_note "Parse the execution result" + parse_expected_output $volsize + + log_note "unmount this zfs file system $TESTPOOL/$TESTFS" + log_must $ZFS unmount $TESTPOOL/$TESTFS + + log_note "Destroy zfs, volume & zpool" + log_must $ZFS destroy $TESTPOOL/$TESTFS + destroy_pool $TESTPOOL + log_must $ZFS destroy $TESTPOOL2/$TESTVOL + destroy_pool $TESTPOOL2 +done + +log_pass "Dateset can be created, mounted & destroy in largest pool succeeded." diff --git a/tests/sys/cddl/zfs/tests/largest_pool/largest_pool_test.sh b/tests/sys/cddl/zfs/tests/largest_pool/largest_pool_test.sh new file mode 100755 index 00000000000..da610430b94 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/largest_pool/largest_pool_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case largest_pool_001_pos cleanup +largest_pool_001_pos_head() +{ + atf_set "descr" "The largest pool can be created and a dataset in thatpool can be created and mounted." + atf_set "require.progs" zfs zpool isainfo + atf_set "timeout" 1800 +} +largest_pool_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/largest_pool.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/largest_pool_001_pos.ksh || atf_fail "Testcase failed" +} +largest_pool_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/largest_pool.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case largest_pool_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/link_count/Makefile b/tests/sys/cddl/zfs/tests/link_count/Makefile new file mode 100644 index 00000000000..1897deafb4f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/link_count/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/link_count/ +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= link_count_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= link_count_001.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= link_count.cfg +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/link_count/cleanup.ksh b/tests/sys/cddl/zfs/tests/link_count/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/link_count/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/link_count/link_count.cfg b/tests/sys/cddl/zfs/tests/link_count/link_count.cfg new file mode 100644 index 00000000000..30efae31f8d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/link_count/link_count.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)link_count.cfg 1.3 08/08/15 SMI" +# + +export ITERS=10 +export NUMFILES=10000 diff --git a/tests/sys/cddl/zfs/tests/link_count/link_count_001.ksh b/tests/sys/cddl/zfs/tests/link_count/link_count_001.ksh new file mode 100644 index 00000000000..9d8b43134de --- /dev/null +++ b/tests/sys/cddl/zfs/tests/link_count/link_count_001.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)link_count_001.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: link_count_001 +# +# DESCRIPTION: +# Verify file link count is zero on zfs +# +# STRATEGY: +# 1. Make sure this test executes on multi-processes system +# 2. Make zero size files and remove them in the background +# 3. Call the binary +# 4. Make sure the files can be removed successfully +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-07-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify file link count is zero on zfs" + +# Detect and make sure this test must be executed on a multi-process system +NCPUS=`sysctl -n kern.smp.cpus` +#NCPUS=`sysctl -a | awk -F '"' '/cpu count="[0-9+]"/ {print $2; exit}'` +if [[ $? -ne 0 || -z "$NCPUS" || "$NCPUS" -le 1 ]]; then + log_unsupported "This test must be executed on a multi-processor system." +fi + +log_must $MKDIR -p ${TESTDIR}/tmp + +typeset -i i=0 +while [ $i -lt $NUMFILES ]; do + (( i = i + 1 )) + $TOUCH ${TESTDIR}/tmp/x$i > /dev/null 2>&1 +done + +sleep 3 + +$RM -f ${TESTDIR}/tmp/x* >/dev/null 2>&1 + +$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test${TESTCASE_ID} > /dev/null 2>&1 & +PID=$! +log_note "$RM_LNKCNT_ZERO_FILE ${TESTDIR}/tmp/test${TESTCASE_ID} pid: $PID" + +i=0 +while [ $i -lt $ITERS ]; do + if ! $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null ; then + log_note "$RM_LNKCNT_ZERO_FILE completes" + break + fi + log_must $SLEEP 10 + (( i = i + 1 )) +done + +if $PGREP $RM_LNKCNT_ZERO_FILE > /dev/null; then + log_must $KILL -9 $PID + log_fail "file link count is zero" +fi + +log_must $RM -f ${TESTDIR}/tmp/test${TESTCASE_ID}* + +log_pass "Verify file link count is zero on zfs" diff --git a/tests/sys/cddl/zfs/tests/link_count/link_count_test.sh b/tests/sys/cddl/zfs/tests/link_count/link_count_test.sh new file mode 100755 index 00000000000..577c65d588e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/link_count/link_count_test.sh @@ -0,0 +1,55 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case link_count_001 cleanup +link_count_001_head() +{ + atf_set "descr" "Verify file link count is zero on zfs" + atf_set "require.progs" zfs +} +link_count_001_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/link_count.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/link_count_001.ksh || atf_fail "Testcase failed" +} +link_count_001_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/link_count.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_init_test_cases() +{ + + atf_add_test_case link_count_001 +} diff --git a/tests/sys/cddl/zfs/tests/link_count/setup.ksh b/tests/sys/cddl/zfs/tests/link_count/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/link_count/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/migration/Makefile b/tests/sys/cddl/zfs/tests/migration/Makefile new file mode 100644 index 00000000000..379c0c7c1cc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/Makefile @@ -0,0 +1,30 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/migration/ +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= migration_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= migration_011_pos.ksh +${PACKAGE}FILES+= migration_008_pos.ksh +${PACKAGE}FILES+= migration_004_pos.ksh +${PACKAGE}FILES+= migration.cfg +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= migration_005_pos.ksh +${PACKAGE}FILES+= migration_001_pos.ksh +${PACKAGE}FILES+= migration_009_pos.ksh +${PACKAGE}FILES+= migration_010_pos.ksh +${PACKAGE}FILES+= migration_007_pos.ksh +${PACKAGE}FILES+= migration_003_pos.ksh +${PACKAGE}FILES+= migration_012_pos.ksh +${PACKAGE}FILES+= migration.kshlib +${PACKAGE}FILES+= migration_006_pos.ksh +${PACKAGE}FILES+= migration_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/migration/cleanup.ksh b/tests/sys/cddl/zfs/tests/migration/cleanup.ksh new file mode 100644 index 00000000000..3ca167036f9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/cleanup.ksh @@ -0,0 +1,57 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +ismounted $NONZFS_TESTDIR ufs +(( $? == 0 )) && log_must $UMOUNT -f $NONZFS_TESTDIR + +ismounted $TESTPOOL/$TESTFS +[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR +destroy_pool $TESTPOOL + +# recreate and destroy a zpool over the disks to restore the partitions to +# normal +case $DISK_COUNT in +0) + log_note "No disk devices to restore" + ;; +1) + log_must cleanup_devices $ZFS_DISK + ;; +*) + log_must cleanup_devices $ZFS_DISK $NONZFS_DISK + ;; +esac + +log_pass diff --git a/tests/sys/cddl/zfs/tests/migration/migration.cfg b/tests/sys/cddl/zfs/tests/migration/migration.cfg new file mode 100644 index 00000000000..8b65994865b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration.cfg @@ -0,0 +1,67 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration.cfg 1.3 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +set -A disk_array $(find_disks $DISKS) +case "${#disk_array[*]}" in +0) + DISK_COUNT=0 + ;; +1) + # We need to repartition the single disk to two partitions. + DISK_COUNT=1 + ZFS_DISK=${disk_array[0]} + SINGLE_DISK=$ZFS_DISK + NONZFS_DISK=$ZFS_DISK + ZFSSIDE_DISK=${SINGLE_DISK}p1 + NONZFSSIDE_DISK=${SINGLE_DISK}p2 + ;; +*) + # In this case there are at least enough disks to use. + DISK_COUNT=2 + ZFS_DISK=${disk_array[0]} + NONZFS_DISK=${disk_array[1]} + ZFSSIDE_DISK=${ZFS_DISK}p1 + NONZFSSIDE_DISK=${NONZFS_DISK}p1 + ;; +esac + +export DISK_COUNT ZFS_DISK NONZFS_DISK SINGLE_DISK ZFSSIDE_DISK NONZFSSIDE_DISK + +export TESTFILE=/etc/passwd +export NONZFS_TESTDIR=$TESTDIR/nonzfstestdir${TESTCASE_ID} +tmp=`$SUM $TESTFILE` +export SUMA=`$ECHO $tmp | $AWK '{print $1}'` +export SUMB=`$ECHO $tmp | $AWK '{print $2}'` +export FS_SIZE=1g +export BNAME=`$BASENAME $TESTFILE` +export DNAME=`$DIRNAME $TESTFILE` diff --git a/tests/sys/cddl/zfs/tests/migration/migration.kshlib b/tests/sys/cddl/zfs/tests/migration/migration.kshlib new file mode 100644 index 00000000000..542644e5316 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration.kshlib @@ -0,0 +1,152 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration.kshlib 1.2 07/01/09 SMI" +# + +# +# This function creates the test archive for migration. +# +# Usage: +# prepare srcdir cmd +# +# Return value: 0 on success +# 1 on failure +# +# Where: +# srcdir: is the directory where the testfile is +# cmd: is the command to be executed. +# E.g. +# $TAR cf $TESTDIR/tar${TESTCASE_ID}.tar +# +function prepare #srcdir cmd +{ + typeset srcdir=$1 + typeset cmd=$2 + typeset -i retval=0 + + cwd=$PWD + cd $srcdir + (( $? != 0 )) && return 1 + + $cmd + (( $? != 0 )) && return 1 + + cd $cwd + (( $? != 0 )) && return 1 + + return 0 +} + +# +# This function executes a passed in command and then determines the chksum +# of the resulting file. The chksum components are checked against the ones +# passed in to determine if they are equal. If they are equal, 0 is returned +# otherwise 1 is returned. +# +# Usage: +# migrate destdir oldsuma oldsumb command_to_execute +# +# Return value: 0 on success +# 1 on failure +# +# Where: +# destdir: is the directory where the command is to be executed on +# oldsuma: is the first part of the values returned by sum +# oldsumb: is the second part of the values returned by sum +# cmd: is the command to be executed; +# E.g. +# "$TAR xf $TESTDIR/tar${TESTCASE_ID}.tar" +# +function migrate #destdir oldsuma oldsumb cmd +{ + typeset destdir=$1 + typeset oldsuma=$2 + typeset oldsumb=$3 + typeset cmd=$4 + typeset -i retval=0 + + cwd=$PWD + cd $destdir + (( $? != 0 )) && return 1 + + $cmd + (( $? != 0 )) && return 1 + + sumy=`$SUM ./$BNAME` + suma=`$ECHO $sumy | $AWK '{print $1}'` + sumb=`$ECHO $sumy | $AWK '{print $2}'` + + if (( $oldsuma != $suma )); then + log_note "$SUM values are not the same" + retval=1 + fi + + if (( $oldsumb != $sumb )); then + log_note "$SUM values are not the same" + retval=1 + fi + + cd $cwd + (( $? != 0 )) && return 1 + return $retval +} + +function migrate_cpio +{ + typeset destdir=$1 + typeset archive=$2 + typeset oldsuma=$3 + typeset oldsumb=$4 + typeset -i retval=0 + + cwd=$PWD + cd $destdir + (( $? != 0 )) && return 1 + + $CPIO -iv < $archive + (( $? != 0 )) && return 1 + + sumy=`$SUM ./$BNAME` + suma=`$ECHO $sumy | $AWK '{print $1}'` + sumb=`$ECHO $sumy | $AWK '{print $2}'` + + if (( $oldsuma != $suma )); then + log_note "$SUM values are not the same" + retval=1 + fi + + if (( $oldsumb != $sumb )); then + log_note "$SUM values are not the same" + retval=1 + fi + + cd $cwd + (( $? != 0 )) && return 1 + return $retval +} diff --git a/tests/sys/cddl/zfs/tests/migration/migration_001_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_001_pos.ksh new file mode 100644 index 00000000000..5abf1cfb2be --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_001_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_001_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to ZFS fs using tar. +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Tar up test file and place on a ZFS filesystem +# 3. Extract tar contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/tar${TESTCASE_ID}.tar + $RM -rf $TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to ZFS fs using tar" + +log_onexit cleanup + +prepare $DNAME "$TAR cf $TESTDIR/tar${TESTCASE_ID}.tar $BNAME" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $TESTDIR $SUMA $SUMB "$TAR xf $TESTDIR/tar${TESTCASE_ID}.tar" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to ZFS fs" + +log_pass "Successully migrated test file from ZFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_002_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_002_pos.ksh new file mode 100644 index 00000000000..9ea020de38a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_002_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_002_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to UFS fs using tar. +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Tar up test file and place on a ZFS filesystem +# 3. Extract tar contents to a UFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/tar${TESTCASE_ID}.tar + $RM -rf $NONZFS_TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to UFS fs using tar" + +log_onexit cleanup + +prepare $DNAME "$TAR cf $TESTDIR/tar${TESTCASE_ID}.tar $BNAME" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $NONZFS_TESTDIR $SUMA $SUMB "$TAR xf $TESTDIR/tar${TESTCASE_ID}.tar" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to UFS fs" + +log_pass "Successully migrated test file from ZFS fs to UFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_003_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_003_pos.ksh new file mode 100644 index 00000000000..68719d74ef6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_003_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_003_pos +# +# DESCRIPTION: +# Migrating test file from UFS fs to ZFS fs using tar. +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Tar up test file and place on a UFS filesystem +# 3. Extract tar contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $NONZFS_TESTDIR/tar${TESTCASE_ID}.tar + $RM -rf $TESTDIR/$BNAME +} + +log_assert "Migrating test file from UFS fs to ZFS fs using tar" + +log_onexit cleanup + +prepare $DNAME "$TAR cf $NONZFS_TESTDIR/tar${TESTCASE_ID}.tar $BNAME" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $TESTDIR $SUMA $SUMB "$TAR xvf $NONZFS_TESTDIR/tar${TESTCASE_ID}.tar" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "UFS fs to ZFS fs" + +log_pass "Successully migrated test file from UFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_004_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_004_pos.ksh new file mode 100644 index 00000000000..0da907d3c29 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_004_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_004_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to ZFS fs using cpio +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Cpio up test file and place on a ZFS filesystem +# 3. Extract cpio contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/cpio${TESTCASE_ID}.cpio + $RM -rf $TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to ZFS fs using cpio" + +log_onexit cleanup + +cwd=$PWD +cd $DNAME +(( $? != 0 )) && log_untested "Could not change directory to $DNAME" + +$LS $BNAME | $CPIO -oc > $TESTDIR/cpio${TESTCASE_ID}.cpio +(( $? != 0 )) && log_failED "Unable to create cpio archive" + +cd $cwd +(( $? != 0 )) && log_untested "Could not change directory to $cwd" + +migrate_cpio $TESTDIR "$TESTDIR/cpio${TESTCASE_ID}.cpio" $SUMA $SUMB +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to ZFS fs" + +log_pass "Successully migrated test file from ZFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_005_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_005_pos.ksh new file mode 100644 index 00000000000..13fb56892f3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_005_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_005_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to UFS fs using cpio +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Cpio up test file and place on a ZFS filesystem +# 3. Extract cpio contents to a UFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/cpio${TESTCASE_ID}.cpio + $RM -rf $NONZFS_TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to uFS fs using cpio" + +log_onexit cleanup + +cwd=$PWD +cd $DNAME +(( $? != 0 )) && log_untested "Could not change directory to $DNAME" + +$LS $BNAME | $CPIO -oc > $TESTDIR/cpio${TESTCASE_ID}.cpio +(( $? != 0 )) && log_failED "Unable to create cpio archive" + +cd $cwd +(( $? != 0 )) && log_untested "Could not change directory to $cwd" + +migrate_cpio $NONZFS_TESTDIR "$TESTDIR/cpio${TESTCASE_ID}.cpio" $SUMA $SUMB +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to UFS fs" + +log_pass "Successully migrated test file from ZFS fs to UFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_006_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_006_pos.ksh new file mode 100644 index 00000000000..c9231d5cba1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_006_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_006_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_006_pos +# +# DESCRIPTION: +# Migrating test file from UFS fs to ZFS fs using cpio +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Cpio up test file and place on a UFS filesystem +# 3. Extract cpio contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $NONZFS_TESTDIR/cpio${TESTCASE_ID}.cpio + $RM -rf $TESTDIR/$BNAME +} + +log_assert "Migrating test file from UFS fs to ZFS fs using cpio" + +log_onexit cleanup + +cwd=$PWD +cd $DNAME +(( $? != 0 )) && log_untested "Could not change directory to $DNAME" + +$LS $BNAME | $CPIO -oc > $NONZFS_TESTDIR/cpio${TESTCASE_ID}.cpio +(( $? != 0 )) && log_failED "Unable to create cpio archive" + +cd $cwd +(( $? != 0 )) && log_untested "Could not change directory to $cwd" + +migrate_cpio $TESTDIR "$NONZFS_TESTDIR/cpio${TESTCASE_ID}.cpio" $SUMA $SUMB +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to ZFS fs" + +log_pass "Successully migrated test file from UFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_007_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_007_pos.ksh new file mode 100644 index 00000000000..eab0b068d77 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_007_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_007_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_007_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to ZFS fs using dd. +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Dd up test file and place on a ZFS filesystem +# 3. Extract dd contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/dd${TESTCASE_ID}.dd + $RM -rf $TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to ZFS fs using dd" + +log_onexit cleanup + +prepare $DNAME "$DD if=$BNAME obs=128k of=$TESTDIR/dd${TESTCASE_ID}.dd" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $TESTDIR $SUMA $SUMB "$DD if=$TESTDIR/dd${TESTCASE_ID}.dd obs=128k of=$BNAME" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to ZFS fs" + +log_pass "Successully migrated test file from ZFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_008_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_008_pos.ksh new file mode 100644 index 00000000000..06d41bdb027 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_008_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_008_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_008_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to UFS fs using dd. +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Dd up test file and place on a ZFS filesystem +# 3. Extract dd contents to a UFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/dd${TESTCASE_ID}.dd + $RM -rf $NONZFS_TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to UFS fs using dd" + +log_onexit cleanup + +prepare $DNAME "$DD if=$BNAME obs=128k of=$TESTDIR/dd${TESTCASE_ID}.dd" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $NONZFS_TESTDIR $SUMA $SUMB "$DD if=$TESTDIR/dd${TESTCASE_ID}.dd obs=128k of=$BNAME" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to ZFS fs" + +log_pass "Successully migrated test file from ZFS fs to UFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_009_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_009_pos.ksh new file mode 100644 index 00000000000..82382160957 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_009_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_009_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_009_pos +# +# DESCRIPTION: +# Migrating test file from UFS fs to ZFS fs using dd. +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. Dd up test file and place on a UFS filesystem +# 3. Extract dd contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/dd${TESTCASE_ID}.dd + $RM -rf $NONZFS_TESTDIR/$BNAME +} + +log_assert "Migrating test file from UFS fs to ZFS fs using dd" + +log_onexit cleanup + +prepare $DNAME "$DD if=$BNAME obs=128k of=$NONZFS_TESTDIR/dd${TESTCASE_ID}.dd" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $TESTDIR $SUMA $SUMB "$DD if=$NONZFS_TESTDIR/dd${TESTCASE_ID}.dd obs=128k of=$BNAME" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to ZFS fs" + +log_pass "Successully migrated test file from UFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_010_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_010_pos.ksh new file mode 100644 index 00000000000..b04f38ce963 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_010_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_010_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_010_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to ZFS fs using cp +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. CP up test file and place on a ZFS filesystem +# 3. Extract cp contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/cp${TESTCASE_ID}.cp + $RM -rf $TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to ZFS fs using cp" + +log_onexit cleanup + +prepare $DNAME "$CP $BNAME $TESTDIR/cp${TESTCASE_ID}.cp" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $TESTDIR $SUMA $SUMB "$CP $TESTDIR/cp${TESTCASE_ID}.cp $BNAME" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to ZFS fs" + +log_pass "Successully migrated test file from ZFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_011_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_011_pos.ksh new file mode 100644 index 00000000000..17cba15dc68 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_011_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_011_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_011_pos +# +# DESCRIPTION: +# Migrating test file from ZFS fs to UFS fs using cp +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. CP up test file and place on a ZFS filesystem +# 3. Extract cp contents to a UFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $NONZFS_TESTDIR/cp${TESTCASE_ID}.cp + $RM -rf $TESTDIR/$BNAME +} + +log_assert "Migrating test file from ZFS fs to UFS fs using cp" + +log_onexit cleanup + +prepare $DNAME "$CP $BNAME $TESTDIR/cp${TESTCASE_ID}.cp" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $NONZFS_TESTDIR $SUMA $SUMB "$CP $TESTDIR/cp${TESTCASE_ID}.cp $BNAME" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "ZFS fs to UFS fs" + +log_pass "Successully migrated test file from ZFS fs to UFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_012_pos.ksh b/tests/sys/cddl/zfs/tests/migration/migration_012_pos.ksh new file mode 100644 index 00000000000..e6fa0acfd3e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_012_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)migration_012_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/migration/migration.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: migration_012_pos +# +# DESCRIPTION: +# Migrating test file from UFS fs to ZFS fs using cp +# +# STRATEGY: +# 1. Calculate chksum of testfile +# 2. CP up test file and place on a UFS filesystem +# 3. Extract cp contents to a ZFS file system +# 4. Calculate chksum of extracted file +# 5. Compare old and new chksums. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + $RM -rf $TESTDIR/cp${TESTCASE_ID}.cp + $RM -rf $NONZFS_TESTDIR/$BNAME +} + +log_assert "Migrating test file from UFS fs to ZFS fs using cp" + +log_onexit cleanup + +prepare $DNAME "$CP $BNAME $NONZFS_TESTDIR/cp${TESTCASE_ID}.cp" +(( $? != 0 )) && log_fail "Unable to create src archive" + +migrate $TESTDIR $SUMA $SUMB "$CP $NONZFS_TESTDIR/cp${TESTCASE_ID}.cp $BNAME" +(( $? != 0 )) && log_fail "Uable to successfully migrate test file from" \ + "UFS fs to ZFS fs" + +log_pass "Successully migrated test file from UFS fs to ZFS fs". diff --git a/tests/sys/cddl/zfs/tests/migration/migration_test.sh b/tests/sys/cddl/zfs/tests/migration/migration_test.sh new file mode 100755 index 00000000000..15513463b0d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/migration_test.sh @@ -0,0 +1,356 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case migration_001_pos cleanup +migration_001_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to ZFS fs using tar" + atf_set "require.progs" zfs +} +migration_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_001_pos.ksh || atf_fail "Testcase failed" +} +migration_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_002_pos cleanup +migration_002_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to UFS fs using tar" + atf_set "require.progs" zfs +} +migration_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_002_pos.ksh || atf_fail "Testcase failed" +} +migration_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_003_pos cleanup +migration_003_pos_head() +{ + atf_set "descr" "Migrating test file from UFS fs to ZFS fs using tar" + atf_set "require.progs" zfs +} +migration_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_003_pos.ksh || atf_fail "Testcase failed" +} +migration_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_004_pos cleanup +migration_004_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to ZFS fs using cpio" + atf_set "require.progs" zfs +} +migration_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_004_pos.ksh || atf_fail "Testcase failed" +} +migration_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_005_pos cleanup +migration_005_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to uFS fs using cpio" + atf_set "require.progs" zfs +} +migration_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_005_pos.ksh || atf_fail "Testcase failed" +} +migration_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_006_pos cleanup +migration_006_pos_head() +{ + atf_set "descr" "Migrating test file from UFS fs to ZFS fs using cpio" + atf_set "require.progs" zfs +} +migration_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_006_pos.ksh || atf_fail "Testcase failed" +} +migration_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_007_pos cleanup +migration_007_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to ZFS fs using dd" + atf_set "require.progs" zfs +} +migration_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_007_pos.ksh || atf_fail "Testcase failed" +} +migration_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_008_pos cleanup +migration_008_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to UFS fs using dd" + atf_set "require.progs" zfs +} +migration_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_008_pos.ksh || atf_fail "Testcase failed" +} +migration_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_009_pos cleanup +migration_009_pos_head() +{ + atf_set "descr" "Migrating test file from UFS fs to ZFS fs using dd" + atf_set "require.progs" zfs +} +migration_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_009_pos.ksh || atf_fail "Testcase failed" +} +migration_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_010_pos cleanup +migration_010_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to ZFS fs using cp" + atf_set "require.progs" zfs +} +migration_010_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_010_pos.ksh || atf_fail "Testcase failed" +} +migration_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_011_pos cleanup +migration_011_pos_head() +{ + atf_set "descr" "Migrating test file from ZFS fs to UFS fs using cp" + atf_set "require.progs" zfs +} +migration_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_011_pos.ksh || atf_fail "Testcase failed" +} +migration_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case migration_012_pos cleanup +migration_012_pos_head() +{ + atf_set "descr" "Migrating test file from UFS fs to ZFS fs using cp" + atf_set "require.progs" zfs +} +migration_012_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/migration_012_pos.ksh || atf_fail "Testcase failed" +} +migration_012_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/migration.kshlib + . $(atf_get_srcdir)/migration.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case migration_001_pos + atf_add_test_case migration_002_pos + atf_add_test_case migration_003_pos + atf_add_test_case migration_004_pos + atf_add_test_case migration_005_pos + atf_add_test_case migration_006_pos + atf_add_test_case migration_007_pos + atf_add_test_case migration_008_pos + atf_add_test_case migration_009_pos + atf_add_test_case migration_010_pos + atf_add_test_case migration_011_pos + atf_add_test_case migration_012_pos +} diff --git a/tests/sys/cddl/zfs/tests/migration/setup.ksh b/tests/sys/cddl/zfs/tests/migration/setup.ksh new file mode 100644 index 00000000000..9dd09020849 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/migration/setup.ksh @@ -0,0 +1,69 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +case $DISK_COUNT in +0) + log_untested "Need at least 1 disk device for test" + ;; +1) + log_note "Partitioning a single disk ($SINGLE_DISK)" + ;; +*) + log_note "Partitioning disks ($ZFS_DISK $NONZFS_DISK)" + ;; +esac + +wipe_partition_table $ZFS_DISK $NONZFS_DISK +set_partition ${ZFSSIDE_DISK##*p} "" $FS_SIZE $ZFS_DISK +set_partition ${NONZFSSIDE_DISK##*p} "" $FS_SIZE $NONZFS_DISK + +log_must create_pool $TESTPOOL "$ZFSSIDE_DISK" + +$RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR +$MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR + +log_must $ZFS create $TESTPOOL/$TESTFS +log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +$RM -rf $NONZFS_TESTDIR || log_unresolved Could not remove $NONZFS_TESTDIR +$MKDIR -p $NONZFS_TESTDIR || log_unresolved Could not create $NONZFS_TESTDIR + +$NEWFS $NONZFSSIDE_DISK +(( $? != 0 )) && + log_untested "Unable to setup a UFS file system" + +log_must $MOUNT $NONZFSSIDE_DISK $NONZFS_TESTDIR + +log_pass diff --git a/tests/sys/cddl/zfs/tests/mmap/Makefile b/tests/sys/cddl/zfs/tests/mmap/Makefile new file mode 100644 index 00000000000..cc1e4d6a031 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mmap/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/mmap +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= mmap_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= mmap.cfg +${PACKAGE}FILES+= mmap_read_001_pos.ksh +${PACKAGE}FILES+= mmap_write_001_pos.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/mmap/cleanup.ksh b/tests/sys/cddl/zfs/tests/mmap/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mmap/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/mmap/mmap.cfg b/tests/sys/cddl/zfs/tests/mmap/mmap.cfg new file mode 100644 index 00000000000..6a13c479b85 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mmap/mmap.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mmap_read.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE=testfile${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/mmap/mmap_read_001_pos.ksh b/tests/sys/cddl/zfs/tests/mmap/mmap_read_001_pos.ksh new file mode 100644 index 00000000000..a4aaa8c69f1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mmap/mmap_read_001_pos.ksh @@ -0,0 +1,69 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mmap_read_001_pos.ksh 1.3 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +########################################################################### +# +# __stc_assertion_start +# +# ID: read_mmap_001_pos +# +# DESCRIPTION: +# read()s from mmap()'ed file contain correct data. +# +# STRATEGY: +# 1. Create a pool & dataset +# 2. Call readmmap binary +# 3. unmount this file system +# 4. Verify the integrity of this pool & dateset +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "read()s from mmap()'ed file contain correct data." + +log_must $CHMOD 777 $TESTDIR +log_must $READMMAP $TESTDIR/$TESTFILE +log_must $ZFS unmount $TESTPOOL/$TESTFS + +typeset dir=$(get_device_dir $DISKS) +verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir" + +log_pass "read(2) calls from a mmap(2)'ed file succeeded." diff --git a/tests/sys/cddl/zfs/tests/mmap/mmap_test.sh b/tests/sys/cddl/zfs/tests/mmap/mmap_test.sh new file mode 100755 index 00000000000..5ded1b48283 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mmap/mmap_test.sh @@ -0,0 +1,80 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case mmap_read_001_pos cleanup +mmap_read_001_pos_head() +{ + atf_set "descr" "read()s from mmap()'ed file contain correct data." + atf_set "require.progs" zfs zdb +} +mmap_read_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mmap.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mmap_read_001_pos.ksh || atf_fail "Testcase failed" +} +mmap_read_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mmap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case mmap_write_001_pos cleanup +mmap_write_001_pos_head() +{ + atf_set "descr" "write()s to a file and mmap() that file at the same time does notresult in a deadlock." +} +mmap_write_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mmap.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mmap_write_001_pos.ksh || atf_fail "Testcase failed" +} +mmap_write_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mmap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case mmap_read_001_pos + atf_add_test_case mmap_write_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/mmap/mmap_write_001_pos.ksh b/tests/sys/cddl/zfs/tests/mmap/mmap_write_001_pos.ksh new file mode 100644 index 00000000000..cce4b8c7600 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mmap/mmap_write_001_pos.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mmap_write_001_pos.ksh 1.3 07/07/31 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +# ########################################################################## +# +# __stc_assertion_start +# +# ID: mmap_write_001_pos +# +# DESCRIPTION: +# Writing to a file and mmaping that file at the +# same time does not result in a deadlock. +# +# STRATEGY: +# 1. Make sure this test executes on multi-processes system. +# 2. Call mmapwrite binary. +# 3. wait 120s and make sure the test file existed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Default is 120 seconds or 2 minutes +WAITTIME=${WAITTIME-120} + +log_assert "write()s to a file and mmap() that file at the same time does not "\ + "result in a deadlock." + +# Detect and make sure this test must be executed on a multi-process system +NCPUS=`sysctl -a | awk -F '"' '/cpu count="[0-9+]"/ {print $2; exit}'` +if [[ $? -ne 0 || -z $NCPUS || $NCPUS -le 1 ]]; then + log_unsupported "This test must be executed on a multi-processor system." +fi + +log_must $CHMOD 777 $TESTDIR +$MMAPWRITE $TESTDIR/$TESTFILE & +PID_MMAPWRITE=$! +log_note "$MMAPWRITE $TESTDIR/$TESTFILE pid: $PID_MMAPWRITE" +log_must $SLEEP 10 + +typeset -i i=0 +while (( i < $WAITTIME )); do + if ! $PS -ef | $PGREP $MMAPWRITE > /dev/null ; then + log_must $WAIT $PID_MMAPWRITE + break + fi + $SLEEP 1 + (( i += 1 )) +done + +if $PS -ef | $PGREP $MMAPWRITE > /dev/null ; then + log_must $KILL -9 $PID_MMAPWRITE +fi +log_must $LS -l $TESTDIR/$TESTFILE + +log_pass "write(2) a mmap(2)'ing file succeeded." diff --git a/tests/sys/cddl/zfs/tests/mmap/setup.ksh b/tests/sys/cddl/zfs/tests/mmap/setup.ksh new file mode 100644 index 00000000000..65fbd87ff45 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mmap/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/mount/Makefile b/tests/sys/cddl/zfs/tests/mount/Makefile new file mode 100644 index 00000000000..1abb3ea93ea --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mount/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/mount/ +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= mount_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= vars.cfg +${PACKAGE}FILES+= mounttest.ksh +${PACKAGE}FILES+= mount_test.sh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/mount/cleanup.ksh b/tests/sys/cddl/zfs/tests/mount/cleanup.ksh new file mode 100644 index 00000000000..836fc7c9f6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mount/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/mount/mount_test.sh b/tests/sys/cddl/zfs/tests/mount/mount_test.sh new file mode 100755 index 00000000000..9fb539db7a5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mount/mount_test.sh @@ -0,0 +1,86 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case umount_001 cleanup +umount_001_head() +{ + atf_set "descr" "zfs umount should unmount a file system" + atf_set "require.progs" zfs +} +umount_001_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/vars.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mounttest.ksh -u umount || \ + atf_fail "Testcase failed" +} +umount_001_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/vars.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case umountall_001 cleanup +umountall_001_head() +{ + atf_set "descr" "zfs umount -a should unmount all ZFS file systems" + atf_set "require.progs" zfs +} +umountall_001_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/vars.cfg + + if other_pools_exist; then + atf_skip "Can't test unmount -a with existing pools" + fi + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mounttest.ksh -u 'umount -a' || \ + atf_fail "Testcase failed" +} +umountall_001_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/vars.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_init_test_cases() +{ + + atf_add_test_case umount_001 + atf_add_test_case umountall_001 +} diff --git a/tests/sys/cddl/zfs/tests/mount/mounttest.ksh b/tests/sys/cddl/zfs/tests/mount/mounttest.ksh new file mode 100644 index 00000000000..6e3856de218 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mount/mounttest.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# +# ident "@(#)mounttest.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: mounttest +# +# DESCRIPTION: +# zfs mount and unmount commands should mount and unmount existing +# file systems. +# +# STRATEGY: +# 1. Call zfs mount command +# 2. Make sure the file systems were mounted +# 3. Call zfs unmount command +# 4. Make sure the file systems were unmounted +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + + +unmountcmd="" +while getopts u: OPT ; do + case $OPT in + u) unmountcmd=$OPTARG + ;; + ?) log_fail Usage: $0 [-u unmountcmd] + ;; + esac +done + +log_note Mount file systems +typeset -i i=1 +for fs in $TESTFSS ; do + log_must $ZFS mount $fs + ((i = i + 1)) +done + +log_note Make sure the file systems were mounted +for fs in $TESTFSS ; do + mounted $fs || log_fail File system $fs not mounted +done + +log_note Unmount the file systems +if [[ $unmountcmd = *all ]] ; then + log_must $ZFS $unmountcmd -F zfs +else + if [[ $unmountcmd = *-a ]] ; then + log_must $ZFS $unmountcmd + else + for fs in $TESTFSS ; do + log_must $ZFS $unmountcmd $fs + done + fi +fi + +log_note Make sure the file systems were unmounted +for fs in $TESTFSS ; do + unmounted $fs || log_fail File system $fs not unmounted +done + +log_pass All file systems are unmounted diff --git a/tests/sys/cddl/zfs/tests/mount/setup.ksh b/tests/sys/cddl/zfs/tests/mount/setup.ksh new file mode 100644 index 00000000000..2eb9a483769 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mount/setup.ksh @@ -0,0 +1,69 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +create_pool $TESTPOOL "$DISK" + +log_note Create file systems with mountpoints, so they are mounted automatically +i=1 +TESTFSS="" +TESTDIRS="" +while [ $i -le $FS_CNT ] ; do + dir=$TESTDIR.$i + fs=$TESTPOOL/$TESTFS.$i + + log_pos $RM -rf $dir || log_unresolved Could not remove $dir + + log_pos $MKDIR -p $dir || log_unresolved Could not create $dir + + TESTDIRS="$TESTDIRS $dir" + + log_must $ZFS create $fs + log_must $ZFS set mountpoint=$dir $fs + + TESTFSS="$TESTFSS $fs" + + log_note Make sure file system $fs was mounted + mounted $fs || log_fail File system $fs is not mounted + + log_note Unmount the file system + log_must $ZFS unmount $fs + + log_note Make sure file system $fs is unmounted + unmounted $fs || log_fail File system $fs is not unmounted + + (( i = i + 1 )) +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/mount/vars.cfg b/tests/sys/cddl/zfs/tests/mount/vars.cfg new file mode 100644 index 00000000000..9f4ee7ae7df --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mount/vars.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)vars.cfg 1.4 08/08/15 SMI" +# + +export FS_CNT=3 + diff --git a/tests/sys/cddl/zfs/tests/mv_files/Makefile b/tests/sys/cddl/zfs/tests/mv_files/Makefile new file mode 100644 index 00000000000..6e74238727e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/mv_files +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= mv_files_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= mv_files_common.kshlib +${PACKAGE}FILES+= mv_files_002_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= mv_files_001_pos.ksh +${PACKAGE}FILES+= mv_files.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/mv_files/cleanup.ksh b/tests/sys/cddl/zfs/tests/mv_files/cleanup.ksh new file mode 100644 index 00000000000..9fd716e410f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/cleanup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +[[ -f $TMPDIR/exitsZero.ksh ]] && \ + log_must $RM -f $TMPDIR/exitsZero.ksh +[[ -f $TMPDIR/testbackgprocs.ksh ]] && \ + log_must $RM -f $TMPDIR/testbackgprocs.ksh + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/mv_files/mv_files.cfg b/tests/sys/cddl/zfs/tests/mv_files/mv_files.cfg new file mode 100644 index 00000000000..1dab961e612 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/mv_files.cfg @@ -0,0 +1,46 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mv_files.cfg 1.3 08/08/15 SMI" +# + +export DISK=${DISKS%% *} + +export TESTFILE=testfile${TESTCASE_ID} + +export TESTDIR_TGT=${TEST_BASE_DIR%%/}/testdir_tgt${TESTCASE_ID} +export TESTFS_TGT=testzfs_tgt${TESTCASE_ID} +export OLDDIR=$TESTDIR/olddir${TESTCASE_ID} +export NEWDIR_IN_FS=$TESTDIR/newdir${TESTCASE_ID} +export NEWDIR_ACROSS_FS=$TESTDIR_TGT/newdir${TESTCASE_ID} + +export MVNUMFILES=2000 # +export MVNUMINCR=1000 # +export GANGPIDS=50 # + +export STF_TIMEOUT=1200 diff --git a/tests/sys/cddl/zfs/tests/mv_files/mv_files_001_pos.ksh b/tests/sys/cddl/zfs/tests/mv_files/mv_files_001_pos.ksh new file mode 100644 index 00000000000..f0d0ff92475 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/mv_files_001_pos.ksh @@ -0,0 +1,84 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mv_files_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/mv_files/mv_files_common.kshlib + +############################################################################## +# +# __stc_assertion_start +# +# ID: mv_files_001_pos +# +# DESCRIPTION: +# Doing a 'mv' of a large amount of files between two directories +# within a zfs filesystem works without errors. +# +# STRATEGY: +# +# 1. create a pool and a zfs filesystem +# 2. create two directories within the filesystem +# 3. create a large number of files within a directory +# 4. Move files from one directory to another and back again +# 5. validate file number +# 6. increase the number of files to $MVNUMFILES + $MVNUMINCR +# 7. repeat steps 3,4,5,6 above +# 8. verify the data integrity +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + PIDS="" + $RM -f $OLDDIR/* >/dev/null 2>&1 + $RM -f $NEWDIR_IN_FS/* >/dev/null 2>&1 +} + +log_assert "Doing a 'mv' of a large amount of files within a zfs filesystem" \ + "works without errors." + +log_onexit cleanup + +mv_test $OLDDIR $NEWDIR_IN_FS +(($? != 0 )) && \ + log_fail "'mv' test failed to complete." + +log_pass diff --git a/tests/sys/cddl/zfs/tests/mv_files/mv_files_002_pos.ksh b/tests/sys/cddl/zfs/tests/mv_files/mv_files_002_pos.ksh new file mode 100644 index 00000000000..69d027a755a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/mv_files_002_pos.ksh @@ -0,0 +1,85 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mv_files_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/mv_files/mv_files_common.kshlib + +############################################################################## +# +# __stc_assertion_start +# +# ID: mv_files_002_pos +# +# DESCRIPTION: +# Doing a 'mv' of a large amount of files between two directories across +# two zfs filesystems works without errors. +# +# STRATEGY: +# +# 1. create a pool and two zfs filesystems +# 2. create a directory in each filesystem +# 3. create a large number of files in a directory of a filesystem +# 4. Move files from the directory to another directory in another +# filesystem and back again +# 5. validate file number +# 6. increase the number of files to $MVNUMFILES + $MVNUMINCR +# 7. repeat steps 3,4,5,6 above +# 8. verify the data integrity +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + PIDS="" + $RM -f $OLDDIR/* >/dev/null 2>&1 + $RM -f $NEWDIR_ACROSS_FS/* >/dev/null 2>&1 +} + +log_assert "Doing a 'mv' of a large amount of files across two zfs filesystems" \ + "works without errors." + +log_onexit cleanup + +mv_test $OLDDIR $NEWDIR_ACROSS_FS +(($? != 0 )) && \ + log_fail "'mv' test failed to complete." + +log_pass diff --git a/tests/sys/cddl/zfs/tests/mv_files/mv_files_common.kshlib b/tests/sys/cddl/zfs/tests/mv_files/mv_files_common.kshlib new file mode 100644 index 00000000000..e1d332798fc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/mv_files_common.kshlib @@ -0,0 +1,216 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)mv_files_common.kshlib 1.5 09/06/22 SMI" +# + +# +# Determine whether this version of the ksh being +# executed has a bug where the limit of background +# processes of 25. +# +function check_bg_procs_limit_num +{ +$ECHO "#!/usr/local/bin/ksh93" > $TMPDIR/exitsZero.ksh +$ECHO "exit 0" >> $TMPDIR/exitsZero.ksh +$CHMOD 777 $TMPDIR/exitsZero.ksh + +$CAT < $TMPDIR/testbackgprocs.ksh +#!/usr/local/bin/ksh93 +# +# exitsZero.ksh is a one line script +# that exit with status of "0" +# + +PIDS="" +typeset -i i=1 +while [ \$i -le 50 ] +do + $TMPDIR/exitsZero.ksh & + PIDS="\$PIDS \$!" + (( i = i + 1 )) +done + +\$SLEEP 1 + +for pid in \$PIDS +do + \$WAIT \$pid + (( \$? == 127 )) && exit 1 +done +exit 0 +EOF + +$KSH93 $TMPDIR/testbackgprocs.ksh +if [[ $? -eq 1 ]]; then +# +# Current ksh being executed has a limit +# of 25 background processes. +# + return 1 +else + return 0 +fi +} + +function init_setup +{ + + typeset disklist=$1 + + create_pool $TESTPOOL "$disklist" + + if ! is_global_zone ; then + reexport_pool + fi + + $RM -rf $TESTDIR || log_unresolved Could not remove $TESTDIR + $MKDIR -p $TESTDIR || log_unresolved Could not create $TESTDIR + + $RM -rf $TESTDIR_TGT || log_unresolved Could not remove $TESTDIR_TGT + $MKDIR -p $TESTDIR_TGT || log_unresolved Could not create $TESTDIR_TGT + + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + log_must $ZFS create $TESTPOOL/$TESTFS_TGT + log_must $ZFS set mountpoint=$TESTDIR_TGT $TESTPOOL/$TESTFS_TGT + + $MKDIR -p $OLDDIR || log_unresolved Could not create $OLDDIR + $MKDIR -p $NEWDIR_IN_FS || log_unresolved Could not create $NEWDIR_IN_FS + $MKDIR -p $NEWDIR_ACROSS_FS || log_unresolved Could not create $NEWDIR_ACROSS_FS + +} + +function wait_pid +{ + for pid in $1 + do + $PS -e | $GREP $pid >/dev/null 2>&1 + (( $? == 0 )) && $WAIT $pid + done +} + + +# +# Generate given number files in a +# directory of zfs file system +# $1 - the directory holds the generated files +# $2 - number of to-be-generated files +# + +function generate_files +{ + typeset -i count + typeset -i proc_num=0 + + if (( $2 == $MVNUMFILES )); then + count=1 + else + count=$MVNUMFILES+1 + fi + + while (( count <= $2 )) + do + $CP /etc/passwd $1/file_$count \ + > /dev/null 2>&1 & + + PIDS="$PIDS $!" + + proc_num=`$ECHO $PIDS | $WC -w` + if (( proc_num >= GANGPIDS )); then + wait_pid "$PIDS" + proc_num=0 + PIDS="" + fi + + (( count = count + 1 )) + done + +} + +# +# Move given number files from one directory to +# another directory in parallel +# $1 - source directory +# $2 - target directory +# +function mv_files +{ + $FIND $1 -type f -print | xargs -J % \ + $MV % $2 > /dev/null 2>&1 +} + +# +# Count the files number after moving, and +# compare it with the original number +# $1 - directory that to be operated +# $2 - original files number +# +function count_files +{ + typeset -i file_num + file_num=`$FIND $1 -type f -print | \ + wc -l` + (( file_num != $2 )) && \ + log_fail "The file number of target directory"\ + "$2 is not equal to that of the source "\ + "directory $1" + +} + +# +# Running the 'mv' test +# $1 - old directory +# $2 - new directory +# +function mv_test +{ + typeset old=$1 + typeset new=$2 + + typeset -i inc_num=$(( MVNUMFILES + MVNUMINCR )) + typeset -i num=0 + + for num in $MVNUMFILES $inc_num + do + generate_files $old $num + + mv_files $old $new + count_files $new $num + + mv_files $new $old + count_files $old $num + done + + typeset dir=$(get_device_dir $DISKS) + verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir" + + return 0 +} + diff --git a/tests/sys/cddl/zfs/tests/mv_files/mv_files_test.sh b/tests/sys/cddl/zfs/tests/mv_files/mv_files_test.sh new file mode 100755 index 00000000000..943b447e107 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/mv_files_test.sh @@ -0,0 +1,88 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case mv_files_001_pos cleanup +mv_files_001_pos_head() +{ + atf_set "descr" "Doing a 'mv' of a large amount of files within a zfs filesystemworks without errors." + atf_set "require.progs" zfs zdb + atf_set "timeout" 1200 +} +mv_files_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mv_files_common.kshlib + . $(atf_get_srcdir)/mv_files.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mv_files_001_pos.ksh || atf_fail "Testcase failed" +} +mv_files_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mv_files_common.kshlib + . $(atf_get_srcdir)/mv_files.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case mv_files_002_pos cleanup +mv_files_002_pos_head() +{ + atf_set "descr" "Doing a 'mv' of a large amount of files across two zfs filesystemsworks without errors." + atf_set "require.progs" zfs zdb + atf_set "timeout" 1200 +} +mv_files_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mv_files_common.kshlib + . $(atf_get_srcdir)/mv_files.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/mv_files_002_pos.ksh || atf_fail "Testcase failed" +} +mv_files_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/mv_files_common.kshlib + . $(atf_get_srcdir)/mv_files.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case mv_files_001_pos + atf_add_test_case mv_files_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/mv_files/setup.ksh b/tests/sys/cddl/zfs/tests/mv_files/setup.ksh new file mode 100644 index 00000000000..941e122de56 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/mv_files/setup.ksh @@ -0,0 +1,47 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/mv_files/mv_files_common.kshlib + +verify_runnable "global" + +check_bg_procs_limit_num +if [[ $? -ne 0 ]]; then + log_note "ksh background process limit number is 25" + export GANGPIDS=25 +fi + +export PIDS="" + +init_setup $DISK + +log_pass diff --git a/tests/sys/cddl/zfs/tests/nestedfs/Makefile b/tests/sys/cddl/zfs/tests/nestedfs/Makefile new file mode 100644 index 00000000000..071316e20f5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/nestedfs/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/nestedfs +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= nestedfs_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= nestedfs.cfg +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= nestedfs_001_pos.ksh +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/nestedfs/cleanup.ksh b/tests/sys/cddl/zfs/tests/nestedfs/cleanup.ksh new file mode 100644 index 00000000000..e2ccfb86862 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/nestedfs/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_container_cleanup diff --git a/tests/sys/cddl/zfs/tests/nestedfs/nestedfs.cfg b/tests/sys/cddl/zfs/tests/nestedfs/nestedfs.cfg new file mode 100644 index 00000000000..39a87297e27 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/nestedfs/nestedfs.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)nestedfs.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE0=testfile0.${TESTCASE_ID} +export TESTFILE1=testfile1.${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/nestedfs/nestedfs_001_pos.ksh b/tests/sys/cddl/zfs/tests/nestedfs/nestedfs_001_pos.ksh new file mode 100644 index 00000000000..51401027300 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/nestedfs/nestedfs_001_pos.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)nestedfs_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: nestedfs_001_pos +# +# DESCRIPTION: +# Given a pool create a nested file system and a ZFS file system +# in the nested file system. Populate the file system. +# +# As a sub-assertion, the test verifies that a nested file system with +# a mounted file system cannot be destroyed. +# +# STRATEGY: +# 1. Create a file in the new mountpoint +# 2. Unmount the new mountpoint +# 3. Show a nested file system with file systems cannot be destroyed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +typeset OP=create +typeset -i BLOCKSZ=8192 +typeset -i NUM_WRITES=600 +typeset -i DATA=0 + +log_assert "Verify a nested file system can be created/destroyed." + +log_must $FILE_WRITE -o $OP -f $TESTDIR1/$TESTFILE0 -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA + +log_must $ZFS unmount $TESTDIR1 + +log_note "Verify that a nested file system with a mounted file system "\ + "cannot be destroyed." +log_mustnot $ZFS destroy $TESTPOOL/$TESTCTR + +log_pass "A nested file system was successfully populated." diff --git a/tests/sys/cddl/zfs/tests/nestedfs/nestedfs_test.sh b/tests/sys/cddl/zfs/tests/nestedfs/nestedfs_test.sh new file mode 100755 index 00000000000..7643d99ef48 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/nestedfs/nestedfs_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case nestedfs_001_pos cleanup +nestedfs_001_pos_head() +{ + atf_set "descr" "Verify a nested file system can be created/destroyed." + atf_set "require.progs" zfs +} +nestedfs_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/nestedfs.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/nestedfs_001_pos.ksh || atf_fail "Testcase failed" +} +nestedfs_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/nestedfs.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case nestedfs_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/nestedfs/setup.ksh b/tests/sys/cddl/zfs/tests/nestedfs/setup.ksh new file mode 100644 index 00000000000..1c30df46ae8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/nestedfs/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_container_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/no_space/Makefile b/tests/sys/cddl/zfs/tests/no_space/Makefile new file mode 100644 index 00000000000..b0daef2c10d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/no_space/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/no_space +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= no_space_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= enospc.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= enospc_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/no_space/cleanup.ksh b/tests/sys/cddl/zfs/tests/no_space/cleanup.ksh new file mode 100644 index 00000000000..21fdcc3528b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/no_space/cleanup.ksh @@ -0,0 +1,47 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +ismounted "$TESTPOOL/$TESTFS" +(( $? == 0 )) && \ + log_must $ZFS umount $TESTDIR + +destroy_pool $TESTPOOL +# +# Remove 100mb partition. +# +cleanup_devices "$DISK" + +log_pass diff --git a/tests/sys/cddl/zfs/tests/no_space/enospc.cfg b/tests/sys/cddl/zfs/tests/no_space/enospc.cfg new file mode 100644 index 00000000000..0cec26f9e79 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/no_space/enospc.cfg @@ -0,0 +1,39 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)enospc.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE0=testfile0.${TESTCASE_ID} +export TESTFILE1=testfile1.${TESTCASE_ID} + +export SIZE=100mb +export ENOSPC=28 +export BLOCKSZ=8192 +export NUM_WRITES=65536 +export DATA=0 diff --git a/tests/sys/cddl/zfs/tests/no_space/enospc_001_pos.ksh b/tests/sys/cddl/zfs/tests/no_space/enospc_001_pos.ksh new file mode 100644 index 00000000000..807f901dce3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/no_space/enospc_001_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)enospc_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: enospc_001 +# +# DESCRIPTION: +# ENOSPC is returned on an attempt to write a second file +# to a file system after a first file was written that terminated +# with ENOSPC on a cleanly initialized file system. +# +# STRATEGY: +# 1. Write a file until the file system is full. +# 2. Ensure that ENOSPC is returned. +# 3. Write a second file while the file system remains full. +# 4. Verify the return code is ENOSPC. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "ENOSPC is returned when file system is full." +log_must $ZFS set compression=off $TESTPOOL/$TESTFS + +log_note "Writing file: $TESTFILE0 until ENOSPC." +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE0 -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA +ret=$? + +(( $ret != $ENOSPC )) && \ + log_fail "$TESTFILE0 returned: $ret rather than ENOSPC." + +log_note "Write another file: $TESTFILE1 but expect ENOSPC." +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA +ret=$? + +(( $ret != $ENOSPC )) && \ + log_fail "$TESTFILE1 returned: $ret rather than ENOSPC." + +log_pass "ENOSPC returned as expected." diff --git a/tests/sys/cddl/zfs/tests/no_space/no_space_test.sh b/tests/sys/cddl/zfs/tests/no_space/no_space_test.sh new file mode 100755 index 00000000000..db86bcc15b0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/no_space/no_space_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case enospc_001_pos cleanup +enospc_001_pos_head() +{ + atf_set "descr" "ENOSPC is returned when file system is full." + atf_set "require.progs" zfs +} +enospc_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/enospc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/enospc_001_pos.ksh || atf_fail "Testcase failed" +} +enospc_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/enospc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case enospc_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/no_space/setup.ksh b/tests/sys/cddl/zfs/tests/no_space/setup.ksh new file mode 100644 index 00000000000..60cd910c96d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/no_space/setup.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +wipe_partition_table $DISK +log_must set_partition 1 "" $SIZE $DISK + +default_setup $DISK"p1" diff --git a/tests/sys/cddl/zfs/tests/online_offline/Makefile b/tests/sys/cddl/zfs/tests/online_offline/Makefile new file mode 100644 index 00000000000..ad5cb1a73b4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/online_offline/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/online_offline +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= online_offline_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= online_offline_001_pos.ksh +${PACKAGE}FILES+= online_offline.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= online_offline_002_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/online_offline/cleanup.ksh b/tests/sys/cddl/zfs/tests/online_offline/cleanup.ksh new file mode 100644 index 00000000000..8dcf65f6cda --- /dev/null +++ b/tests/sys/cddl/zfs/tests/online_offline/cleanup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +verify_runnable "global" + +reap_children +default_cleanup_noexit +cleanup_devices ${DISKS} +log_pass diff --git a/tests/sys/cddl/zfs/tests/online_offline/online_offline.cfg b/tests/sys/cddl/zfs/tests/online_offline/online_offline.cfg new file mode 100644 index 00000000000..5a59f01c843 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/online_offline/online_offline.cfg @@ -0,0 +1,31 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2014 Spectra Logic Corporation +# Use is subject to license terms. +# + +export TESTFILE=testfile.${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/online_offline/online_offline_001_pos.ksh b/tests/sys/cddl/zfs/tests/online_offline/online_offline_001_pos.ksh new file mode 100644 index 00000000000..d98206275ff --- /dev/null +++ b/tests/sys/cddl/zfs/tests/online_offline/online_offline_001_pos.ksh @@ -0,0 +1,67 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Copyright 2014 Spectra Logic Corporation. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +function verify_assertion +{ + busy_path $TESTDIR + for disk in $DISKS; do + log_must $ZPOOL offline $TESTPOOL $disk + check_state $TESTPOOL $disk "offline" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL is not offline." + fi + + log_must $ZPOOL online $TESTPOOL $disk + check_state $TESTPOOL $disk "online" + if [[ $? != 0 ]]; then + log_fail "$disk of $TESTPOOL did not match online state" + fi + done + reap_children + + typeset dir=$(get_device_dir $DISKS) + verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir" +} + +log_assert "Turning a disk offline and back online during I/O completes." +log_onexit cleanup + +for keyword in "mirror" "raidz"; do + typeset child_pid="" + default_setup_noexit "$keyword $DISKS" + verify_assertion + destroy_pool $TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/online_offline/online_offline_002_neg.ksh b/tests/sys/cddl/zfs/tests/online_offline/online_offline_002_neg.ksh new file mode 100644 index 00000000000..f1608539454 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/online_offline/online_offline_002_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Copyright 2014 Spectra Logic Corporation. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +function verify_assertion +{ + keyword="$1" + typeset -i redundancy + set -A DISKLIST $DISKS + + case "$keyword" in + "") redundancy=0 ;; + "mirror") (( redundancy=${#DISKLIST[@]} - 1 )) ;; + "raidz") redundancy=1 ;; + "raidz2") redundancy=2 ;; + "raidz3") redundancy=3 ;; + *) log_fail "Unknown keyword" ;; + esac + + echo redundancy is $redundancy + + if [ ${#DISKLIST[@]} -le "$redundancy" ]; then + log_fail "Insufficiently many disks configured for this test" + fi + + busy_path $TESTDIR + # Offline the allowed number of disks + for ((i=0; i<$redundancy; i=$i+1 )); do + log_must $ZPOOL offline $TESTPOOL ${DISKLIST[$i]} + done + + #Verify that offlining any additional disks should fail + for ((i=$redundancy; i<${#DISKLIST[@]}; i=$i+1 )); do + log_mustnot $ZPOOL offline $TESTPOOL ${DISKLIST[$i]} + done + reap_children + + typeset dir=$(get_device_dir $DISKS) + verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir" +} + +log_assert "Turning both disks offline should fail." + +for keyword in "" "mirror" "raidz" "raidz2"; do + child_pids="" + default_setup_noexit "$keyword $DISKS" + verify_assertion "$keyword" + destroy_pool $TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/online_offline/online_offline_test.sh b/tests/sys/cddl/zfs/tests/online_offline/online_offline_test.sh new file mode 100755 index 00000000000..927a1f2bae5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/online_offline/online_offline_test.sh @@ -0,0 +1,82 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case online_offline_001_pos cleanup +online_offline_001_pos_head() +{ + atf_set "descr" "Turning a disk offline and back online during I/O completes." + atf_set "require.progs" zpool zdb + atf_set "timeout" 3600 +} +online_offline_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/online_offline.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/online_offline_001_pos.ksh || atf_fail "Testcase failed" +} +online_offline_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/online_offline.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case online_offline_002_neg cleanup +online_offline_002_neg_head() +{ + atf_set "descr" "Offlining a disk should fail if the pool would go critical" + atf_set "require.progs" zpool zdb + atf_set "timeout" 3600 +} +online_offline_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/online_offline.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/online_offline_002_neg.ksh || atf_fail "Testcase failed" +} +online_offline_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/online_offline.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case online_offline_001_pos + atf_add_test_case online_offline_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/pool_names/Makefile b/tests/sys/cddl/zfs/tests/pool_names/Makefile new file mode 100644 index 00000000000..82969777d3d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/pool_names/Makefile @@ -0,0 +1,17 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/pool_names +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= pool_names_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= pool_names_002_neg.ksh +${PACKAGE}FILES+= pool_names.cfg +${PACKAGE}FILES+= pool_names_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/pool_names/pool_names.cfg b/tests/sys/cddl/zfs/tests/pool_names/pool_names.cfg new file mode 100644 index 00000000000..dd726c9f0fb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/pool_names/pool_names.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)pool_names.cfg 1.3 08/08/15 SMI" +# +export STF_TIMEOUT=1200 +export DISK=${DISKS%% *} diff --git a/tests/sys/cddl/zfs/tests/pool_names/pool_names_001_pos.ksh b/tests/sys/cddl/zfs/tests/pool_names/pool_names_001_pos.ksh new file mode 100644 index 00000000000..c8ca079e2f6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/pool_names/pool_names_001_pos.ksh @@ -0,0 +1,126 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)pool_names_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: pool_names_001_pos +# +# DESCRIPTION: +# +# Test that a set of valid names can be used to create pools. Further +# verify that the created pools can be destroyed. +# +# STRATEGY: +# 1) For each valid character in the character set, try to create +# and destroy the pool. +# 2) Given a list of valid pool names, try to create and destroy +# pools with the given names. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-11-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Ensure that pool names can use the ASCII subset of UTF-8" + +function cleanup +{ + [[ -n "$name" ]] && destroy_pool $name + + if [[ -d $TESTDIR ]]; then + log_must $RM -rf $TESTDIR + fi + +} + +log_onexit cleanup + +if [[ ! -e $TESTDIR ]]; then + log_must $MKDIR $TESTDIR +fi + +log_note "Ensure letters of the alphabet are allowable" + +typeset name="" + +for name in A B C D E F G H I J K L M \ + N O P Q R S T U V W X Y Z \ + a b c d e f g h i j k l m \ + n o p q r s t u v w x y z +do + log_must $ZPOOL create -m $TESTDIR $name $DISK + if ! poolexists $name; then + log_fail "Could not create a pool called '$name'" + fi + + log_must $ZPOOL destroy $name +done + +log_note "Ensure a variety of unusual names passes" + +name="" + +for name in "a.............................." "a_" "a-" "a:" \ + "a." "a123456" "bc0t0d0" "m1rr0r_p00l" "ra1dz_p00l" \ + "araidz2" "C0t2d0" "cc0t0" "raid2:-_." "mirr_:-." \ + "m1rr0r-p00l" "ra1dz-p00l" "spar3_p00l" \ + "spar3-p00l" "hiddenmirrorpool" "hiddenraidzpool" \ + "hiddensparepool" +do + log_must $ZPOOL create -m $TESTDIR $name $DISK + if ! poolexists $name; then + log_fail "Could not create a pool called '$name'" + fi + + # + # Since the naming convention applies to datasets too, + # create datasets with the same names as above. + # + log_must $ZFS create $name/$name + log_must $ZFS snapshot $name/$name@$name + log_must $ZFS clone $name/$name@$name $name/clone_$name + log_must $ZFS create -V 150m $name/$name/$name + + log_must $ZPOOL destroy $name +done + +log_pass "Valid pool names were accepted correctly." diff --git a/tests/sys/cddl/zfs/tests/pool_names/pool_names_002_neg.ksh b/tests/sys/cddl/zfs/tests/pool_names/pool_names_002_neg.ksh new file mode 100644 index 00000000000..963defc359b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/pool_names/pool_names_002_neg.ksh @@ -0,0 +1,147 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)pool_names_002_neg.ksh 1.4 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: pool_names_002_neg +# +# DESCRIPTION: +# +# Ensure that a set of invalid names cannot be used to create pools. +# +# STRATEGY: +# 1) For each invalid character in the character set, try to create +# and destroy the pool. Verify it fails. +# 2) Given a list of invalid pool names, ensure the pools are not +# created. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-11-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Ensure that a set of invalid names cannot be used to create pools." + +# Global variable use to cleanup failures. +POOLNAME="" + +function cleanup +{ + destroy_pool $POOLNAME + + if [[ -d $TESTDIR ]]; then + log_must $RM -rf $TESTDIR + fi +} + +log_onexit cleanup + +if [[ ! -e $TESTDIR ]]; then + log_must $MKDIR $TESTDIR +fi + +log_note "Ensure invalid characters fail" +for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \ + "\*" "+" "," "-" "\." "/" "\\" \ + ":" ";" "<" "=" ">" "\?" "@" \ + "[" "]" "^" "_" "\`" "{" "|" "}" "~" +do + log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK + if poolexists $POOLNAME; then + log_fail "Unexpectedly created pool: '$POOLNAME'" + fi + + log_mustnot $ZPOOL destroy $POOLNAME +done + +# poolexists cannot be used to test pools with numeric names, because +# "zpool list" will interpret the name as a repeat interval and never return. +log_note "Ensure invalid characters fail" +for POOLNAME in 0 1 2 3 4 5 6 7 8 9 2222222222222222222 +do + log_mustnot $ZPOOL create -m $TESTDIR $POOLNAME $DISK + log_mustnot $ZPOOL destroy $POOLNAME +done + +log_note "Check that invalid octal values fail" +for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \ + "\010" "\011" "\012" "\013" "\014" "\015" "\017" \ + "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \ + "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \ + "\040" "\177" +do + # Be careful not to print the poolname, because it might be a terminal + # control character + POOLNAME=`eval "print x | tr 'x' '$oct'"` + $ZPOOL create -m $TESTDIR $POOLNAME $DISK > /dev/null 2>&1 + if [ $? = 0 ]; then + log_fail "Unexpectedly created pool: \"$oct\"" + elif poolexists $POOLNAME; then + log_fail "Unexpectedly created pool: \"$oct\"" + fi + + $ZPOOL destroy $POOLNAME > /dev/null 2>&1 + if [ $? = 0 ]; then + log_fail "Unexpectedly destroyed pool: \"$oct\"" + fi +done + +log_note "Verify invalid pool names fail" +set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \ + "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \ + "mirror_pool" "raidz_pool" \ + "mirror-pool" "raidz-pool" "spare" "spare_pool" \ + "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd" +POOLNAME[${#POOLNAME[@]}]='log' +typeset -i i=0 +while ((i < ${#POOLNAME[@]})); do + log_mustnot $ZPOOL create -m $TESTDIR ${POOLNAME[$i]} $DISK + if poolexists ${POOLNAME[$i]}; then + log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'" + fi + + log_mustnot $ZPOOL destroy ${POOLNAME[$i]} + + ((i += 1)) +done + +log_pass "Invalid names and characters were caught correctly" diff --git a/tests/sys/cddl/zfs/tests/pool_names/pool_names_test.sh b/tests/sys/cddl/zfs/tests/pool_names/pool_names_test.sh new file mode 100755 index 00000000000..fca517909a7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/pool_names/pool_names_test.sh @@ -0,0 +1,68 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case pool_names_001_pos +pool_names_001_pos_head() +{ + atf_set "descr" "Ensure that pool names can use the ASCII subset of UTF-8" + atf_set "require.progs" zfs zpool + atf_set "timeout" 1200 +} +pool_names_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/pool_names.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/pool_names_001_pos.ksh || atf_fail "Testcase failed" +} + + +atf_test_case pool_names_002_neg +pool_names_002_neg_head() +{ + atf_set "descr" "Ensure that a set of invalid names cannot be used to create pools." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +pool_names_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/pool_names.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/pool_names_002_neg.ksh || atf_fail "Testcase failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case pool_names_001_pos + atf_add_test_case pool_names_002_neg +} diff --git a/tests/sys/cddl/zfs/tests/poolversion/Makefile b/tests/sys/cddl/zfs/tests/poolversion/Makefile new file mode 100644 index 00000000000..06adc458cd3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/poolversion/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/poolversion +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= poolversion_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= poolversion_002_pos.ksh +${PACKAGE}FILES+= poolversion_001_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/poolversion/cleanup.ksh b/tests/sys/cddl/zfs/tests/poolversion/cleanup.ksh new file mode 100644 index 00000000000..56e053f41c0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/poolversion/cleanup.ksh @@ -0,0 +1,45 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/10/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +verify_runnable "global" + +$ZPOOL set 2>&1 | $GREP version > /dev/null +if [ $? -eq 1 ] +then + log_unsupported "zpool version property not supported on this system." +fi + +destroy_pool $TESTPOOL +destroy_pool $TESTPOOL2 + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/poolversion/poolversion_001_pos.ksh b/tests/sys/cddl/zfs/tests/poolversion/poolversion_001_pos.ksh new file mode 100644 index 00000000000..7d15cf61bdb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/poolversion/poolversion_001_pos.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)poolversion_001_pos.ksh 1.2 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: poolversion_001_pos +# +# DESCRIPTION: +# +# zpool set version can upgrade a pool +# +# STRATEGY: +# 1. Taking a version 1 pool +# 2. For all known versions, set the version of the pool using zpool set +# 3. Verify that pools version +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" +log_assert "zpool set version can upgrade a pool" +for version in 1 2 3 4 5 6 7 8 +do + log_must $ZPOOL set version=$version $TESTPOOL + ACTUAL=$($ZPOOL get version $TESTPOOL | $GREP version \ + | $AWK '{print $3}') + if [ "$ACTUAL" != "$version" ] + then + log_fail "v. $ACTUAL set for $TESTPOOL, expected v. $version!" + fi +done + +log_pass "zpool set version can upgrade a pool" + diff --git a/tests/sys/cddl/zfs/tests/poolversion/poolversion_002_pos.ksh b/tests/sys/cddl/zfs/tests/poolversion/poolversion_002_pos.ksh new file mode 100644 index 00000000000..f25aa7c2a60 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/poolversion/poolversion_002_pos.ksh @@ -0,0 +1,86 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)poolversion_002_pos.ksh 1.2 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: poolversion_002_pos +# +# DESCRIPTION: +# +# zpool set version can only increment pool version +# +# STRATEGY: +# 1. Set a version 1 pool to be a version 6 pool +# 2. Verify it's set to version 6 +# 3. Attempt to set prior versions +# 4. Verify it's still set to version 6 +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-07-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" +log_assert "zpool set version can only increment pool version" + +log_must $ZPOOL set version=6 $TESTPOOL2 +# verify it's actually that version - by checking the version property +# and also by trying to set bootfs (which should fail if it is not version 6) + +VERSION=$($ZPOOL get version $TESTPOOL2| $GREP version | $AWK '{print $3}') +if [ "$VERSION" != "6" ] +then + log_fail "Version $VERSION set for $TESTPOOL2 expected version 6!" +fi +log_must $ZPOOL set bootfs=$TESTPOOL2 $TESTPOOL2 + +# now verify we can't downgrade the version +log_mustnot $ZPOOL set version=5 $TESTPOOL2 +log_mustnot $ZPOOL set version=-1 $TESTPOOL2 + +# verify the version is still 6 +VERSION=$($ZPOOL get version $TESTPOOL2 | $GREP version | $AWK '{print $3}') +if [ "$VERSION" != "6" ] +then + log_fail "Version $VERSION set for $TESTPOOL2, expected version 6!" +fi + +log_pass "zpool set version can only increment pool version" + diff --git a/tests/sys/cddl/zfs/tests/poolversion/poolversion_test.sh b/tests/sys/cddl/zfs/tests/poolversion/poolversion_test.sh new file mode 100755 index 00000000000..46f71377f19 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/poolversion/poolversion_test.sh @@ -0,0 +1,78 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case poolversion_001_pos cleanup +poolversion_001_pos_head() +{ + atf_set "descr" "zpool set version can upgrade a pool" + atf_set "require.progs" zpool +} +poolversion_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/poolversion_001_pos.ksh || atf_fail "Testcase failed" +} +poolversion_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case poolversion_002_pos cleanup +poolversion_002_pos_head() +{ + atf_set "descr" "zpool set version can only increment pool version" + atf_set "require.progs" zpool +} +poolversion_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/poolversion_002_pos.ksh || atf_fail "Testcase failed" +} +poolversion_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case poolversion_001_pos + atf_add_test_case poolversion_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/poolversion/setup.ksh b/tests/sys/cddl/zfs/tests/poolversion/setup.ksh new file mode 100644 index 00000000000..5aec1d27023 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/poolversion/setup.ksh @@ -0,0 +1,50 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 07/10/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +verify_runnable "global" + +$ZPOOL set 2>&1 | $GREP version > /dev/null +if [ $? -eq 1 ] +then + log_unsupported "zpool version property not supported on this system." +fi + +DISKS_ARRAY=($DISKS) +# create a version 1 pool +log_must $ZPOOL create -f -o version=1 $TESTPOOL ${DISKS_ARRAY[0]} + + +# create another version 1 pool +log_must $ZPOOL create -f -o version=1 $TESTPOOL2 ${DISKS_ARRAY[1]} + +log_pass diff --git a/tests/sys/cddl/zfs/tests/quota/Makefile b/tests/sys/cddl/zfs/tests/quota/Makefile new file mode 100644 index 00000000000..e1895f92f6b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/Makefile @@ -0,0 +1,24 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/quota +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= quota_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= quota_003_pos.ksh +${PACKAGE}FILES+= quota_006_neg.ksh +${PACKAGE}FILES+= quota_002_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= quota.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= quota_004_pos.ksh +${PACKAGE}FILES+= quota_005_pos.ksh +${PACKAGE}FILES+= quota_001_pos.ksh +${PACKAGE}FILES+= quota.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/quota/cleanup.ksh b/tests/sys/cddl/zfs/tests/quota/cleanup.ksh new file mode 100644 index 00000000000..e2ccfb86862 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_container_cleanup diff --git a/tests/sys/cddl/zfs/tests/quota/quota.cfg b/tests/sys/cddl/zfs/tests/quota/quota.cfg new file mode 100644 index 00000000000..4728d085482 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota.cfg @@ -0,0 +1,36 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota.cfg 1.3 08/08/15 SMI" +# + +export BLOCK_SIZE=8192 +export QUOTA_VALUE=10000000 +export TESTFILE1=file1.${TESTCASE_ID} +export TESTFILE2=file2.${TESTCASE_ID} +export TOLERANCE=131071 diff --git a/tests/sys/cddl/zfs/tests/quota/quota.kshlib b/tests/sys/cddl/zfs/tests/quota/quota.kshlib new file mode 100644 index 00000000000..d54c7a43458 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota.kshlib @@ -0,0 +1,88 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota.kshlib 1.2 07/01/09 SMI" +# + +# BLOCK_SIZE, QUOTA_VALUE and TOLERANCE set in quota.cfg +readonly EDQUOT=69 + +# +# Function to fill the quota of a zfs filesystem +# +# $1 - The File system or container to fill. +# $2 - The mountpoint to use. +# +function fill_quota +{ + typeset FILESYSTEM="$1" + typeset MNTPT="$2" + + log_must $ZFS set quota=$QUOTA_VALUE $FILESYSTEM + + typeset -i write_size=0 + (( write_size = 2 * QUOTA_VALUE )) + + typeset -i zret=0 + $FILE_WRITE -o create -f $MNTPT/$TESTFILE1 -b $BLOCK_SIZE \ + -c $write_size -d 0 + zret=$? + [[ $zret -ne EDQUOT ]] && log_fail "Got error $zret; expected $EDQUOT" + + typeset -i file_size=`$LS -ls $MNTPT/$TESTFILE1 | $AWK '{ print $1 }'` + typeset -i limit=0 + (( file_size = file_size * 512 )) + (( limit = QUOTA_VALUE + TOLERANCE )) + (( file_size > limit )) && \ + log_fail "File was created larger than the quota value, aborting!!!" + return 0 +} + +# +# Function attempts to write another file in a ZFS filesystem +# that has already filled its quota +# +function exceed_quota +{ + typeset FILESYSTEM="$1" + typeset MNTPT="$2" + + log_must fill_quota $FILESYSTEM $MNTPT + typeset -i write_size=0 + (( write_size = 2 * QUOTA_VALUE )) + typeset -i zret=0 + # + # Writing a file without API to access return code + # + log_note "Creating a file in a FS that has already exceeded its quota" + $FILE_WRITE -o create -f $MNTPT/$TESTFILE2 \ + -b $BLOCK_SIZE -c $write_size -d 0 + zret=$? + [[ $zret -ne EDQUOT ]] && log_fail "Got error $zret; expected $EDQUOT" + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/quota/quota_001_pos.ksh b/tests/sys/cddl/zfs/tests/quota/quota_001_pos.ksh new file mode 100644 index 00000000000..47e3d05a031 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota_001_pos.ksh @@ -0,0 +1,91 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/quota/quota.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: quota_001_pos +# +# DESCRIPTION: +# +# A ZFS file system quota limits the amount of pool space +# available to a file system. Apply a quota and verify +# that no more file creates are permitted. +# +# STRATEGY: +# 1) Apply quota to ZFS file system +# 2) Create a file which is larger than the set quota +# 3) Verify that the resulting file size is less than the quota limit +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify that file size is limited by the file system quota" + +# +# cleanup to be used internally as otherwise quota assertions cannot be +# run independently or out of order +# +function cleanup +{ + [[ -e $TESTDIR/$TESTFILE1 ]] && \ + log_must $RM $TESTDIR/$TESTFILE1 + # + # Need to allow time for space to be released back to + # pool, otherwise next test will fail trying to set a + # quota which is less than the space used. + # + sleep 5 + log_must $ZFS set quota=none $TESTPOOL/$TESTFS +} + +log_onexit cleanup + +# +# Sets the quota value and attempts to fill it with a file +# twice the size of the quota +# +log_must fill_quota $TESTPOOL/$TESTFS $TESTDIR + +log_pass "File size limited by quota" diff --git a/tests/sys/cddl/zfs/tests/quota/quota_002_pos.ksh b/tests/sys/cddl/zfs/tests/quota/quota_002_pos.ksh new file mode 100644 index 00000000000..4b6fae50ce8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota_002_pos.ksh @@ -0,0 +1,88 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/quota/quota.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: quota_002_pos +# +# DESCRIPTION: +# A zfs file system quota limits the amount of pool space +# available to a given ZFS file system. Once exceeded, it is impossible +# to write any more files to the file system. +# +# STRATEGY: +# 1) Apply quota to the ZFS file system +# 2) Exceed the quota +# 3) Attempt to write another file +# 4) Verify the attempt fails with error code 49 (EDQUOTA) +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify that a file write cannot exceed the file system quota" + +# +# cleanup to be used internally as otherwise quota assertions cannot be +# run independently or out of order +# +function cleanup +{ + [[ -e $TESTDIR/$TESTFILE1 ]] && \ + log_must $RM $TESTDIR/$TESTFILE1 + + [[ -e $TESTDIR/$TESTFILE2 ]] && \ + log_must $RM $TESTDIR/$TESTFILE2 + log_must $ZFS set quota=none $TESTPOOL/$TESTFS +} + +log_onexit cleanup + +# +# Fills the quota & attempts to write another file +# +log_must exceed_quota $TESTPOOL/$TESTFS $TESTDIR + +log_pass "Could not write file. Quota limit enforced as expected" diff --git a/tests/sys/cddl/zfs/tests/quota/quota_003_pos.ksh b/tests/sys/cddl/zfs/tests/quota/quota_003_pos.ksh new file mode 100644 index 00000000000..5143eb29de1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota_003_pos.ksh @@ -0,0 +1,94 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota_003_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/quota/quota.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: quota_003_pos +# +# DESCRIPTION: +# A ZFS file system quota limits the amount of pool space +# available to a file system dataset. Apply a quota and verify +# that no more file creates are permitted. +# +# NOTE: THis test applies to a dataset rather than a file system. +# +# STRATEGY: +# 1) Apply quota to ZFS file system dataset +# 2) Create a file which is larger than the set quota +# 3) Verify that the resulting file size is less than the quota limit +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify that file size is limited by the file system quota" \ + "(dataset version)" + +# +# cleanup to be used internally as otherwise quota assertions cannot be +# run independently or out of order +# +function cleanup +{ + [[ -e $TESTDIR1/$TESTFILE1 ]] && \ + log_must $RM $TESTDIR1/$TESTFILE1 + + # + # Need to allow time for space to be released back to + # pool, otherwise next test will fail trying to set a + # quota which is less than the space used. + # + sleep 5 + log_must $ZFS set quota=none $TESTPOOL/$TESTFS +} + +log_onexit cleanup + +# +# Sets the quota value and attempts to fill it with a file +# twice the size of the quota +# +log_must fill_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1 + +log_pass "File size limited by quota" diff --git a/tests/sys/cddl/zfs/tests/quota/quota_004_pos.ksh b/tests/sys/cddl/zfs/tests/quota/quota_004_pos.ksh new file mode 100644 index 00000000000..f5fe5f4f220 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota_004_pos.ksh @@ -0,0 +1,89 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota_004_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/quota/quota.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: quota_004_pos +# +# DESCRIPTION: +# A zfs file system quota limits the amount of pool space +# available to a given ZFS file system dataset. Once exceeded, it +# is impossible to write any more files to the file system. +# +# STRATEGY: +# 1) Apply quota to the ZFS file system dataset +# 2) Exceed the quota +# 3) Attempt to write another file +# 4) Verify the attempt fails with error code 49 (EDQUOTA) +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify that a file write cannot exceed the file system quota" \ + "(dataset version)" + +# +# cleanup to be used internally as otherwise quota assertions cannot be +# run independently or out of order +# +function cleanup +{ + [[ -e $TESTDIR1/$TESTFILE1 ]] && \ + log_must $RM $TESTDIR1/$TESTFILE1 + + [[ -e $TESTDIR1/$TESTFILE2 ]] && \ + log_must $RM $TESTDIR1/$TESTFILE2 + log_must $ZFS set quota=none $TESTPOOL/$TESTFS +} + +log_onexit cleanup + +# +# Fills the quota & attempts to write another file +# +log_must exceed_quota $TESTPOOL/$TESTCTR/$TESTFS1 $TESTDIR1 + +log_pass "Could not write file. Quota limit enforced as expected" diff --git a/tests/sys/cddl/zfs/tests/quota/quota_005_pos.ksh b/tests/sys/cddl/zfs/tests/quota/quota_005_pos.ksh new file mode 100644 index 00000000000..1cb2415de37 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota_005_pos.ksh @@ -0,0 +1,88 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: quota_005_pos +# +# DESCRIPTION: +# +# Verify that quota doesn't inherit its value from parent. +# +# STRATEGY: +# 1) Set quota for parents +# 2) Create a filesystem tree +# 3) Verify that the 'quota' for descendent doesnot inherit the value. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-17) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +function cleanup +{ + datasetexists $fs_child && \ + log_must $ZFS destroy $fs_child + + log_must $ZFS set quota=none $fs +} + +log_onexit cleanup + +log_assert "Verify that quota does not inherit its value from parent." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +fs_child=$TESTPOOL/$TESTFS/$TESTFS + +typeset -l space_avail=$(get_prop available $fs) +typeset -l quotasize=$space_avail +((quotasize = quotasize * 2 )) +log_must $ZFS list +log_must $ZFS set quota=$quotasize $fs + +log_must $ZFS create $fs_child +typeset -l quota_space=$(get_prop quota $fs_child) +[[ $quota_space == $quotasize ]] && \ + log_fail "The quota of child dataset inherits its value from parent." + +log_pass "quota doesnot inherit its value from parent as expected." diff --git a/tests/sys/cddl/zfs/tests/quota/quota_006_neg.ksh b/tests/sys/cddl/zfs/tests/quota/quota_006_neg.ksh new file mode 100644 index 00000000000..f2531904efb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota_006_neg.ksh @@ -0,0 +1,84 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)quota_006_neg.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: quota_006_neg +# +# DESCRIPTION: +# +# Can't set a quota to less than currently being used by the dataset. +# +# STRATEGY: +# 1) Create a filesystem +# 2) Set a quota on the filesystem that is lower than the space +# currently in use. +# 3) Verify that the attempt fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-09-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify cannot set quota lower than the space currently in use" + +function cleanup +{ + log_must $ZFS set quota=none $TESTPOOL/$TESTFS +} + +log_onexit cleanup + +typeset -l quota_integer_size=0 +typeset invalid_size="123! @456 7#89 0\$ abc123% 123%s 12%s3 %c123 123%d %x123 12%p3 \ + ^def456 789&ghi" +typeset -l space_used=`get_prop used $TESTPOOL/$TESTFS` +(( quota_integer_size = space_used - 1 )) +typeset -l quota_fp_size=${quota_integer_size}.123 + +for size in 0 -1 $quota_integer_size -$quota_integer_size $quota_fp_size -$quota_fp_size \ + $invalid_size ; do + log_mustnot $ZFS set quota=$size $TESTPOOL/$TESTFS +done +log_must $ZFS set quota=$space_used $TESTPOOL/$TESTFS + +log_pass "As expected cannot set quota lower than space currently in use" diff --git a/tests/sys/cddl/zfs/tests/quota/quota_test.sh b/tests/sys/cddl/zfs/tests/quota/quota_test.sh new file mode 100755 index 00000000000..43f8ce24cc2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/quota_test.sh @@ -0,0 +1,194 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case quota_001_pos cleanup +quota_001_pos_head() +{ + atf_set "descr" "Verify that file size is limited by the file system quota" + atf_set "require.progs" zfs +} +quota_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/quota_001_pos.ksh || atf_fail "Testcase failed" +} +quota_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case quota_002_pos cleanup +quota_002_pos_head() +{ + atf_set "descr" "Verify that a file write cannot exceed the file system quota" + atf_set "require.progs" zfs +} +quota_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/quota_002_pos.ksh || atf_fail "Testcase failed" +} +quota_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case quota_003_pos cleanup +quota_003_pos_head() +{ + atf_set "descr" "Verify that file size is limited by the file system quota(dataset version)" + atf_set "require.progs" zfs +} +quota_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/quota_003_pos.ksh || atf_fail "Testcase failed" +} +quota_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case quota_004_pos cleanup +quota_004_pos_head() +{ + atf_set "descr" "Verify that a file write cannot exceed the file system quota(dataset version)" + atf_set "require.progs" zfs +} +quota_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/quota_004_pos.ksh || atf_fail "Testcase failed" +} +quota_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case quota_005_pos cleanup +quota_005_pos_head() +{ + atf_set "descr" "Verify that quota does not inherit its value from parent." + atf_set "require.progs" zfs +} +quota_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/quota_005_pos.ksh || atf_fail "Testcase failed" +} +quota_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case quota_006_neg cleanup +quota_006_neg_head() +{ + atf_set "descr" "Verify cannot set quota lower than the space currently in use" + atf_set "require.progs" zfs +} +quota_006_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/quota_006_neg.ksh || atf_fail "Testcase failed" +} +quota_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/quota.kshlib + . $(atf_get_srcdir)/quota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case quota_001_pos + atf_add_test_case quota_002_pos + atf_add_test_case quota_003_pos + atf_add_test_case quota_004_pos + atf_add_test_case quota_005_pos + atf_add_test_case quota_006_neg +} diff --git a/tests/sys/cddl/zfs/tests/quota/setup.ksh b/tests/sys/cddl/zfs/tests/quota/setup.ksh new file mode 100644 index 00000000000..f60a4587cbb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/quota/setup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/quota/quota.kshlib + +DISK=${DISKS%% *} + +default_container_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/redundancy/Makefile b/tests/sys/cddl/zfs/tests/redundancy/Makefile new file mode 100644 index 00000000000..697120a56eb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/redundancy +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= redundancy_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= redundancy.cfg +${PACKAGE}FILES+= redundancy_003_pos.ksh +${PACKAGE}FILES+= redundancy_002_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= redundancy.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= redundancy_001_pos.ksh +${PACKAGE}FILES+= redundancy_004_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/redundancy/cleanup.ksh b/tests/sys/cddl/zfs/tests/redundancy/cleanup.ksh new file mode 100644 index 00000000000..ba37281ee17 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/cleanup.ksh @@ -0,0 +1,38 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 08/05/14 SMI" +# + +. $STF_SUITE/tests/redundancy/redundancy.kshlib + +verify_runnable "global" + +cleanup + +log_pass diff --git a/tests/sys/cddl/zfs/tests/redundancy/redundancy.cfg b/tests/sys/cddl/zfs/tests/redundancy/redundancy.cfg new file mode 100644 index 00000000000..e04b4cc209b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/redundancy.cfg @@ -0,0 +1,43 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)redundancy.cfg 1.4 08/08/15 SMI" +# + +export BASEDIR=$TMPDIR/basedir.${TESTCASE_ID} +export TESTFILE=testfile.${TESTCASE_ID} + +export PRE_RECORD_FILE=$BASEDIR/pre-record-file.${TESTCASE_ID} +export PST_RECORD_FILE=$BASEDIR/pst-record-file.${TESTCASE_ID} + +export DEV_SIZE=64M +export STF_TIMEOUT=1800 + +export BLOCKSZ=$(( 1024 * 1024 )) +export NUM_WRITES=40 + diff --git a/tests/sys/cddl/zfs/tests/redundancy/redundancy.kshlib b/tests/sys/cddl/zfs/tests/redundancy/redundancy.kshlib new file mode 100644 index 00000000000..4a1142d08d9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/redundancy.kshlib @@ -0,0 +1,304 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)redundancy.kshlib 1.8 09/01/12 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +function cleanup +{ + # Log the status of the pool to assist failures. + poolexists $TESTPOOL && $ZPOOL status -v $TESTPOOL + destroy_pool $TESTPOOL + typeset dir + for dir in $TESTDIR $BASEDIR; do + if [[ -d $dir ]]; then + log_must $RM -rf $dir + fi + done +} + +# +# Record the directories construction and checksum all the files which reside +# within the specified pool +# +# $1 The specified pool +# $2 The file which save the record. +# +function record_data +{ + typeset pool=$1 + typeset recordfile=$2 + + [[ -z $pool ]] && log_fail "No specified pool." + [[ -f $recordfile ]] && log_must $RM -f $recordfile + + typeset mntpnt + mntpnt=$(get_prop mountpoint $pool) + log_must eval "$DU -a $mntpnt > $recordfile 2>&1" + # + # When the data was damaged, checksum is failing and return 1 + # So, will not use log_must + # + $FIND $mntpnt -type f -exec $CKSUM {} + >> $recordfile 2>&1 +} + +# +# Create test pool and fill with files and directories. +# +# $1 pool name +# $2 pool type +# $3 virtual devices number +# +function setup_test_env +{ + typeset pool=$1 + typeset keyword=$2 + typeset -i vdev_cnt=$3 + typeset vdevs + + typeset -i i=0 + while (( i < vdev_cnt )); do + vdevs="$vdevs $BASEDIR/vdev$i" + ((i += 1)) + done + + log_must $MKDIR -p $BASEDIR + destroy_pool $pool + log_must create_vdevs $vdevs + + $ECHO $vdevs | tr ' ' '\n' > $BASEDIR/vdevs + log_must $ZPOOL create -m $TESTDIR $pool $keyword $vdevs + + typeset file=$TESTDIR/file + log_must $FILE_WRITE -o create -f $file -b $BLOCKSZ -c $NUM_WRITES + log_must force_sync_path $TESTDIR + record_data $TESTPOOL $PRE_RECORD_FILE +} + +# +# Check pool data is valid +# +# $1 pool +# +function is_data_valid +{ + typeset pool=$1 + + record_data $pool $PST_RECORD_FILE + if ! $DIFF $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then + return 1 + fi + + return 0 +} + +# +# Get the specified count devices name +# +# $1 pool name +# $2 devices count +# +function get_vdevs #pool cnt +{ + typeset pool=$1 + typeset -i cnt=$2 + + head -$cnt $BASEDIR/vdevs | tr '\n' ' ' +} + +# +# Synchronize all the data in pool +# +# $1 pool name +# +function sync_pool #pool +{ + typeset pool=$1 + + log_must force_sync_path $pool + + # If the OS has detected corruption on the pool, it will have + # automatically initiated a scrub. In that case, our "zpool scrub" + # command will fail. So we ignore its exit status and just check that + # the pool is scrubbing or has been scrubbed. + $ZPOOL scrub $pool >/dev/null 2>&1 + is_pool_scrubbing $pool || is_pool_scrubbed $pool || \ + log_fail "$ZPOOL scrub $pool failed." + log_note "$pool: $ZPOOL scrub issued." +} + +# +# Create and replace the same name virtual device files +# +# $1 pool name +# $2-n virtual device files +# +function replace_missing_devs +{ + typeset pool=$1 + shift + + typeset vdev + for vdev in $@; do + [ ! -f $vdev ] && log_must create_vdevs $vdev + log_must $ZPOOL replace -f $pool $vdev $vdev + wait_for 20 1 is_pool_resilvered $pool + done +} + +# +# Damage the labels of the specified devices. Returns 0 if all such devices +# are UNAVAIL, 1 otherwise. +# +function damage_dev_labels # pool [vdev ...] +{ + typeset pool=$1 + typeset -i ret=0 + shift + + for vdev in $*; do + check_state $pool $vdev UNAVAIL && continue + log_must create_vdevs $vdev + ret=1 + done + [ $ret -eq 0 ] && return $ret + sync_pool $pool + return $ret +} + +# +# Damage the pool's virtual device files. +# +# $1 pool name +# $2 Failing devices count +# $3 damage vdevs method, if not null, we keep the label for the vdevs +# +function damage_devs +{ + typeset pool=$1 + typeset -i cnt=$2 + typeset label="$3" + typeset vdevs + typeset -i bs_count + + vdevs=$(get_vdevs $pool $cnt) + log_note "Damaging pool $pool devices: $vdevs" + if [[ -n $label ]]; then + typeset -i i=0 + log_mustnot pool_has_errors $pool + while [ $i -lt $cnt ]; do + corrupt_file $TESTPOOL $TESTDIR/file $i + (( i += 1 )) + done + sync_pool $pool + wait_for 20 1 is_pool_scrubbed $pool + + log_must pool_has_errors $pool + else + # The pool can be syncing, thus fixing its labels. So we + # have to keep trying until all the devices go offline. + wait_for 20 1 damage_dev_labels $pool $vdevs + fi + + log_note "Pool $pool vdevs $vdevs damage completed." +} + +# +# Clear errors in the pool caused by data corruptions +# +# $1 pool name +# +function clear_errors +{ + typeset pool=$1 + + log_must $ZPOOL clear $pool + # The pool may need to resilver (issued async by 'zpool clear'), + # give it a chance to do so. + wait_for 30 1 is_pool_healthy $pool + + if ! is_data_valid $pool ; then + $ZPOOL status -x $pool + log_note "Data should be valid in $pool." + return 1 + fi + + return 0 +} + +# +# Remove the specified pool's virtual device files +# +# $1 Pool name +# $2 Missing devices count +# +function remove_devs +{ + typeset pool=$1 + typeset -i cnt=$2 + typeset vdevs + + vdevs=$(get_vdevs $pool $cnt) + log_note "Removing pool $pool vdevs: $vdevs" + log_must $RM -f $vdevs + + sync_pool $pool + for vdev in $vdevs; do + wait_for 20 1 check_state $pool $vdev UNAVAIL + done +} + +# +# Recover the bad or missing device files in the pool +# +# $1 Pool name +# $2 Missing devices count +# +function recover_bad_missing_devs +{ + typeset pool=$1 + typeset -i cnt=$2 + typeset vdevs + + vdevs=$(get_vdevs $pool $cnt) + log_note "Replacing missing pool $pool vdevs: $vdevs" + replace_missing_devs $pool $vdevs + + if ! is_pool_healthy $pool ; then + log_note "$pool should be healthy." + return 1 + fi + if ! is_data_valid $pool ; then + log_note "Data should be valid in $pool." + return 1 + fi + + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/redundancy/redundancy_001_pos.ksh b/tests/sys/cddl/zfs/tests/redundancy/redundancy_001_pos.ksh new file mode 100644 index 00000000000..2e7e8b11f55 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/redundancy_001_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)redundancy_001_pos.ksh 1.3 07/05/25 SMI" +# + +. $STF_SUITE/tests/redundancy/redundancy.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: redundancy_001_pos +# +# DESCRIPTION: +# A raidz pool can withstand at most 1 device failing or missing. +# +# STRATEGY: +# 1. Create N(>2,<5) virtual disk files. +# 2. Create raidz pool based on the virtual disk files. +# 3. Fill the filesystem with directories and files. +# 4. Record all the files and directories checksum information. +# 5. Damaged one of the virtual disk file. +# 6. Verify the data is correct to prove raidz can withstand 1 devicd is +# failing. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify raidz pool can withstand one device is failing." +log_onexit cleanup + +for cnt in 3 2; do + setup_test_env $TESTPOOL raidz $cnt + + # + # Inject data corruption error for raidz pool + # + damage_devs $TESTPOOL 1 "label" + log_must is_data_valid $TESTPOOL + log_must clear_errors $TESTPOOL + + # + # Inject bad device error for raidz pool + # + damage_devs $TESTPOOL 1 + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL 1 + + # + # Inject missing device error for raidz pool + # + remove_devs $TESTPOOL 1 + log_must is_data_valid $TESTPOOL +done + +log_pass "Raidz pool can withstand one devices is failing passed." diff --git a/tests/sys/cddl/zfs/tests/redundancy/redundancy_002_pos.ksh b/tests/sys/cddl/zfs/tests/redundancy/redundancy_002_pos.ksh new file mode 100644 index 00000000000..448c41e9793 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/redundancy_002_pos.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)redundancy_002_pos.ksh 1.3 07/05/25 SMI" +# + +. $STF_SUITE/tests/redundancy/redundancy.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: redundancy_002_pos +# +# DESCRIPTION: +# A raidz2 pool can withstand 2 devices are failing or missing. +# +# STRATEGY: +# 1. Create N(>3,<5) virtual disk files. +# 2. Create raidz2 pool based on the virtual disk files. +# 3. Fill the filesystem with directories and files. +# 4. Record all the files and directories checksum information. +# 5. Damaged at most two of the virtual disk files. +# 6. Verify the data is correct to prove raidz2 can withstand 2 devices +# are failing. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify raidz2 pool can withstand two devices are failing." +log_onexit cleanup + +for cnt in 3 4; do + setup_test_env $TESTPOOL raidz2 $cnt + + # + # Inject data corruption errors for raidz2 pool + # + for i in 1 2; do + damage_devs $TESTPOOL $i "label" + log_must is_data_valid $TESTPOOL + log_must clear_errors $TESTPOOL + done + + # + # Inject bad devices errors for raidz2 pool + # + for i in 1 2; do + damage_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i + done + + # + # Inject missing device errors for raidz2 pool + # + for i in 1 2; do + remove_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i + done +done + +log_pass "Raidz2 pool can withstand two devices are failing passed." diff --git a/tests/sys/cddl/zfs/tests/redundancy/redundancy_003_pos.ksh b/tests/sys/cddl/zfs/tests/redundancy/redundancy_003_pos.ksh new file mode 100644 index 00000000000..5971fcefd8a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/redundancy_003_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)redundancy_003_pos.ksh 1.4 07/06/05 SMI" +# + +. $STF_SUITE/tests/redundancy/redundancy.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: redundancy_003_pos +# +# DESCRIPTION: +# A mirrored pool can withstand N-1 device are failing or missing. +# +# STRATEGY: +# 1. Create N(>2,<5) virtual disk files. +# 2. Create mirror pool based on the virtual disk files. +# 3. Fill the filesystem with directories and files. +# 4. Record all the files and directories checksum information. +# 5. Damaged at most N-1 of the virtual disk files. +# 6. Verify the data are correct to prove mirror can withstand N-1 devices +# are failing. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify mirrored pool can withstand N-1 devices are failing or missing." +log_onexit cleanup + +for cnt in 3 2; do + typeset -i i=1 + + setup_test_env $TESTPOOL mirror $cnt + + # + # Inject data corruption errors for mirrored pool + # + while (( i < cnt )); do + damage_devs $TESTPOOL $i "label" + log_must is_data_valid $TESTPOOL + log_must clear_errors $TESTPOOL + + (( i +=1 )) + done + + # + # Inject bad devices errors for mirrored pool + # + i=1 + while (( i < cnt )); do + damage_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i + + (( i +=1 )) + done + + # + # Inject missing device errors for mirrored pool + # + i=1 + while (( i < cnt )); do + remove_devs $TESTPOOL $i + log_must is_data_valid $TESTPOOL + log_must recover_bad_missing_devs $TESTPOOL $i + + (( i +=1 )) + done +done + +log_pass "Mirrored pool can withstand N-1 devices failing as expected." diff --git a/tests/sys/cddl/zfs/tests/redundancy/redundancy_004_neg.ksh b/tests/sys/cddl/zfs/tests/redundancy/redundancy_004_neg.ksh new file mode 100644 index 00000000000..1eaf09c523c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/redundancy_004_neg.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)redundancy_004_neg.ksh 1.4 07/05/25 SMI" +# + +. $STF_SUITE/tests/redundancy/redundancy.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: redundancy_004_neg +# +# DESCRIPTION: +# Striped pool have no data redundancy. Any device errors will +# cause data corruption. +# +# STRATEGY: +# 1. Create N virtual disk file. +# 2. Create stripe pool based on the virtual disk files. +# 3. Fill the filesystem with directories and files. +# 4. Record all the files and directories checksum information. +# 5. Damage one of the virtual disk file. +# 6. Verify the data is error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify striped pool have no data redundancy." +log_onexit cleanup + +for cnt in 2 3; do + setup_test_env $TESTPOOL "" $cnt + damage_devs $TESTPOOL 1 "keep_label" + log_must $ZPOOL clear $TESTPOOL + log_mustnot is_pool_healthy $TESTPOOL +done + +log_pass "Striped pool has no data redundancy as expected." diff --git a/tests/sys/cddl/zfs/tests/redundancy/redundancy_test.sh b/tests/sys/cddl/zfs/tests/redundancy/redundancy_test.sh new file mode 100755 index 00000000000..73ea0317151 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/redundancy_test.sh @@ -0,0 +1,137 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case redundancy_001_pos cleanup +redundancy_001_pos_head() +{ + atf_set "descr" "Verify raidz pool can withstand one device is failing." + atf_set "timeout" 1800 +} +redundancy_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/redundancy_001_pos.ksh || atf_fail "Testcase failed" +} +redundancy_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case redundancy_002_pos cleanup +redundancy_002_pos_head() +{ + atf_set "descr" "Verify raidz2 pool can withstand two devices are failing." + atf_set "timeout" 1800 +} +redundancy_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/redundancy_002_pos.ksh || atf_fail "Testcase failed" +} +redundancy_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case redundancy_003_pos cleanup +redundancy_003_pos_head() +{ + atf_set "descr" "Verify mirrored pool can withstand N-1 devices are failing or missing." + atf_set "timeout" 1800 +} +redundancy_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/redundancy_003_pos.ksh || atf_fail "Testcase failed" +} +redundancy_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case redundancy_004_neg cleanup +redundancy_004_neg_head() +{ + atf_set "descr" "Verify striped pool have no data redundancy." + atf_set "require.progs" zpool + atf_set "timeout" 1800 +} +redundancy_004_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/redundancy_004_neg.ksh || atf_fail "Testcase failed" +} +redundancy_004_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/redundancy.kshlib + . $(atf_get_srcdir)/redundancy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case redundancy_001_pos + atf_add_test_case redundancy_002_pos + atf_add_test_case redundancy_003_pos + atf_add_test_case redundancy_004_neg +} diff --git a/tests/sys/cddl/zfs/tests/redundancy/setup.ksh b/tests/sys/cddl/zfs/tests/redundancy/setup.ksh new file mode 100644 index 00000000000..dfe4773865e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/redundancy/setup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 07/02/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +verify_runnable "global" + +log_pass diff --git a/tests/sys/cddl/zfs/tests/refquota/Makefile b/tests/sys/cddl/zfs/tests/refquota/Makefile new file mode 100644 index 00000000000..7af91081201 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/Makefile @@ -0,0 +1,23 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/refquota +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= refquota_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= refquota_001_pos.ksh +${PACKAGE}FILES+= refquota_005_pos.ksh +${PACKAGE}FILES+= refquota.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= refquota_004_pos.ksh +${PACKAGE}FILES+= refquota_002_pos.ksh +${PACKAGE}FILES+= refquota_003_pos.ksh +${PACKAGE}FILES+= refquota_006_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/refquota/cleanup.ksh b/tests/sys/cddl/zfs/tests/refquota/cleanup.ksh new file mode 100644 index 00000000000..3997674d22c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/cleanup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "both" +if ! fs_prop_exist "refquota" ; then + log_unsupported "refquota is not supported by this release." +fi + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota.cfg b/tests/sys/cddl/zfs/tests/refquota/refquota.cfg new file mode 100644 index 00000000000..9bb06f7e381 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refquota.cfg 1.2 08/08/15 SMI" +# + +export TESTFILE=testfile${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota_001_pos.ksh b/tests/sys/cddl/zfs/tests/refquota/refquota_001_pos.ksh new file mode 100644 index 00000000000..ad14597a383 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota_001_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refquota_001_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refquota_001_pos +# +# DESCRIPTION: +# refquota limits the amount of space a dataset can consume, but does +# not include space used by descendents. +# +# STRATEGY: +# 1. Setting refquota in given filesystem +# 2. Create descendent filesystem +# 3. Verify refquota limits the amount of space a dataset can consume +# 4. Verify the limit does not impact descendents +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-12-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "refquota limits the amount of space a dataset can consume, " \ + "but does not include space used by descendents." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +sub=$fs/sub +log_must $ZFS create $sub + +log_must $ZFS set refquota=10M $fs +mntpnt=$(get_prop mountpoint $fs) + +log_mustnot $MKFILE 11M $mntpnt/file +log_must $MKFILE 9M $mntpnt/file +log_must $ZFS snapshot $fs@snap +log_mustnot $MKFILE 2M $mntpnt/file2 + +mntpnt=$(get_prop mountpoint $sub) +log_must $MKFILE 10M $mntpnt/file +log_must $ZFS snapshot $sub@snap +log_must $MKFILE 10 $mntpnt/file2 + +log_pass "refquota limits the amount of space a dataset can consume, " \ + "but does not include space used by descendents." diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota_002_pos.ksh b/tests/sys/cddl/zfs/tests/refquota/refquota_002_pos.ksh new file mode 100644 index 00000000000..30e74eca670 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota_002_pos.ksh @@ -0,0 +1,103 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refquota_002_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refquota_002_pos +# +# DESCRIPTION: +# Quotas are enforced using the minimum of the two properties: +# quota & refquota +# +# STRATEGY: +# 1. Set value for quota and refquota. Quota less than refquota. +# 2. Creating file which should be limited by quota. +# 3. Switch the value of quota and refquota. +# 4. Verify file should be limited by refquota. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Quotas are enforced using the minimum of the two properties" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +log_must $ZFS set quota=15M $fs +log_must $ZFS set refquota=25M $fs + +mntpnt=$(get_prop mountpoint $fs) +log_mustnot $MKFILE 20M $mntpnt/$TESTFILE +typeset -i used quota +used=$(get_prop used $fs) +quota=$(get_prop quota $fs) +((used = used / (1024 * 1024))) +((quota = quota / (1024 * 1024))) +if [[ $used -ne $quota ]]; then + log_fail "ERROR: $used -ne $quota Quotas are not limited by quota" +fi + +# +# Switch the value of them and try again +# +[ -f $mntpnt/$TESTFILE ] && log_must $RM $mntpnt/$TESTFILE +log_must $ZFS set quota=25M $fs +log_must $ZFS set refquota=15M $fs + +log_mustnot $MKFILE 20M $mntpnt/$TESTFILE +used=$(get_prop used $fs) +refquota=$(get_prop refquota $fs) +((used = used / (1024 * 1024))) +((refquota = refquota / (1024 * 1024))) +if [[ $used -ne $refquota ]]; then + log_fail "ERROR: $used -ne $refquota Quotas are not limited by refquota" +fi + +log_pass "Quotas are enforced using the minimum of the two properties" diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota_003_pos.ksh b/tests/sys/cddl/zfs/tests/refquota/refquota_003_pos.ksh new file mode 100644 index 00000000000..6f9c420eac4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota_003_pos.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refquota_003_pos.ksh 1.1 08/02/29 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refquota_003_pos +# +# DESCRIPTION: +# Sub-filesystem quotas are not enforced by property 'refquota' +# +# STRATEGY: +# 1. Setting quota and refquota for parent. refquota < quota +# 2. Verify sub-filesystem will not be limited by refquota +# 3. Verify sub-filesystem will only be limited by quota +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Sub-filesystem quotas are not enforced by property 'refquota'" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +log_must $ZFS set quota=25M $fs +log_must $ZFS set refquota=10M $fs +log_must $ZFS create $fs/subfs + +mntpnt=$(get_prop mountpoint $fs/subfs) +log_must $MKFILE 20M $mntpnt/$TESTFILE + +typeset -i used quota refquota +used=$(get_prop used $fs) +refquota=$(get_prop refquota $fs) +((used = used / (1024 * 1024))) +((refquota = refquota / (1024 * 1024))) +if [[ $used -lt $refquota ]]; then + log_fail "ERROR: $used < $refquota subfs quotas are limited by refquota" +fi + +log_mustnot $MKFILE 20M $mntpnt/$TESTFILE.2 +used=$(get_prop used $fs) +quota=$(get_prop quota $fs) +((used = used / (1024 * 1024))) +((quota = quota / (1024 * 1024))) +if [[ $used -gt $quota ]]; then + log_fail "ERROR: $used > $quota subfs quotas aren't limited by quota" +fi + +log_pass "Sub-filesystem quotas are not enforced by property 'refquota'" diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota_004_pos.ksh b/tests/sys/cddl/zfs/tests/refquota/refquota_004_pos.ksh new file mode 100644 index 00000000000..8578f397d4f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota_004_pos.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refquota_004_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refquota_004_pos +# +# DESCRIPTION: +# refquotas are not limited by snapshots. +# +# STRATEGY: +# 1. Setting refquota < quota +# 2. Create file in filesytem, take snapshot and remove the file +# 3. Verify snapshot will not consume refquota +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "refquotas are not limited by snapshots." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +log_must $ZFS set quota=25M $fs +log_must $ZFS set refquota=15M $fs + +mntpnt=$(get_prop mountpoint $fs) +typeset -i i=0 +while ((i < 3)); do + log_must $MKFILE 7M $mntpnt/$TESTFILE.$i + log_must $ZFS snapshot $fs@snap.$i + log_must $RM $mntpnt/$TESTFILE.$i + + ((i += 1)) +done + +# +# Verify out of the limitation of 'quota' +# +log_mustnot $MKFILE 7M $mntpnt/$TESTFILE + +log_pass "refquotas are not limited by snapshots." diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota_005_pos.ksh b/tests/sys/cddl/zfs/tests/refquota/refquota_005_pos.ksh new file mode 100644 index 00000000000..1c15b8c9fb0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota_005_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refquota_005_pos.ksh 1.1 08/02/29 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refquota_005_pos +# +# DESCRIPTION: +# refquotas are not limited by sub-filesystem snapshots. +# +# STRATEGY: +# 1. Setting refquota < quota for parent +# 2. Create file in sub-filesytem, take snapshot and remove the file +# 3. Verify sub-filesystem snapshot will not consume refquota +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "refquotas are not limited by sub-filesystem snapshots." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +log_must $ZFS set quota=25M $fs +log_must $ZFS set refquota=15M $fs +log_must $ZFS create $fs/subfs + +mntpnt=$(get_prop mountpoint $fs/subfs) +typeset -i i=0 +while ((i < 3)); do + log_must $MKFILE 7M $mntpnt/$TESTFILE.$i + log_must $ZFS snapshot $fs/subfs@snap.$i + log_must $RM $mntpnt/$TESTFILE.$i + + ((i += 1)) +done + +# +# Verify out of the limitation of 'quota' +# +log_mustnot $MKFILE 7M $mntpnt/$TESTFILE + +log_pass "refquotas are not limited by sub-filesystem snapshots" diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota_006_neg.ksh b/tests/sys/cddl/zfs/tests/refquota/refquota_006_neg.ksh new file mode 100644 index 00000000000..0e2b0f9cb67 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota_006_neg.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refquota_006_neg.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refquota_006_neg +# +# DESCRIPTION: +# 'zfs set refquota/refreserv' can handle incorrect arguments correctly. +# +# STRATEGY: +# 1. Setup incorrect arguments arrays. +# 2. Set the bad argument to refquota. +# 3. Verify zfs can handle it correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-09) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS set refquota=none $TESTPOOL/$TESTFS + log_must $ZFS set refreserv=none $TESTPOOL/$TESTFS +} + +log_assert "'zfs set refquota' can handle incorrect arguments correctly." +log_onexit cleanup + +set -A badopt \ + "None" "-1" "1TT" "%5" \ + "123!" "@456" "7#89" "0\$" \ + "abc123%" "123%s" "12%s3" "%c123" \ + "123%d" "%x123" "12%p3" "^def456" \ + "x0" + +typeset -i i=0 +while ((i < ${#badopt[@]})); do + log_mustnot $ZFS set refquota=${badopt[$i]} $TESTPOOL/$TESTFS + log_mustnot $ZFS set refreserv=${badopt[$i]} $TESTPOOL/$TESTFS + + ((i += 1)) +done + +# Try using a null as the opt value. We can't use log_mustnot, because +# that echoes the character, which screws up ATF by creating a non-well formed +# XML file +$ZFS set refquota="\0" $TESTPOOL/$TESTFS > /dev/null 2>&1 +[[ $? != 0 ]] || log_fail "FAILURE: zfs set refquota=\\\\0 passed" +$ZFS set refreserv="\0" $TESTPOOL/$TESTFS > /dev/null 2>&1 +[[ $? != 0 ]] || log_fail "FAILURE: zfs set refreserv=\\\\0 passed" + +log_pass "'zfs set refquota' can handle incorrect arguments correctly." diff --git a/tests/sys/cddl/zfs/tests/refquota/refquota_test.sh b/tests/sys/cddl/zfs/tests/refquota/refquota_test.sh new file mode 100755 index 00000000000..28b71359841 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/refquota_test.sh @@ -0,0 +1,182 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case refquota_001_pos cleanup +refquota_001_pos_head() +{ + atf_set "descr" "refquota limits the amount of space a dataset can consume,but does not include space used by descendents." + atf_set "require.progs" zfs +} +refquota_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refquota_001_pos.ksh || atf_fail "Testcase failed" +} +refquota_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refquota_002_pos cleanup +refquota_002_pos_head() +{ + atf_set "descr" "Quotas are enforced using the minimum of the two properties" + atf_set "require.progs" zfs +} +refquota_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refquota_002_pos.ksh || atf_fail "Testcase failed" +} +refquota_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refquota_003_pos cleanup +refquota_003_pos_head() +{ + atf_set "descr" "Sub-filesystem quotas are not enforced by property 'refquota'" + atf_set "require.progs" zfs +} +refquota_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refquota_003_pos.ksh || atf_fail "Testcase failed" +} +refquota_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refquota_004_pos cleanup +refquota_004_pos_head() +{ + atf_set "descr" "refquotas are not limited by snapshots." + atf_set "require.progs" zfs +} +refquota_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refquota_004_pos.ksh || atf_fail "Testcase failed" +} +refquota_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refquota_005_pos cleanup +refquota_005_pos_head() +{ + atf_set "descr" "refquotas are not limited by sub-filesystem snapshots." + atf_set "require.progs" zfs +} +refquota_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refquota_005_pos.ksh || atf_fail "Testcase failed" +} +refquota_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refquota_006_neg cleanup +refquota_006_neg_head() +{ + atf_set "descr" "'zfs set refquota' can handle incorrect arguments correctly." + atf_set "require.progs" zfs +} +refquota_006_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refquota_006_neg.ksh || atf_fail "Testcase failed" +} +refquota_006_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case refquota_001_pos + atf_add_test_case refquota_002_pos + atf_add_test_case refquota_003_pos + atf_add_test_case refquota_004_pos + atf_add_test_case refquota_005_pos + atf_add_test_case refquota_006_neg +} diff --git a/tests/sys/cddl/zfs/tests/refquota/setup.ksh b/tests/sys/cddl/zfs/tests/refquota/setup.ksh new file mode 100644 index 00000000000..fa42935d095 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refquota/setup.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 08/02/29 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "both" +if ! fs_prop_exist "refquota" ; then + log_unsupported "refquota is not supported by this release." +fi + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/refreserv/Makefile b/tests/sys/cddl/zfs/tests/refreserv/Makefile new file mode 100644 index 00000000000..1ac7a8aa9d8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/refreserv +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= refreserv_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= refreserv_004_pos.ksh +${PACKAGE}FILES+= refreserv_005_pos.ksh +${PACKAGE}FILES+= refreserv_001_pos.ksh +${PACKAGE}FILES+= refreserv_003_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= refreserv.cfg +${PACKAGE}FILES+= refreserv_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/refreserv/cleanup.ksh b/tests/sys/cddl/zfs/tests/refreserv/cleanup.ksh new file mode 100644 index 00000000000..3de896d1401 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/cleanup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "both" +if ! fs_prop_exist "refreservation" ; then + log_unsupported "refreservation is not supported in this system." +fi + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/refreserv/refreserv.cfg b/tests/sys/cddl/zfs/tests/refreserv/refreserv.cfg new file mode 100644 index 00000000000..6df3c120a37 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/refreserv.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refreserv.cfg 1.2 08/08/15 SMI" +# + +export TESTFILE=testfile${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/refreserv/refreserv_001_pos.ksh b/tests/sys/cddl/zfs/tests/refreserv/refreserv_001_pos.ksh new file mode 100644 index 00000000000..d4fa0707dd3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/refreserv_001_pos.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refreserv_001_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refreserv_001_pos +# +# DESCRIPTION: +# Reservations are enforced using the maximum of 'reserv' and 'refreserv' +# +# STRATEGY: +# 1. Setting quota for parent filesystem. +# 2. Setting reservation and refreservation for sub-filesystem. +# 3. Verify the sub-fs reservation are enforced by the maximum of 'reserv' +# and 'refreserv'. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Reservations are enforced using the maximum of " \ + "'reserv' and 'refreserv'" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS ; subfs=$fs/subfs +log_must $ZFS create $subfs +log_must $ZFS set quota=25M $fs + +log_must $ZFS set reserv=10M $subfs +log_must $ZFS set refreserv=20M $subfs +mntpnt=$(get_prop mountpoint $fs) +log_mustnot $MKFILE 15M $mntpnt/$TESTFILE + +log_must $RM -f $mntpnt/$TESTFILE + +log_must $ZFS set reserv=20M $subfs +log_must $ZFS set refreserv=10M $subfs +log_mustnot $MKFILE 15M $mntpnt/$TESTFILE + +log_pass "Reservations are enforced using the maximum of " \ + "'reserv' and 'refreserv'" diff --git a/tests/sys/cddl/zfs/tests/refreserv/refreserv_002_pos.ksh b/tests/sys/cddl/zfs/tests/refreserv/refreserv_002_pos.ksh new file mode 100644 index 00000000000..d2f32b18ddf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/refreserv_002_pos.ksh @@ -0,0 +1,127 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refreserv_002_pos.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refreserv_002_pos +# +# DESCRIPTION: +# Setting full size as refreservation, verify no snapshot can be created. +# +# STRATEGY: +# 1. Setting full size as refreservation on pool +# 2. Verify no snapshot can be created on this pool +# 3. Setting full size as refreservation on filesystem +# 4. Verify no snapshot can be created on it and its subfs +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if is_global_zone ; then + log_must $ZFS set refreservation=none $TESTPOOL + + if datasetexists $TESTPOOL@snap ; then + log_must $ZFS destroy -f $TESTPOOL@snap + fi + fi + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +# This function iteratively increases refreserv to its highest possible +# value. Simply setting refreserv == quota can allow enough writes to +# complete that the test fails. +function max_refreserv +{ + typeset ds=$1 + typeset -i incsize=131072 + typeset -i rr=$(get_prop available $ds) + + log_must $ZFS set refreserv=$rr $ds + while :; do + $ZFS set refreserv=$((rr + incsize)) $ds >/dev/null 2>&1 + if [[ $? == 0 ]]; then + ((rr += incsize)) + continue + else + ((incsize /= 2)) + ((incsize == 0)) && break + fi + done +} + + +log_assert "Setting full size as refreservation, verify no snapshot " \ + "can be created." +log_onexit cleanup + +log_must $ZFS create $TESTPOOL/$TESTFS/subfs + +typeset datasets +if is_global_zone; then + datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs" +else + datasets="$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs" +fi + +for ds in $datasets; do + # + # Verify refreservation on dataset + # + log_must $ZFS set quota=25M $ds + max_refreserv $ds + log_mustnot $ZFS snapshot $ds@snap + if datasetexists $ds@snap ; then + log_fail "ERROR: $ds@snap should not exists." + fi + + log_must $ZFS set quota=none $ds + log_must $ZFS set refreservation=none $ds +done + +log_pass "Setting full size as refreservation, verify no snapshot " \ + "can be created." diff --git a/tests/sys/cddl/zfs/tests/refreserv/refreserv_003_pos.ksh b/tests/sys/cddl/zfs/tests/refreserv/refreserv_003_pos.ksh new file mode 100644 index 00000000000..0168b0ac8dd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/refreserv_003_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refreserv_003_pos.ksh 1.1 08/02/29 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refreserv_003_pos +# +# DESCRIPTION: +# Verify a snapshot will only be allowed if there is enough free pool +# space outside of this refreservation. +# +# STRATEGY: +# 1. Setting quota and refservation +# 2. Verify snapshot can be created, when used =< quota - refreserv +# 3. Verify failed to create snapshot, when used > quota - refreserv +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Verify a snapshot will only be allowed if there is enough " \ + "free space outside of this refreservation." +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS +log_must $ZFS set quota=25M $fs +log_must $ZFS set refreservation=10M $fs + +mntpnt=$(get_prop mountpoint $fs) +log_must $MKFILE 7M $mntpnt/$TESTFILE +log_must $ZFS snapshot $fs@snap + +log_must $MKFILE 7M $mntpnt/$TESTFILE.2 +log_must $ZFS snapshot $fs@snap2 + +log_must $MKFILE 7M $mntpnt/$TESTFILE.3 +log_mustnot $ZFS snapshot $fs@snap3 +if datasetexists $fs@snap3 ; then + log_fail "ERROR: $fs@snap3 should not exists." +fi + +log_pass "Verify a snapshot will only be allowed if there is enough " \ + "free space outside of this refreservation." diff --git a/tests/sys/cddl/zfs/tests/refreserv/refreserv_004_pos.ksh b/tests/sys/cddl/zfs/tests/refreserv/refreserv_004_pos.ksh new file mode 100644 index 00000000000..4b8e2b3d629 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/refreserv_004_pos.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refreserv_004_pos.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refreserv_004_pos +# +# DESCRIPTION: +# Verify refreservation is limited by available space. +# +# STRATEGY: +# 1. Setting quota and refreservation on parent filesystem. +# 2. Get available space on sub-filesystem. +# 3. Verify refreservation is limited by available on it. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if is_global_zone ; then + log_must $ZFS set refreservation=none $TESTPOOL + fi + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Verify refreservation is limited by available space." +log_onexit cleanup + +pool=$TESTPOOL ; fs=$pool/$TESTFS ; subfs=$fs/subfs +log_must $ZFS create $subfs + +typeset datasets +if is_global_zone; then + datasets="$pool $fs" +else + datasets="$fs" +fi + +for ds in $datasets; do + log_must $ZFS set quota=25M $ds + log_must $ZFS set refreservation=15M $ds + + typeset avail + avail=5M + log_must $ZFS set refreservation=$avail $subfs + typeset mntpnt + mntpnt=$(get_prop mountpoint $subfs) + log_must $MKFILE $avail $mntpnt/$TESTFILE + + typeset exceed + exceed=15M + log_mustnot $ZFS set refreservation=$exceed $subfs + log_mustnot $MKFILE $exceed $mntpnt/$TESTFILE + + log_must $ZFS set quota=none $ds +done + +log_pass "Verify refreservation is limited by available space." diff --git a/tests/sys/cddl/zfs/tests/refreserv/refreserv_005_pos.ksh b/tests/sys/cddl/zfs/tests/refreserv/refreserv_005_pos.ksh new file mode 100644 index 00000000000..29cd01f0485 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/refreserv_005_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)refreserv_005_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: refreserv_005_pos +# +# DESCRIPTION: +# Volume refreservation is limited by volsize +# +# STRATEGY: +# 1. Create volume on filesystem +# 2. Setting quota for parenet filesytem +# 3. Verify volume refreservation is only limited by volsize +# 4. Verify volume refreservation can be changed when volsize changed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-11-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + log_must $ZFS destroy -rf $TESTPOOL/$TESTFS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Volume refreservation is limited by volsize" +log_onexit cleanup + +fs=$TESTPOOL/$TESTFS; vol=$fs/vol +log_must $ZFS create -V 10M $vol + +# Verify the parent filesystem does not affect volume +log_must $ZFS set quota=25M $fs +log_must $ZFS set refreservation=10M $vol +avail=$(get_prop mountpoint $vol) +log_mustnot $ZFS set refreservation=$avail $vol + +# Verify it is affected by volsize +log_must $ZFS set volsize=15M $vol +log_must $ZFS set refreservation=15M $vol +log_mustnot $ZFS set refreservation=16M $vol + +log_pass "Volume refreservation is limited by volsize" diff --git a/tests/sys/cddl/zfs/tests/refreserv/refreserv_test.sh b/tests/sys/cddl/zfs/tests/refreserv/refreserv_test.sh new file mode 100755 index 00000000000..cef9353dd4c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/refreserv_test.sh @@ -0,0 +1,157 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case refreserv_001_pos cleanup +refreserv_001_pos_head() +{ + atf_set "descr" "Reservations are enforced using the maximum of'reserv' and 'refreserv'" + atf_set "require.progs" zfs +} +refreserv_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refreserv_001_pos.ksh || atf_fail "Testcase failed" +} +refreserv_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refreserv_002_pos cleanup +refreserv_002_pos_head() +{ + atf_set "descr" "Setting full size as refreservation, verify no snapshotcan be created." + atf_set "require.progs" zfs +} +refreserv_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refreserv_002_pos.ksh || atf_fail "Testcase failed" +} +refreserv_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refreserv_003_pos cleanup +refreserv_003_pos_head() +{ + atf_set "descr" "Verify a snapshot will only be allowed if there is enoughfree space outside of this refreservation." + atf_set "require.progs" zfs +} +refreserv_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refreserv_003_pos.ksh || atf_fail "Testcase failed" +} +refreserv_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refreserv_004_pos cleanup +refreserv_004_pos_head() +{ + atf_set "descr" "Verify refreservation is limited by available space." + atf_set "require.progs" zfs +} +refreserv_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refreserv_004_pos.ksh || atf_fail "Testcase failed" +} +refreserv_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case refreserv_005_pos cleanup +refreserv_005_pos_head() +{ + atf_set "descr" "Volume refreservation is limited by volsize" + atf_set "require.progs" zfs +} +refreserv_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/refreserv_005_pos.ksh || atf_fail "Testcase failed" +} +refreserv_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/refreserv.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case refreserv_001_pos + atf_add_test_case refreserv_002_pos + atf_add_test_case refreserv_003_pos + atf_add_test_case refreserv_004_pos + atf_add_test_case refreserv_005_pos +} diff --git a/tests/sys/cddl/zfs/tests/refreserv/setup.ksh b/tests/sys/cddl/zfs/tests/refreserv/setup.ksh new file mode 100644 index 00000000000..95f1ac7b74a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/refreserv/setup.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 08/02/29 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "both" +if ! fs_prop_exist "refreservation" ; then + log_unsupported "refreservation is not supported in this system." +fi + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/rename_dirs/Makefile b/tests/sys/cddl/zfs/tests/rename_dirs/Makefile new file mode 100644 index 00000000000..582931c0fb0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rename_dirs/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/rename_dirs +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= rename_dirs_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= rename_dirs_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= rename_dirs.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/rename_dirs/cleanup.ksh b/tests/sys/cddl/zfs/tests/rename_dirs/cleanup.ksh new file mode 100644 index 00000000000..2ee7cfb6028 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rename_dirs/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs.cfg b/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs.cfg new file mode 100644 index 00000000000..c64983c4bb5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rename_dirs.cfg 1.2 08/08/15 SMI" +# + +export WAITTIME=600 +export STF_TIMEOUT=1200 diff --git a/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs_001_pos.ksh b/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs_001_pos.ksh new file mode 100644 index 00000000000..e8f680a5c9e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs_001_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rename_dirs_001_pos.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +########################################################################### +# +# __stc_assertion_start +# +# ID: rename_dirs_001_pos +# +# DESCRIPTION: +# Create two directory trees in ZFS filesystem, and concurently rename +# directory across the two trees. ZFS should be able to handle the race +# situation. +# +# STRATEGY: +# 1. Create a ZFS filesystem +# 2. Make two directory tree in the zfs file system +# 3. Continually rename directory from one tree to another tree in two process +# 4. After the specified time duration, the system should not be panic. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-02-05) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + log_must $RM -rf $TESTDIR/* +} + +log_assert "ZFS can handle race directory rename operation." + +log_onexit cleanup + +$CD $TESTDIR +$MKDIR -p 1/2/3/4/5 a/b/c/d/e + +$RENAME_DIR & + +$SLEEP $WAITTIME +typeset -i retval=1 +$PGREP $RENAME_DIR >/dev/null 2>&1 +retval=$? +if (( $retval == 0 )); then + $PKILL -9 $RENAME_DIR >/dev/null 2>&1 +fi + +log_pass "ZFS handle race directory rename operation as expected." diff --git a/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs_test.sh b/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs_test.sh new file mode 100755 index 00000000000..84fb11b542d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rename_dirs/rename_dirs_test.sh @@ -0,0 +1,56 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case rename_dirs_001_pos cleanup +rename_dirs_001_pos_head() +{ + atf_set "descr" "ZFS can handle race directory rename operation." + atf_set "timeout" 1200 +} +rename_dirs_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rename_dirs.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rename_dirs_001_pos.ksh || atf_fail "Testcase failed" +} +rename_dirs_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rename_dirs.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case rename_dirs_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/rename_dirs/setup.ksh b/tests/sys/cddl/zfs/tests/rename_dirs/setup.ksh new file mode 100644 index 00000000000..e3aad622ec2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rename_dirs/setup.ksh @@ -0,0 +1,35 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/replacement/Makefile b/tests/sys/cddl/zfs/tests/replacement/Makefile new file mode 100644 index 00000000000..85ffd323573 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/replacement/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/replacement +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= replacement_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= replacement_002_pos.ksh +${PACKAGE}FILES+= replacement_003_pos.ksh +${PACKAGE}FILES+= replacement_001_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= replacement.kshlib + +.include diff --git a/tests/sys/cddl/zfs/tests/replacement/cleanup.ksh b/tests/sys/cddl/zfs/tests/replacement/cleanup.ksh new file mode 100644 index 00000000000..fa10285bd98 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/replacement/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/replacement/replacement.kshlib b/tests/sys/cddl/zfs/tests/replacement/replacement.kshlib new file mode 100644 index 00000000000..d3f370de924 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/replacement/replacement.kshlib @@ -0,0 +1,51 @@ +# vim: filetype=sh +# Common routines for replacement tests. + +# $FreeBSD$ + +function check_vdev_action # [disk2] +{ + typeset action=$1 + typeset expect=$2 + typeset opt=$3 + typeset disk1="$4" + typeset disk2="$5" + + busy_path $TESTDIR + $expect $ZPOOL $action $opt $TESTPOOL $disk1 $disk2 + reap_children + log_must $ZPOOL export $TESTPOOL + log_must $ZPOOL import $TESTPOOL + log_must $ZFS umount $TESTPOOL/$TESTFS + log_must $ZDB -cdui $TESTPOOL/$TESTFS + log_must $ZFS mount $TESTPOOL/$TESTFS +} + +function pool_action # +{ + typeset tvd_type=$1 + typeset action=$2 + typeset actionexpect=$3 + typeset existexpect=$4 + + typeset disk=${disk_array[3]} + typeset short=${disk##/dev/} + + for opt in "" "-f"; do + [ "$action" = "detach" -a "$opt" = "-f" ] && continue + create_pool $TESTPOOL $tvd_type ${disk_array[@]:0:3} + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + check_vdev_action $action $actionexpect "$opt" \ + ${disk_array[0]} $disk + + $existexpect eval "$ZPOOL iostat -v $TESTPOOL | $GREP -q $short" + destroy_pool $TESTPOOL + done +} + +function replacement_cleanup +{ + poolexists $TESTPOOL && log_must $ZPOOL status $TESTPOOL + reap_children +} diff --git a/tests/sys/cddl/zfs/tests/replacement/replacement_001_pos.ksh b/tests/sys/cddl/zfs/tests/replacement/replacement_001_pos.ksh new file mode 100644 index 00000000000..3a41f3aa269 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/replacement/replacement_001_pos.ksh @@ -0,0 +1,44 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2014 Spectra Logic Corporation. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/replacement/replacement.kshlib + +verify_runnable "global" + +child_pids="" +log_onexit replacement_cleanup +set_disks + +log_assert "Replacing a disk during I/O completes." +for pooltype in "" "raidz" "raidz1" "mirror"; do + pool_action "$pooltype" replace log_must log_must +done +log_pass diff --git a/tests/sys/cddl/zfs/tests/replacement/replacement_002_pos.ksh b/tests/sys/cddl/zfs/tests/replacement/replacement_002_pos.ksh new file mode 100644 index 00000000000..3f2dfaecc26 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/replacement/replacement_002_pos.ksh @@ -0,0 +1,50 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2014 Spectra Logic Corporation. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/replacement/replacement.kshlib + +verify_runnable "global" + +child_pids="" +log_onexit replacement_cleanup +set_disks + +log_assert "Attaching a disk during I/O completes for mirrors and stripes." +for pooltype in "" "mirror"; do + pool_action "$pooltype" attach log_must log_must +done + +log_note "Verify 'zpool attach' fails for RAIDZ." +for pooltype in "raidz1" "raidz2"; do + pool_action "$pooltype" attach log_mustnot log_mustnot +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/replacement/replacement_003_pos.ksh b/tests/sys/cddl/zfs/tests/replacement/replacement_003_pos.ksh new file mode 100644 index 00000000000..6b46380b7a2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/replacement/replacement_003_pos.ksh @@ -0,0 +1,48 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Copyright 2014 Spectra Logic Corporation. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/replacement/replacement.kshlib + +verify_runnable "global" + +child_pids="" +log_onexit replacement_cleanup +set_disks + +log_assert "Detaching a disk during I/O completes for mirrors." +pool_action mirror detach log_must log_mustnot + +log_note "Verify 'zpool detach' fails with non-mirrors." +for pooltype in "" "raidz" "raidz1" ; do + pool_action "$pooltype" detach log_mustnot log_mustnot +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/replacement/replacement_test.sh b/tests/sys/cddl/zfs/tests/replacement/replacement_test.sh new file mode 100755 index 00000000000..6aa8c0087df --- /dev/null +++ b/tests/sys/cddl/zfs/tests/replacement/replacement_test.sh @@ -0,0 +1,100 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case replacement_001_pos cleanup +replacement_001_pos_head() +{ + atf_set "descr" "Replacing a disk during I/O completes." + atf_set "require.progs" zfs zpool zdb + atf_set "timeout" 3600 +} +replacement_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 3 + ksh93 $(atf_get_srcdir)/replacement_001_pos.ksh || atf_fail "Testcase failed" +} +replacement_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case replacement_002_pos cleanup +replacement_002_pos_head() +{ + atf_set "descr" "Replacing a disk during I/O completes." + atf_set "require.progs" zfs zpool zdb + atf_set "timeout" 3600 +} +replacement_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 3 + ksh93 $(atf_get_srcdir)/replacement_002_pos.ksh || atf_fail "Testcase failed" +} +replacement_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case replacement_003_pos cleanup +replacement_003_pos_head() +{ + atf_set "descr" "Replacing a disk during I/O completes." + atf_set "require.progs" zfs zpool zdb + atf_set "timeout" 3600 +} +replacement_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/replacement_003_pos.ksh || atf_fail "Testcase failed" +} +replacement_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + atf_add_test_case replacement_001_pos + atf_add_test_case replacement_002_pos + atf_add_test_case replacement_003_pos +} diff --git a/tests/sys/cddl/zfs/tests/reservation/Makefile b/tests/sys/cddl/zfs/tests/reservation/Makefile new file mode 100644 index 00000000000..596c35c4f98 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/Makefile @@ -0,0 +1,36 @@ +# $FreeBSD$ + +.include + +PACKAGE= tests +TESTSDIR= ${TESTSBASE}/sys/cddl/zfs/tests/reservation +FILESDIR= ${TESTSDIR} + +ATF_TESTS_KSH93+= reservation_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= reservation.cfg +${PACKAGE}FILES+= reservation_007_pos.ksh +${PACKAGE}FILES+= reservation_003_pos.ksh +${PACKAGE}FILES+= reservation_012_pos.ksh +${PACKAGE}FILES+= reservation_016_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= reservation_013_pos.ksh +${PACKAGE}FILES+= reservation_017_pos.ksh +${PACKAGE}FILES+= reservation_006_pos.ksh +${PACKAGE}FILES+= reservation_002_pos.ksh +${PACKAGE}FILES+= reservation_011_pos.ksh +${PACKAGE}FILES+= reservation_015_pos.ksh +${PACKAGE}FILES+= reservation_004_pos.ksh +${PACKAGE}FILES+= reservation_008_pos.ksh +${PACKAGE}FILES+= reservation_009_pos.ksh +${PACKAGE}FILES+= reservation_005_pos.ksh +${PACKAGE}FILES+= reservation_001_pos.ksh +${PACKAGE}FILES+= reservation.kshlib +${PACKAGE}FILES+= reservation_010_pos.ksh +${PACKAGE}FILES+= reservation_014_pos.ksh +${PACKAGE}FILES+= reservation_018_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/reservation/cleanup.ksh b/tests/sys/cddl/zfs/tests/reservation/cleanup.ksh new file mode 100644 index 00000000000..26ce7c30a0b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation.cfg b/tests/sys/cddl/zfs/tests/reservation/reservation.cfg new file mode 100644 index 00000000000..b47a75cfa37 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation.cfg @@ -0,0 +1,47 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation.cfg 1.3 08/08/15 SMI" +# + +export RESV_DELTA=5242880 +export RESV_TOLERANCE=5242880 # Acceptable limit (5MB) for diff in space stats +export RESV_SIZE=52428800 # Default reservation size (50MB) +export RESV_FREE_SPACE=52428800 # Amount of space (50MB) to leave free in a pool +export RESV_NUM_FS=10 # Number of filesystems to create +export RESV_ITER=10 # Number of iterations + +export VOLSIZE=64M +export BLOCK_SIZE=8192 +export ENOSPC=28 + +export ZFSROOT= +export TESTVOL=testvol${TESTCASE_ID} +export TESTVOL2=testvol2-${TESTCASE_ID} +export TESTFILE1=file1.${TESTCASE_ID} +export TESTFILE2=file2.${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation.kshlib b/tests/sys/cddl/zfs/tests/reservation/reservation.kshlib new file mode 100644 index 00000000000..e73528b77be --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation.kshlib @@ -0,0 +1,180 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation.kshlib 1.3 09/01/12 SMI" +# + +# +# Function to set the reservation property of a dataset to +# 'none' and verify that it is correctly set using both the +# "normal" 'zfs get reservation' and the '-p' option which +# gives a numerical value. +# +function zero_reservation +{ + typeset resv_val + dataset=$1 + + log_must $ZFS set reservation=none $dataset + log_must $ZFS set refreservation=none $dataset + + resv_val=`$ZFS get -H refreservation $dataset | awk '{print $3}'` + if [[ $? -ne 0 ]]; then + log_fail "Unable to get reservation prop on $dataset" + elif [[ $resv_val != "none" ]]; then + log_fail "Reservation not 'none' ($resv_val) as expected" + fi + + + resv_val=`$ZFS get -pH refreservation $dataset | awk '{print $3}'` + if [[ $? -ne 0 ]]; then + log_fail "Unable to get reservation prop on $dataset" + elif [[ $resv_val -ne 0 ]]; then + log_fail "Reservation not 0 ($resv_val) as expected" + fi + + return 0 +} + +# +# Utility function to see if two values are within a certain specified +# limit of each other. Used primarily to check that a dataset's parent +# is correctly accounting for space used/available. Need this function as +# currently there is some slop in the way space is accounted (i.e. can't +# do a direct comparison). +# +function within_limits +{ + typeset -l valA=$1 + typeset -l valB=$2 + typeset -l delta=$3 + + if (( valA <= valB )); then + if (( (valB - valA) <= delta )); then + return 0 + fi + elif (( valB <= valA )); then + if (( (valA - valB) <= delta )); then + return 0 + fi + fi + + return 1 +} + +# +# Function to create and mount multiple filesystems. The filesystem +# will be named according to the name specified with a suffix value +# taken from the loop counter. +# +function create_multiple_fs # num_fs base_fs_name base_mnt_name +{ + typeset -i iter=0 + typeset -i count=$1 + typeset FS_NAME=$2 + typeset MNT_NAME=$3 + + while (( $iter < $count )); do + log_must $ZFS create ${FS_NAME}$iter + log_must $ZFS set mountpoint=${MNT_NAME}$iter ${FS_NAME}$iter + (( iter = iter + 1 )) + done +} + +# +# This function compute the largest volume size which is multiple of volume +# block size (default 8K) and not greater than the largest expected volsize. +# +# $1 The largest expected volume size. +# $2 The volume block size +# +function floor_volsize # [volblksize] +{ + typeset -l largest_volsize=$1 + typeset -l volblksize=${2:-8192} + + if (( largest_volsize < volblksize )); then + log_fail "The largest_volsize must be greater than volblksize." + fi + typeset -l real_volsize + typeset -l n + + (( n = largest_volsize / volblksize )) + (( largest_volsize = volblksize * n )) + + print $largest_volsize +} + +# +# Simple function to get the expected reservation for a ZVOL given the +# volume size, block size, and number of copies. +# +# NB: This routine must be kept in sync with the ZFS library function +# libzfs_dataset.c:zvol_volsize_to_reservation(). Refer to that function +# for the logic behind the calculations. +# +function zvol_volsize_to_reservation +{ + typeset resv_val + typeset nblocks + typeset numdb + typeset volsize=$1 + typeset volblocksize=$2 + typeset ncopies=$3 + typeset ncopies_bp + typeset DN_MAX_INDBLKSHIFT=17 + typeset SPA_BLKPTRSHIFT=7 + typeset SPA_DVAS_PER_BP=3 + typeset DVAS_PER_BP + typeset DNODES_PER_LEVEL_SHIFT + typeset DNODES_PER_LEVEL + typeset DN_MAX_INDBLKS + + (( DNODES_PER_LEVEL_SHIFT = DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT )) + (( DNODES_PER_LEVEL = 1 << DNODES_PER_LEVEL_SHIFT )) + (( DN_MAX_INDBLKS = 1 << DN_MAX_INDBLKSHIFT )) + + resv_val=$volsize + (( nblocks = volsize / volblocksize )) + numdb=7 + while (( nblocks > 1 )); do + (( nblocks = nblocks + DNODES_PER_LEVEL - 1 )) + (( nblocks = nblocks / DNODES_PER_LEVEL )) + (( numdb = numdb + nblocks )) + done + (( ncopies_bp = ncopies + 1 )) + DVAS_PER_BP=$(min $SPA_DVAS_PER_BP $ncopies_bp) + (( numdb = numdb * DVAS_PER_BP )) + (( resv_val = volsize * ncopies )) + (( numdb = numdb * DN_MAX_INDBLKS )) + (( resv_val = resv_val + numdb )) + + $ECHO $resv_val + return 0 +} + diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_001_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_001_pos.ksh new file mode 100644 index 00000000000..dbcb8ec7236 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_001_pos.ksh @@ -0,0 +1,132 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_001_pos.ksh 1.3 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_001_pos +# +# DESCRIPTION: +# +# ZFS allows reservations to be set on filesystems and volumes, provided +# the reservation is less than the space available in the pool. +# +# STRATEGY: +# 1) Create a regular and sparse volume +# (filesystem already created by default_setup) +# 2) Get the space available in the pool +# 3) Set a reservation on the filesystem less than the space available. +# 4) Verify that the 'reservation' property for the filesystem has +# the correct value. +# 5) Reset the reservation to 'none' +# 6) Repeat steps 2-5 for both volume types +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-19) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +log_assert "Verify that to set a reservation on a filesystem" \ + " or volume must use value smaller than space" \ + " available property of pool" + +space_avail=`get_prop available $TESTPOOL` + +if ! is_global_zone ; then + OBJ_LIST="" +else + OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" + + (( vol_set_size = space_avail / 4 )) + vol_set_size=$(floor_volsize $vol_set_size) + (( sparse_vol_set_size = space_avail * 4 )) + sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) + + # + # Note that when creating a regular volume we are implicitly + # setting a reservation upon it (i.e. the size of the volume) + # which we reset back to zero initially. + # + log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL + log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL + if fs_prop_exist refreserv; then + log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL + fi + log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 +fi + + +for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do + + space_avail=`get_prop available $TESTPOOL` + resv_size_set=`expr $space_avail - $RESV_DELTA` + + # + # For a regular (non-sparse) volume the upper limit + # for reservations is not determined by the space + # available in the pool but rather by the size of + # the volume itself. + # + [[ $obj == $TESTPOOL/$TESTVOL ]] && \ + (( resv_size_set = vol_set_size - RESV_DELTA )) + + log_must $ZFS set reservation=$resv_size_set $obj + + resv_size_get=`get_prop reservation $obj` + if [[ $resv_size_set != $resv_size_get ]]; then + log_fail "Reservation not the expected value "\ + "($resv_size_set != $resv_size_get)" + fi + + log_must zero_reservation $obj + + new_space_avail=`get_prop available $obj` + + # + # Due to the way space is consumed and released by metadata we + # can't do an exact check here, but we do do a basic sanity + # check. + # + log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE +done + +log_pass "Successfully set reservation on filesystem and volume" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_002_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_002_pos.ksh new file mode 100644 index 00000000000..84884aa2391 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_002_pos.ksh @@ -0,0 +1,111 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_002_pos +# +# DESCRIPTION: +# +# Reservation values cannot exceed the amount of space available +# in the pool. Verify that attempting to set a reservation greater +# than this value fails. +# +# STRATEGY: +# 1) Create a filesystem, regular and sparse volume +# 2) Get the space available in the pool +# 3) Attempt to set a reservation greater than the available space +# on the filesystem and verify it fails. +# 4) Verify that the reservation is still set to 'none' (or 0) on +# the filesystem. +# 5) Repeat 3-4 for regular and sparse volume +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Reservation values cannot exceed the amount of space" \ + " available in the pool" + +space_avail=`get_prop available $TESTPOOL` + +if ! is_global_zone ; then + OBJ_LIST="" +else + OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" + + (( vol_set_size = space_avail / 4 )) + vol_set_size=$(floor_volsize $vol_set_size) + (( sparse_vol_set_size = space_avail * 4 )) + sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) + + log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL + log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL + log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 +fi + +for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do + + space_avail=`get_prop available $TESTPOOL` + resv_size_set=`expr $space_avail + $RESV_DELTA` + + # + # For regular (non-sparse) volumes the upper limit is determined + # not by the space available in the pool but rather by the size + # of the volume itself. + # + [[ $obj == $TESTPOOL/$TESTVOL ]] && \ + (( resv_size_set = vol_set_size + RESV_DELTA )) + + log_must zero_reservation $obj + log_mustnot $ZFS set reservation=$resv_size_set $obj + + resv_size_get=`get_prop reservation $obj` + + if (( $resv_size_get != 0 )); then + log_fail "Reservation value non-zero ($resv_size_get)" + fi +done + +log_pass "Attempting to set too large reservation failed as expected" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_003_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_003_pos.ksh new file mode 100644 index 00000000000..b87630323a7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_003_pos.ksh @@ -0,0 +1,137 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_003_pos.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_003_pos +# +# DESCRIPTION: +# +# Verify that it's possible to set a reservation on a filesystem, +# or volume multiple times, without resetting the reservation +# to none. +# +# STRATEGY: +# 1) Create a regular volume and a sparse volume +# 2) Get the space available in the pool +# 3) Set a reservation on the filesystem less than the space available. +# 4) Verify that the 'reservation' property for the filesystem has +# the correct value. +# 5) Repeat 2-4 for different reservation values +# 6) Repeat 3-5 for regular and sparse volume +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify it is possible to set reservations multiple times " \ + "on a filesystem regular and sparse volume" + + +# +# Set a reservation $RESV_ITER times on a dataset and verify that +# the reservation is correctly set each time. +# +function multiple_resv { #dataset + typeset -i i=0 + + dataset=$1 + + log_must zero_reservation $dataset + space_avail=`get_prop available $TESTPOOL` + + (( resv_size = ( space_avail - RESV_DELTA ) / RESV_ITER )) + + # + # For regular (non-sparse) volumes the upper limit is determined + # not by the space available in the pool but rather by the size + # of the volume itself. + # + [[ $obj == $TESTPOOL/$TESTVOL ]] && \ + (( resv_size = ( vol_set_size - RESV_DELTA ) / RESV_ITER )) + + resv_size_set=$resv_size + + while (( $i < $RESV_ITER )); do + + (( i = i + 1 )) + + (( resv_size_set = resv_size * i )) + + log_must $ZFS set reservation=$resv_size_set $dataset + + resv_size_get=`get_prop reservation $dataset` + if [[ $resv_size_set != $resv_size_get ]]; then + log_fail "Reservation not the expected value " \ + "($resv_size_set != $resv_size_get)" + fi + done + + log_must zero_reservation $dataset +} + +space_avail=`get_prop available $TESTPOOL` + +if ! is_global_zone ; then + OBJ_LIST="" +else + OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" + + (( vol_set_size = space_avail / 4 )) + vol_set_size=$(floor_volsize $vol_set_size) + (( sparse_vol_set_size = space_avail * 4 )) + sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) + + + log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL + log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL + log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 +fi + +for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do + multiple_resv $obj +done + +log_pass "Multiple reservations successfully set on filesystem" \ + " and both volume types" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_004_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_004_pos.ksh new file mode 100644 index 00000000000..95aa97ea6c8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_004_pos.ksh @@ -0,0 +1,131 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_004_pos.ksh 1.3 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_004_pos +# +# DESCRIPTION: +# +# When a dataset which has a reservation set on it is destroyed, +# the space consumed or reserved by that dataset should be released +# back into the pool. +# +# STRATEGY: +# 1) Create a filesystem, regular and sparse volume +# 2) Get the space used and available in the pool +# 3) Set a reservation on the filesystem less than the space available. +# 4) Verify that the 'reservation' property for the filesystem has +# the correct value. +# 5) Destroy the filesystem without resetting the reservation value. +# 6) Verify that the space used and available totals for the pool have +# changed by the expected amounts (within tolerances). +# 7) Repeat steps 3-6 for a regular volume and sparse volume +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify space released when a dataset with reservation is destroyed" + +log_must $ZFS create $TESTPOOL/$TESTFS2 + +space_avail=`get_prop available $TESTPOOL` + +if ! is_global_zone ; then + OBJ_LIST="$TESTPOOL/$TESTFS2" +else + OBJ_LIST="$TESTPOOL/$TESTFS2 \ + $TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" + + (( vol_set_size = space_avail / 4 )) + vol_set_size=$(floor_volsize $vol_set_size) + (( sparse_vol_set_size = space_avail * 4 )) + sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) + + log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL + if fs_prop_exist refreserv; then + log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL + fi + log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL + log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 +fi + +# re-calculate space available. +space_avail=`get_prop available $TESTPOOL` + +# Calculate a large but valid reservation value. +resv_size_set=`expr $space_avail - $RESV_DELTA` + +for obj in $OBJ_LIST ; do + + space_avail=`get_prop available $TESTPOOL` + space_used=`get_prop used $TESTPOOL` + + # + # For regular (non-sparse) volumes the upper limit is determined + # not by the space available in the pool but rather by the size + # of the volume itself. + # + [[ $obj == $TESTPOOL/$TESTVOL ]] && \ + (( resv_size_set = vol_set_size - RESV_DELTA )) + + log_must $ZFS set reservation=$resv_size_set $obj + + resv_size_get=`get_prop reservation $obj` + if [[ $resv_size_set != $resv_size_get ]]; then + log_fail "Reservation not the expected value " \ + "($resv_size_set != $resv_size_get)" + fi + + log_must $ZFS destroy -f $obj + + new_space_avail=`get_prop available $TESTPOOL` + new_space_used=`get_prop used $TESTPOOL` + + log_must within_limits $space_used $new_space_used $RESV_TOLERANCE + log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE +done + +log_pass "Space correctly released when dataset is destroyed" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_005_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_005_pos.ksh new file mode 100644 index 00000000000..2a8999e4bf8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_005_pos.ksh @@ -0,0 +1,123 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_005_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_005_pos +# +# DESCRIPTION: +# +# When a reservation property of a filesystem, regular volume +# or sparse volume is set to 'none' the space previously consumed by the +# reservation should be released back to the pool +# +# STRATEGY: +# 1) Create a filesystem, regular volume and sparse volume +# 2) Get the space used and available in the pool +# 3) Set a reservation on the filesystem less than the space available. +# 4) Verify that the 'reservation' property for the filesystem has +# the correct value. +# 5) Reset the reservation value back to zero (or 'none') +# 6) Verify that the space used and available totals for the pool have +# changed by the expected amounts (within tolerances). +# 7) Repeat steps 3-6 for a regular volume, sparse volume +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify space released when reservation on a dataset is set "\ + "to 'none'" + +space_avail=`get_prop available $TESTPOOL` + +if ! is_global_zone ; then + OBJ_LIST="" +else + OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" + (( vol_set_size = space_avail / 4 )) + vol_set_size=$(floor_volsize $vol_set_size) + (( sparse_vol_set_size = space_avail * 4 )) + sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) + + + log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL + log_must $ZFS set reservation=none $TESTPOOL/$TESTVOL + log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 +fi + +space_avail=`get_prop available $TESTPOOL` +space_used=`get_prop used $TESTPOOL` + +# Calculate a large but valid reservation value. +resv_size_set=`expr $space_avail - $RESV_DELTA` + +for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do + + # + # For regular (non-sparse) volumes the upper limit is determined + # not by the space available in the pool but rather by the size + # of the volume itself. + # + [[ $obj == $TESTPOOL/$TESTVOL ]] && \ + (( resv_size_set = vol_set_size - RESV_DELTA )) + + log_must $ZFS set reservation=$resv_size_set $obj + + resv_size_get=`get_prop reservation $obj` + if [[ $resv_size_set != $resv_size_get ]]; then + log_fail "Reservation not the expected value "\ + "($resv_size_set != $resv_size_get)" + fi + + log_must $ZFS set reservation=none $obj + + new_space_avail=`get_prop available $TESTPOOL` + new_space_used=`get_prop used $TESTPOOL` + + log_must within_limits $space_used $new_space_used $RESV_TOLERANCE + log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE +done + +log_pass "Space correctly released when dataset reservation set to 'none'" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_006_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_006_pos.ksh new file mode 100644 index 00000000000..40dc6ad4e0f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_006_pos.ksh @@ -0,0 +1,87 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_006_pos.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_006_pos +# +# DESCRIPTION: +# +# Reservations (if successfully set) guarantee a minimum amount of space +# for a dataset. Unlike quotas however there should be no restrictions +# on accessing space outside of the limits of the reservation (if the +# space is available in the pool). Verify that in a filesystem with a +# reservation set that its possible to create files both within the +# reserved space and also outside. +# +# STRATEGY: +# 1) Create a filesystem +# 2) Get the space used and available in the pool +# 3) Set a reservation on the filesystem +# 4) Verify can write a file that is bigger than the reserved space +# +# i.e. we start writing within the reserved region and then continue +# for 20MB outside it. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify can create files both inside and outside reserved areas" + +space_used=`get_prop used $TESTPOOL` + +log_must $ZFS set reservation=$RESV_SIZE $TESTPOOL/$TESTFS + +# +# Calculate how many writes of BLOCK_SIZE it would take to fill +# up RESV_SIZE + 20971520 (20 MB). +# +fill_size=`expr $RESV_SIZE + 20971520` +write_count=`expr $fill_size / $BLOCK_SIZE` + +log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \ + -c $write_count -d 0 + +log_pass "Able to create files inside and outside reserved area" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_007_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_007_pos.ksh new file mode 100644 index 00000000000..88147247164 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_007_pos.ksh @@ -0,0 +1,131 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_007_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_007_pos +# +# DESCRIPTION: +# +# Setting a reservation on dataset should have no effect on any other +# dataset at the same level in the hierarchy beyond using up available +# space in the pool. +# +# STRATEGY: +# 1) Create a filesystem +# 2) Set a reservation on the filesystem +# 3) Create another filesystem at the same level +# 4) Set a reservation on the second filesystem +# 5) Destroy both the filesystems +# 6) Verify space accounted for correctly +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify reservations on data sets doesn't affect other data sets at" \ + " same level except for consuming space from common pool" + +space_avail=`get_prop available $TESTPOOL` +space_used=`get_prop used $TESTPOOL` + +resv_size_set=`expr $space_avail / 3` + +# +# Function which creates two datasets, sets reservations on them, +# then destroys them and ensures that space is correctly accounted +# for. +# +# Any special arguments for create are passed in via the args +# parameter. +# +function create_resv_destroy { # args1 dataset1 args2 dataset2 + + args1=$1 + dataset1=$2 + args2=$3 + dataset2=$4 + + log_must $ZFS create $args1 $dataset1 + + log_must $ZFS set reservation=$RESV_SIZE $dataset1 + + avail_aft_dset1=`get_prop available $TESTPOOL` + used_aft_dset1=`get_prop used $TESTPOOL` + + log_must $ZFS create $args2 $dataset2 + + log_must $ZFS set reservation=$RESV_SIZE $dataset2 + + + # After destroying the second dataset the space used and + # available totals should revert back to the values they + # had after creating the first dataset. + # + log_must $ZFS destroy -f $dataset2 + + avail_dest_dset2=`get_prop available $TESTPOOL` + used_dest_dset2=`get_prop used $TESTPOOL` + + log_must within_limits $avail_aft_dset1 $avail_dest_dset2 $RESV_TOLERANCE + log_must within_limits $used_aft_dset1 $used_dest_dset2 $RESV_TOLERANCE + + + # After destroying the first dataset the space used and + # space available totals should revert back to the values + # they had when the pool was first created. + log_must $ZFS destroy -f $dataset1 + + avail_dest_dset1=`get_prop available $TESTPOOL` + used_dest_dset1=`get_prop used $TESTPOOL` + + log_must within_limits $avail_dest_dset1 $space_avail $RESV_TOLERANCE + log_must within_limits $used_dest_dset1 $space_used $RESV_TOLERANCE +} + +create_resv_destroy "" $TESTPOOL/$TESTFS1 "" $TESTPOOL/$TESTFS2 +create_resv_destroy "" $TESTPOOL/$TESTFS2 "" $TESTPOOL/$TESTFS1 + +log_pass "Verify reservations on data sets doesn't affect other data sets at" \ + " same level except for consuming space from common pool" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_008_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_008_pos.ksh new file mode 100644 index 00000000000..55a386f50c4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_008_pos.ksh @@ -0,0 +1,123 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_008_pos.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_008_pos +# +# DESCRIPTION: +# +# Setting a reservation reserves a defined minimum amount of space for +# a dataset, and prevents other datasets using that space. Verify that +# reducing the reservation on a filesystem allows other datasets in +# the pool to use that space. +# +# STRATEGY: +# 1) Create multiple filesystems +# 2) Set reservations on all bar one of the filesystems +# 3) Fill up the one non-reserved filesystem +# 4) Reduce one of the reservations and verify can write more +# data into the non-reserved filesystem +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify reducing reservation allows other datasets to use space" + +log_must create_multiple_fs $RESV_NUM_FS $TESTPOOL/$TESTFS $TESTDIR + +space_avail=`get_prop available $TESTPOOL` +space_used=`get_prop used $TESTPOOL` + +# +# To make sure this test doesn't take too long to execute on +# large pools, we calculate a reservation setting which when +# applied to all bar one of the filesystems (RESV_NUM_FS-1) will +# ensure we have RESV_FREE_SPACE left free in the pool, which we will +# be able to quickly fill. +# +resv_space_avail=`expr $space_avail - $RESV_FREE_SPACE` +num_resv_fs=`expr $RESV_NUM_FS - 1` # Number of FS to which resv will be applied +resv_size_set=`expr $resv_space_avail / $num_resv_fs` + +# +# We set the reservations now, rather than when we created the filesystems +# to allow us to take into account space used by the filsystem metadata +# +# Note we don't set a reservation on the first filesystem we created, +# hence num=1 rather than zero below. +# +typeset -i num=1 +while (( $num < $RESV_NUM_FS )); do + log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS$num + (( num = num + 1 )) +done + +space_avail_still=`get_prop available $TESTPOOL` + +fill_size=`expr $space_avail_still + $RESV_TOLERANCE` +write_count=`expr $fill_size / $BLOCK_SIZE` + +# Now fill up the first filesystem (which doesn't have a reservation set +# and thus will use up whatever free space is left in the pool). +num=0 +log_note "Writing to $TESTDIR$num/$TESTFILE1" + +$FILE_WRITE -o create -f $TESTDIR$num/$TESTFILE1 -b $BLOCK_SIZE \ + -c $write_count -d 0 +ret=$? +if (( $ret != $ENOSPC )); then + log_fail "Did not get ENOSPC as expected (got $ret)." +fi + +# Remove the reservation on one of the other filesystems and verify +# can write more data to the original non-reservation filesystem. +num=1 +log_must $ZFS set reservation=none $TESTPOOL/${TESTFS}$num +num=0 +log_must $FILE_WRITE -o create -f ${TESTDIR}$num/$TESTFILE2 -b $BLOCK_SIZE \ + -c 1000 -d 0 + +log_pass "reducing reservation allows other datasets to use space" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_009_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_009_pos.ksh new file mode 100644 index 00000000000..3ee8ad83923 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_009_pos.ksh @@ -0,0 +1,105 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_009_pos.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_009_pos +# +# DESCRIPTION: +# +# In pool with a full filesystem and another filesystem with a reservation +# setting the reservation on the second filesystem to 'none' should allow more +# data to be written to the first filesystem. +# +# +# STRATEGY: +# 1) Create a filesystem as a dataset +# 2) Create a filesystem at the same level +# 3) Set a reservation on the dataset filesystem +# 4) Fill up the filesystem +# 5) Set the reservation on the dataset filesystem to 'none' +# 6) Verify we can write more data to the first filesystem +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Setting top level dataset reservation to 'none' allows more data to" \ + " be written to top level filesystem" + +log_must $ZFS create $TESTPOOL/$TESTFS1 + +space_avail=`get_prop available $TESTPOOL` + +# +# To make sure this test doesn't take too long to execute on +# large pools, we calculate a reservation setting which when +# applied to the dataset will ensure we have RESV_FREE_SPACE +# left free in the pool which we can quickly fill. +# +(( resv_size_set = space_avail - RESV_FREE_SPACE )) + +log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS1 + +space_avail_still=`get_prop available $TESTPOOL` + +fill_size=`expr $space_avail_still + $RESV_TOLERANCE` +write_count=`expr $fill_size / $BLOCK_SIZE` + +# Now fill up the filesystem (which doesn't have a reservation set +# and thus will use up whatever free space is left in the pool). +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \ + -c $write_count -d 0 +ret=$? +if (( $ret != $ENOSPC )); then + log_fail "Did not get ENOSPC as expected (got $ret)." +fi + +log_must $ZFS set reservation=none $TESTPOOL/$TESTFS1 + +log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE \ + -c 1000 -d 0 + +log_pass "Setting top level dataset reservation to 'none' allows more " \ + "data to be written to the top level filesystem" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_010_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_010_pos.ksh new file mode 100644 index 00000000000..d799c196250 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_010_pos.ksh @@ -0,0 +1,105 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_010_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_010_pos +# +# DESCRIPTION: +# +# In pool with a full filesystem and a filesystem with a reservation +# destroying another filesystem should allow more data to be written to +# the full filesystem +# +# +# STRATEGY: +# 1) Create a filesystem as dataset +# 2) Create a filesystem at the same level +# 3) Set a reservation on the dataset filesystem +# 4) Fill up the second filesystem +# 5) Destroy the dataset filesystem +# 6) Verify can write more data to the full filesystem +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Destroying top level filesystem with reservation allows more data to" \ + " be written to another top level filesystem" + +log_must $ZFS create $TESTPOOL/$TESTFS1 + +space_avail=`get_prop available $TESTPOOL` + +# +# To make sure this test doesn't take too long to execute on +# large pools, we calculate a reservation setting which when +# applied to the dataset filesystem will ensure we have +# RESV_FREE_SPACE left free in the pool. +# +(( resv_size_set = space_avail - RESV_FREE_SPACE )) + +log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS1 + +space_avail_still=`get_prop available $TESTPOOL` + +fill_size=`expr $space_avail_still + $RESV_TOLERANCE` +write_count=`expr $fill_size / $BLOCK_SIZE` + +# Now fill up the filesystem (which doesn't have a reservation set +# and thus will use up whatever free space is left in the pool). +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \ + -c $write_count -d 0 +ret=$? +if (( $ret != $ENOSPC )); then + log_fail "Did not get ENOSPC as expected (got $ret)." +fi + +log_must $ZFS destroy -f $TESTPOOL/$TESTFS1 + +log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE \ + -c 1000 -d 0 + +log_pass "Destroying top level filesystem with reservation allows more data to" \ + " be written to another top level filesystem" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_011_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_011_pos.ksh new file mode 100644 index 00000000000..9a99b780d3d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_011_pos.ksh @@ -0,0 +1,81 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_011_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_011_pos +# +# DESCRIPTION: +# +# ZFS has two mechanisms dealing with space for datasets, namely +# reservations and quotas. Setting one should not affect the other, +# provided the values are legal (i.e. enough space in pool etc). +# +# STRATEGY: +# 1) Create one filesystem +# 2) Get the current quota setting +# 3) Set a reservation +# 4) Verify that the quota value remains unchanged +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify reservation settings do not affect quota settings" + +space_avail=`get_prop available $TESTPOOL` + +(( resv_size_set = (space_avail - RESV_DELTA) / 2 )) + +fs_quota=`$ZFS get quota $TESTPOOL/$TESTFS` + +log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS + +new_fs_quota=`$ZFS get quota $TESTPOOL/$TESTFS` + +if [[ $fs_quota != $new_fs_quota ]]; then + log_fail "Quota value on $TESTFS has changed ($fs_quota != $new_fs_quota)" +fi + +log_pass "Quota settings unaffected by reservation settings" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_012_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_012_pos.ksh new file mode 100644 index 00000000000..659f3d4cf9a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_012_pos.ksh @@ -0,0 +1,98 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_012_pos.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_012_pos +# +# DESCRIPTION: +# +# A reservation guarantees a certain amount of space for a dataset. +# Nothing else which happens in the same pool should affect that +# space, i.e. even if the rest of the pool fills up the reserved +# space should still be accessible. +# +# STRATEGY: +# 1) Create 2 filesystems +# 2) Set a reservation on one filesystem +# 3) Fill up the other filesystem (which does not have a reservation +# set) until all space is consumed +# 4) Verify can still write to the filesystem which has a reservation +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify reservations protect space" + +function cleanup +{ + $ZFS destroy -f $TESTPOOL/$TESTFS2 + [[ -d $TESTDIR2 ]] && \ + log_must $RM -rf $TESTDIR2 +} + +log_onexit cleanup + +log_must $ZFS create $TESTPOOL/$TESTFS2 +log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS2 + +space_avail=`get_prop available $TESTPOOL` + +(( resv_size_set = space_avail - RESV_FREE_SPACE )) + +log_must $ZFS set reservation=$resv_size_set $TESTPOOL/$TESTFS + +(( write_count = ( RESV_FREE_SPACE + RESV_TOLERANCE ) / BLOCK_SIZE )) + +$FILE_WRITE -o create -f $TESTDIR2/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0 +ret=$? +if [[ $ret != $ENOSPC ]]; then + log_fail "Did not get ENOSPC (got $ret) for non-reserved filesystem" +fi + +(( write_count = ( RESV_FREE_SPACE - RESV_TOLERANCE ) / BLOCK_SIZE )) +log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE -c $write_count -d 0 + +log_pass "Reserved space preserved correctly" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_013_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_013_pos.ksh new file mode 100644 index 00000000000..774d1540d4d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_013_pos.ksh @@ -0,0 +1,121 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_013_pos.ksh 1.4 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_013_pos +# +# DESCRIPTION: +# +# Reservation properties on data objects should be preserved when the +# pool within which they are contained is exported and then re-imported. +# +# +# STRATEGY: +# 1) Create a filesystem as dataset +# 2) Create another filesystem at the same level +# 3) Create a regular volume at the same level +# 4) Create a sparse volume at the same level +# 5) Create a filesystem within the dataset filesystem +# 6) Set reservations on all filesystems +# 7) Export the pool +# 8) Re-import the pool +# 9) Verify that the reservation settings are correct +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Reservation properties preserved across exports and imports" + +OBJ_LIST="$TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1 \ + $TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" + +log_must $ZFS create $TESTPOOL/$TESTFS1 +log_must $ZFS create $TESTPOOL/$TESTFS1/$TESTFS2 + +space_avail=`get_prop available $TESTPOOL` +[[ $? -ne 0 ]] && \ + log_fail "Unable to get space available property for $TESTPOOL" + +(( resv_set = space_avail / 8 )) +resv_set=$(floor_volsize $resv_set) +(( sparse_vol_set_size = space_avail * 8 )) +sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) +reg_vol_blksz=8192 + +# When initially created, a regular volume's refreservation property is set +# equal to its size (unlike a sparse volume), so we don't need to set it +# explicitly later on. However, since the zfs command modifies the +# reservation based on the volume size, it is necessary to test it separately. +log_must $ZFS create -b $reg_vol_blksz -V $resv_set $TESTPOOL/$TESTVOL +log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 + +log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTFS +log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTFS1 +log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTFS1/$TESTFS2 +log_must $ZFS set refreservation=$resv_set $TESTPOOL/$TESTVOL2 + +log_must $ZPOOL export $TESTPOOL + +typeset dir=$(get_device_dir $DISKS) +log_must $ZPOOL import -d $dir $TESTPOOL + +alloc_vol_size=$(zvol_volsize_to_reservation $resv_set $reg_vol_blksz 1) +resv_get=$(get_prop refreservation $TESTPOOL/$TESTVOL) +[[ $resv_get != $alloc_vol_size ]] && \ + log_fail "Reservation property for $TESTPOOL/$TESTVOL incorrect;" \ + " expected $alloc_vol_size but got $resv_get" + +for obj in $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS1 \ + $TESTPOOL/$TESTVOL2 $TESTPOOL/$TESTFS1/$TESTFS2 +do + resv_get=`get_prop refreservation $obj` + + [[ $resv_get != $resv_set ]] && \ + log_fail "Reservation property for $obj incorrect " \ + " expected $resv_set but got $resv_get" +done + +log_pass "Reservation properties preserved across exports and imports" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_014_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_014_pos.ksh new file mode 100644 index 00000000000..e5c23c211ce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_014_pos.ksh @@ -0,0 +1,126 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_014_pos.ksh 1.3 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_014_pos +# +# DESCRIPTION: +# +# A reservation cannot exceed the quota on a dataset +# +# STRATEGY: +# 1) Create a filesystem and volume +# 2) Set a quota on the filesystem +# 3) Attempt to set a reservation larger than the quota. Verify +# that the attempt fails. +# 4) Repeat 2-3 for volume +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify cannot set reservation larger than quota" + +space_avail=`get_prop available $TESTPOOL` + +if ! is_global_zone ; then + OBJ_LIST="" +else + OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" + + (( vol_set_size = space_avail / 4 )) + vol_set_size=$(floor_volsize $vol_set_size) + (( sparse_vol_set_size = space_avail * 4 )) + sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) + + + log_must $ZFS create -V $vol_set_size $TESTPOOL/$TESTVOL + log_must $ZFS create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 +fi + +for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do + + space_avail=`get_prop available $TESTPOOL` + (( quota_set_size = space_avail / 3 )) + + # + # A regular (non-sparse) volume's size is effectively + # its quota so only need to explicitly set quotas for + # filesystems and datasets. + # + # A volumes size is effectively its quota. The maximum + # reservation value that can be set on a volume is + # determined by the size of the volume or the amount of + # space in the pool, whichever is smaller. + # + if [[ $obj == $TESTPOOL/$TESTFS ]]; then + log_must $ZFS set quota=$quota_set_size $obj + (( resv_set_size = quota_set_size + RESV_SIZE )) + + elif [[ $obj == $TESTPOOL/$TESTVOL2 ]] ; then + + (( resv_set_size = sparse_vol_set_size + RESV_SIZE )) + + elif [[ $obj == $TESTPOOL/$TESTVOL ]] ; then + + (( resv_set_size = vol_set_size + RESV_SIZE )) + fi + + orig_quota=`get_prop quota $obj` + + log_mustnot $ZFS set reservation=$resv_set_size $obj + new_quota=`get_prop quota $obj` + + if [[ $orig_quota != $new_quota ]]; then + log_fail "Quota value changed from $orig_quota " \ + "to $new_quota" + fi + + if [[ $obj == $TESTPOOL/$TESTFS ]]; then + log_must $ZFS set quota=none $obj + fi +done + +log_pass "As expected cannot set reservation larger than quota" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_015_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_015_pos.ksh new file mode 100644 index 00000000000..d0fb00e77ae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_015_pos.ksh @@ -0,0 +1,114 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_015_pos.ksh 1.4 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_015_pos +# +# DESCRIPTION: +# +# In pool with a full filesystem and a regular volume with an implicit +# reservation, setting the reservation on the volume to 'none' should allow +# more data to be written to the filesystem. +# +# +# STRATEGY: +# 1) Create a regular non-sparse volume (which implicitly sets the reservation +# property to a value equal to the volume size) +# 2) Create a filesystem at the same level +# 3) Fill up the filesystem +# 4) Set the reservation on the volume to 'none' +# 5) Verify can write more data to the filesystem +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Setting volume reservation to 'none' allows more data to" \ + " be written to top level filesystem" + +space_avail=`get_prop available $TESTPOOL` + +# +# To make sure this test doesn't take too long to execute on +# large pools, we calculate a volume size which when applied +# to the volume will ensure we have RESV_FREE_SPACE +# left free in the pool which we can quickly fill. +# +# For the volume itself, set a reservation to 95% of available +# space to allow space for metadata. +# +(( resv_size_set = space_avail * 95 / 100 )) +resv_size_set=$(floor_volsize $resv_size_set $BLOCK_SIZE) + +log_must $ZFS create -b $BLOCK_SIZE -V $resv_size_set $TESTPOOL/$TESTVOL + +# Create a secondary filesystem to soak up what's left to get +# to RESV_FREE_SPACE for the pool. +space_avail_still=`get_prop available $TESTPOOL` +(( zfs_res = space_avail_still - RESV_FREE_SPACE )) +log_must $ZFS create -o refreservation=$zfs_res $TESTPOOL/$TESTFS2 + +space_avail_still=`get_prop available $TESTPOOL` + +fill_size=`expr $space_avail_still + $RESV_TOLERANCE` +write_count=`expr $fill_size / $BLOCK_SIZE` + +# Now fill up the filesystem (which doesn't have a reservation set +# and thus will use up whatever free space is left in the pool). +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \ + -c $write_count -d 0 +ret=$? + +if (( $ret != $ENOSPC )); then + log_fail "Did not get ENOSPC as expected (got $ret)." +fi + +log_must $ZFS set refreservation=none $TESTPOOL/$TESTVOL + +log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE \ + -c 1000 -d 0 + +log_pass "Setting top level volume reservation to 'none' allows more " \ + "data to be written to the top level filesystem" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_016_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_016_pos.ksh new file mode 100644 index 00000000000..b6825fe6ab7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_016_pos.ksh @@ -0,0 +1,112 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_016_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_016_pos +# +# DESCRIPTION: +# +# In pool with a full filesystem and a regular volume (with implicit +# reservation) destroying the volume should allow more data to be written +# to the filesystem +# +# +# STRATEGY: +# 1) Create a regular (non-sparse) volume +# 2) Create a filesystem at the same level +# 3) Fill up the filesystem +# 4) Destroy the volume +# 5) Verify can write more data to the filesystem +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-19) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Destroying a regular volume with reservation allows more data to" \ + " be written to top level filesystem" + +space_avail=`get_prop available $TESTPOOL` + +# +# To make sure this test doesn't take too long to execute on +# large pools, we calculate a volume size which will ensure we +# have RESV_FREE_SPACE left free in the pool. +# +(( vol_set_size = space_avail * 95 / 100 )) +vol_set_size=$(floor_volsize $vol_set_size $BLOCK_SIZE) + +# Creating a regular volume implicitly sets its reservation +# property to the same value. +log_must $ZFS create -b $BLOCK_SIZE -V $vol_set_size $TESTPOOL/$TESTVOL + +space_avail_still=`get_prop available $TESTPOOL` + +# Create a secondary filesystem to soak up what's left to get +# to RESV_FREE_SPACE for the pool. +space_avail_still=`get_prop available $TESTPOOL` +(( zfs_res = space_avail_still - RESV_FREE_SPACE )) +log_must $ZFS create -o refreservation=$zfs_res $TESTPOOL/$TESTFS2 + +space_avail_still=`get_prop available $TESTPOOL` + +fill_size=`expr $space_avail_still + $RESV_TOLERANCE` +write_count=`expr $fill_size / $BLOCK_SIZE` + +# Now fill up the filesystem (which doesn't have a reservation set +# and thus will use up whatever free space is left in the pool). +$FILE_WRITE -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \ + -c $write_count -d 0 +ret=$? +if (( $ret != $ENOSPC )); then + log_fail "Did not get ENOSPC as expected (got $ret)." +fi + +log_must $ZFS destroy -f $TESTPOOL/$TESTVOL + +log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE2 -b $BLOCK_SIZE \ + -c 1000 -d 0 + +log_pass "Destroying volume with reservation allows more data to" \ + " be written to top level filesystem" diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_017_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_017_pos.ksh new file mode 100644 index 00000000000..da5978a52d1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_017_pos.ksh @@ -0,0 +1,105 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_017_pos.ksh 1.5 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_017_pos +# +# DESCRIPTION: +# +# For a sparse volume changes to the volsize are not reflected in the reservation +# +# STRATEGY: +# 1) Create a regular and sparse volume +# 2) Get the space available in the pool +# 3) Set reservation with various size on the regular and sparse volume +# 4) Verify that the 'reservation' property for the regular volume has +# the correct value. +# 5) Verify that the 'reservation' property for the sparse volume is set to 'none' +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-17) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +log_assert "Verify that the volsize changes of sparse volume are not reflected" \ + "in the reservation" + +#Create a regular and sparse volume for testing. +regvol=$TESTPOOL/$TESTVOL +sparsevol=$TESTPOOL/$TESTVOL2 +log_must $ZFS create -V $VOLSIZE -o volblocksize=16k $regvol +log_must $ZFS create -s -V $VOLSIZE -o volblocksize=16k $sparsevol + +typeset -l vsize=$(get_prop available $TESTPOOL) +typeset -i iterate=10 +typeset -l regreserv +typeset -l sparsereserv +typeset -l vblksize1=$(get_prop volblocksize $regvol) +typeset -l vblksize2=$(get_prop volblocksize $sparsevol) +typeset -l blknum=0 +if [ "$vblksize1" != "$vblksize2" ]; then + log_must $ZFS set volblocksize=$vblksize1 $sparsevol +fi +(( blknum = vsize / vblksize1 )) + +typeset -i randomblknum +while (( iterate > 1 )); do + (( randomblknum = 1 + $RANDOM % $blknum )) + #Make sure volsize is a multiple of volume block size + (( vsize = $randomblknum * $vblksize1 )) + log_must $ZFS set volsize=$vsize $regvol + log_must $ZFS set volsize=$vsize $sparsevol + regreserv=$(get_prop refreservation $regvol) + sparsereserv=$(get_prop refreservation $sparsevol) + reg_shouldreserv=$(zvol_volsize_to_reservation $vsize $vblksize1 1) + + (( $sparsereserv == $vsize )) && \ + log_fail "volsize changes of sparse volume is reflected in reservation." + (( $regreserv != $reg_shouldreserv )) && \ + log_fail "volsize changes of regular volume isnot reflected in reservation." + + (( iterate = iterate - 1 )) +done + +log_pass "The volsize change of sparse volume is not reflected in reservation as expected." diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_018_pos.ksh b/tests/sys/cddl/zfs/tests/reservation/reservation_018_pos.ksh new file mode 100644 index 00000000000..dd93beeb946 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_018_pos.ksh @@ -0,0 +1,78 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)reservation_018_pos.ksh 1.4 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/reservation/reservation.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: reservation_018_pos +# +# DESCRIPTION: +# +# Verify that reservation doesn't inherit its value from parent. +# +# STRATEGY: +# 1) Create a filesystem tree +# 2) Set reservation for parents +# 3) Verify that the 'reservation' for descendent doesnot inherit the value. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-08-17) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +log_assert "Verify that reservation doesnot inherit its value from parent." + +fs=$TESTPOOL/$TESTFS +fs_child=$TESTPOOL/$TESTFS/$TESTFS + +space_avail=$(get_prop available $fs) +reserv_val=$(get_prop reservation $fs) +typeset -l reservsize=$space_avail +((reservsize = reservsize / 2 )) +log_must $ZFS set reservation=$reservsize $fs + +log_must $ZFS create $fs_child +rsv_space=$(get_prop reservation $fs_child) +[[ $rsv_space == $reservsize ]] && \ + log_fail "The reservation of child dataset inherits its value from parent." + +log_pass "reservation doesnot inherit its value from parent as expected." diff --git a/tests/sys/cddl/zfs/tests/reservation/reservation_test.sh b/tests/sys/cddl/zfs/tests/reservation/reservation_test.sh new file mode 100755 index 00000000000..1928dd0908c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/reservation_test.sh @@ -0,0 +1,524 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case reservation_001_pos cleanup +reservation_001_pos_head() +{ + atf_set "descr" "Verify that to set a reservation on a filesystem or volume must use value smaller than space \ available property of pool" + atf_set "require.progs" zfs +} +reservation_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_001_pos.ksh || atf_fail "Testcase failed" +} +reservation_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_002_pos cleanup +reservation_002_pos_head() +{ + atf_set "descr" "Reservation values cannot exceed the amount of space available in the pool" + atf_set "require.progs" zfs +} +reservation_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_002_pos.ksh || atf_fail "Testcase failed" +} +reservation_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_003_pos cleanup +reservation_003_pos_head() +{ + atf_set "descr" "Verify it is possible to set reservations multiple times on a filesystem regular and sparse volume" + atf_set "require.progs" zfs +} +reservation_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_003_pos.ksh || atf_fail "Testcase failed" +} +reservation_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_004_pos cleanup +reservation_004_pos_head() +{ + atf_set "descr" "Verify space released when a dataset with reservation is destroyed" + atf_set "require.progs" zfs +} +reservation_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_004_pos.ksh || atf_fail "Testcase failed" +} +reservation_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_005_pos cleanup +reservation_005_pos_head() +{ + atf_set "descr" "Verify space released when reservation on a dataset is setto 'none'" + atf_set "require.progs" zfs +} +reservation_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_005_pos.ksh || atf_fail "Testcase failed" +} +reservation_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_006_pos cleanup +reservation_006_pos_head() +{ + atf_set "descr" "Verify can create files both inside and outside reserved areas" + atf_set "require.progs" zfs +} +reservation_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_006_pos.ksh || atf_fail "Testcase failed" +} +reservation_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_007_pos cleanup +reservation_007_pos_head() +{ + atf_set "descr" "Verify reservations on data sets doesn't affect other data sets at same level except for consuming space from common pool" + atf_set "require.progs" zfs +} +reservation_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_007_pos.ksh || atf_fail "Testcase failed" +} +reservation_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_008_pos cleanup +reservation_008_pos_head() +{ + atf_set "descr" "Verify reducing reservation allows other datasets to use space" + atf_set "require.progs" zfs + atf_set "timeout" 600 +} +reservation_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_008_pos.ksh || atf_fail "Testcase failed" +} +reservation_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_009_pos cleanup +reservation_009_pos_head() +{ + atf_set "descr" "Setting top level dataset reservation to 'none' allows more data to be written to top level filesystem" + atf_set "require.progs" zfs + atf_set "timeout" 600 +} +reservation_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_009_pos.ksh || atf_fail "Testcase failed" +} +reservation_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_010_pos cleanup +reservation_010_pos_head() +{ + atf_set "descr" "Destroying top level filesystem with reservation allows more data to be written to another top level filesystem" + atf_set "require.progs" zfs + atf_set "timeout" 600 +} +reservation_010_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_010_pos.ksh || atf_fail "Testcase failed" +} +reservation_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_011_pos cleanup +reservation_011_pos_head() +{ + atf_set "descr" "Verify reservation settings do not affect quota settings" + atf_set "require.progs" zfs +} +reservation_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_011_pos.ksh || atf_fail "Testcase failed" +} +reservation_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_012_pos cleanup +reservation_012_pos_head() +{ + atf_set "descr" "Verify reservations protect space" + atf_set "require.progs" zfs + atf_set "timeout" 600 +} +reservation_012_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_012_pos.ksh || atf_fail "Testcase failed" +} +reservation_012_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_013_pos cleanup +reservation_013_pos_head() +{ + atf_set "descr" "Reservation properties preserved across exports and imports" + atf_set "require.progs" zfs zpool +} +reservation_013_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_013_pos.ksh || atf_fail "Testcase failed" +} +reservation_013_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_014_pos cleanup +reservation_014_pos_head() +{ + atf_set "descr" "Verify cannot set reservation larger than quota" + atf_set "require.progs" zfs +} +reservation_014_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_014_pos.ksh || atf_fail "Testcase failed" +} +reservation_014_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_015_pos cleanup +reservation_015_pos_head() +{ + atf_set "descr" "Setting volume reservation to 'none' allows more data to be written to top level filesystem" + atf_set "require.progs" zfs + atf_set "timeout" 600 +} +reservation_015_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_015_pos.ksh || atf_fail "Testcase failed" +} +reservation_015_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_016_pos cleanup +reservation_016_pos_head() +{ + atf_set "descr" "Destroying a regular volume with reservation allows more data to be written to top level filesystem" + atf_set "require.progs" zfs + atf_set "timeout" 600 +} +reservation_016_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_016_pos.ksh || atf_fail "Testcase failed" +} +reservation_016_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_017_pos cleanup +reservation_017_pos_head() +{ + atf_set "descr" "Verify that the volsize changes of sparse volume are not reflectedin the reservation" + atf_set "require.progs" zfs +} +reservation_017_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_017_pos.ksh || atf_fail "Testcase failed" +} +reservation_017_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case reservation_018_pos cleanup +reservation_018_pos_head() +{ + atf_set "descr" "Verify that reservation doesnot inherit its value from parent." + atf_set "require.progs" zfs +} +reservation_018_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/reservation_018_pos.ksh || atf_fail "Testcase failed" +} +reservation_018_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/reservation.kshlib + . $(atf_get_srcdir)/reservation.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case reservation_001_pos + atf_add_test_case reservation_002_pos + atf_add_test_case reservation_003_pos + atf_add_test_case reservation_004_pos + atf_add_test_case reservation_005_pos + atf_add_test_case reservation_006_pos + atf_add_test_case reservation_007_pos + atf_add_test_case reservation_008_pos + atf_add_test_case reservation_009_pos + atf_add_test_case reservation_010_pos + atf_add_test_case reservation_011_pos + atf_add_test_case reservation_012_pos + atf_add_test_case reservation_013_pos + atf_add_test_case reservation_014_pos + atf_add_test_case reservation_015_pos + atf_add_test_case reservation_016_pos + atf_add_test_case reservation_017_pos + atf_add_test_case reservation_018_pos +} diff --git a/tests/sys/cddl/zfs/tests/reservation/setup.ksh b/tests/sys/cddl/zfs/tests/reservation/setup.ksh new file mode 100644 index 00000000000..6fd6a597a9d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/reservation/setup.ksh @@ -0,0 +1,43 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup_noexit $DISK +# +# Set compression=off to make sure the data is not compressed for +# reservation testing. +# +log_must $ZFS set compression=off $TESTPOOL + +log_pass diff --git a/tests/sys/cddl/zfs/tests/rootpool/Makefile b/tests/sys/cddl/zfs/tests/rootpool/Makefile new file mode 100644 index 00000000000..352866fc416 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rootpool/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE= tests +TESTSDIR= ${TESTSBASE}/sys/cddl/zfs/tests/rootpool +FILESDIR= ${TESTSDIR} + +ATF_TESTS_KSH93+= rootpool_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= rootpool_007_neg.ksh +${PACKAGE}FILES+= rootpool_002_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= rootpool_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/rootpool/cleanup.ksh b/tests/sys/cddl/zfs/tests/rootpool/cleanup.ksh new file mode 100644 index 00000000000..473c351808c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rootpool/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 08/05/14 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/rootpool/rootpool_001_pos.ksh b/tests/sys/cddl/zfs/tests/rootpool/rootpool_001_pos.ksh new file mode 100644 index 00000000000..ac2ba378235 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rootpool/rootpool_001_pos.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rootpool_001_pos.ksh 1.1 08/05/14 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: rootpool_001_pos +# +# DESCRIPTION: +# +# rootpool's bootfs property must be equal to +# +# STRATEGY: +# 1) check if the system is zfsroot or not. +# 2) get the rootpool and rootfs if it's zfs root +# 3) check the rootpool's bootfs value +# 4) chek if the boofs equal to rootfs +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-01-21) +# +# __stc_assertion_end +# +################################################################################ +verify_runnable "global" +log_assert "rootpool's bootfs property must be equal to " + +typeset rootfs=$(get_rootfs) +typeset rootpool=$(get_rootpool) +typeset bootfs=$(get_pool_prop bootfs $rootpool) + +if [[ $bootfs != $rootfs ]]; then + log_fail "rootfs is not same as bootfs." +fi + +log_pass "rootpool's bootfs property equal to rootfs." + diff --git a/tests/sys/cddl/zfs/tests/rootpool/rootpool_002_neg.ksh b/tests/sys/cddl/zfs/tests/rootpool/rootpool_002_neg.ksh new file mode 100644 index 00000000000..c61a56714fa --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rootpool/rootpool_002_neg.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rootpool_002_neg.ksh 1.2 09/05/19 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: rootpool_002_neg +# +# DESCRIPTION: +# +# the zfs rootpool can not be destroyed +# +# STRATEGY: +# 1) check if the current system is installed as zfs root +# 2) get the rootpool +# 3) try to destroy the rootpool, which should fail. +# 4) try to destroy the rootpool filesystem, which should fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-01-21) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" +log_assert "zpool/zfs destory should return error" + + +typeset rootpool=$(get_rootpool) + +log_mustnot $ZPOOL destroy $rootpool + +log_mustnot $ZFS destroy $rootpool + +log_pass "rootpool can not be destroyed" + diff --git a/tests/sys/cddl/zfs/tests/rootpool/rootpool_007_neg.ksh b/tests/sys/cddl/zfs/tests/rootpool/rootpool_007_neg.ksh new file mode 100644 index 00000000000..95e83b37652 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rootpool/rootpool_007_neg.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +#ident "@(#)rootpool_007_neg.ksh 1.1 08/08/15 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: rootpool_007_neg +# +# DESCRIPTION: +# +# the zfs rootfilesystem's compression property can not set to gzip[1-9] +# +# STRATEGY: +# 1) check if the current system is installed as zfs root +# 2) get the rootfs +# 3) set the rootfs's compression to gzip 1-9 which should fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-07-08) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup { + log_must $ZFS set compression=$orig_compress $rootfs +} + +log_onexit cleanup +log_assert $assert_msg + +typeset rootpool=$(get_rootpool) +typeset rootfs=$(get_pool_prop bootfs $rootpool) +typeset orig_compress=$(get_prop compression $rootfs) + +typeset assert_msg="the zfs rootfs's compression property can not set to \ + gzip and gzip[1-9]" + +set -A gtype "gzip" "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" \ + "gzip-6" "gzip-7" "gzip-8" "gzip-9" + +typeset -i i=0 +while (( i < ${#gtype[@]} )); do + log_mustnot $ZFS set compression=${gtype[i]} $rootfs + (( i += 1 )) +done + +log_pass $assert_msg diff --git a/tests/sys/cddl/zfs/tests/rootpool/rootpool_test.sh b/tests/sys/cddl/zfs/tests/rootpool/rootpool_test.sh new file mode 100755 index 00000000000..9d992bfb8d2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rootpool/rootpool_test.sh @@ -0,0 +1,107 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case rootpool_001_pos cleanup +rootpool_001_pos_head() +{ + atf_set "descr" "rootpool's bootfs property must be equal to " +} +rootpool_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + if ! is_zfsroot ; then + atf_skip "This test requires a ZFS root filesystem." + fi + + ksh93 $(atf_get_srcdir)/setup.ksh + ksh93 $(atf_get_srcdir)/rootpool_001_pos.ksh || atf_fail "Testcase failed" +} +rootpool_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rootpool_002_neg cleanup +rootpool_002_neg_head() +{ + atf_set "descr" "zpool/zfs destory should return error" + atf_set "require.progs" zfs zpool +} +rootpool_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + if ! is_zfsroot ; then + atf_skip "This test requires a ZFS root filesystem." + fi + + ksh93 $(atf_get_srcdir)/rootpool_002_neg.ksh || atf_fail "Testcase failed" +} +rootpool_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rootpool_007_neg cleanup +rootpool_007_neg_head() +{ + atf_set "descr" "the zfs rootfs's compression property can not set to gzip and gzip[1-9]" + atf_set "require.progs" zfs +} +rootpool_007_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + if ! is_zfsroot ; then + atf_skip "This test requires a ZFS root filesystem." + fi + + ksh93 $(atf_get_srcdir)/rootpool_007_neg.ksh || atf_fail "Testcase failed" +} +rootpool_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case rootpool_001_pos + atf_add_test_case rootpool_002_neg + atf_add_test_case rootpool_007_neg +} diff --git a/tests/sys/cddl/zfs/tests/rootpool/setup.ksh b/tests/sys/cddl/zfs/tests/rootpool/setup.ksh new file mode 100644 index 00000000000..a9823674a75 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rootpool/setup.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 08/05/14 SMI" +# +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if ! is_zfsroot ; then + log_unsupported "current system is not installed as zfs root fs" +fi + diff --git a/tests/sys/cddl/zfs/tests/rsend/Makefile b/tests/sys/cddl/zfs/tests/rsend/Makefile new file mode 100644 index 00000000000..67425df4738 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/Makefile @@ -0,0 +1,31 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/rsend +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= rsend_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= rsend_003_pos.ksh +${PACKAGE}FILES+= rsend_007_pos.ksh +${PACKAGE}FILES+= rsend_012_pos.ksh +${PACKAGE}FILES+= rsend_013_pos.ksh +${PACKAGE}FILES+= rsend_002_pos.ksh +${PACKAGE}FILES+= rsend_006_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= rsend_011_pos.ksh +${PACKAGE}FILES+= rsend.kshlib +${PACKAGE}FILES+= rsend_008_pos.ksh +${PACKAGE}FILES+= rsend_004_pos.ksh +${PACKAGE}FILES+= rsend_001_pos.ksh +${PACKAGE}FILES+= rsend_005_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= rsend_009_pos.ksh +${PACKAGE}FILES+= rsend.cfg +${PACKAGE}FILES+= rsend_010_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/rsend/cleanup.ksh b/tests/sys/cddl/zfs/tests/rsend/cleanup.ksh new file mode 100644 index 00000000000..dee363f19a4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/cleanup.ksh @@ -0,0 +1,53 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.3 09/06/22 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +verify_runnable "both" + +# +# Check if the system support 'send -R' +# +$ZFS send 2>&1 | grep -w "[-R]" > /dev/null 2>&1 +if (($? != 0)); then + log_unsupported +fi + +if is_global_zone ; then + destroy_pool $POOL + destroy_pool $POOL2 +else + cleanup_pool $POOL + cleanup_pool $POOL2 +fi +log_must $RM -rf $BACKDIR $TESTDIR + +log_pass diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend.cfg b/tests/sys/cddl/zfs/tests/rsend/rsend.cfg new file mode 100644 index 00000000000..ce70b66cd7c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend.cfg @@ -0,0 +1,43 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend.cfg 1.2 08/08/15 SMI" +# + +export BACKDIR=${TEST_BASE_DIR%%/}/backdir${TESTCASE_ID} + +export DISK1=$($ECHO $DISKS | $AWK '{print $1}') +export DISK2=$($ECHO $DISKS | $AWK '{print $2}') + +export POOL=$TESTPOOL +export POOL2=$TESTPOOL1 +export FS=$TESTFS +export CLONE=testclone.${TESTCASE_ID} +export VOL=testvol.${TESTCASE_ID} + +export STF_TIMEOUT=2700 diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend.kshlib b/tests/sys/cddl/zfs/tests/rsend/rsend.kshlib new file mode 100644 index 00000000000..b20cd203543 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend.kshlib @@ -0,0 +1,373 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend.kshlib 1.3 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Set up test model which includes various datasets +# +# @final +# @snapB +# @init +# | +# ______ pclone +# | / +# |@psnap +# || @final +# ||@final @final @snapC +# ||@snapC @snapC @snapB +# ||@snapA @snapB @snapA +# ||@init @init @init +# ||| | | +# $pool -------- $FS ------- fs1 ------- fs2 +# \ \\_____ \ | +# vol vol \____ \ @fsnap +# | | \ \ \ +# @init @vsnap | ------------ fclone +# @snapA @init \ | | +# @final @snapB \ | @init +# @snapC vclone @snapA +# @final | @final +# @init +# @snapC +# @final +# +# $1 pool name +# +function setup_test_model +{ + typeset pool=$1 + + log_must $ZFS create -p $pool/$FS/fs1/fs2 + + log_must $ZFS snapshot $pool@psnap + log_must $ZFS clone $pool@psnap $pool/pclone + + if is_global_zone ; then + log_must $ZFS create -V 16M $pool/vol + log_must $ZFS create -V 16M $pool/$FS/vol + + log_must $ZFS snapshot $pool/$FS/vol@vsnap + log_must $ZFS clone $pool/$FS/vol@vsnap $pool/$FS/vclone + fi + + log_must snapshot_tree $pool/$FS/fs1/fs2@fsnap + log_must $ZFS clone $pool/$FS/fs1/fs2@fsnap $pool/$FS/fs1/fclone + log_must $ZFS snapshot -r $pool@init + + log_must snapshot_tree $pool@snapA + log_must snapshot_tree $pool@snapC + log_must snapshot_tree $pool/pclone@snapB + log_must snapshot_tree $pool/$FS@snapB + log_must snapshot_tree $pool/$FS@snapC + log_must snapshot_tree $pool/$FS/fs1@snapA + log_must snapshot_tree $pool/$FS/fs1@snapB + log_must snapshot_tree $pool/$FS/fs1@snapC + log_must snapshot_tree $pool/$FS/fs1/fclone@snapA + + if is_global_zone ; then + log_must $ZFS snapshot $pool/vol@snapA + log_must $ZFS snapshot $pool/$FS/vol@snapB + log_must $ZFS snapshot $pool/$FS/vol@snapC + log_must $ZFS snapshot $pool/$FS/vclone@snapC + fi + + log_must $ZFS snapshot -r $pool@final + + return 0 +} + +# +# Cleanup the BACKDIR and given pool content and all the sub datasets +# +# $1 pool name +# +function cleanup_pool +{ + typeset pool=$1 + log_must $RM -rf $BACKDIR/* + + if is_global_zone ; then + log_must $ZFS destroy -Rf $pool + else + typeset list=$($ZFS list -H -r -t filesystem,snapshot,volume -o name $pool) + for ds in $list ; do + if [[ $ds != $pool ]] ; then + if datasetexists $ds ; then + log_must $ZFS destroy -Rf $ds + fi + fi + done + fi + + typeset mntpnt=$(get_prop mountpoint $pool) + if ! ismounted $pool ; then + # Make sure mountpoint directory is empty + if [[ -d $mntpnt ]]; then + log_must $RM -rf $mntpnt/* + fi + + log_must $ZFS mount $pool + fi + if [[ -d $mntpnt ]]; then + log_must $RM -rf $mntpnt/* + fi + + return 0 +} + +# +# Detect if the given two filesystems have same sub-datasets +# +# $1 source filesystem +# $2 destination filesystem +# +function cmp_ds_subs +{ + typeset src_fs=$1 + typeset dst_fs=$2 + + $ZFS list -r -H -t filesystem,snapshot,volume -o name $src_fs > $BACKDIR/src1 + $ZFS list -r -H -t filesystem,snapshot,volume -o name $dst_fs > $BACKDIR/dst1 + + eval $SED -e 's:^$src_fs:PREFIX:g' < $BACKDIR/src1 > $BACKDIR/src + eval $SED -e 's:^$dst_fs:PREFIX:g' < $BACKDIR/dst1 > $BACKDIR/dst + + $DIFF $BACKDIR/src $BACKDIR/dst + typeset -i ret=$? + + $RM -f $BACKDIR/src $BACKDIR/dst $BACKDIR/src1 $BACKDIR/dst1 + + return $ret +} + +# +# Compare all the directores and files in two filesystems +# +# $1 source filesystem +# $2 destination filesystem +# +function cmp_ds_cont +{ + typeset src_fs=$1 + typeset dst_fs=$2 + + typeset srcdir dstdir + srcdir=$(get_prop mountpoint $src_fs) + dstdir=$(get_prop mountpoint $dst_fs) + + $DIFF -r $srcdir $dstdir > /dev/null 2>&1 + print $? +} + +# +# Compare the given two dataset properties +# +# $1 dataset 1 +# $2 dataset 2 +# +function cmp_ds_prop +{ + typeset dtst1=$1 + typeset dtst2=$2 + + for item in "type" "origin" "volblocksize" "aclinherit" "aclmode" \ + "atime" "canmount" "checksum" "compression" "copies" "devices" \ + "exec" "quota" "readonly" "recordsize" "reservation" "setuid" \ + "shareiscsi" "sharenfs" "snapdir" "version" "volsize" "xattr" \ + "zoned" "mountpoint"; + do + $ZFS get -H -o property,value,source $item $dtst1 >> \ + $BACKDIR/dtst1 + $ZFS get -H -o property,value,source $item $dtst2 >> \ + $BACKDIR/dtst2 + done + + eval $SED -e 's:$dtst1:PREFIX:g' < $BACKDIR/dtst1 > $BACKDIR/dtst1 + eval $SED -e 's:$dtst2:PREFIX:g' < $BACKDIR/dtst2 > $BACKDIR/dtst2 + + $DIFF $BACKDIR/dtst1 $BACKDIR/dtst2 + typeset -i ret=$? + + $RM -f $BACKDIR/dtst1 $BACKDIR/dtst2 + + return $ret + +} + +# +# Random create directories and files +# +# $1 directory +# +function random_tree +{ + typeset dir=$1 + + if [[ -d $dir ]]; then + $RM -rf $dir + fi + $MKDIR -p $dir + typeset -i ret=$? + + typeset -i nl nd nf + ((nl = RANDOM % 6 + 1)) + ((nd = RANDOM % 3 )) + ((nf = RANDOM % 5 )) + $MKTREE -b $dir -l $nl -d $nd -f $nf + ((ret |= $?)) + + return $ret +} + +# +# Put data in filesystem and take snapshot +# +# $1 snapshot name +# +function snapshot_tree +{ + typeset snap=$1 + typeset ds=${snap%%@*} + typeset type=$(get_prop "type" $ds) + + typeset -i ret=0 + if [[ $type == "filesystem" ]]; then + typeset mntpnt=$(get_prop mountpoint $ds) + ((ret |= $?)) + + if ((ret == 0)) ; then + eval random_tree $mntpnt/${snap##$ds} + ((ret |= $?)) + fi + fi + + if ((ret == 0)) ; then + $ZFS snapshot $snap + ((ret |= $?)) + fi + + return $ret +} + +# +# Destroy the given snapshot and stuff +# +# $1 snapshot +# +function destroy_tree +{ + typeset -i ret=0 + typeset snap + for snap in "$@" ; do + $ZFS destroy $snap + ret=$? + + typeset ds=${snap%%@*} + typeset type=$(get_prop "type" $ds) + if [[ $type == "filesystem" ]]; then + typeset mntpnt=$(get_prop mountpoint $ds) + ((ret |= $?)) + + if ((ret != 0)); then + $RM -r $mntpnt/$snap + ((ret |= $?)) + fi + fi + + if ((ret != 0)); then + return $ret + fi + done + + return 0 +} + +# +# Get all the sub-datasets of give dataset with specific suffix +# +# $1 Given dataset +# $2 Suffix +# +function getds_with_suffix +{ + typeset ds=$1 + typeset suffix=$2 + + typeset list=$($ZFS list -r -H -t filesystem,snapshot,volume -o name $ds \ + | $GREP "$suffix$") + + $ECHO $list +} + +# +# Output inherited properties whitch is edited for file system +# +function fs_inherit_prop +{ + typeset fs_prop + if is_global_zone ; then + fs_prop=$($ZFS inherit 2>&1 | \ + $AWK '$2=="YES" && $3=="YES" {print $1}') + else + fs_prop=$($ZFS inherit 2>&1 | \ + $AWK '$2=="YES" && $3=="YES" {print $1}'| + $EGREP -v "devices|sharenfs|sharesmb|zoned") + fi + + $ECHO $fs_prop +} + +# +# Output inherited properties for volume +# +function vol_inherit_prop +{ + $ECHO "checksum readonly shareiscsi" +} + +# +# Get the destination dataset to compare +# +function get_dst_ds +{ + typeset srcfs=$1 + typeset dstfs=$2 + + # + # If the srcfs is not pool + # + if ! $ZPOOL list $srcfs > /dev/null 2>&1 ; then + eval dstfs="$dstfs/${srcfs#*/}" + fi + + $ECHO $dstfs +} diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_001_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_001_pos.ksh new file mode 100644 index 00000000000..699cc51216a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_001_pos.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_001_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_001_pos +# +# DESCRIPTION: +# zfs send -R send replication stream up to the named snap. +# +# STRATEGY: +# 1. Back up all the data from POOL/FS +# 2. Verify all the datasets and data can be recovered in POOL2 +# 3. Back up all the data from root filesystem POOL2 +# 4. Verify all the data can be recovered, too +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs send -R send replication stream up to the named snap." +log_onexit cleanup_pool $POOL2 + +# +# Verify the entire pool and sub-ds can be backup and restored. +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" + +dstds=$(get_dst_ds $POOL $POOL2) +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +# Cleanup POOL2 +log_must cleanup_pool $POOL2 + +# +# Verify all the filesystem and sub-fs can be backup and restored. +# +log_must eval "$ZFS send -R $POOL/$FS@final > $BACKDIR/fs-final-R" +log_must eval "$ZFS receive -d $POOL2 < $BACKDIR/fs-final-R" + +dstds=$(get_dst_ds $POOL/$FS $POOL2) +log_must cmp_ds_subs $POOL/$FS $dstds +log_must cmp_ds_cont $POOL/$FS $dstds + +log_pass "zfs send -R send replication stream up to the named snap." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_002_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_002_pos.ksh new file mode 100644 index 00000000000..7bbf0be23a4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_002_pos.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_002_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_002_pos +# +# DESCRIPTION: +# zfs send -I sends all incrementals from fs@init to fs@final. +# +# STRATEGY: +# 1. Create several snapshots in pool2 +# 2. Send -I @snapA @final +# 3. Destroy all the snapshot except @snapA +# 4. Make sure all the snapshots and content are recovered +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs send -I sends all incrementals from fs@init to fs@final." +log_onexit cleanup_pool $POOL2 + +# +# Duplicate POOL2 +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R" + +if is_global_zone ; then + # + # Verify send -I will backup all the incrementals in pool + # + log_must eval "$ZFS send -I $POOL2@init $POOL2@final > " \ + "$BACKDIR/pool-init-final-I" + log_must destroy_tree $POOL2@final $POOL2@snapC $POOL2@snapA + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-I" + log_must cmp_ds_subs $POOL $POOL2 + log_must cmp_ds_cont $POOL $POOL2 +fi + +dstds=$(get_dst_ds $POOL $POOL2) + +# +# Verify send -I will backup all the incrementals in filesystem +# +log_must eval "$ZFS send -I @init $dstds/$FS@final > $BACKDIR/fs-init-final-I" +log_must destroy_tree $dstds/$FS@final $dstds/$FS@snapC $dstds/$FS@snapB +log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-I" +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +if is_global_zone ; then + # + # Verify send -I will backup all the incrementals in volume + # + dataset=$POOL2/$FS/vol + log_must eval "$ZFS send -I @vsnap $dataset@final > " \ + "$BACKDIR/vol-vsnap-final-I" + log_must destroy_tree $dataset@final $dataset@snapC \ + $dataset@snapB $dataset@init + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-vsnap-final-I" + log_must cmp_ds_subs $POOL $POOL2 + log_must cmp_ds_cont $POOL $POOL2 +fi + +log_pass "zfs send -I sends all incrementals from fs@init to fs@final." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_003_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_003_pos.ksh new file mode 100644 index 00000000000..60a11ddcd80 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_003_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_003_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_003_pos +# +# DESCRIPTION: +# zfs send -I dataset@init to clone@snap can create a clone +# +# STRATEGY: +# 1. Setup test model +# 2. send -I pool@init to clone@snap +# 3. Verify the clone and snapshot can be recovered via receive +# 4. Verify the similar operating in filesystem and volume +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs send -I send all incrementals from dataset@init to clone@snap" +log_onexit cleanup_pool $POOL2 + +# +# Duplicate POOL2 +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R" + +if is_global_zone ; then + # + # Verify send -I backup all incrementals from pool + # + log_must eval "$ZFS send -I $POOL2@psnap $POOL2/pclone@final > " \ + "$BACKDIR/pool-clone-I" + log_must $ZFS destroy -rf $POOL2/pclone + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-clone-I" + log_must cmp_ds_subs $POOL $POOL2 + log_must cmp_ds_cont $POOL $POOL2 +fi + +dstds=$(get_dst_ds $POOL $POOL2) + +# +# Verify send -I backup all incrementals from filesystem +# +ds=$dstds/$FS/fs1 +log_must eval "$ZFS send -I $ds/fs2@fsnap $ds/fclone@final > " \ + "$BACKDIR/fs-clone-I" +log_must $ZFS destroy -rf $ds/fclone +log_must eval "$ZFS receive -F $ds/fclone < $BACKDIR/fs-clone-I" + +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +if is_global_zone ; then + # + # Verify send -I backup all incrementals from volume + # + ds=$POOL2/$FS + log_must eval "$ZFS send -I $ds/vol@vsnap $ds/vclone@final > " \ + "$BACKDIR/vol-clone-I" + log_must $ZFS destroy -rf $ds/vclone + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-clone-I" + log_must cmp_ds_subs $POOL $POOL2 + log_must cmp_ds_cont $POOL $POOL2 +fi + +log_pass "zfs send -I send all incrementals from dataset@init to clone@snap" diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_004_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_004_pos.ksh new file mode 100644 index 00000000000..0a9aaa2f5fe --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_004_pos.ksh @@ -0,0 +1,134 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_004_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_004_pos +# +# DESCRIPTION: +# zfs send -R -i send incremental from fs@init to fs@final. +# +# STRATEGY: +# 1. Create a set of snapshots and fill with data. +# 2. Create sub filesystems. +# 3. Create final snapshot +# 4. Verify zfs send -R -i will backup all the datasets which has +# snapshot suffix @final +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs send -R -i send incremental from fs@init to fs@final." +log_onexit cleanup_pool $POOL2 + +# +# Duplicate POOL2 for testing +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" + +if is_global_zone ; then + # + # Testing send -R -i backup from pool + # + srclist=$(getds_with_suffix $POOL2 @final) + interlist="$srclist $(getds_with_suffix $POOL2 @snapC)" + interlist="$interlist $(getds_with_suffix $POOL2 @snapB)" + interlist="$interlist $(getds_with_suffix $POOL2 @snapA)" + + log_must eval "$ZFS send -R -i @init $POOL2@final > " \ + "$BACKDIR/pool-init-final-iR" + log_must destroy_tree $interlist + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-iR" + + # Get current datasets with suffix @final + dstlist=$(getds_with_suffix $POOL2 @final) + if [[ $srclist != $dstlist ]]; then + log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)" + fi + log_must cmp_ds_cont $POOL $POOL2 +fi + +dstds=$(get_dst_ds $POOL $POOL2) +# +# Testing send -R -i backup from filesystem +# +log_must eval "$ZFS send -R -i @init $dstds/$FS@final > " \ + "$BACKDIR/fs-init-final-iR" + +srclist=$(getds_with_suffix $dstds/$FS @final) +interlist="$srclist $(getds_with_suffix $dstds/$FS @snapC)" +interlist="$interlist $(getds_with_suffix $dstds/$FS @snapB)" +interlist="$interlist $(getds_with_suffix $dstds/$FS @snapA)" +log_must destroy_tree $interlist +if is_global_zone ; then + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/fs-init-final-iR" +else + $ZFS receive -F -d $dstds/$FS < $BACKDIR/fs-init-final-iR +fi + +dstlist=$(getds_with_suffix $dstds/$FS @final) +if [[ $srclist != $dstlist ]]; then + log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)" +fi +log_must cmp_ds_cont $POOL $POOL2 + +if is_global_zone ; then + # + # Testing send -R -i backup from volume + # + srclist=$(getds_with_suffix $POOL2/$FS/vol @final) + log_must eval "$ZFS send -R -i @init $POOL2/$FS/vol@final > " \ + "$BACKDIR/vol-init-final-iR" + log_must destroy_tree $srclist + log_must eval "$ZFS receive -d $POOL2 < $BACKDIR/vol-init-final-iR" + + dstlist=$(getds_with_suffix $POOL2/$FS/vol @final) + if [[ $srclist != $dstlist ]]; then + log_fail "Unexpected: srclist($srclist) != dstlist($dstlist)" + fi + log_must cmp_ds_cont $POOL $POOL2 +fi + +log_pass "zfs send -R -i send incremental from fs@init to fs@final." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_005_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_005_pos.ksh new file mode 100644 index 00000000000..439c857e3c2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_005_pos.ksh @@ -0,0 +1,118 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_005_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_005_pos +# +# DESCRIPTION: +# zfs send -R -I send all the incremental between fs@init with fs@final +# +# STRATEGY: +# 1. Setup test model +# 2. Send -R -I @init @final on pool +# 3. Destroy all the snapshots which is later than @init +# 4. Verify receive can restore all the snapshots and data +# 5. Do the same test on filesystem and volume +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "zfs send -R -I send all the incremental between @init with @final" +log_onexit cleanup_pool $POOL2 + +# +# Duplicate POOL2 for testing +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" + +if is_global_zone ; then + # + # Testing send -R -I from pool + # + log_must eval "$ZFS send -R -I @init $POOL2@final > " \ + "$BACKDIR/pool-init-final-IR" + list=$(getds_with_suffix $POOL2 @snapA) + list="$list $(getds_with_suffix $POOL2 @snapB)" + list="$list $(getds_with_suffix $POOL2 @snapC)" + list="$list $(getds_with_suffix $POOL2 @final)" + log_must destroy_tree $list + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-init-final-IR" + log_must cmp_ds_cont $POOL $POOL2 +fi + +dstds=$(get_dst_ds $POOL $POOL2) +# +# Testing send -R -I from filesystem +# +log_must eval "$ZFS send -R -I @init $dstds/$FS@final > " \ + "$BACKDIR/fs-init-final-IR" +list=$(getds_with_suffix $dstds/$FS @snapA) +list="$list $(getds_with_suffix $dstds/$FS @snapB)" +list="$list $(getds_with_suffix $dstds/$FS @snapC)" +list="$list $(getds_with_suffix $dstds/$FS @final)" +log_must destroy_tree $list +if is_global_zone ; then + log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-IR" +else + $ZFS receive -d -F $dstds < $BACKDIR/fs-init-final-IR +fi +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +if is_global_zone ; then + # + # Testing send -I -R for volume + # + vol=$POOL2/$FS/vol + log_must eval "$ZFS send -R -I @init $vol@final > " \ + "$BACKDIR/vol-init-final-IR" + log_must destroy_tree $vol@snapB $vol@snapC $vol@final + log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/vol-init-final-IR" + log_must cmp_ds_subs $POOL $POOL2 + log_must cmp_ds_cont $POOL $POOL2 +fi + +log_pass "zfs send -R -I send all the incremental between @init with @final" diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_006_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_006_pos.ksh new file mode 100644 index 00000000000..22445101b59 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_006_pos.ksh @@ -0,0 +1,96 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_006_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_006_pos +# +# DESCRIPTION: +# Rename snapshot name will not change the dependent order. +# +# STRATEGY: +# 1. Set up a set of datasets. +# 2. Rename part of snapshots. +# 3. Send -R all the POOL +# 4. Verify snapshot name will not change the dependent order. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Source Target +# +set -A snaps "$POOL@init" "$POOL@snap0" \ + "$POOL@snapA" "$POOL@snap1" \ + "$POOL@snapC" "$POOL@snap2" \ + "$POOL@final" "$POOL@init" + +function cleanup +{ + log_must cleanup_pool $POOL + log_must cleanup_pool $POOL2 + + log_must setup_test_model $POOL +} + +log_assert "Rename snapshot name will not change the dependent order." +log_onexit cleanup + +typeset -i i=0 +while ((i < ${#snaps[@]})); do + log_must $ZFS rename -r ${snaps[$i]} ${snaps[((i+1))]} + + ((i += 2)) +done + +# +# Duplicate POOL2 for testing +# +log_must eval "$ZFS send -R $POOL@init > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" + +dstds=$(get_dst_ds $POOL $POOL2) +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +log_pass "Rename snapshot name will not change the dependent order." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_007_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_007_pos.ksh new file mode 100644 index 00000000000..219366253b3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_007_pos.ksh @@ -0,0 +1,113 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_007_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_007_pos +# +# DESCRIPTION: +# Rename parent filesystem name will not change the dependent order. +# +# STRATEGY: +# 1. Separately rename pool clone, filesystem and volume name. +# 2. Send -R all the POOL +# 3. Verify renamed dataset will not change the snapshot dependent order. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +set -A dtst \ + "$POOL/pclone" "$POOL/$FS/pclone" \ + "$POOL/$FS/fs1/fs2" "$POOL/fs2" +if is_global_zone ; then + typeset -i n=${#dtst[@]} + dtst[((n))]="$POOL/vol"; dtst[((n+1))]="$POOL/$FS/fs1/vol" +fi + +function cleanup +{ + log_must cleanup_pool $POOL + log_must cleanup_pool $POOL2 + + log_must setup_test_model $POOL +} + +log_assert "Rename parent filesystem name will not change the dependent order." +log_onexit cleanup + +typeset -i i=0 +while ((i < ${#dtst[@]})); do + log_must $ZFS rename ${dtst[$i]} ${dtst[((i+1))]} + + ((i += 2)) +done + +# +# Verify zfs send -R should succeed +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" +dstds=$(get_dst_ds $POOL $POOL2) +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +# +# Verify zfs send -R -I should succeed +# +log_must eval "$ZFS send -R -I @init $dstds@final > " \ + "$BACKDIR/pool-init-final-IR" +list=$(getds_with_suffix $dstds @snapA) +list="$list $(getds_with_suffix $dstds @snapB)" +list="$list $(getds_with_suffix $dstds @snapC)" +list="$list $(getds_with_suffix $dstds @final)" +log_must destroy_tree $list +if is_global_zone ; then + log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/pool-init-final-IR" +else + $ZFS receive -d -F $dstds < $BACKDIR/pool-init-final-IR +fi +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +log_pass "Rename parent filesystem name will not change the dependent order." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_008_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_008_pos.ksh new file mode 100644 index 00000000000..380fb31955e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_008_pos.ksh @@ -0,0 +1,142 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_008_pos.ksh 1.2 09/01/12 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_008_pos +# +# DESCRIPTION: +# Changes made by 'zfs promote' can be properly received. +# +# STRATEGY: +# 1. Separately promote pool clone, filesystem clone and volume clone. +# 2. Recursively backup all the POOL and restore in POOL2 +# 3. Verify all the datesets and property be properly received. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Origin Clone +# +set -A dtst "$POOL" "$POOL/pclone" \ + "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" +if is_global_zone ; then + typeset -i n=${#dtst[@]} + dtst[((n))]="$POOL/$FS/vol"; dtst[((n+1))]="$POOL/$FS/vclone" +fi + +function cleanup +{ + typeset origin + typeset -i i=0 + while ((i < ${#dtst[@]})); do + origin=$(get_prop origin ${dtst[$i]}) + + if [[ $origin != "-" ]]; then + log_must $ZFS promote ${dtst[$i]} + fi + + ((i += 2)) + done + + origin=$(get_prop origin $POOL2) + if [[ $origin != "-" ]]; then + log_must $ZFS promote $POOL2 + fi + log_must cleanup_pool $POOL2 +} + +log_assert "Changes made by 'zfs promote' can be properly received." +log_onexit cleanup + +typeset -i i=0 +while ((i < ${#dtst[@]})); do + log_must $ZFS promote ${dtst[((i+1))]} + + ((i += 2)) +done + +# +# Verify zfs send -R should succeed +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" + +dstds=$(get_dst_ds $POOL $POOL2) +# +# Define all the POOL/POOL2 datasets pair +# +set -A pair "$POOL" "$dstds" \ + "$POOL/$FS" "$dstds/$FS" \ + "$POOL/$FS/fs1" "$dstds/$FS/fs1" \ + "$POOL/$FS/fs1/fs2" "$dstds/$FS/fs1/fs2" \ + "$POOL/pclone" "$dstds/pclone" \ + "$POOL/$FS/fs1/fclone" "$dstds/$FS/fs1/fclone" + +if is_global_zone ; then + typeset -i n=${#pair[@]} + pair[((n))]="$POOL/vol"; pair[((n+1))]="$dstds/vol" + pair[((n+2))]="$POOL/$FS/vol" pair[((n+3))]="$dstds/$FS/vol" +fi + +# +# Verify all the sub-datasets can be properly received. +# +log_must cmp_ds_subs $POOL $dstds +typeset -i i=0 +while ((i < ${#pair[@]})); do + log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]} + log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]} + + ((i += 2)) +done + +# Verify the original filesystem can be promoted +log_must $ZFS promote $dstds +if is_global_zone ; then + log_must $ZFS promote $dstds/$FS/vol +fi +log_must $ZFS promote $dstds/$FS/fs1/fs2 + +log_pass "Changes made by 'zfs promote' can be properly received." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_009_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_009_pos.ksh new file mode 100644 index 00000000000..aeac359455f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_009_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_009_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_009_pos +# +# DESCRIPTION: +# zfs receive can handle out of space correctly. +# +# STRATEGY: +# 1. Create two pools, one is big and another is small. +# 2. Fill the big pool with data. +# 3. Take snapshot and backup the whole pool. +# 4. Receive this stream in small pool. +# 5. Verify zfs receive can handle the out of space error correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-10-10) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if datasetexists bpool ; then + log_must $ZPOOL destroy -f bpool + fi + if datasetexists spool ; then + log_must $ZPOOL destroy -f spool + fi +} + +log_assert "Verify zfs receive can handle out of space correctly." +log_onexit cleanup + +log_must $TRUNCATE -s 100M $TESTDIR/bfile +log_must $TRUNCATE -s 64M $TESTDIR/sfile +log_must $ZPOOL create bpool $TESTDIR/bfile +log_must $ZPOOL create spool $TESTDIR/sfile + +# +# Test out of space on sub-filesystem +# +log_must $ZFS create bpool/fs +mntpnt=$(get_prop mountpoint bpool/fs) +log_must $TRUNCATE -s 30M $mntpnt/file + +log_must $ZFS snapshot bpool/fs@snap +log_must eval "$ZFS send -R bpool/fs@snap > $BACKDIR/fs-R" +log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/fs-R" + +log_must datasetnonexists spool/fs +log_must ismounted spool + +# +# Test out of space on top filesystem +# +mntpnt2=$(get_prop mountpoint bpool) +log_must $MV $mntpnt/file $mntpnt2 +log_must $ZFS destroy -rf bpool/fs + +log_must $ZFS snapshot bpool@snap +log_must eval "$ZFS send -R bpool@snap > $BACKDIR/bpool-R" +log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/bpool-R" + +log_must datasetnonexists spool/fs +log_must ismounted spool + +log_pass "zfs receive can handle out of space correctly." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_010_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_010_pos.ksh new file mode 100644 index 00000000000..6a67b6c27a3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_010_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_010_pos.ksh 1.1 08/02/27 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_010_pos +# +# DESCRIPTION: +# ZFS can handle stream with multiple identical (same GUID) snapshots +# +# STRATEGY: +# 1. Recursively backup snapshot +# 2. Restore it to the given filesystem +# 3. Resend the snapshot again +# 4. Verify this stream can be restore to this filesystem again +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-10-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "ZFS can handle stream with multiple identical (same GUID) snapshots" +log_onexit cleanup_pool $POOL2 + +log_must $ZFS create $POOL2/$FS +log_must $ZFS snapshot $POOL2/$FS@snap + +# +# First round restore the stream +# +log_must eval "$ZFS send -R $POOL2/$FS@snap > $BACKDIR/fs-R" +log_must eval "$ZFS receive -d -F $POOL2/$FS < $BACKDIR/fs-R" + +# +# In order to avoid 'zfs send -R' failed, create snapshot for +# all the sub-systems +# +list=$($ZFS list -r -H -o name -t filesystem $POOL2/$FS) +for item in $list ; do + if datasetnonexists $item@snap ; then + log_must $ZFS snapshot $item@snap + fi +done + +# +# Second round restore the stream +# +log_must eval "$ZFS send -R $POOL2/$FS@snap > $BACKDIR/fs-R" +dstds=$(get_dst_ds $POOL2/$FS $POOL2/$FS) +log_must eval "$ZFS receive -d -F $dstds < $BACKDIR/fs-R" + +log_pass "ZFS can handle stream with multiple identical (same GUID) snapshots" diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_011_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_011_pos.ksh new file mode 100644 index 00000000000..0c07f069c96 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_011_pos.ksh @@ -0,0 +1,137 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_011_pos.ksh 1.2 09/08/06 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_011_pos +# +# DESCRIPTION: +# Changes made by 'zfs inherit' can be properly received. +# +# STRATEGY: +# 1. Inherit property for filesystem and volume +# 2. Send and restore them in the target pool +# 3. Verify all the datasets can be properly backup and receive +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-10-10) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + unmount_all_safe > /dev/null 2>&1 + log_must cleanup_pool $POOL + log_must cleanup_pool $POOL2 + + log_must setup_test_model $POOL +} + +log_assert "Verify changes made by 'zfs inherit' can be properly received." +log_onexit cleanup + +# +# Setting all the $FS properties as local value, +# +for prop in $(fs_inherit_prop); do + value=$(get_prop $prop $POOL/$FS) + log_must $ZFS set $prop=$value $POOL/$FS +done + +# +# Inherit propertes in sub-datasets +# +for ds in "$POOL/$FS/fs1" "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do + for prop in $(fs_inherit_prop) ; do + $ZFS inherit $prop $ds + if (($? !=0 )); then + log_fail "$ZFS inherit $prop $ds" + fi + done +done +if is_global_zone ; then + for prop in $(vol_inherit_prop) ; do + $ZFS inherit $prop $POOL/$FS/vol + if (($? !=0 )); then + log_fail "$ZFS inherit $prop $POOL/$FS/vol" + fi + done +fi + +# +# Verify datasets can be backup and restore correctly +# Unmount $POOL/$FS to avoid two fs mount in the same mountpoint +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-R" +log_must $ZFS unmount -f $POOL/$FS +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-R" + +dstds=$(get_dst_ds $POOL $POOL2) +# +# Define all the POOL/POOL2 datasets pair +# +set -A pair "$POOL" "$dstds" \ + "$POOL/$FS" "$dstds/$FS" \ + "$POOL/$FS/fs1" "$dstds/$FS/fs1" \ + "$POOL/$FS/fs1/fs2" "$dstds/$FS/fs1/fs2" \ + "$POOL/pclone" "$dstds/pclone" \ + "$POOL/$FS/fs1/fclone" "$dstds/$FS/fs1/fclone" + +if is_global_zone ; then + typeset -i n=${#pair[@]} + pair[((n))]="$POOL/vol"; pair[((n+1))]="$dstds/vol" + pair[((n+2))]="$POOL/$FS/vol" pair[((n+3))]="$dstds/$FS/vol" +fi + +# +# Verify all the sub-datasets can be properly received. +# +log_must cmp_ds_subs $POOL $dstds +typeset -i i=0 +while ((i < ${#pair[@]})); do + log_must cmp_ds_cont ${pair[$i]} ${pair[((i+1))]} + log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]} + + ((i += 2)) +done + +log_pass "Changes made by 'zfs inherit' can be properly received." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_012_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_012_pos.ksh new file mode 100644 index 00000000000..295ebe63bdf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_012_pos.ksh @@ -0,0 +1,211 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_012_pos.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_012_pos +# +# DESCRIPTION: +# zfs send -R will backup all the filesystem properties correctly. +# +# STRATEGY: +# 1. Setting properties for all the filesystem and volumes randomly +# 2. Backup all the data from POOL by send -R +# 3. Restore all the data in POOL2 +# 4. Verify all the perperties in two pools are same +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-08-27) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function rand_set_prop +{ + typeset dtst=$1 + typeset prop=$2 + shift 2 + typeset value=$(random_get $@) + + log_must eval "$ZFS set $prop='$value' $dtst" +} + +function edited_prop +{ + typeset behaviour=$1 + typeset ds=$2 + typeset backfile=$TESTDIR/edited_prop_$ds + + case $behaviour in + "get") + typeset props=$($ZFS inherit 2>&1 | \ + $AWK '$2=="YES" {print $1}' | \ + $EGREP -v "^vol|\.\.\.$") + for item in $props ; do + $ZFS get -H -o property,value $item $ds >> \ + $backfile + if (($? != 0)); then + log_fail "zfs get -H -o property,value"\ + "$item $ds > $backfile" + fi + done + ;; + "set") + if [[ ! -f $backfile ]] ; then + log_fail "$ds need backup properties firstly." + fi + + typeset prop value + while read prop value ; do + eval $ZFS set $prop='$value' $ds + if (($? != 0)); then + log_fail "$ZFS set $prop=$value $ds" + fi + done < $backfile + ;; + *) + log_fail "Unrecognized behaviour: $behaviour" + esac +} + +function cleanup +{ + log_must cleanup_pool $POOL + log_must cleanup_pool $POOL2 + + log_must edited_prop "set" $POOL + log_must edited_prop "set" $POOL2 + + typeset prop + for prop in $(fs_inherit_prop) ; do + log_must $ZFS inherit $prop $POOL + log_must $ZFS inherit $prop $POOL2 + done + + #if is_shared $POOL; then + # log_must $ZFS set sharenfs=off $POOL + #fi + log_must setup_test_model $POOL + + if [[ -d $TESTDIR ]]; then + log_must $RM -rf $TESTDIR/* + fi +} + +log_assert "Verify zfs send -R will backup all the filesystem properties " \ + "correctly." +log_onexit cleanup + +log_must edited_prop "get" $POOL +log_must edited_prop "get" $POOL2 + +for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \ + "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do + rand_set_prop $fs aclinherit "discard" "noallow" "secure" "passthrough" + rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256" + rand_set_prop $fs aclmode "discard" "groupmask" "passthrough" + rand_set_prop $fs atime "on" "off" + rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256" + rand_set_prop $fs compression "on" "off" "lzjb" "gzip" \ + "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6" \ + "gzip-7" "gzip-8" "gzip-9" + rand_set_prop $fs copies "1" "2" "3" + rand_set_prop $fs devices "on" "off" + rand_set_prop $fs exec "on" "off" + rand_set_prop $fs quota "512M" "1024M" + rand_set_prop $fs recordsize "512" "2K" "8K" "32K" "128K" + rand_set_prop $fs setuid "on" "off" + rand_set_prop $fs snapdir "hidden" "visible" + rand_set_prop $fs xattr "on" "off" + rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?" +done + +for vol in "$POOL/vol" "$POOL/$FS/vol" ; do + rand_set_prop $vol checksum "on" "off" "fletcher2" "fletcher4" "sha256" + rand_set_prop $vol compression "on" "off" "lzjb" "gzip" \ + "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" "gzip-6" \ + "gzip-7" "gzip-8" "gzip-9" + rand_set_prop $vol readonly "on" "off" + rand_set_prop $vol copies "1" "2" "3" + rand_set_prop $vol user:prop "aaa" "bbb" "23421" "()-+?" +done + + +# Verify inherited property can be received +rand_set_prop $POOL sharenfs "on" "off" "rw" + +# +# Duplicate POOL2 for testing +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -d -F $POOL2 < $BACKDIR/pool-final-R" + +# +# Define all the POOL/POOL2 datasets pair +# +set -A pair "$POOL" "$POOL2" \ + "$POOL/$FS" "$POOL2/$FS" \ + "$POOL/$FS/fs1" "$POOL2/$FS/fs1" \ + "$POOL/$FS/fs1/fs2" "$POOL2/$FS/fs1/fs2" \ + "$POOL/pclone" "$POOL2/pclone" \ + "$POOL/$FS/fs1/fclone" "$POOL2/$FS/fs1/fclone" \ + "$POOL/vol" "$POOL2/vol" \ + "$POOL/$FS/vol" "$POOL2/$FS/vol" + +typeset -i i=0 +while ((i < ${#pair[@]})); do + log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]} + + ((i += 2)) +done + + +$ZPOOL upgrade -v | $GREP "Snapshot properties" > /dev/null 2>&1 +if (( $? == 0 )) ; then + i=0 + while ((i < ${#pair[@]})); do + log_must cmp_ds_prop ${pair[$i]}@final ${pair[((i+1))]}@final + ((i += 2)) + done +fi + +log_pass "Verify zfs send -R will backup all the filesystem properties " \ + "correctly." diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_013_pos.ksh b/tests/sys/cddl/zfs/tests/rsend/rsend_013_pos.ksh new file mode 100644 index 00000000000..8bd1b91acd1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_013_pos.ksh @@ -0,0 +1,100 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rsend_013_pos.ksh 1.1 09/01/12 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: rsend_013_pos +# +# DESCRIPTION: +# zfs receive -dF with incremental stream will destroy all the +# dataset that not exist on the sender side. +# +# STRATEGY: +# 1. Setup test model +# 2. Send -R @final on pool +# 3. Destroy some dataset within the @final, and create @destroy +# 4. Send -R -I @final @destroy on pool +# 5. Verify receive -dF will destroy all the dataset that not exist +# on the sender side. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-15) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + cleanup_pool $POOL2 + cleanup_pool $POOL + log_must setup_test_model $POOL +} + +log_assert "zfs receive -dF will destroy all the dataset that not exist" \ + "on the sender side" +log_onexit cleanup + +cleanup + +# +# Duplicate POOL2 for testing +# +log_must eval "$ZFS send -R $POOL@final > $BACKDIR/pool-final-R" +log_must eval "$ZFS receive -dF $POOL2 < $BACKDIR/pool-final-R" + +log_must $ZFS destroy -Rf $POOL/$FS +log_must $ZFS destroy -Rf $POOL/pclone + +if is_global_zone ; then + log_must $ZFS destroy -Rf $POOL/vol +fi +log_must $ZFS snapshot -r $POOL@destroy + +log_must eval "$ZFS send -R -I @final $POOL@destroy > " \ + "$BACKDIR/pool-final-destroy-IR" +log_must eval "$ZFS receive -dF $POOL2 < $BACKDIR/pool-final-destroy-IR" + +dstds=$(get_dst_ds $POOL $POOL2) +log_must cmp_ds_subs $POOL $dstds +log_must cmp_ds_cont $POOL $dstds + +log_pass "zfs receive -dF will destroy all the dataset that not exist" \ + "on the sender side" diff --git a/tests/sys/cddl/zfs/tests/rsend/rsend_test.sh b/tests/sys/cddl/zfs/tests/rsend/rsend_test.sh new file mode 100755 index 00000000000..8ab38b48bd5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/rsend_test.sh @@ -0,0 +1,396 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case rsend_001_pos cleanup +rsend_001_pos_head() +{ + atf_set "descr" "zfs send -R send replication stream up to the named snap." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_001_pos.ksh || atf_fail "Testcase failed" +} +rsend_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_002_pos cleanup +rsend_002_pos_head() +{ + atf_set "descr" "zfs send -I sends all incrementals from fs@init to fs@final." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_002_pos.ksh || atf_fail "Testcase failed" +} +rsend_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_003_pos cleanup +rsend_003_pos_head() +{ + atf_set "descr" "zfs send -I send all incrementals from dataset@init to clone@snap" + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_003_pos.ksh || atf_fail "Testcase failed" +} +rsend_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_004_pos cleanup +rsend_004_pos_head() +{ + atf_set "descr" "zfs send -R -i send incremental from fs@init to fs@final." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_004_pos.ksh || atf_fail "Testcase failed" +} +rsend_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_005_pos cleanup +rsend_005_pos_head() +{ + atf_set "descr" "zfs send -R -I send all the incremental between @init with @final" + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_005_pos.ksh || atf_fail "Testcase failed" +} +rsend_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_006_pos cleanup +rsend_006_pos_head() +{ + atf_set "descr" "Rename snapshot name will not change the dependent order." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_006_pos.ksh || atf_fail "Testcase failed" +} +rsend_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_007_pos cleanup +rsend_007_pos_head() +{ + atf_set "descr" "Rename parent filesystem name will not change the dependent order." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_007_pos.ksh || atf_fail "Testcase failed" +} +rsend_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_008_pos cleanup +rsend_008_pos_head() +{ + atf_set "descr" "Changes made by 'zfs promote' can be properly received." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_008_pos.ksh || atf_fail "Testcase failed" +} +rsend_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_009_pos cleanup +rsend_009_pos_head() +{ + atf_set "descr" "Verify zfs receive can handle out of space correctly." + atf_set "require.progs" zpool zfs + atf_set "timeout" 2700 +} +rsend_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_009_pos.ksh || atf_fail "Testcase failed" +} +rsend_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_010_pos cleanup +rsend_010_pos_head() +{ + atf_set "descr" "ZFS can handle stream with multiple identical (same GUID) snapshots" + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_010_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_010_pos.ksh || atf_fail "Testcase failed" +} +rsend_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_011_pos cleanup +rsend_011_pos_head() +{ + atf_set "descr" "Verify changes made by 'zfs inherit' can be properly received." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_011_pos.ksh || atf_fail "Testcase failed" +} +rsend_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_012_pos cleanup +rsend_012_pos_head() +{ + atf_set "descr" "Verify zfs send -R will backup all the filesystem propertiescorrectly." + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_012_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_012_pos.ksh || atf_fail "Testcase failed" +} +rsend_012_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rsend_013_pos cleanup +rsend_013_pos_head() +{ + atf_set "descr" "zfs receive -dF will destroy all the dataset that not existon the sender side" + atf_set "require.progs" zfs zpool + atf_set "timeout" 2700 +} +rsend_013_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rsend_013_pos.ksh || atf_fail "Testcase failed" +} +rsend_013_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/rsend.kshlib + . $(atf_get_srcdir)/rsend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case rsend_001_pos + atf_add_test_case rsend_002_pos + atf_add_test_case rsend_003_pos + atf_add_test_case rsend_004_pos + atf_add_test_case rsend_005_pos + atf_add_test_case rsend_006_pos + atf_add_test_case rsend_007_pos + atf_add_test_case rsend_008_pos + atf_add_test_case rsend_009_pos + atf_add_test_case rsend_010_pos + atf_add_test_case rsend_011_pos + atf_add_test_case rsend_012_pos + atf_add_test_case rsend_013_pos +} diff --git a/tests/sys/cddl/zfs/tests/rsend/setup.ksh b/tests/sys/cddl/zfs/tests/rsend/setup.ksh new file mode 100644 index 00000000000..3b901cd3586 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/rsend/setup.ksh @@ -0,0 +1,52 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/rsend/rsend.kshlib + +verify_runnable "both" + +# +# Check if the system support 'send -R' +# +$ZFS send 2>&1 | grep -w "[-R]" > /dev/null 2>&1 +if (($? != 0)); then + log_unsupported +fi + +if is_global_zone ; then + log_must $ZPOOL create $POOL $DISK1 + log_must $ZPOOL create $POOL2 $DISK2 +fi +log_must $MKDIR $BACKDIR $TESTDIR + +log_must setup_test_model $POOL + +log_pass diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/Makefile b/tests/sys/cddl/zfs/tests/scrub_mirror/Makefile new file mode 100644 index 00000000000..874e97949ce --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/scrub_mirror +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= scrub_mirror_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= scrub_mirror_004_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= scrub_mirror_001_pos.ksh +${PACKAGE}FILES+= scrub_mirror_003_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= default.cfg +${PACKAGE}FILES+= scrub_mirror_002_pos.ksh +${PACKAGE}FILES+= scrub_mirror_common.kshlib + +.include diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/cleanup.ksh b/tests/sys/cddl/zfs/tests/scrub_mirror/cleanup.ksh new file mode 100644 index 00000000000..d48ac23d041 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/cleanup.ksh @@ -0,0 +1,48 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)cleanup.ksh 1.3 07/02/06 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +$DF -t zfs -h | $GREP "$TESTFS " >/dev/null +[[ $? == 0 ]] && log_must $ZFS umount -f $TESTDIR +destroy_pool $TESTPOOL + +# recreate and destroy a zpool over the disks to restore the partitions to +# normal +if [[ -n $SINGLE_DISK ]]; then + log_must cleanup_devices $MIRROR_PRIMARY +else + log_must cleanup_devices $MIRROR_PRIMARY $MIRROR_SECONDARY +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/default.cfg b/tests/sys/cddl/zfs/tests/scrub_mirror/default.cfg new file mode 100644 index 00000000000..1664bb71f33 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/default.cfg @@ -0,0 +1,57 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)default.cfg 1.3 08/08/15 SMI" +# + +typeset -i NUMBER_OF_DISKS=0 +for i in $DISKS; do + [[ -n $MIRROR_PRIMARY ]] && MIRROR_SECONDARY=$i + [[ -z $MIRROR_PRIMARY ]] && MIRROR_PRIMARY=$i +done + +if [[ -z $MIRROR_SECONDARY ]]; then + # We need to repartition the single disk to two partitions + SINGLE_DISK=$MIRROR_PRIMARY + MIRROR_SECONDARY=$MIRROR_PRIMARY + SIDE_PRIMARY=${SINGLE_DISK}p1 + SIDE_SECONDARY=${SINGLE_DISK}p2 +else + SIDE_PRIMARY=${MIRROR_PRIMARY}p1 + SIDE_SECONDARY=${MIRROR_SECONDARY}p1 +fi + +export MIRROR_PRIMARY MIRROR_SECONDARY SINGLE_DISK SIDE_PRIMARY SIDE_SECONDARY + +export FILE_COUNT=30 +export FILE_SIZE=$(( 1024 * 1024 )) +export MIRROR_MEGS=70 +export MIRROR_SIZE=${MIRROR_MEGS}m # default mirror size +export BLOCKSZ=$(( 64 * 1024 )) +export WRITE_COUNT=$(( MIRROR_MEGS * 1024 * 1024 / BLOCKSZ )) +export TESTFILE=testfile${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_001_pos.ksh b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_001_pos.ksh new file mode 100644 index 00000000000..cb5345853cb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_001_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)scrub_mirror_001_pos.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/scrub_mirror/scrub_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: scrub_mirror_001_pos +# +# DESCRIPTION: +# The primary side of a zpool mirror can be zeroed without causing damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem mirror +# 2) dd from /dev/zero over the primary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely wiped" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $TESTPOOL $SIDE_PRIMARY /dev/zero + +log_pass "The overwrite had no effect on the data" diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_002_pos.ksh b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_002_pos.ksh new file mode 100644 index 00000000000..c0cfebf1293 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_002_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)scrub_mirror_002_pos.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/scrub_mirror/scrub_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: scrub_mirror_002_pos +# +# DESCRIPTION: +# The secondary side of a zpool mirror can be zeroed without causing damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem in the mirrored pool +# 2) dd from /dev/zero over the secondary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely wiped" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $TESTPOOL $SIDE_SECONDARY /dev/zero + +log_pass "The overwrite had no effect on the data" diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_003_pos.ksh b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_003_pos.ksh new file mode 100644 index 00000000000..4a3fa933701 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_003_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)scrub_mirror_003_pos.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/scrub_mirror/scrub_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: scrub_mirror_003_pos +# +# DESCRIPTION: +# The primary side of a zpool mirror can be mangled causing without damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem mirror +# 2) dd from /dev/urandom over the primary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely mangled" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $TESTPOOL $SIDE_PRIMARY /dev/urandom + +log_pass "The overwrite did not have any effect on the data" diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_004_pos.ksh b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_004_pos.ksh new file mode 100644 index 00000000000..18f2ee234a3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_004_pos.ksh @@ -0,0 +1,67 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)scrub_mirror_004_pos.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/scrub_mirror/scrub_mirror_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: scrub_mirror_004_pos +# +# DESCRIPTION: +# The secondary side of a zpool mirror can be mangled causing without damage +# to the data in the pool +# +# STRATEGY: +# 1) Write several files to the ZFS filesystem in the mirrored pool +# 2) dd from /dev/urandom over the secondary side of the mirror +# 3) verify that all the file contents are unchanged on the file system +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "The primary side of a zpool mirror may be completely mangled" \ + "without affecting the content of the pool" + +overwrite_verify_mirror $TESTPOOL $SIDE_SECONDARY /dev/urandom + +log_pass "The overwrite had no effect on the data" diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_common.kshlib b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_common.kshlib new file mode 100644 index 00000000000..2e774bfb808 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_common.kshlib @@ -0,0 +1,83 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)scrub_mirror_common.kshlib 1.5 07/10/09 SMI" +# + +function overwrite_verify_mirror +{ + typeset POOL=$1 + typeset AFFECTED_DEVICE=$2 + typeset OVERWRITING_DEVICE=$3 + + typeset atfile=0 + set -A files + set -A cksums + set -A newcksums + + fill_fs $TESTDIR -1 $FILE_COUNT $BLOCKSZ $WRITE_COUNT + while [ "$atfile" -lt "$FILE_COUNT" ]; do + if [ -f ${TESTDIR}/0/${TESTFILE}.${atfile} ]; then + cksums[$atfile]=$($CKSUM ${TESTDIR}/0/${TESTFILE}.${atfile}) + fi + (( atfile = $atfile + 1 )) + done + + # unmount and export before dd + log_must $ZPOOL export $POOL + + # dd the affected side of the mirror + log_must $DD if=$OVERWRITING_DEVICE of=$(bsddevmap $AFFECTED_DEVICE) \ + seek=8 bs=$BLOCKSZ count=$(( WRITE_COUNT - 8 )) conv=notrunc + + # now remount and scrub + log_must $ZPOOL import $POOL + log_must $ZPOOL scrub $POOL + wait_for 60 1 is_pool_scrubbed $POOL + + atfile=0 + typeset -i failedcount=0 + while [ "$atfile" -lt "$FILE_COUNT" ]; do + if [ -f ${TESTDIR}/0/${TESTFILE}.${atfile} ]; then + newcksum=$($CKSUM $TESTDIR/0/${TESTFILE}.${atfile}) + if [[ $newcksum != ${cksums[$atfile]} ]]; then + (( failedcount = $failedcount + 1 )) + else + log_note "${TESTFILE}.${atfile} checksums match:"\ + "old ${cksums[$atfile]} new $newcksum" + fi + $RM -f ${files[$atfile]} + fi + (( atfile = $atfile + 1 )) + done + + if [ "$failedcount" -gt 0 ]; then + log_fail "of the $FILE_COUNT files $failedcount did not " \ + "have the same checksum before and after." + fi +} diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_test.sh b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_test.sh new file mode 100755 index 00000000000..eb523c2777d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/scrub_mirror_test.sh @@ -0,0 +1,140 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case scrub_mirror_001_pos cleanup +scrub_mirror_001_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely wipedwithout affecting the content of the pool" + atf_set "require.progs" zfs +} +scrub_mirror_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/scrub_mirror_001_pos.ksh || atf_fail "Testcase failed" +} +scrub_mirror_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case scrub_mirror_002_pos cleanup +scrub_mirror_002_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely wipedwithout affecting the content of the pool" + atf_set "require.progs" zfs +} +scrub_mirror_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/scrub_mirror_002_pos.ksh || atf_fail "Testcase failed" +} +scrub_mirror_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case scrub_mirror_003_pos cleanup +scrub_mirror_003_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely mangledwithout affecting the content of the pool" + atf_set "require.progs" zfs +} +scrub_mirror_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/scrub_mirror_003_pos.ksh || atf_fail "Testcase failed" +} +scrub_mirror_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case scrub_mirror_004_pos cleanup +scrub_mirror_004_pos_head() +{ + atf_set "descr" "The primary side of a zpool mirror may be completely mangledwithout affecting the content of the pool" + atf_set "require.progs" zfs +} +scrub_mirror_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/scrub_mirror_004_pos.ksh || atf_fail "Testcase failed" +} +scrub_mirror_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/scrub_mirror_common.kshlib + . $(atf_get_srcdir)/default.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case scrub_mirror_001_pos + atf_add_test_case scrub_mirror_002_pos + atf_add_test_case scrub_mirror_003_pos + atf_add_test_case scrub_mirror_004_pos +} diff --git a/tests/sys/cddl/zfs/tests/scrub_mirror/setup.ksh b/tests/sys/cddl/zfs/tests/scrub_mirror/setup.ksh new file mode 100644 index 00000000000..cbe061c24be --- /dev/null +++ b/tests/sys/cddl/zfs/tests/scrub_mirror/setup.ksh @@ -0,0 +1,47 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)setup.ksh 1.5 09/01/12 SMI" +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if [[ -n $SINGLE_DISK ]]; then + log_note "Partitioning a single disk ($SINGLE_DISK)" +else + log_note "Partitioning disks ($MIRROR_PRIMARY $MIRROR_SECONDARY)" +fi +wipe_partition_table $SINGLE_DISK $MIRROR_PRIMARY $MIRROR_SECONDARY +log_must set_partition ${SIDE_PRIMARY##*p} "" $MIRROR_SIZE $MIRROR_PRIMARY +log_must set_partition ${SIDE_SECONDARY##*p} "" $MIRROR_SIZE $MIRROR_SECONDARY + +default_mirror_setup $SIDE_PRIMARY $SIDE_SECONDARY + +log_pass diff --git a/tests/sys/cddl/zfs/tests/slog/Makefile b/tests/sys/cddl/zfs/tests/slog/Makefile new file mode 100644 index 00000000000..4fb7f00b84c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/Makefile @@ -0,0 +1,32 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/slog +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= slog_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= slog_012_neg.ksh +${PACKAGE}FILES+= slog_013_pos.ksh +${PACKAGE}FILES+= slog_002_pos.ksh +${PACKAGE}FILES+= slog_006_pos.ksh +${PACKAGE}FILES+= slog.kshlib +${PACKAGE}FILES+= slog_003_pos.ksh +${PACKAGE}FILES+= slog_007_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= slog.cfg +${PACKAGE}FILES+= slog_001_pos.ksh +${PACKAGE}FILES+= slog_005_pos.ksh +${PACKAGE}FILES+= slog_008_neg.ksh +${PACKAGE}FILES+= slog_011_neg.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= slog_014_pos.ksh +${PACKAGE}FILES+= slog_010_neg.ksh +${PACKAGE}FILES+= slog_004_pos.ksh +${PACKAGE}FILES+= slog_009_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/slog/cleanup.ksh b/tests/sys/cddl/zfs/tests/slog/cleanup.ksh new file mode 100644 index 00000000000..6840d4828a2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/cleanup.ksh @@ -0,0 +1,49 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if datasetexists $TESTPOOL ; then + log_must $ZPOOL destroy -f $TESTPOOL +fi +if datasetexists $TESTPOOL2 ; then + log_must $ZPOOL destroy -f $TESTPOOL2 +fi +if [[ -d $VDIR ]]; then + log_must $RM -rf $VDIR +fi +if [[ -d $VDIR2 ]]; then + log_must $RM -rf $VDIR2 +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/slog/setup.ksh b/tests/sys/cddl/zfs/tests/slog/setup.ksh new file mode 100644 index 00000000000..06011c117ae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/setup.ksh @@ -0,0 +1,45 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if [[ -d $VDEV ]]; then + log_must $RM -rf $VDIR +fi +if [[ -d $VDEV2 ]]; then + log_must $RM -rf $VDIR2 +fi +log_must $MKDIR -p $VDIR $VDIR2 +log_must create_vdevs $VDEV $SDEV $LDEV $VDEV2 $SDEV2 $LDEV2 + +log_pass diff --git a/tests/sys/cddl/zfs/tests/slog/slog.cfg b/tests/sys/cddl/zfs/tests/slog/slog.cfg new file mode 100644 index 00000000000..53c99d2dc47 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog.cfg @@ -0,0 +1,44 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog.cfg 1.1 07/07/31 SMI" +# + +export SIZE=64M + +export VDIR=$TMPDIR/disk.${TESTCASE_ID} +export VDIR2=$TMPDIR/disk2.${TESTCASE_ID} + +export VDEV="$VDIR/a $VDIR/b $VDIR/c" +export SDEV="$VDIR/d" +export LDEV="$VDIR/e $VDIR/f" +export VDEV2="$VDIR2/a $VDIR2/b $VDIR2/c" +export SDEV2="$VDIR2/d" +export LDEV2="$VDIR2/e $VDIR2/f" + +export STF_TIMEOUT=1200 diff --git a/tests/sys/cddl/zfs/tests/slog/slog.kshlib b/tests/sys/cddl/zfs/tests/slog/slog.kshlib new file mode 100644 index 00000000000..64fee40ccfb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog.kshlib @@ -0,0 +1,181 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog.kshlib 1.2 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +function cleanup +{ + poolexists $TESTPOOL && log_must $ZPOOL status $TESTPOOL + poolexists $TESTPOOL && log_must $ZPOOL status $TESTPOOL2 + destroy_pool $TESTPOOL + destroy_pool $TESTPOOL2 +} + +# +# Try zpool status/iostat for given pool +# +# $1 pool +# +function display_status +{ + typeset pool=$1 + + typeset -i ret=0 + $ZPOOL status -xv $pool > /dev/null 2>&1 + ret=$? + + $ZPOOL iostat > /dev/null 2>&1 + ((ret |= $?)) + + typeset mntpnt=$(get_prop mountpoint $pool) + $DD if=/dev/random of=$mntpnt/testfile.${TESTCASE_ID} & + typeset pid=$! + + $ZPOOL iostat -v 1 3 > /dev/null + ((ret |= $?)) + + kill -9 $pid + + return $ret +} + +function slog_devstat_table +{ + typeset pool=$1 + + $ZPOOL status -v $pool | $NAWK ' + BEGIN { start = 0; } + /\tlogs/ { start = 1; } + (start == 0) { next; } + /\t (\/|[a-zA-Z])/ { print "stripe:" $1 " " $2; } + /\t (\/|[a-zA-Z])/ { print "mirror:" $1 " " $2; } + /\t (\/|[0-9])/ {print "stripe:" $NF " " $2} + /\t (\/|[0-9])/ {print "mirror:" $NF " " $2} + # When a hotspare is replacing + /\t (\/|[a-zA-Z])/ {print "mirror:" $1 " " $2} + ' +} + +# +# Verify the given slog device have correct type and status +# +# $1 pool name +# $2 device name +# $3 device status +# $4 device type +# +function verify_slog_device +{ + typeset pool=$1 + typeset device=$2 + typeset status=$3 + typeset type=$4 + + if [[ -z $pool || -z $device || -z $status ]]; then + log_fail "Usage: verify_slog_device " \ + " [type]" + fi + + if [[ $WRAPPER == *"smi"* ]]; then + $ECHO $device | $EGREP "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 + if (( $? == 0 )); then + device=${device}s2 + fi + fi + + # + # Get all the slog devices and status table like below + # + # mirror:/disks/d ONLINE mirror:/disks/e ONLINE stripe:/disks/f ONLINE + # + set -A dev_stat_tab $(slog_devstat_table $pool) + + typeset find=0 + for (( i = 0; i < ${#dev_stat_tab[@]}; i += 2 )); do + typeset dev=${dev_stat_tab[$i]} + typeset stat=${dev_stat_tab[((i+1))]} + + typeset statmsg="$dev: Status($stat) != Expected stat($status)" + case $dev in + stripe:$device) + if [[ "$type" == 'mirror' ]]; then + log_note "Unexpected type: mirror" + return 1 + fi + if [[ $stat != $status ]]; then + log_note statmsg + return 1 + fi + return 0 + ;; + mirror:$device) + if [[ -z "$type" || $type == 'stripe' ]]; then + log_note "Unexpected type: stripe" + return 1 + fi + if [[ $stat != $status ]]; then + log_note statmsg + return 1 + fi + return 0 + ;; + esac + done + return 1 +} + +# Calls [args...] . +function slog_foreach_nologtype # +{ + typeset callback="$1" + + for pooltype in "" "mirror" "raidz" "raidz2"; do + for sparetype in "" "spare"; do + $callback "$pooltype" "$sparetype" + done + done +} + +# Calls [args...] . +# Unfortunately, this has to be duplicated because some arguments are empty, +# so if they aren't explicitly forwarded they aren't arguments to $callback. +function slog_foreach_all # +{ + typeset callback="$1" + + for pooltype in "" "mirror" "raidz" "raidz2"; do + for sparetype in "" "spare"; do + for logtype in "" "mirror"; do + $callback "$pooltype" "$sparetype" "$logtype" + done + done + done +} diff --git a/tests/sys/cddl/zfs/tests/slog/slog_001_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_001_pos.ksh new file mode 100644 index 00000000000..daa6079a465 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_001_pos.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_001_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_001_pos +# +# DESCRIPTION: +# Creating a pool with a log device succeeds. +# +# STRATEGY: +# 1. Create pool with separated log devices. +# 2. Display pool status +# 3. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Creating a pool with a log device succeeds." +log_onexit cleanup + +function test_creating_with_slog # +{ + typeset pooltype=$1 + typeset sparetype=$2 + typeset logtype=$3 + + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV log $logtype $LDEV + log_must display_status $TESTPOOL + ldev=$(random_get $LDEV) + log_must verify_slog_device $TESTPOOL $ldev ONLINE $logtype + destroy_pool $TESTPOOL +} + +slog_foreach_all test_creating_with_slog + +log_pass "Creating a pool with a log device succeeds." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_002_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_002_pos.ksh new file mode 100644 index 00000000000..89169606590 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_002_pos.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_002_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_002_pos +# +# DESCRIPTION: +# Adding a log device to normal pool works. +# +# STRATEGY: +# 1. Create pool +# 2. Add log devices with different configuration +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Adding a log device to normal pool works." +log_onexit cleanup + +function test_adding_slog # +{ + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV + log_must $ZPOOL add $TESTPOOL log $logtype $LDEV + log_must display_status $TESTPOOL + typeset ldev=$(random_get $LDEV) + log_must verify_slog_device $TESTPOOL $ldev ONLINE $logtype + destroy_pool $TESTPOOL +} + +slog_foreach_all test_adding_slog + +log_pass "Adding a log device to normal pool works." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_003_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_003_pos.ksh new file mode 100644 index 00000000000..3fd37bc593e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_003_pos.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_003_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_003_pos +# +# DESCRIPTION: +# Adding an extra log device works +# +# STRATEGY: +# 1. Create pool with separated log devices. +# 2. Add an extra log devices +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Adding an extra log device works." +log_onexit cleanup + +function test_adding_extra_slog # +{ + typeset pooltype=$1 + typeset sparetype=$2 + typeset logtype=$3 + + for newtype in "" "mirror"; do + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV \ + log $logtype $LDEV + log_must $ZPOOL add $TESTPOOL log $newtype $LDEV2 + log_must display_status $TESTPOOL + ldev=$(random_get $LDEV2) + log_must verify_slog_device $TESTPOOL $ldev ONLINE $newtype + destroy_pool $TESTPOOL + done +} + +slog_foreach_all test_adding_extra_slog + +log_pass "Adding an extra log device works." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_004_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_004_pos.ksh new file mode 100644 index 00000000000..1c82f2ff1f4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_004_pos.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_004_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_004_pos +# +# DESCRIPTION: +# Attaching a log device passes. +# +# STRATEGY: +# 1. Create pool with separated log devices. +# 2. Attaching a log device for existing log device +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Attaching a log device passes." +log_onexit cleanup + +function test_attaching_slog # +{ + typeset pooltype=$1 + typeset sparetype=$2 + typeset logtype=$3 + + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV \ + log $logtype $LDEV + typeset ldev=$(random_get $LDEV) + typeset ldev2=$(random_get $LDEV2) + log_must $ZPOOL attach $TESTPOOL $ldev $ldev2 + log_must display_status $TESTPOOL + log_must verify_slog_device $TESTPOOL $ldev ONLINE mirror + log_must verify_slog_device $TESTPOOL $ldev2 ONLINE mirror + destroy_pool $TESTPOOL +} +slog_foreach_all test_attaching_slog + +log_pass "Attaching a log device passes." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_005_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_005_pos.ksh new file mode 100644 index 00000000000..651be1aa36a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_005_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_005_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_005_pos +# +# DESCRIPTION: +# Detaching a log device passes. +# +# STRATEGY: +# 1. Create pool with mirror log devices. +# 2. Detaching a log device +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Detaching a log device passes." +log_onexit cleanup + +function test_detaching_slog # +{ + typeset pooltype="$1" + typeset sparetype="$2" + + log_note "test_detaching_slog args: $* -EOA-" + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV \ + log mirror $LDEV mirror $LDEV2 + ldev=$(random_get $LDEV $LDEV2) + log_must $ZPOOL detach $TESTPOOL $ldev + log_must display_status $TESTPOOL + log_mustnot verify_slog_device $TESTPOOL $ldev ONLINE mirror + destroy_pool $TESTPOOL +} +slog_foreach_nologtype test_detaching_slog + +log_pass "Detaching a log device passes." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_006_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_006_pos.ksh new file mode 100644 index 00000000000..ba9d505cd07 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_006_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_006_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_006_pos +# +# DESCRIPTION: +# Replacing a log device passes. +# +# STRATEGY: +# 1. Create pool with log devices. +# 2. Replacing one log device +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Replacing a log device passes." +log_onexit cleanup + +function test_slog_replacing # +{ + typeset pooltype=$1 + typeset sparetype=$2 + typeset logtype=$3 + + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV log $logtype $LDEV + sdev=$(random_get $LDEV) + tdev=$(random_get $LDEV2) + log_must $ZPOOL replace $TESTPOOL $sdev $tdev + log_must display_status $TESTPOOL + wait_for 15 1 verify_slog_device $TESTPOOL $tdev ONLINE $logtype + destroy_pool $TESTPOOL +} +slog_foreach_all test_slog_replacing + +log_pass "Replacing a log device passes." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_007_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_007_pos.ksh new file mode 100644 index 00000000000..4bd2cae8c6b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_007_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_007_pos.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_007_pos +# +# DESCRIPTION: +# Exporting and importing pool with log devices passes. +# +# STRATEGY: +# 1. Create pool with log devices. +# 2. Export and import the pool +# 3. Display pool status +# 4. Destroy and import the pool again +# 5. Display pool status +# 6. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Exporting and importing pool with log devices passes." +log_onexit cleanup + +function test_slog_exporting_importing # +{ + typeset pooltype=$1 + typeset sparetype=$2 + typeset logtype=$3 + + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV \ + log $logtype $LDEV $LDEV2 + ldev=$(random_get $LDEV $LDEV2) + log_must verify_slog_device $TESTPOOL $ldev ONLINE $logtype + log_must $ZPOOL export $TESTPOOL + log_must $ZPOOL import -d $VDIR -d $VDIR2 $TESTPOOL + log_must display_status $TESTPOOL + ldev=$(random_get $LDEV $LDEV2) + log_must verify_slog_device $TESTPOOL $ldev ONLINE $logtype + + destroy_pool $TESTPOOL + log_must $ZPOOL import -Df -d $VDIR -d $VDIR2 $TESTPOOL + log_must display_status $TESTPOOL + ldev=$(random_get $LDEV $LDEV2) + log_must verify_slog_device $TESTPOOL $ldev ONLINE $logtype + destroy_pool $TESTPOOL +} +slog_foreach_all test_slog_exporting_importing + +log_pass "Exporting and importing pool with log devices passes." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_008_neg.ksh b/tests/sys/cddl/zfs/tests/slog/slog_008_neg.ksh new file mode 100644 index 00000000000..a3aad90e1e8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_008_neg.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_008_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_008_neg +# +# DESCRIPTION: +# A raidz/raidz2 log is not supported. +# +# STRATEGY: +# 1. Try to create pool with unsupported type +# 2. Verify failed to create pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A raidz/raidz2 log is not supported." +log_onexit cleanup + +function test_no_raidz_slog # +{ + typeset pooltype=$1 + typeset sparetype=$2 + + for logtype in "raidz" "raidz1" "raidz2"; do + log_mustnot $ZPOOL create $TESTPOOL $type $VDEV \ + $spare $SDEV log $logtype $LDEV $LDEV2 + ldev=$(random_get $LDEV $LDEV2) + log_mustnot verify_slog_device $TESTPOOL $ldev ONLINE $logtype + log_must datasetnonexists $TESTPOOL + done +} +slog_foreach_nologtype test_no_raidz_slog + +log_pass "A raidz/raidz2 log is not supported." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_009_neg.ksh b/tests/sys/cddl/zfs/tests/slog/slog_009_neg.ksh new file mode 100644 index 00000000000..c4310ac065d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_009_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_009_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_009_neg +# +# DESCRIPTION: +# A raidz/raidz2 log can not be added to existed pool. +# +# STRATEGY: +# 1. Create pool with or without log. +# 2. Add a raidz/raidz2 log to this pool. +# 3. Verify failed to add. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A raidz/raidz2 log can not be added to existed pool." +log_onexit cleanup + +function test_no_raidz_slog_add # +{ + typeset pooltype=$1 + typeset sparetype=$2 + typeset logtype=$3 + + log=$(random_get_with_non "log") + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV $logtype $LDEV + + log_mustnot $ZPOOL add $TESTPOOL log $logtype $LDEV2 + ldev=$(random_get $LDEV2) + log_mustnot verify_slog_device $TESTPOOL $ldev 'ONLINE' $logtype + destroy_pool $TESTPOOL +} + +log_pass "A raidz/raidz2 log can not be added to existed pool." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_010_neg.ksh b/tests/sys/cddl/zfs/tests/slog/slog_010_neg.ksh new file mode 100644 index 00000000000..1a52d46f2c3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_010_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_010_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_010_neg +# +# DESCRIPTION: +# Slog device can not be replaced with spare device +# +# STRATEGY: +# 1. Create a pool with hotspare and log devices. +# 2. Verify slog device can not be replaced with hotspare device. +# 3. Create pool2 with hotspare +# 4. Verify slog device can not be replaced with hotspare device in pool2. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Slog device can not be replaced with spare device." +log_onexit cleanup + +log_must $ZPOOL create $TESTPOOL $VDEV spare $SDEV log $LDEV +sdev=$(random_get $SDEV) +ldev=$(random_get $LDEV) +log_mustnot $ZPOOL replace $TESTPOOL $ldev $sdev +log_mustnot verify_slog_device $TESTPOOL $sdev 'ONLINE' +log_must verify_slog_device $TESTPOOL $ldev 'ONLINE' + +log_must $ZPOOL create $TESTPOOL2 $VDEV2 spare $SDEV2 +sdev2=$(random_get $SDEV2) +log_mustnot $ZPOOL replace $TESTPOOL $ldev $sdev2 +log_mustnot $ZPOOL replace -f $TESTPOOL $ldev $sdev2 +log_mustnot verify_slog_device $TESTPOOL $sdev2 'ONLINE' +log_must verify_slog_device $TESTPOOL $ldev 'ONLINE' + +log_pass "Slog device can not be replaced with spare device." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_011_neg.ksh b/tests/sys/cddl/zfs/tests/slog/slog_011_neg.ksh new file mode 100644 index 00000000000..ce43d30c938 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_011_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_011_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_011_neg +# +# DESCRIPTION: +# Offline and online a log device passes. +# +# STRATEGY: +# 1. Create pool with mirror log devices. +# 2. Offine and online a log device +# 3. Display pool status +# 4. Destroy and loop to create pool with different configuration. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Offline and online a log device passes." +log_onexit cleanup + +function test_slog_online_offline # +{ + create_pool $TESTPOOL $type $VDEV $spare $SDEV \ + log mirror $LDEV mirror $LDEV2 + + ldev=$(random_get $LDEV $LDEV2) + log_must $ZPOOL offline $TESTPOOL $ldev + log_must display_status $TESTPOOL + log_must verify_slog_device $TESTPOOL $ldev OFFLINE mirror + + log_must $ZPOOL online $TESTPOOL $ldev + log_must display_status $TESTPOOL + log_must verify_slog_device $TESTPOOL $ldev ONLINE mirror + + destroy_pool $TESTPOOL +} +slog_foreach_nologtype test_slog_online_offline + +log_pass "Offline and online a log device passes." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_012_neg.ksh b/tests/sys/cddl/zfs/tests/slog/slog_012_neg.ksh new file mode 100644 index 00000000000..0535c4ee4a1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_012_neg.ksh @@ -0,0 +1,87 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_012_neg.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_012_neg +# +# DESCRIPTION: +# Pool can survive when one of mirror log device get corrupted +# +# STRATEGY: +# 1. Create pool with mirror slog devices +# 2. Make corrupted on one disk +# 3. Verify the pool is fine +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Pool can survive when one of mirror log device get corrupted." +log_onexit cleanup + +function test_slog_mirror_corruption # +{ + typeset pooltype=$1 + typeset sparetype=$2 + + create_pool $TESTPOOL $type $VDEV $spare $SDEV log mirror $LDEV + + mntpnt=$(get_prop mountpoint $TESTPOOL) + # + # Create file in pool to trigger writing in slog devices + # + log_must $DD if=/dev/urandom of=$mntpnt/testfile.${TESTCASE_ID} count=100 + + ldev=$(random_get $LDEV) + log_must create_vdevs $ldev + log_must $ZPOOL scrub $TESTPOOL + + log_must display_status $TESTPOOL + log_must verify_slog_device $TESTPOOL $ldev UNAVAIL mirror + + destroy_pool $TESTPOOL +} +slog_foreach_nologtype test_slog_mirror_corruption + +log_pass "Pool can survive when one of mirror log device get corrupted." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_013_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_013_pos.ksh new file mode 100644 index 00000000000..3aea01cab31 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_013_pos.ksh @@ -0,0 +1,107 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_013_pos.ksh 1.2 09/05/19 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_013_pos +# +# DESCRIPTION: +# Verify slog device can be disk, file, lofi device or any device that +# presents a block interface. +# +# STRATEGY: +# 1. Create a pool +# 2. Loop to add different object as slog +# 3. Verify it passes +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup_testenv +{ + cleanup + if datasetexists $TESTPOOL2 ; then + log_must $ZPOOL destroy -f $TESTPOOL2 + fi + if [[ -n $lofidev ]]; then + $LOFIADM -d $lofidev + fi +} + +log_assert "Verify slog device can be disk, file, lofi device or any device " \ + "that presents a block interface." +log_onexit cleanup_testenv + +dsk1=${DISKS%% *} +log_must $ZPOOL create $TESTPOOL ${DISKS#$dsk1} + +# Add nomal disk +log_must $ZPOOL add $TESTPOOL log $dsk1 +log_must verify_slog_device $TESTPOOL $dsk1 'ONLINE' +# Add nomal file +log_must $ZPOOL add $TESTPOOL log $LDEV +ldev=$(random_get $LDEV) +log_must verify_slog_device $TESTPOOL $ldev 'ONLINE' + +# Add lofi device +lofidev=${LDEV2%% *} +log_must $LOFIADM -a $lofidev +lofidev=$($LOFIADM $lofidev) +log_must $ZPOOL add $TESTPOOL log $lofidev +log_must verify_slog_device $TESTPOOL $lofidev 'ONLINE' + +log_pass "Verify slog device can be disk, file, lofi device or any device " \ + "that presents a block interface." + +# Temp disable fore bug 6569095 +# Add file which reside in the itself +mntpnt=$(get_prop mountpoint $TESTPOOL) +log_must create_vdevs $mntpnt/vdev +log_must $ZPOOL add $TESTPOOL $mntpnt/vdev + +# Temp disable fore bug 6569072 +# Add ZFS volume +vol=$TESTPOOL/vol +log_must $ZPOOL create -V 64M $vol +log_must $ZPOOL add $TESTPOOL /dev/zvol/dsk/$vol diff --git a/tests/sys/cddl/zfs/tests/slog/slog_014_pos.ksh b/tests/sys/cddl/zfs/tests/slog/slog_014_pos.ksh new file mode 100644 index 00000000000..c9ea000e6c4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_014_pos.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)slog_014_pos.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/tests/slog/slog.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: slog_014_pos +# +# DESCRIPTION: +# log device can survive when one of pool device get corrupted +# +# STRATEGY: +# 1. Create pool with slog devices +# 2. remove one disk +# 3. Verify the log is fine +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-05-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "log device can survive when one of the pool device get corrupted." +log_onexit cleanup + +function test_slog_survives_pool_corruption # +{ + typeset pooltype=$1 + typeset sparetype=$2 + + # This only works for pools that have redundancy + [ -z "$pooltype" ] && return + + create_pool $TESTPOOL $pooltype $VDEV $sparetype $SDEV log $LDEV + + # Remove one of the pool device, then scrub to make the pool DEGRADED + log_must $RM -f $VDIR/a + log_must $ZPOOL scrub $TESTPOOL + + # Check and verify pool status + log_must display_status $TESTPOOL + log_must $ZPOOL status $TESTPOOL 2>&1 >/dev/null + + # Check that there is some status: field informing us of a + # problem. The exact error string is unspecified. + log_must $ZPOOL status -v $TESTPOOL | $GREP "status:" + for l in $LDEV; do + log_must check_state $TESTPOOL $l ONLINE + done + + destroy_pool $TESTPOOL + create_vdevs $VDIR/a +} +slog_foreach_nologtype test_slog_survives_pool_corruption + +log_pass "log device can survive when one of the pool device get corrupted." diff --git a/tests/sys/cddl/zfs/tests/slog/slog_test.sh b/tests/sys/cddl/zfs/tests/slog/slog_test.sh new file mode 100755 index 00000000000..1071146d024 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/slog/slog_test.sh @@ -0,0 +1,411 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case slog_001_pos cleanup +slog_001_pos_head() +{ + atf_set "descr" "Creating a pool with a log device succeeds." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_001_pos.ksh || atf_fail "Testcase failed" +} +slog_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_002_pos cleanup +slog_002_pos_head() +{ + atf_set "descr" "Adding a log device to normal pool works." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_002_pos.ksh || atf_fail "Testcase failed" +} +slog_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_003_pos cleanup +slog_003_pos_head() +{ + atf_set "descr" "Adding an extra log device works." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_003_pos.ksh || atf_fail "Testcase failed" +} +slog_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_004_pos cleanup +slog_004_pos_head() +{ + atf_set "descr" "Attaching a log device passes." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_004_pos.ksh || atf_fail "Testcase failed" +} +slog_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_005_pos cleanup +slog_005_pos_head() +{ + atf_set "descr" "Detaching a log device passes." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_005_pos.ksh || atf_fail "Testcase failed" +} +slog_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_006_pos cleanup +slog_006_pos_head() +{ + atf_set "descr" "Replacing a log device passes." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_006_pos.ksh || atf_fail "Testcase failed" +} +slog_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_007_pos cleanup +slog_007_pos_head() +{ + atf_set "descr" "Exporting and importing pool with log devices passes." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_007_pos.ksh || atf_fail "Testcase failed" +} +slog_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_008_neg cleanup +slog_008_neg_head() +{ + atf_set "descr" "A raidz/raidz2 log is not supported." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_008_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_008_neg.ksh || atf_fail "Testcase failed" +} +slog_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_009_neg cleanup +slog_009_neg_head() +{ + atf_set "descr" "A raidz/raidz2 log can not be added to existed pool." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_009_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_009_neg.ksh || atf_fail "Testcase failed" +} +slog_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_010_neg cleanup +slog_010_neg_head() +{ + atf_set "descr" "Slog device can not be replaced with spare device." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_010_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_010_neg.ksh || atf_fail "Testcase failed" +} +slog_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_011_neg cleanup +slog_011_neg_head() +{ + atf_set "descr" "Offline and online a log device passes." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_011_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_011_neg.ksh || atf_fail "Testcase failed" +} +slog_011_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_012_neg cleanup +slog_012_neg_head() +{ + atf_set "descr" "Pool can survive when one of mirror log device get corrupted." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_012_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_012_neg.ksh || atf_fail "Testcase failed" +} +slog_012_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_013_pos cleanup +slog_013_pos_head() +{ + atf_set "descr" "Verify slog device can be disk, file, lofi device or any devicethat presents a block interface." + atf_set "require.progs" zpool lofiadm + atf_set "timeout" 1200 +} +slog_013_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_013_pos.ksh || atf_fail "Testcase failed" +} +slog_013_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case slog_014_pos cleanup +slog_014_pos_head() +{ + atf_set "descr" "log device can survive when one of the pool device get corrupted." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +slog_014_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/slog_014_pos.ksh || atf_fail "Testcase failed" +} +slog_014_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/slog.kshlib + . $(atf_get_srcdir)/slog.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case slog_001_pos + atf_add_test_case slog_002_pos + atf_add_test_case slog_003_pos + atf_add_test_case slog_004_pos + atf_add_test_case slog_005_pos + atf_add_test_case slog_006_pos + atf_add_test_case slog_007_pos + atf_add_test_case slog_008_neg + atf_add_test_case slog_009_neg + atf_add_test_case slog_010_neg + atf_add_test_case slog_011_neg + atf_add_test_case slog_012_neg + atf_add_test_case slog_013_pos + atf_add_test_case slog_014_pos +} diff --git a/tests/sys/cddl/zfs/tests/snapshot/Makefile b/tests/sys/cddl/zfs/tests/snapshot/Makefile new file mode 100644 index 00000000000..321568c7f56 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/Makefile @@ -0,0 +1,42 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/snapshot +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= snapshot_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= rollback_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= snapshot_017_pos.ksh +${PACKAGE}FILES+= snapshot_013_pos.ksh +${PACKAGE}FILES+= ctldir_acl.txt +${PACKAGE}FILES+= snapshot_002_pos.ksh +${PACKAGE}FILES+= snapshot_006_pos.ksh +${PACKAGE}FILES+= clone_001_pos.ksh +${PACKAGE}FILES+= snapshot_003_pos.ksh +${PACKAGE}FILES+= snapshot_007_pos.ksh +${PACKAGE}FILES+= snapshot_016_pos.ksh +${PACKAGE}FILES+= snapshot_012_pos.ksh +${PACKAGE}FILES+= snapshot_009_pos.ksh +${PACKAGE}FILES+= snapshot_001_pos.ksh +${PACKAGE}FILES+= snapshot_005_pos.ksh +${PACKAGE}FILES+= snapshot.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= rollback_002_pos.ksh +${PACKAGE}FILES+= snapshot_014_pos.ksh +${PACKAGE}FILES+= snapshot_010_pos.ksh +${PACKAGE}FILES+= snapshot_018_pos.ksh +${PACKAGE}FILES+= rollback_003_pos.ksh +${PACKAGE}FILES+= snapshot_019_pos.ksh +${PACKAGE}FILES+= snapshot_015_pos.ksh +${PACKAGE}FILES+= snapshot_011_pos.ksh +${PACKAGE}FILES+= snapshot_004_pos.ksh +${PACKAGE}FILES+= snapshot_008_pos.ksh +${PACKAGE}FILES+= snapshot_020_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/snapshot/cleanup.ksh b/tests/sys/cddl/zfs/tests/snapshot/cleanup.ksh new file mode 100644 index 00000000000..e2ccfb86862 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_container_cleanup diff --git a/tests/sys/cddl/zfs/tests/snapshot/clone_001_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/clone_001_pos.ksh new file mode 100644 index 00000000000..d025d9fa5b1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/clone_001_pos.ksh @@ -0,0 +1,143 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)clone_001_pos.ksh 1.6 09/06/22 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: clone_001_pos +# +# DESCRIPTION: +# Create a snapshot from regular filesystem, volume, +# or filesystem upon volume, Build a clone file system +# from the snapshot and verify new files can be written. +# +# STRATEGY: +# 1. Create snapshot use 3 combination: +# - Regular filesystem +# - Regular volume +# - Filesystem upon volume +# 2. Clone a new file system from the snapshot +# 3. Verify the cloned file system is writable +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-08-25) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +# Setup array, 4 elements as a group, refer to: +# i+0: name of a snapshot +# i+1: mountpoint of the snapshot +# i+2: clone created from the snapshot +# i+3: mountpoint of the clone + +set -A args "$SNAPFS" "$SNAPDIR" "$TESTPOOL/$TESTCLONE" "$TESTDIR.0" \ + "$SNAPFS1" "$SNAPDIR3" "$TESTPOOL/$TESTCLONE1" "" \ + "$SNAPFS2" "$SNAPDIR2" "$TESTPOOL1/$TESTCLONE2" "$TESTDIR.2" + +function setup_all +{ + create_pool $TESTPOOL1 /dev/zvol/$TESTPOOL/$TESTVOL + log_must $ZFS create $TESTPOOL1/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR2 $TESTPOOL1/$TESTFS + + return 0 +} + +function cleanup_all +{ + destroy_pool $TESTPOOL1 + + [[ -d $TESTDIR2 ]] && \ + log_must $RM -rf $TESTDIR2 + + return 0 +} + +log_assert "Verify a cloned file system is writable." + +log_onexit cleanup_all + +setup_all + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +for mtpt in $TESTDIR $TESTDIR2 ; do + log_note "Populate the $mtpt directory (prior to snapshot)" + populate_dir $mtpt/before_file $COUNT $NUM_WRITES $BLOCKSZ ITER +done + +typeset -i i=0 +while (( i < ${#args[*]} )); do + # + # Take a snapshot of the test file system. + # + log_must $ZFS snapshot ${args[i]} + + # + # Clone a new file system from the snapshot + # + log_must $ZFS clone ${args[i]} ${args[i+2]} + if [[ -n ${args[i+3]} ]] ; then + log_must $ZFS set mountpoint=${args[i+3]} ${args[i+2]} + + FILE_COUNT=`$LS -Al ${args[i+3]} | $GREP -v "total" | wc -l` + if [[ $FILE_COUNT -ne $COUNT ]]; then + $LS -Al ${args[i+3]} + log_fail "AFTER: ${args[i+3]} contains $FILE_COUNT files(s)." + fi + + log_note "Verify the ${args[i+3]} directory is writable" + populate_dir ${args[i+3]}/after_file $COUNT $NUM_WRITES \ + $BLOCKSZ ITER + + FILE_COUNT=`$LS -Al ${args[i+3]}/after* | $GREP -v "total" | wc -l` + if [[ $FILE_COUNT -ne $COUNT ]]; then + $LS -Al ${args[i+3]} + log_fail "${args[i+3]} contains $FILE_COUNT after* files(s)." + fi + fi + + (( i = i + 4 )) +done + +log_pass "The clone file system is writable." diff --git a/tests/sys/cddl/zfs/tests/snapshot/ctldir_acl.txt b/tests/sys/cddl/zfs/tests/snapshot/ctldir_acl.txt new file mode 100644 index 00000000000..d0afd0a2e5a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/ctldir_acl.txt @@ -0,0 +1,3 @@ + owner@:r-x---a---c--s:-------:allow + group@:r-x---a---c--s:-------:allow + everyone@:r-x---a---c--s:-------:allow diff --git a/tests/sys/cddl/zfs/tests/snapshot/rollback_001_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/rollback_001_pos.ksh new file mode 100644 index 00000000000..baa058c1e2b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/rollback_001_pos.ksh @@ -0,0 +1,114 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rollback_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: rollback_001_pos +# +# DESCRIPTION: +# Populate a file system and take a snapshot. Add some more files to the +# file system and rollback to the last snapshot. Verify no post snapshot +# file exist. +# +# STRATEGY: +# 1. Empty a file system +# 2. Populate the file system +# 3. Take a snapshot of the file system +# 4. Add new files to the file system +# 5. Perform a rollback +# 6. Verify the snapshot and file system agree +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + snapexists $SNAPFS + [[ $? -eq 0 ]] && \ + log_must $ZFS destroy $SNAPFS + + [[ -e $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 +} + +log_assert "Verify that a rollback to a previous snapshot succeeds." + +log_onexit cleanup + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +log_note "Populate the $TESTDIR directory (prior to snapshot)" +populate_dir $TESTDIR/before_file $COUNT $NUM_WRITES $BLOCKSZ ITER +log_must $ZFS snapshot $SNAPFS + +FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l` +if [[ $FILE_COUNT -ne $COUNT ]]; then + $LS -Al $SNAPDIR + log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." +fi + +log_note "Populate the $TESTDIR directory (post snapshot)" +populate_dir $TESTDIR/after_file $COUNT $NUM_WRITES $BLOCKSZ ITER + +# +# Now rollback to latest snapshot +# +log_must $ZFS rollback $SNAPFS + +FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l` +if [[ $FILE_COUNT -ne 0 ]]; then + $LS -Al $TESTDIR + log_fail "$TESTDIR contains $FILE_COUNT after* files(s)." +fi + +FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \ + | $GREP -v "total" | wc -l` +if [[ $FILE_COUNT -ne $COUNT ]]; then + $LS -Al $TESTDIR + log_fail "$TESTDIR contains $FILE_COUNT before* files(s)." +fi + +log_pass "The rollback operation succeeded." diff --git a/tests/sys/cddl/zfs/tests/snapshot/rollback_002_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/rollback_002_pos.ksh new file mode 100644 index 00000000000..42d7604f84d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/rollback_002_pos.ksh @@ -0,0 +1,126 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rollback_002_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: rollback_002_pos +# +# DESCRIPTION: +# Verify that rollbacks are with respect to the latest snapshot. +# +# STRATEGY: +# 1. Empty a file system +# 2. Populate the file system +# 3. Take a snapshot of the file system +# 4. Add new files to the file system +# 5. Take a snapshot +# 6. Remove the original files +# 7. Perform a rollback +# 8. Verify the latest snapshot and file system agree +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + snapexists $SNAPFS.1 + [[ $? -eq 0 ]] && \ + log_must $ZFS destroy $SNAPFS.1 + + snapexists $SNAPFS + [[ $? -eq 0 ]] && \ + log_must $ZFS destroy $SNAPFS + + [[ -e $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 +} + +log_assert "Verify rollback is with respect to latest snapshot." + +log_onexit cleanup + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +log_note "Populate the $TESTDIR directory (prior to first snapshot)" +populate_dir $TESTDIR/original_file $COUNT $NUM_WRITES $BLOCKSZ ITER + +log_must $ZFS snapshot $SNAPFS + +FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l` +if [[ $FILE_COUNT -ne $COUNT ]]; then + $LS -Al $SNAPDIR + log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." +fi + +log_note "Populate the $TESTDIR directory (prior to second snapshot)" +populate_dir $TESTDIR/afterfirst_file $COUNT $NUM_WRITES $BLOCKSZ ITER +log_must $ZFS snapshot $SNAPFS.1 + +log_note "Populate the $TESTDIR directory (Post second snapshot)" +populate_dir $TESTDIR/aftersecond_file $COUNT $NUM_WRITES $BLOCKSZ ITER + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/original_file* > /dev/null 2>&1 + +# +# Now rollback to latest snapshot +# +log_must $ZFS rollback $SNAPFS.1 + +FILE_COUNT=`$LS -Al $TESTDIR/aftersecond* 2> /dev/null \ + | $GREP -v "total" | wc -l` +if [[ $FILE_COUNT -ne 0 ]]; then + $LS -Al $TESTDIR + log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)." +fi + +FILE_COUNT=`$LS -Al $TESTDIR/original* $TESTDIR/afterfirst*| $GREP -v "total" | wc -l` +if [[ $FILE_COUNT -ne 20 ]]; then + $LS -Al $TESTDIR + log_fail "$TESTDIR contains $FILE_COUNT original* files(s)." +fi + +log_pass "The rollback to the latest snapshot succeeded." diff --git a/tests/sys/cddl/zfs/tests/snapshot/rollback_003_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/rollback_003_pos.ksh new file mode 100644 index 00000000000..f1d3128f41f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/rollback_003_pos.ksh @@ -0,0 +1,114 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)rollback_003_pos.ksh 1.6 09/08/06 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + + +################################################################################ +# +# __stc_assertion_start +# +# ID: rollback_003_pos +# +# DESCRIPTION: +# Verify that rollbacks succeed when there are nested file systems. +# +# STRATEGY: +# 1) Snapshot an empty file system and rollback +# 2) Create a file in the file system +# 3) Rollback the file system to empty +# 4) Create a nested file system with the same name as the file created in (2) +# 5) Verify a rollback succeeds +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-01-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset snap="" + typeset fs="" + + log_must $ZFS mount -a + + for snap in "$SNAPPOOL.1" "$SNAPPOOL" + do + snapexists $snap + [[ $? -eq 0 ]] && \ + log_must $ZFS destroy $snap + done + + for fs in "$TESTPOOL/$TESTFILE/$TESTFILE.1" "$TESTPOOL/$TESTFILE" + do + datasetexists $fs + [[ $? -eq 0 ]] && \ + log_must $ZFS destroy -r $fs + done + + [[ -e /$TESTPOOL ]] && \ + log_must $RM -rf $TESTPOOL/* +} + +log_assert "Verify rollback succeeds when there are nested file systems." + +log_onexit cleanup + +log_must $ZFS snapshot $SNAPPOOL +log_must $ZFS rollback $SNAPPOOL +log_mustnot $ZFS snapshot $SNAPPOOL + +log_must $TOUCH /$TESTPOOL/$TESTFILE + +log_must $ZFS rollback $SNAPPOOL +log_must $ZFS create $TESTPOOL/$TESTFILE + +log_must $ZFS rollback $SNAPPOOL + +log_note "Verify rollback of multiple nested file systems succeeds." +log_must $ZFS snapshot $TESTPOOL/$TESTFILE@$TESTSNAP +log_must $ZFS snapshot $SNAPPOOL.1 + +unmount_all_safe > /dev/null 2>&1 +log_must $ZFS mount -a + +log_must $TOUCH /$TESTPOOL/$TESTFILE/$TESTFILE.1 + +log_must $ZFS rollback $SNAPPOOL.1 + +log_pass "Rollbacks succeed when nested file systems are present." diff --git a/tests/sys/cddl/zfs/tests/snapshot/setup.ksh b/tests/sys/cddl/zfs/tests/snapshot/setup.ksh new file mode 100644 index 00000000000..eb1c316dfae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_container_volume_setup ${DISK} diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot.cfg b/tests/sys/cddl/zfs/tests/snapshot/snapshot.cfg new file mode 100644 index 00000000000..492c28ee3ed --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot.cfg @@ -0,0 +1,62 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot.cfg 1.4 08/08/15 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +export ZFSROOT= +export TESTVOL=testvol${TESTCASE_ID} +export TESTVOL1=testvol1.${TESTCASE_ID} +export TESTSNAP=testsnap${TESTCASE_ID} +export TESTSNAP1=testsnap1.${TESTCASE_ID} +export TESTCLONE=testclone${TESTCASE_ID} +export TESTCLONE1=testclone1${TESTCASE_ID} +export TESTCLONE2=testclone2${TESTCASE_ID} +export TESTFILE=testfile${TESTCASE_ID} +export TESTFILE1=testfile1${TESTCASE_ID} +export SNAPROOT="$(get_snapdir_name)" + +export SNAPPOOL="$TESTPOOL@$TESTSNAP" +export SNAPFS="$TESTPOOL/$TESTFS@$TESTSNAP" +export SNAPFS1="$TESTPOOL/$TESTVOL@$TESTSNAP" +export SNAPFS2="$TESTPOOL1/$TESTFS@$TESTSNAP" +export SNAPCTR="$TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP" +export SNAPDIR="$TESTDIR/$SNAPROOT/$TESTSNAP" +export SNAPDIR1="$TESTDIR1/$SNAPROOT/$TESTSNAP" +export SNAPDIR2="$TESTDIR2/$SNAPROOT/$TESTSNAP" +export SNAPDIR3="$ZFSROOT/$SNAPFS1" + +export VOLSIZE=1gb +export BLOCKSZ=8192 +export NUM_WRITES=20 +export DATA=0 +export LIMIT=524288 # tolerance measured in bytes, 512K +export FSQUOTA=500m +export FILESIZE=400m +export FILESIZE1=200m diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_001_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_001_pos.ksh new file mode 100644 index 00000000000..73499c4b508 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_001_pos.ksh @@ -0,0 +1,103 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_001_pos +# +# DESCRIPTION: +# A zfs file system snapshot is identical to +# the originally snapshot'd file system, after the file +# system has been changed. Uses 'sum -r'. +# +# STRATEGY: +# 1. Create a file in the zfs file system +# 2. Checksum the file for later comparison +# 3. Create a snapshot of the dataset +# 4. Append to the original file +# 5. Verify the snapshot and file agree +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +function cleanup +{ + snapexists $SNAPFS + if [[ $? -eq 0 ]]; then + log_must $ZFS destroy $SNAPFS + fi + + if [[ -e $SNAPDIR ]]; then + log_must $RM -rf $SNAPDIR > /dev/null 2>&1 + fi + + if [[ -e $TESTDIR ]]; then + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + fi +} + +log_assert "Verify a file system snapshot is identical to original." + +log_onexit cleanup + +log_note "Create a file in the zfs filesystem..." +log_must $FILE_WRITE -o create -f $TESTDIR/$TESTFILE -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA + +log_note "Sum the file, save for later comparison..." +FILE_SUM=`$SUM -r $TESTDIR/$TESTFILE | $AWK '{ print $1 }'` +log_note "FILE_SUM = $FILE_SUM" + +log_note "Create a snapshot and mount it..." +log_must $ZFS snapshot $SNAPFS + +log_note "Append to the original file..." +log_must $FILE_WRITE -o append -f $TESTDIR/$TESTFILE -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA + +SNAP_FILE_SUM=`$SUM -r $SNAPDIR/$TESTFILE | $AWK '{ print $1 }'` +if [[ $SNAP_FILE_SUM -ne $FILE_SUM ]]; then + log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)" +fi + +log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)" diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_002_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_002_pos.ksh new file mode 100644 index 00000000000..d3c6476facb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_002_pos.ksh @@ -0,0 +1,139 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_002_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_002_pos +# +# DESCRIPTION: +# An archive of a zfs file system and an archive of its snapshot +# is identical even though the original file system has +# changed sinced the snapshot was taken. +# +# STRATEGY: +# 1) Create files in all of the zfs file systems +# 2) Create a tarball of the file system +# 3) Create a snapshot of the dataset +# 4) Remove all the files in the original file system +# 5) Create a tarball of the snapshot +# 6) Extract each tarball and compare directory structures +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if [[ -d $CWD ]]; then + cd $CWD || log_fail "Could not cd $CWD" + fi + + snapexists $SNAPFS + if [[ $? -eq 0 ]]; then + log_must $ZFS destroy $SNAPFS + fi + + if [[ -e $SNAPDIR ]]; then + log_must $RM -rf $SNAPDIR > /dev/null 2>&1 + fi + + if [[ -e $TESTDIR ]]; then + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + fi + + if [[ -e $TMPDIR/zfs_snapshot2.${TESTCASE_ID} ]]; then + log_must $RM -rf $TMPDIR/zfs_snapshot2.${TESTCASE_ID} > /dev/null 2>&1 + fi + +} + +log_assert "Verify an archive of a file system is identical to " \ + "an archive of its snapshot." + +log_onexit cleanup + +typeset -i COUNT=21 +typeset OP=create + +[[ -n $TESTDIR ]] && \ + $RM -rf $TESTDIR/* > /dev/null 2>&1 + +log_note "Create files in the zfs filesystem..." +populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ $DATA + +log_note "Create a tarball from $TESTDIR contents..." +CWD=$PWD +cd $TESTDIR || log_fail "Could not cd $TESTDIR" +log_must $TAR cf $TESTDIR/tarball.original.tar file* +cd $CWD || log_fail "Could not cd $CWD" + +log_note "Create a snapshot and mount it..." +log_must $ZFS snapshot $SNAPFS + +log_note "Remove all of the original files..." +log_must $RM -f $TESTDIR/file* > /dev/null 2>&1 + +log_note "Create tarball of snapshot..." +CWD=$PWD +cd $SNAPDIR || log_fail "Could not cd $SNAPDIR" +log_must $TAR cf $TESTDIR/tarball.snapshot.tar file* +cd $CWD || log_fail "Could not cd $CWD" + +log_must $MKDIR $TESTDIR/original +log_must $MKDIR $TESTDIR/snapshot + +CWD=$PWD +cd $TESTDIR/original || log_fail "Could not cd $TESTDIR/original" +log_must $TAR xf $TESTDIR/tarball.original.tar + +cd $TESTDIR/snapshot || log_fail "Could not cd $TESTDIR/snapshot" +log_must $TAR xf $TESTDIR/tarball.snapshot.tar + +cd $CWD || log_fail "Could not cd $CWD" + +$DIRCMP $TESTDIR/original $TESTDIR/snapshot > $TMPDIR/zfs_snapshot2.${TESTCASE_ID} +$GREP different $TMPDIR/zfs_snapshot2.${TESTCASE_ID} >/dev/null 2>&1 +if [[ $? -ne 1 ]]; then + log_fail "Directory structures differ." +fi + +log_pass "Directory structures match." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_003_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_003_pos.ksh new file mode 100644 index 00000000000..7121ede50cc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_003_pos.ksh @@ -0,0 +1,108 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_003_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_003_pos +# +# DESCRIPTION: +# Verify that many snapshots can be made on a zfs file system. +# +# STRATEGY: +# 1) Create a files in the zfs file system +# 2) Create a snapshot of the dataset +# 3) Remove all the files from the original file system +# 4) Verify consistency of each snapshot directory +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset -i i=1 + while [ $i -lt $COUNT ]; do + snapexists $SNAPFS.$i + if [[ $? -eq 0 ]]; then + log_must $ZFS destroy $SNAPFS.$i + fi + + if [[ -e $SNAPDIR.$i ]]; then + log_must $RM -rf $SNAPDIR.$i > /dev/null 2>&1 + fi + + (( i = i + 1 )) + done + + if [[ -e $TESTDIR ]]; then + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + fi +} + +log_assert "Verify many snapshots of a file system can be taken." + +log_onexit cleanup + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +log_note "Create some files in the $TESTDIR directory..." +populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ ITER $SNAPFS + +log_note "Remove all of the original files" +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/file* > /dev/null 2>&1 + +i=1 +while [[ $i -lt $COUNT ]]; do + FILECOUNT=`$LS $SNAPDIR.$i/file* | wc -l` + typeset j=1 + while [ $j -lt $FILECOUNT ]; do + log_must $FILE_CHECK $SNAPDIR.$i/file.$j $j + (( j = j + 1 )) + done + (( i = i + 1 )) +done + +log_pass "All files are consistent" diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_004_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_004_pos.ksh new file mode 100644 index 00000000000..020fcdd70cb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_004_pos.ksh @@ -0,0 +1,96 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_004_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_004_pos +# +# DESCRIPTION: +# Create a null snapshot i.e. a snapshot created before file system +# activity is empty. +# +# STRATEGY: +# 1. Empty a file system +# 2. Take a snapshot of the empty file system. +# 3. Populate the file system +# 4. Verify the snapshot is still empty +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + snapexists $SNAPFS + [[ $? -eq 0 ]] && \ + log_must $ZFS destroy $SNAPFS + + [[ -e $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 +} + +log_assert "Verify that a snapshot of an empty file system remains empty." + +log_onexit cleanup + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +log_must $ZFS snapshot $SNAPFS +FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total 0" | wc -l` +if [[ $FILE_COUNT -ne 0 ]]; then + $LS $SNAPDIR + log_fail "BEFORE: $SNAPDIR contains $FILE_COUNT files(s)." +fi + +typeset -i COUNT=10 + +log_note "Populate the $TESTDIR directory" +populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ ITER + +FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total 0" | wc -l` +if [[ $FILE_COUNT -ne 0 ]]; then + $LS $SNAPDIR + log_fail "AFTER: $SNAPDIR contains $FILE_COUNT files(s)." +fi + +log_pass "The NULL snapshot remains empty." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_005_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_005_pos.ksh new file mode 100644 index 00000000000..bdfbac815d4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_005_pos.ksh @@ -0,0 +1,102 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_005_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_005_pos +# +# DESCRIPTION: +# to the originally snapshot'd file system, after the file +# system has been changed. Uses 'sum -r'. +# +# STRATEGY: +# 1) Create a file in the zfs dataset +# 2) Sum the file for later comparison +# 3) Create a snapshot of the dataset +# 4) Append to the original file +# 5) Verify both checksums match +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +function cleanup +{ + snapexists $SNAPCTR + if [[ $? -eq 0 ]]; then + log_must $ZFS destroy $SNAPCTR + fi + + if [[ -e $SNAPDIR1 ]]; then + log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1 + fi + + if [[ -e $TESTDIR ]]; then + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + fi +} + +log_assert "Verify that a snapshot of a dataset is identical to " \ + "the original dataset." +log_onexit cleanup + +log_note "Create a file in the zfs filesystem..." +log_must $FILE_WRITE -o create -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA + +log_note "Sum the file, save for later comparison..." +FILE_SUM=`$SUM -r $TESTDIR1/$TESTFILE | $AWK '{ print $1 }'` +log_note "FILE_SUM = $FILE_SUM" + +log_note "Create a snapshot and mount it..." +log_must $ZFS snapshot $SNAPCTR + +log_note "Append to the original file..." +log_must $FILE_WRITE -o append -f $TESTDIR1/$TESTFILE -b $BLOCKSZ \ + -c $NUM_WRITES -d $DATA + +SNAP_FILE_SUM=`$SUM -r $SNAPDIR1/$TESTFILE | $AWK '{ print $1 }'` +if [[ $SNAP_FILE_SUM -ne $FILE_SUM ]]; then + log_fail "Sums do not match, aborting!! ($SNAP_FILE_SUM != $FILE_SUM)" +fi + +log_pass "Both Sums match. ($SNAP_FILE_SUM == $FILE_SUM)" diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_006_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_006_pos.ksh new file mode 100644 index 00000000000..ed5d265cbf3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_006_pos.ksh @@ -0,0 +1,137 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_006_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_006_pos +# +# DESCRIPTION: +# An archive of a zfs dataset and an archive of its snapshot +# changed sinced the snapshot was taken. +# +# STRATEGY: +# 1) Create some files in a ZFS dataset +# 2) Create a tarball of the dataset +# 3) Create a snapshot of the dataset +# 4) Remove all the files in the original dataset +# 5) Create a tarball of the snapshot +# 6) Extract each tarball and compare directory structures +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if [[ -d $CWD ]]; then + cd $CWD || log_fail "Could not cd $CWD" + fi + + snapexists $SNAPCTR + if [[ $? -eq 0 ]]; then + log_must $ZFS destroy $SNAPCTR + fi + + if [[ -e $SNAPDIR1 ]]; then + log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1 + fi + + if [[ -e $TESTDIR1 ]]; then + log_must $RM -rf $TESTDIR1/* > /dev/null 2>&1 + fi + + if [[ -e $TMPDIR/zfs_snapshot2.${TESTCASE_ID} ]]; then + log_must $RM -rf $TMPDIR/zfs_snapshot2.${TESTCASE_ID} > /dev/null 2>&1 + fi + +} + +log_assert "Verify that an archive of a dataset is identical to " \ + "an archive of the dataset's snapshot." + +log_onexit cleanup + +typeset -i COUNT=21 +typeset OP=create + +[[ -n $TESTDIR1 ]] && $RM -rf $TESTDIR1/* > /dev/null 2>&1 + +log_note "Create files in the zfs dataset ..." +populate_dir $TESTDIR1/file $COUNT $NUM_WRITES $BLOCKSZ $DATA + +log_note "Create a tarball from $TESTDIR1 contents..." +CWD=$PWD +cd $TESTDIR1 || log_fail "Could not cd $TESTDIR1" +log_must $TAR cf $TESTDIR1/tarball.original.tar file* +cd $CWD || log_fail "Could not cd $CWD" + +log_note "Create a snapshot and mount it..." +log_must $ZFS snapshot $SNAPCTR + +log_note "Remove all of the original files..." +log_must $RM -f $TESTDIR1/file* > /dev/null 2>&1 + +log_note "Create tarball of snapshot..." +CWD=$PWD +cd $SNAPDIR1 || log_fail "Could not cd $SNAPDIR1" +log_must $TAR cf $TESTDIR1/tarball.snapshot.tar file* +cd $CWD || log_fail "Could not cd $CWD" + +log_must $MKDIR $TESTDIR1/original +log_must $MKDIR $TESTDIR1/snapshot + +CWD=$PWD +cd $TESTDIR1/original || log_fail "Could not cd $TESTDIR1/original" +log_must $TAR xf $TESTDIR1/tarball.original.tar + +cd $TESTDIR1/snapshot || log_fail "Could not cd $TESTDIR1/snapshot" +log_must $TAR xf $TESTDIR1/tarball.snapshot.tar + +cd $CWD || log_fail "Could not cd $CWD" + +$DIRCMP $TESTDIR1/original $TESTDIR1/snapshot > $TMPDIR/zfs_snapshot2.${TESTCASE_ID} +$GREP different $TMPDIR/zfs_snapshot2.${TESTCASE_ID} >/dev/null 2>&1 +if [[ $? -ne 1 ]]; then + log_fail "Directory structures differ." +fi + +log_pass "Directory structures match." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_007_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_007_pos.ksh new file mode 100644 index 00000000000..27756fad365 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_007_pos.ksh @@ -0,0 +1,112 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_007_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_007_pos +# +# DESCRIPTION: +# Verify that many snapshots can be made on a zfs dataset. +# +# STRATEGY: +# 1) Create a file in the zfs dataset +# 2) Create a snapshot of the dataset +# 3) Remove all the files from the original dataset +# 4) For each snapshot directory verify consistency +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset -i i=1 + while [ $i -lt $COUNT ]; do + snapexists $SNAPCTR.$i + if [[ $? -eq 0 ]]; then + log_must $ZFS destroy $SNAPCTR.$i + fi + + if [[ -e $SNAPDIR.$i ]]; then + log_must $RM -rf $SNAPDIR1.$i > /dev/null 2>&1 + fi + + (( i = i + 1 )) + done + + if [[ -e $SNAPDIR1 ]]; then + log_must $RM -rf $SNAPDIR1 > /dev/null 2>&1 + fi + + if [[ -e $TESTDIR ]]; then + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + fi +} + +log_assert "Verify that many snapshots can be made on a zfs dataset." + +log_onexit cleanup + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +log_note "Create some files in the $TESTDIR directory..." +populate_dir $TESTDIR1/file $COUNT $NUM_WRITES $BLOCKSZ ITER $SNAPCTR + +log_note "Remove all of the original files" +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR1/file* > /dev/null 2>&1 + +i=1 +while [[ $i -lt $COUNT ]]; do + FILECOUNT=`$LS $SNAPDIR1.$i/file* | wc -l` + typeset j=1 + while [ $j -lt $FILECOUNT ]; do + log_must $FILE_CHECK $SNAPDIR1.$i/file.$j $j + (( j = j + 1 )) + done + (( i = i + 1 )) +done + +log_pass "All files are consistent" diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_008_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_008_pos.ksh new file mode 100644 index 00000000000..d8610fabba4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_008_pos.ksh @@ -0,0 +1,105 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_008_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_008_pos +# +# DESCRIPTION: +# Verify that destroying snapshots returns space to the pool. +# +# STRATEGY: +# 1. Create a file system and populate it while snapshotting. +# 2. Destroy the snapshots and remove the files. +# 3. Verify the space returns to the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-09-29) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset -i i=1 + while [[ $i -lt $COUNT ]]; do + snapexists $SNAPFS.$i + [[ $? -eq 0 ]] && \ + log_must $ZFS destroy $SNAPFS.$i + + (( i = i + 1 )) + done + + [[ -e $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 +} + +log_assert "Verify that destroying snapshots returns space to the pool." + +log_onexit cleanup + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +orig_size=`get_prop available $TESTPOOL` + +log_note "Populate the $TESTDIR directory" +populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ ITER $SNAPFS + +typeset -i i=1 +while [[ $i -lt $COUNT ]]; do + log_must rm -f $TESTDIR/file.$i > /dev/null 2>&1 + log_must $ZFS destroy $SNAPFS.$i + + (( i = i + 1 )) +done + +new_size=`get_prop available $TESTPOOL` + +typeset -i tolerance=0 + +(( tolerance = new_size - orig_size)) +if (( tolerance > LIMIT )); then + log_fail "Space not freed. ($orig_size != $new_size)" +fi + +log_pass "After destroying snapshots, the space is returned to the pool." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_009_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_009_pos.ksh new file mode 100644 index 00000000000..976a3e7f93b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_009_pos.ksh @@ -0,0 +1,131 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_009_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_009_pos +# +# DESCRIPTION: +# Verify 'snapshot -r' and 'destroy -r' can correctly create and destroy +# snapshot tree respectively. +# +# STRATEGY: +# 1. Use the snapshot -r to create snapshot for top level pool +# 2. Verify the children snapshots are created correctly. +# 3. Use destroy -r to destroy the top level snapshot +# 4. Verify that all children snapshots are destroyed too. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset ds + typeset snap + + for ds in $ctr/$TESTVOL1 $ctr/$TESTCLONE; do + datasetexists $ds && \ + log_must $ZFS destroy -f $ds + done + + for snap in $ctr/$TESTFS1@$TESTSNAP1 \ + $snappool $snapvol $snapctr $snapctrvol \ + $snapctrclone $snapctrfs + do + snapexists $snap && \ + log_must $ZFS destroy -rf $snap + done + +} + +log_assert "Verify snapshot -r can correctly create a snapshot tree." +log_onexit cleanup + +ctr=$TESTPOOL/$TESTCTR +ctrfs=$ctr/$TESTFS1 +ctrclone=$ctr/$TESTCLONE +ctrvol=$ctr/$TESTVOL1 +snappool=$SNAPPOOL +snapfs=$SNAPFS +snapctr=$ctr@$TESTSNAP +snapvol=$SNAPFS1 +snapctrvol=$ctrvol@$TESTSNAP +snapctrclone=$ctrclone@$TESTSNAP +snapctrfs=$SNAPCTR + +#preparation for testing +log_must $ZFS snapshot $ctrfs@$TESTSNAP1 +log_must $ZFS clone $ctrfs@$TESTSNAP1 $ctrclone +if is_global_zone; then + log_must $ZFS create -V $VOLSIZE $ctrvol +else + log_must $ZFS create $ctrvol +fi + +log_must $ZFS snapshot -r $snappool + +#verify the snapshot -r results +for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \ + $snapctrclone $snapctrfs +do + ! snapexists $snap && \ + log_fail "The snapshot $snap is not created via -r option." +done + +log_note "Verify that destroy -r can destroy the snapshot tree." + +log_must $ZFS destroy -r $snappool +for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \ + $snapctrclone $snapctrfs +do + snapexists $snap && \ + log_fail "The snapshot $snap is not destroyed correctly." +done + +log_note "Verify that the snapshot with different name should \ + be not destroyed." +! snapexists $ctrfs@$TESTSNAP1 && \ + log_fail "destroy -r incorrectly destroys the snapshot \ + $ctrfs@$TESTSNAP1." + +log_pass "snapshot|destroy -r with snapshot tree works as expected." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_010_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_010_pos.ksh new file mode 100644 index 00000000000..84a3552586d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_010_pos.ksh @@ -0,0 +1,113 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_010_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_010_pos +# +# DESCRIPTION: +# Verify 'destroy -r' can correctly destroy a snapshot tree at any point. +# +# STRATEGY: +# 1. Use the snapshot -r to create snapshot for top level pool +# 2. Select a middle point of the snapshot tree, use destroy -r to destroy all +# snapshots beneath the point. +# 3. Verify the destroy results. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset snap + + datasetexists $ctrvol && \ + log_must $ZFS destroy -f $ctrvol + + for snap in $ctrfs@$TESTSNAP1 \ + $snappool $snapvol $snapctr $snapctrvol \ + $snapctrclone $snapctrfs + do + snapexists $snap && \ + log_must $ZFS destroy -rf $snap + done + +} + +log_assert "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point." +log_onexit cleanup + +ctr=$TESTPOOL/$TESTCTR +ctrfs=$ctr/$TESTFS1 +ctrvol=$ctr/$TESTVOL1 +snappool=$SNAPPOOL +snapfs=$SNAPFS +snapctr=$ctr@$TESTSNAP +snapvol=$SNAPFS1 +snapctrvol=$ctr/$TESTVOL1@$TESTSNAP +snapctrclone=$ctr/$TESTCLONE@$TESTSNAP +snapctrfs=$SNAPCTR + +#preparation for testing +log_must $ZFS snapshot $ctrfs@$TESTSNAP1 +if is_global_zone; then + log_must $ZFS create -V $VOLSIZE $ctrvol +else + log_must $ZFS create $ctrvol +fi + +log_must $ZFS snapshot -r $snappool + +#select the $TESTCTR as destroy point, $TESTCTR is a child of $TESTPOOL +log_must $ZFS destroy -r $snapctr +for snap in $snapctr $snapctrvol $snapctrclone $snapctrfs; do + snapexists $snap && \ + log_fail "The snapshot $snap is not destroyed correctly." +done + +for snap in $snappool $snapfs $snapvol $ctrfs@$TESTSNAP1;do + ! snapexists $snap && \ + log_fail "The snapshot $snap should be not destroyed." +done + +log_pass "'destroy -r' destroys snapshot subtree as expected." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_011_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_011_pos.ksh new file mode 100644 index 00000000000..f79c7110a00 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_011_pos.ksh @@ -0,0 +1,114 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_011_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_011_pos +# +# DESCRIPTION: +# use 'snapshot -r' to create a snapshot tree, add some files to one child +# filesystem, rollback the child filesystem snapshot, verify that the child +# filesystem gets back to the status while taking the snapshot. +# +# STRATEGY: +# 1. Add some files to a target child filesystem +# 2. snapshot -r the parent filesystem +# 3. Add some other files to the target child filesystem +# 4. rollback the child filesystem snapshot +# 5. verify that the child filesystem get back to the status while being +# snapshot'd +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + snapexists $SNAPPOOL && \ + log_must $ZFS destroy -r $SNAPPOOL + + [[ -e $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 +} + +log_assert "Verify that rollback to a snapshot created by snapshot -r succeeds." +log_onexit cleanup + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +log_note "Populate the $TESTDIR directory (prior to snapshot)" +populate_dir $TESTDIR/before_file $COUNT $NUM_WRITES $BLOCKSZ ITER + +log_must $ZFS snapshot -r $SNAPPOOL + +FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l` +if (( FILE_COUNT != COUNT )); then + $LS -Al $SNAPDIR + log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." +fi + +log_note "Populate the $TESTDIR directory (post snapshot)" +typeset -i i=0 +populate_dir $TESTDIR/after_file $COUNT $NUM_WRITES $BLOCKSZ ITER + +# +# Now rollback to latest snapshot +# +log_must $ZFS rollback $SNAPFS + +FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l` +if (( FILE_COUNT != 0 )); then + $LS -Al $TESTDIR + log_fail "$TESTDIR contains $FILE_COUNT after* files(s)." +fi + +FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \ + | $GREP -v "total" | wc -l` +if (( FILE_COUNT != $COUNT )); then + $LS -Al $TESTDIR + log_fail "$TESTDIR contains $FILE_COUNT before* files(s)." +fi + +log_pass "Rollback with child snapshot works as expected." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_012_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_012_pos.ksh new file mode 100644 index 00000000000..3d7f12cb051 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_012_pos.ksh @@ -0,0 +1,116 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_012_pos.ksh 1.3 08/05/14 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_012_pos +# +# DESCRIPTION: +# Verify 'snapshot -r' can create snapshot for promoted clone, and vice +# versa, a clone filesystem from the snapshot created by 'snapshot -r' +# can be correctly promoted. +# +# STRATEGY: +# 1. Create a dataset tree +# 2. snapshot a filesystem and clone the snapshot +# 3. promote the clone +# 4. snapshot -r the dataset tree +# 5. verify that the snapshot of cloned filesystem is created correctly +# 6. clone a snapshot from the snapshot tree +# 7. promote the clone +# 8. verify that the clone is promoted correctly. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + if datasetexists $clone1; then + log_must $ZFS promote $ctrfs + log_must $ZFS destroy $clone1 + fi + + snapexists $snapctr && \ + log_must $ZFS destroy -r $snapctr + + if snapexists $clone@$TESTSNAP1; then + log_must $ZFS promote $ctrfs + log_must $ZFS destroy -rR $ctrfs@$TESTSNAP1 + fi +} + +log_assert "Verify that 'snapshot -r' can work with 'zfs promote'." +log_onexit cleanup + +ctr=$TESTPOOL/$TESTCTR +ctrfs=$ctr/$TESTFS1 +clone=$ctr/$TESTCLONE +clone1=$ctr/$TESTCLONE1 +snappool=$SNAPPOOL +snapfs=$SNAPFS +snapctr=$ctr@$TESTSNAP +snapctrclone=$clone@$TESTSNAP +snapctrclone1=$clone1@$TESTSNAP +snapctrfs=$SNAPCTR + +#preparation for testing +log_must $ZFS snapshot $ctrfs@$TESTSNAP1 +log_must $ZFS clone $ctrfs@$TESTSNAP1 $clone +log_must $ZFS promote $clone + +log_must $ZFS snapshot -r $snapctr + +! snapexists $snapctrclone && \ + log_fail "'snapshot -r' fails to create $snapctrclone for $ctr/$TESTCLONE." + +log_must $ZFS clone $snapctrfs $clone1 +log_must $ZFS promote $clone1 + +#verify the origin value is correct. +orig_value=$(get_prop origin $ctrfs) +if ! snapexists $snapctrclone1 || [[ "$orig_value" != "$snapctrclone1" ]]; then + log_fail "'zfs promote' fails to promote $clone which is cloned from \ + $snapctrfs." +fi + +log_pass "'snapshot -r' can work with 'zfs promote' as expected." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_013_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_013_pos.ksh new file mode 100644 index 00000000000..e6165c4da89 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_013_pos.ksh @@ -0,0 +1,106 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_013_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_013_pos +# +# DESCRIPTION: +# verify that the snapshots created by 'snapshot -r' can be used for +# zfs send/recv +# +# STRATEGY: +# 1. create a dataset tree and populate a filesystem +# 2. snapshot -r the dataset tree +# 3. select one snapshot used for zfs send/recv +# 4. verify the data integrity after zfs send/recv +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-06-20) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $ctrfs && \ + $ZFS destroy -r $ctrfs + + snapexists $snappool && \ + log_must $ZFS destroy -r $snappool + + [[ -e $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 +} + +log_assert "Verify snapshots from 'snapshot -r' can be used for zfs send/recv" +log_onexit cleanup + +ctr=$TESTPOOL/$TESTCTR +ctrfs=$ctr/$TESTFS +snappool=$SNAPPOOL +snapfs=$SNAPFS +snapctr=$ctr@$TESTSNAP +snapctrfs=$ctrfs@$TESTSNAP +fsdir=/$ctrfs +snapdir=$fsdir/$(get_snapdir_name)/$TESTSNAP + +[[ -n $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 + +typeset -i COUNT=10 + +log_note "Populate the $TESTDIR directory (prior to snapshot)" +populate_dir $TESTDIR/file $COUNT $NUM_WRITES $BLOCKSZ ITER + +log_must $ZFS snapshot -r $snappool + +$ZFS send $snapfs | $ZFS receive $ctrfs >/dev/null 2>&1 +if ! datasetexists $ctrfs || ! snapexists $snapctrfs; then + log_fail "zfs send/receive fails with snapshot $snapfs." +fi + +for dir in $fsdir $snapdir; do + FILE_COUNT=`$LS -Al $dir | $GREP -v "total" | wc -l` + (( FILE_COUNT != COUNT )) && \ + log_fail "The data gets changed after zfs send/recv." +done + +log_pass "'zfs send/receive' works as expected with snapshots from 'snapshot -r'" diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_014_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_014_pos.ksh new file mode 100644 index 00000000000..5dd0f2f4145 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_014_pos.ksh @@ -0,0 +1,90 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_014_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_014_pos +# +# DESCRIPTION: +# verify that creating/destroying snapshots do things clean +# +# STRATEGY: +# 1. create a dataset and set a quota with 500m +# 2. create file of size 400m on the dataset +# 3. take a snapshot and destroy it +# 4. then create file to use all spaces in the dataset +# 5. verify removing the first file should succeed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + [[ -e $TESTDIR1 ]] && \ + log_must $RM -rf $TESTDIR1/* > /dev/null 2>&1 + + snapexists $SNAPCTR && \ + log_must $ZFS destroy $SNAPCTR + + datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \ + log_must $ZFS set quota=none $TESTPOOL/$TESTCTR/$TESTFS1 + +} + +log_assert "Verify creating/destroying snapshots do things clean" +log_onexit cleanup + +log_must $ZFS set quota=$FSQUOTA $TESTPOOL/$TESTCTR/$TESTFS1 +log_must $MKFILE $FILESIZE $TESTDIR1/$TESTFILE + +log_must $ZFS snapshot $SNAPCTR +log_must $ZFS destroy $SNAPCTR + +log_note "Make the quota of filesystem is reached" +log_mustnot $MKFILE $FILESIZE1 $TESTDIR1/$TESTFILE1 + +log_note "Verify removing the first file should succeed after the snapshot is \ + removed" +log_must $RM $TESTDIR1/$TESTFILE + +log_pass "Verify creating/destroying snapshots do things clean" diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_015_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_015_pos.ksh new file mode 100644 index 00000000000..23a763beb8c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_015_pos.ksh @@ -0,0 +1,136 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_015_pos.ksh 1.5 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_rollback/zfs_rollback_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapshot_015_pos +# +# DESCRIPTION: +# Verify snapshot can be created or destroy via mkdir or rm +# in $(get_snapdir_name). +# +# STRATEGY: +# 1. Verify make directories only successfully in $(get_snapdir_name). +# 2. Verify snapshot can be created and destroy via mkdir and remove +# directories in $(get_snapdir_name). +# 3. Verify rollback to previous snapshot can succeed. +# 4. Verify remove directory in snapdir can destroy snapshot. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-17) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + typeset -i i=0 + while ((i < snap_cnt)); do + typeset snap=$fs@snap.$i + datasetexists $snap && log_must $ZFS destroy -f $snap + + ((i += 1)) + done +} + +$ZFS 2>&1 | $GREP "allow" > /dev/null +(($? != 0)) && log_unsupported + +log_assert "Verify snapshot can be created via mkdir in $(get_snapdir_name)." +log_onexit cleanup + +[[ $os_name == "FreeBSD" ]] && \ + log_uninitiated "Directory operations on the $(get_snapdir_name) directory are not yet supported in FreeBSD" + +fs=$TESTPOOL/$TESTFS +# Verify all the other directories are readonly. +mntpnt=$(get_prop mountpoint $fs) +snapdir=$mntpnt/.zfs +set -A ro_dirs "$snapdir" "$snapdir/snap" "$snapdir/snapshot" +for dir in ${ro_dirs[@]}; do + if [[ -d $dir ]]; then + log_mustnot $RM -rf $dir + log_mustnot $TOUCH $dir/testfile + else + log_mustnot $MKDIR $dir + fi +done + +# Verify snapshot can be created via mkdir in $(get_snapdir_name) +typeset -i snap_cnt=5 +typeset -i cnt=0 +while ((cnt < snap_cnt)); do + testfile=$mntpnt/testfile.$cnt + log_must $MKFILE 1M $testfile + log_must $MKDIR $mntpnt/$(get_snapdir_name)/snap.$cnt + if ! datasetexists $fs@snap.$cnt ; then + log_fail "ERROR: $fs@snap.$cnt should exists." + fi + + ((cnt += 1)) +done + +# Verify rollback to previous snapshot succeed. +((cnt = RANDOM % snap_cnt)) +log_must $ZFS rollback -r $fs@snap.$cnt + +typeset -i i=0 +while ((i < snap_cnt)); do + testfile=$mntpnt/testfile.$i + if ((i <= cnt)); then + if [[ ! -f $testfile ]]; then + log_fail "ERROR: $testfile should exists." + fi + else + if [[ -f $testfile ]]; then + log_fail "ERROR: $testfile should not exists." + fi + fi + + ((i += 1)) +done + +# Verify remove directory in snapdir can destroy snapshot. +log_must $RMDIR $mntpnt/$(get_snapdir_name)/snap.$cnt +log_mustnot datasetexists $fs@snap.$cnt + +log_pass "Verify snapshot can be created via mkdir in $(get_snapdir_name) passed." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_016_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_016_pos.ksh new file mode 100644 index 00000000000..96d97521592 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_016_pos.ksh @@ -0,0 +1,116 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_016_pos.ksh 1.2 08/11/03 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapshot_016_pos +# +# DESCRIPTION: +# Verify renamed snapshots via mv can be destroyed +# +# STRATEGY: +# 1. Create snapshot +# 2. Rename the snapshot via mv command +# 2. Verify destroying the renamed snapshot via 'zfs destroy' succeeds +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-01-26) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $SNAPFS && \ + log_must $ZFS destroy -Rf $SNAPFS + datasetexists $TESTPOOL/$TESTFS@snap_a && \ + log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS@snap_a + datasetexists $TESTPOOL/$TESTCLONE@snap_a && \ + log_must $ZFS destroy -Rf $TESTPOOL/$TESTCLONE@snap_a + + datasetexists $TESTPOOL/$TESTCLONE && \ + log_must $ZFS destroy $TESTPOOL/$TESTCLONE + datasetexists $TESTPOOL/$TESTFS && \ + log_must $ZFS destroy $TESTPOOL/$TESTFS + + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Verify renamed snapshots via mv can be destroyed." +log_onexit cleanup + +[[ $os_name == "FreeBSD" ]] && \ + log_uninitiated "Directory operations on the $(get_snapdir_name) directory are not yet supported in FreeBSD" + +# scenario 1 + +log_must $ZFS snapshot $SNAPFS +log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a + +datasetexists $TESTPOOL/$TESTFS@snap_a || \ + log_fail "rename snapshot via mv in $(get_snapdir_name) fails." +log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a + +# scenario 2 + +log_must $ZFS snapshot $SNAPFS +log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE +log_must $MV $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a + +datasetexists $TESTPOOL/$TESTFS@snap_a || \ + log_fail "rename snapshot via mv in $(get_snapdir_name) fails." +log_must $ZFS promote $TESTPOOL/$TESTCLONE +# promote back to $TESTPOOL/$TESTFS for scenario 3 +log_must $ZFS promote $TESTPOOL/$TESTFS +log_must $ZFS destroy $TESTPOOL/$TESTCLONE +log_must $ZFS destroy $TESTPOOL/$TESTFS@snap_a + +# scenario 3 + +log_must $ZFS snapshot $SNAPFS +log_must $ZFS clone $SNAPFS $TESTPOOL/$TESTCLONE +log_must $ZFS rename $SNAPFS $TESTPOOL/$TESTFS@snap_a +log_must $ZFS promote $TESTPOOL/$TESTCLONE +log_must $ZFS destroy $TESTPOOL/$TESTFS +log_must $ZFS destroy $TESTPOOL/$TESTCLONE@snap_a + +log_pass "Verify renamed snapshots via mv can be destroyed." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_017_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_017_pos.ksh new file mode 100644 index 00000000000..9178ea071bc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_017_pos.ksh @@ -0,0 +1,213 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapshot_017_pos.ksh 1.1 08/08/15 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_017_pos +# +# DESCRIPTION: +# +# Directory structure of snapshots reflects filesystem structure. +# +# STRATEGY: +# +# This test makes sure that the directory structure of snapshots is +# a proper reflection of the filesystem the snapshot was taken of. +# +# 1. Create a simple directory structure of files and directories +# 2. Take a snapshot of the filesystem +# 3. Modify original filesystem +# 4. Walk down the snapshot directory structure verifying it +# checking with both absolute and relative paths +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-05-31) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + cd $SAVED_DIR + + if datasetexists $TESTPOOL/$TESTFS ; then + log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS + fi + + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +function verify_structure { + + # check absolute paths + DIR=$PWD + verify_file $DIR/file1 + verify_file $DIR/file2 + verify_file $DIR/dir1/file3 + verify_file $DIR/dir1/file4 + verify_file $DIR/dir1/dir2/file5 + verify_file $DIR/dir1/dir2/file6 + + verify_no_file $DIR/file99 + + # check relative paths + verify_file ./file1 + verify_file ./file2 + verify_file ./dir1/file3 + verify_file ./dir1/file4 + verify_file ./dir1/dir2/file5 + verify_file ./dir1/dir2/file6 + + cd dir1 + verify_file ../file1 + verify_file ../file2 + verify_file ./file3 + verify_file ./file4 + + verify_no_file ../file99 + + cd dir2 + verify_file ./file5 + verify_file ./file6 + verify_file ../file3 + verify_file ../file4 + verify_no_file ../file99 + + verify_file ../../file1 + verify_file ../../file2 + verify_no_file ../../file99 +} + +function verify_file { + if [ ! -e $1 ] + then + log_note "Working dir is $PWD" + log_fail "File $1 does not exist!" + fi +} + +function verify_no_file { + if [ -e $1 ] + then + log_note "Working dir is $PWD" + log_fail "File $1 exists when it should not!" + fi +} + +function verify_dir { + if [ ! -d $1 ] + then + log_note "Working dir is $PWD" + log_fail "Directory $1 does not exist!" + fi +} + +log_assert "Directory structure of snapshots reflects filesystem structure." +log_onexit cleanup + +SAVED_DIR=$PWD + +# +# Create a directory structure with the following files +# +# ./file1 +# ./file2 +# ./dir1/file3 +# ./dir1/file4 +# ./dir1/dir2/file5 +# ./dir1/dir2/file6 + +cd $TESTDIR +$TOUCH file1 +$TOUCH file2 +$MKDIR dir1 +cd dir1 +$TOUCH file3 +$TOUCH file4 +$MKDIR dir2 +cd dir2 +$TOUCH file5 +$TOUCH file6 + +# Now walk the directory structure verifying it +cd $TESTDIR +verify_structure + +# Take snapshots +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_a +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap_b + +# Change the filesystem structure by renaming files in the original structure +# The snapshot file structure should not change +cd $TESTDIR +log_must $MV file2 file99 +cd dir1 +log_must $MV file4 file99 +cd dir2 +log_must $MV file6 file99 + +# verify the top level snapshot directories +verify_dir $TESTDIR/$(get_snapdir_name) +verify_dir $TESTDIR/$(get_snapdir_name) +verify_dir $TESTDIR/$(get_snapdir_name)/snap_a +verify_dir $TESTDIR/$(get_snapdir_name)/snap_b + +cd $TESTDIR/$(get_snapdir_name)/snap_a +verify_structure + +cd $TESTDIR/$(get_snapdir_name)/snap_b +verify_structure + +verify_dir $TESTDIR/$(get_snapdir_name) +cd $TESTDIR/$(get_snapdir_name) +verify_dir snap_a +verify_dir snap_b + +cd snap_a +verify_dir ../snap_a +verify_dir ../snap_b + +cd .. +verify_dir snap_a +verify_dir snap_b + +log_pass "Directory structure of snapshots reflects filesystem structure." diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_018_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_018_pos.ksh new file mode 100644 index 00000000000..f313d0c5c66 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_018_pos.ksh @@ -0,0 +1,95 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_018_pos +# +# DESCRIPTION: +# Snapshot directory supports ACL operations +# +# STRATEGY: +# 1. Create a dataset +# 2. Set the snapdir property to visible +# 3. Use getconf to verify that acls are supported +# 4. Use getfacl to verify that the acl can be read +# 5. Verify that the acl is correct +# 6. Verify that ls doesn't print any errors because acl_get_link fails +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2013-01-03) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +log_assert "Verify that the snapshot directory supports ACL operations" + +log_must dataset_setprop $TESTPOOL/$TESTFS "snapdir" "visible" + +function verify_dir # directory +{ + typeset DIR=$1 + # 3. Verify that ACLs are supported by the ctldir + log_must $GETCONF TRUSTEDBSD_ACL_EXTENDED $DIR + # 4. Verify that we can read ACLs + log_must $GETFACL $DIR + # 5. Verify that the ACLs are correct + typeset PROG_DIR=$STF_SUITE/tests/snapshot + typeset SUM=$($SHA1 -q $PROG_DIR/ctldir_acl.txt) + if [[ $( $GETFACL -q $DIR | $SHA1 -q ) != $SUM ]]; then + log_fail "ACL is incorrect" + fi + +} + +typeset -a dirlist +dirlist=( "$TESTDIR/.zfs" "$TESTDIR/.zfs/snapshot" ) +ctldir=".zfs" +for d in ${dirlist[@]}; do + verify_dir $d +done + +# 6. Check for errors with ls +LS_STDERR=$( $LS -la $TESTDIR/$ctldir 2>&1 > /dev/null) +LS_R_STDERR=$( $LS -lar $TESTDIR/$ctldir 2>&1 > /dev/null) +if [[ -n $LS_STDERR || -n $LS_R_STDERR ]]; then + log_fail "ls encountered errors" +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_019_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_019_pos.ksh new file mode 100644 index 00000000000..39eb0724141 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_019_pos.ksh @@ -0,0 +1,119 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: snapshot_019_pos +# +# DESCRIPTION: +# Accessing snapshots and unmounting them in parallel does not panic. +# FreeBSD PR kern/184677 +# +# STRATEGY: +# 1. Create a dataset +# 2. Set the snapdir property to visible +# 3. Do the following in parallel +# a. Repeatedly access the snapshot +# b. Repeatedly unmount the snapshot +# 4. Verify that the system does not panic +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2013-12-23) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +KILL_SWITCH=${PWD}/kill_switch + +function stat_snapshot +{ + while [ ! -f ${KILL_SWITCH} ]; do + cd $SNAPDIR # Exercise forced unmount + stat "$SNAPDIR" > /dev/null 2>&1 + done +} + +function ls_snapshot +{ + # Pre-generate the argument list. + ls_args="" + for ((num=0; $num<100; num=$num+1)); do + ls_args="$ls_args $SNAPDIR/.." + done + + while [ ! -f ${KILL_SWITCH} ]; do + ls $ls_args >/dev/null 2>&1 + done +} + +log_assert "Accessing snapshots and unmounting them in parallel does not panic" + +log_must dataset_setprop $TESTPOOL "snapdir" "visible" + +# Take snapshots +log_must $ZFS snapshot "$TESTPOOL/$TESTFS@$TESTSNAP" + +# Repeatedly access the snapshot directory +stat_snapshot & +stat_pid="$!" +ls_snapshot & +ls_pid="$!" + +# Repeatedly unmount the snapshot directory +for ((i=0; $i<100; i=$i+1)); do + umount "$SNAPDIR" >/dev/null 2>&1 + log_note "$i non-forced done" + # Sleep just long enough for the other "threads" to remount. + sleep 0.1 + umount -f "$SNAPDIR" >/dev/null 2>&1 + log_note "$i forced done" + sleep 0.1 +done + +# Kill the other "threads" and wait for them to die. +touch $KILL_SWITCH +log_note "Waiting for all child processes to die..." +wait + +# Test that no reference leaks occurred and we can cleanup without forcing. +log_must $ZFS unmount $TESTPOOL/$TESTFS +log_must $ZFS destroy -r $TESTPOOL/$TESTFS + +# If we get here, we managed to not panic, deadlock, or leak references. +log_pass diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_020_pos.ksh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_020_pos.ksh new file mode 100644 index 00000000000..bee30b1a13d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_020_pos.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic Corporation +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapshot_020_pos +# +# DESCRIPTION: +# Verify that snapshots can be mounted in the ctldir, then renamed, then +# destroyed. The original bug that this regresses was that the rename +# command failed to unmount the snapshot from its old location, leaving +# the user unable to either mount it or destroy it. +# +# STRATEGY: +# 1. Create snapshot +# 2. Access the snapshot through the ctldir to automount it +# 3. Rename the snapshot +# 4. Destroy the snapshot +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2014-06-02) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + datasetexists $SNAPFS && \ + log_must $ZFS destroy -Rf $SNAPFS + datasetexists $TESTPOOL/$TESTFS@snap_a && \ + log_must $ZFS destroy -Rf $TESTPOOL/$TESTFS@snap_a + datasetexists $TESTPOOL/$TESTCLONE@snap_a && \ + log_must $ZFS destroy -Rf $TESTPOOL/$TESTCLONE@snap_a + + datasetexists $TESTPOOL/$TESTCLONE && \ + log_must $ZFS destroy $TESTPOOL/$TESTCLONE + datasetexists $TESTPOOL/$TESTFS && \ + log_must $ZFS destroy $TESTPOOL/$TESTFS + + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +log_assert "Verify that mounted snapshots can be renamed and destroyed" +log_onexit cleanup + +log_must $ZFS set snapdir=visible $TESTPOOL/$TESTFS +log_must $ZFS snapshot $SNAPFS +log_must stat $TESTDIR/$SNAPROOT/$TESTSNAP +log_must $ZFS rename $SNAPFS $TESTPOOL/$TESTFS@$TESTSNAP1 +log_must stat $TESTDIR/$SNAPROOT/$TESTSNAP1 +log_must $ZFS destroy $TESTPOOL/$TESTFS@$TESTSNAP1 + +log_pass diff --git a/tests/sys/cddl/zfs/tests/snapshot/snapshot_test.sh b/tests/sys/cddl/zfs/tests/snapshot/snapshot_test.sh new file mode 100755 index 00000000000..2f37a61a2bc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapshot/snapshot_test.sh @@ -0,0 +1,634 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case clone_001_pos cleanup +clone_001_pos_head() +{ + atf_set "descr" "Verify a cloned file system is writable." + atf_set "require.progs" zfs +} +clone_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + verify_zvol_recursive + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/clone_001_pos.ksh || atf_fail "Testcase failed" +} +clone_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rollback_001_pos cleanup +rollback_001_pos_head() +{ + atf_set "descr" "Verify that a rollback to a previous snapshot succeeds." + atf_set "require.progs" zfs +} +rollback_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rollback_001_pos.ksh || atf_fail "Testcase failed" +} +rollback_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rollback_002_pos cleanup +rollback_002_pos_head() +{ + atf_set "descr" "Verify rollback is with respect to latest snapshot." + atf_set "require.progs" zfs +} +rollback_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rollback_002_pos.ksh || atf_fail "Testcase failed" +} +rollback_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case rollback_003_pos cleanup +rollback_003_pos_head() +{ + atf_set "descr" "Verify rollback succeeds when there are nested file systems." + atf_set "require.progs" zfs +} +rollback_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/rollback_003_pos.ksh || atf_fail "Testcase failed" +} +rollback_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_001_pos cleanup +snapshot_001_pos_head() +{ + atf_set "descr" "Verify a file system snapshot is identical to original." + atf_set "require.progs" zfs sum +} +snapshot_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_001_pos.ksh || atf_fail "Testcase failed" +} +snapshot_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_002_pos cleanup +snapshot_002_pos_head() +{ + atf_set "descr" "Verify an archive of a file system is identical toan archive of its snapshot." + atf_set "require.progs" zfs +} +snapshot_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_002_pos.ksh || atf_fail "Testcase failed" +} +snapshot_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_003_pos cleanup +snapshot_003_pos_head() +{ + atf_set "descr" "Verify many snapshots of a file system can be taken." + atf_set "require.progs" zfs +} +snapshot_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_003_pos.ksh || atf_fail "Testcase failed" +} +snapshot_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_004_pos cleanup +snapshot_004_pos_head() +{ + atf_set "descr" "Verify that a snapshot of an empty file system remains empty." + atf_set "require.progs" zfs +} +snapshot_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_004_pos.ksh || atf_fail "Testcase failed" +} +snapshot_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_005_pos cleanup +snapshot_005_pos_head() +{ + atf_set "descr" "Verify that a snapshot of a dataset is identical tothe original dataset." + atf_set "require.progs" zfs sum +} +snapshot_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_005_pos.ksh || atf_fail "Testcase failed" +} +snapshot_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_006_pos cleanup +snapshot_006_pos_head() +{ + atf_set "descr" "Verify that an archive of a dataset is identical toan archive of the dataset's snapshot." + atf_set "require.progs" zfs +} +snapshot_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_006_pos.ksh || atf_fail "Testcase failed" +} +snapshot_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_007_pos cleanup +snapshot_007_pos_head() +{ + atf_set "descr" "Verify that many snapshots can be made on a zfs dataset." + atf_set "require.progs" zfs +} +snapshot_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_007_pos.ksh || atf_fail "Testcase failed" +} +snapshot_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_008_pos cleanup +snapshot_008_pos_head() +{ + atf_set "descr" "Verify that destroying snapshots returns space to the pool." + atf_set "require.progs" zfs +} +snapshot_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_008_pos.ksh || atf_fail "Testcase failed" +} +snapshot_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_009_pos cleanup +snapshot_009_pos_head() +{ + atf_set "descr" "Verify snapshot -r can correctly create a snapshot tree." + atf_set "require.progs" zfs +} +snapshot_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_009_pos.ksh || atf_fail "Testcase failed" +} +snapshot_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_010_pos cleanup +snapshot_010_pos_head() +{ + atf_set "descr" "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point." + atf_set "require.progs" zfs +} +snapshot_010_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_010_pos.ksh || atf_fail "Testcase failed" +} +snapshot_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_011_pos cleanup +snapshot_011_pos_head() +{ + atf_set "descr" "Verify that rollback to a snapshot created by snapshot -r succeeds." + atf_set "require.progs" zfs +} +snapshot_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_011_pos.ksh || atf_fail "Testcase failed" +} +snapshot_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_012_pos cleanup +snapshot_012_pos_head() +{ + atf_set "descr" "Verify that 'snapshot -r' can work with 'zfs promote'." + atf_set "require.progs" zfs +} +snapshot_012_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_012_pos.ksh || atf_fail "Testcase failed" +} +snapshot_012_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_013_pos cleanup +snapshot_013_pos_head() +{ + atf_set "descr" "Verify snapshots from 'snapshot -r' can be used for zfs send/recv" + atf_set "require.progs" zfs +} +snapshot_013_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_013_pos.ksh || atf_fail "Testcase failed" +} +snapshot_013_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_014_pos cleanup +snapshot_014_pos_head() +{ + atf_set "descr" "Verify creating/destroying snapshots do things clean" + atf_set "require.progs" zfs +} +snapshot_014_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_014_pos.ksh || atf_fail "Testcase failed" +} +snapshot_014_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_015_pos cleanup +snapshot_015_pos_head() +{ + atf_set "descr" "Verify snapshot can be created via mkdir in .zfs/snapshot." + atf_set "require.progs" zfs +} +snapshot_015_pos_body() +{ + atf_expect_fail "Not all directory operations on the .zfs/snapshot directory are yet supported by FreeBSD" + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_015_pos.ksh || atf_fail "Testcase failed" +} +snapshot_015_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_016_pos cleanup +snapshot_016_pos_head() +{ + atf_set "descr" "Verify renamed snapshots via mv can be destroyed." + atf_set "require.progs" zfs +} +snapshot_016_pos_body() +{ + atf_expect_fail "Not all directory operations on the .zfs/snapshot directory are yet supported by FreeBSD" + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_016_pos.ksh || atf_fail "Testcase failed" +} +snapshot_016_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_017_pos cleanup +snapshot_017_pos_head() +{ + atf_set "descr" "Directory structure of snapshots reflects filesystem structure." + atf_set "require.progs" zfs +} +snapshot_017_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_017_pos.ksh || atf_fail "Testcase failed" +} +snapshot_017_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_018_pos cleanup +snapshot_018_pos_head() +{ + atf_set "descr" "Snapshot directory supports ACL operations" + atf_set "require.progs" zfs getfacl getconf sha1 +} +snapshot_018_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_018_pos.ksh || atf_fail "Testcase failed" +} +snapshot_018_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapshot_019_pos cleanup +snapshot_019_pos_head() +{ + atf_set "descr" "Accessing snapshots and unmounting them in parallel does not panic" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +snapshot_019_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_019_pos.ksh || atf_fail "Testcase failed" +} +snapshot_019_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case snapshot_020_pos cleanup +snapshot_020_pos_head() +{ + atf_set "descr" "Verify mounted snapshots can be renamed and destroyed" + atf_set "require.progs" zfs +} +snapshot_020_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapshot_020_pos.ksh || atf_fail "Testcase failed" +} +snapshot_020_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapshot.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + atf_add_test_case clone_001_pos + atf_add_test_case rollback_001_pos + atf_add_test_case rollback_002_pos + atf_add_test_case rollback_003_pos + atf_add_test_case snapshot_001_pos + atf_add_test_case snapshot_002_pos + atf_add_test_case snapshot_003_pos + atf_add_test_case snapshot_004_pos + atf_add_test_case snapshot_005_pos + atf_add_test_case snapshot_006_pos + atf_add_test_case snapshot_007_pos + atf_add_test_case snapshot_008_pos + atf_add_test_case snapshot_009_pos + atf_add_test_case snapshot_010_pos + atf_add_test_case snapshot_011_pos + atf_add_test_case snapshot_012_pos + atf_add_test_case snapshot_013_pos + atf_add_test_case snapshot_014_pos + atf_add_test_case snapshot_015_pos + atf_add_test_case snapshot_016_pos + atf_add_test_case snapshot_017_pos + atf_add_test_case snapshot_018_pos + atf_add_test_case snapshot_019_pos + atf_add_test_case snapshot_020_pos +} diff --git a/tests/sys/cddl/zfs/tests/snapused/Makefile b/tests/sys/cddl/zfs/tests/snapused/Makefile new file mode 100644 index 00000000000..c9a29d5e01e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/Makefile @@ -0,0 +1,23 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/snapused +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= snapused_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= snapused_005_pos.ksh +${PACKAGE}FILES+= snapused_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= snapused_004_pos.ksh +${PACKAGE}FILES+= snapused.kshlib +${PACKAGE}FILES+= snapused.cfg +${PACKAGE}FILES+= snapused_002_pos.ksh +${PACKAGE}FILES+= snapused_003_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/snapused/cleanup.ksh b/tests/sys/cddl/zfs/tests/snapused/cleanup.ksh new file mode 100644 index 00000000000..63175838afc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/snapused/setup.ksh b/tests/sys/cddl/zfs/tests/snapused/setup.ksh new file mode 100644 index 00000000000..dca69cd4700 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused.cfg b/tests/sys/cddl/zfs/tests/snapused/snapused.cfg new file mode 100644 index 00000000000..78f3b97beac --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused.cfg @@ -0,0 +1,34 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapused.cfg 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +export USEDTEST=$TESTPOOL/$TESTFS/usedtest${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused.kshlib b/tests/sys/cddl/zfs/tests/snapused/snapused.kshlib new file mode 100644 index 00000000000..303d22d4ee8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused.kshlib @@ -0,0 +1,191 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapused.kshlib 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +function usedby_supported +{ + fs_prop_exist "usedbysnapshots" + return $? +} + +function _check_used # dataset +{ + typeset dataset=$1 + + if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then + return + fi + + used=$(get_prop used $dataset) + usedbychildren=$(get_prop usedbychildren $dataset) + usedbydataset=$(get_prop usedbydataset $dataset) + usedbyrefreservation=$(get_prop usedbyrefreservation $dataset) + usedbysnapshots=$(get_prop usedbysnapshots $dataset) + (( used_sum = usedbychildren + usedbydataset + \ + usedbyrefreservation + usedbysnapshots )) + if (( used != used_sum )); then + log_fail "$dataset: used($used) is not the sum($used_sum) of usedby*" + fi +} + +function check_used # dataset +{ + typeset dataset=$1 + for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) + do + _check_used $child + done +} + +function check_usedbychildren # dataset +{ + typeset dataset=$1 + typeset -i usedbychildren_sum=0 + typeset -i parent_usedbychildren=0 + for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) + do + if [[ "$(get_prop type $child)" == "snapshot" ]]; then + continue + fi + + # parent + if [[ "$child" == "$dataset" ]]; then + parent_usedbychildren=$(get_prop usedbychildren $child) + else #child + reservation=$(get_prop reservation $child) + used=$(get_prop used $child) + if (( reservation > used )); then + (( usedbychildren_sum += reservation )) + else + (( usedbychildren_sum += used )) + fi + fi + done + + if (( parent_usedbychildren != usedbychildren_sum )); then + log_fail "$dataset: usedbychildren($parent_usedbychildren) is not the sum($usedbychildren_sum) of used by children" + fi +} + +function _check_usedbydataset # dataset +{ + typeset dataset=$1 + if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then + return + fi + + usedbydataset=$(get_prop usedbydataset $dataset) + referenced=$(get_prop referenced $dataset) + + is_cloned=$(get_prop is:cloned $dataset) + + if [[ "$is_cloned" == "yes" ]]; then + if (( usedbydataset > referenced )); then + log_fail "$dataset(cloned): usedbydataset($usedbydataset) is more than referenced($referenced)" + fi + else + # + # if non-clones, should usedbydataset == referenced + # + if (( usedbydataset != referenced )); then + log_fail "$dataset: usedbydataset($usedbydataset) is not equal to referenced($referenced)" + fi + fi +} + +function check_usedbydataset # dataset +{ + typeset dataset=$1 + for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) + do + _check_usedbydataset $child + done +} + +function _check_usedbyrefreservation # dataset +{ + typeset dataset=$1 + if [[ "$(get_prop type $dataset)" == "snapshot" ]]; then + return + fi + + usedbyrefreservation=$(get_prop usedbyrefreservation $dataset) + referenced=$(get_prop referenced $dataset) + refreservation=$(get_prop refreservation $dataset) + (( diff_ref = refreservation - referenced )) + if (( usedbyrefreservation > refreservation || \ + usedbyrefreservation < diff_ref )); then + log_fail "$dataset: usedbyrefreservation($usedbyrefreservation) checking is not ok" + fi +} + +function check_usedbyrefreservation # dataset +{ + typeset dataset=$1 + for child in $($ZFS list -rH -t filesystem,volume -o name $dataset) + do + _check_usedbyrefreservation $child + done +} + +function check_usedbysnapshots # dataset +{ + typeset dataset=$1 + typeset -i usedbysnapshots_sum=0 + typeset -i parent_usedbysnapshots=0 + for child in $($ZFS list -rH -t filesystem,volume,snapshot -o name $dataset) + do + # parent + if [[ "$child" == "$dataset" ]]; then + parent_usedbysnapshots=$(get_prop usedbysnapshots $child) + continue + fi + + if [[ "$(get_prop type $child)" != "snapshot" ]]; then + continue + fi + + if [[ "$child" != "$dataset@"* ]]; then + continue + fi + + # snapshot + used=$(get_prop used $child) + (( usedbysnapshots_sum += used )) + done + + if (( parent_usedbysnapshots < usedbysnapshots_sum )); then + log_fail "$dataset: usedbysnapshots($parent_usedbysnapshots) is not more than or equal to" \ + "the sum($usedbysnapshots_sum) of used of snapshots" + fi +} + diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused_001_pos.ksh b/tests/sys/cddl/zfs/tests/snapused/snapused_001_pos.ksh new file mode 100644 index 00000000000..07272013aa8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused_001_pos.ksh @@ -0,0 +1,110 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapused_001_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/snapused/snapused.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapused_001_pos +# +# DESCRIPTION: +# Verify used is correct. +# +# STRATEGY: +# 1. Create a filesystem. +# 2. Set refreservation of the filesystem. +# 3. Make file in the filesystem. +# 4. Create sub filesystem and make file in it. +# 5. Create volume under it. +# 6. Snapshot it. +# 7. Check used=usedbychildren+usedbydataset+ +# usedbyrefreservation+usedbysnapshots. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-28) +# +# __stc_assertion_end +# +################################################################################ + +if ! usedby_supported ; then + log_unsupported "snapused property is not supported." +fi + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rR $USEDTEST +} + +log_assert "Verify used is correct." +log_onexit cleanup + +log_must $ZFS create $USEDTEST +check_used $USEDTEST + +typeset -i i=0 +typeset -i r_size=0 +mntpnt=$(get_prop mountpoint $USEDTEST) +while (( i < 5 )); do + ((r_size=(i+1)*16)) + + #usedbyrefreservation + log_must $ZFS set refreservation="$r_size"M $USEDTEST + + #usedbydataset + log_must $MKFILE 16M $mntpnt/file$i + + #usedbychildren + log_must $ZFS create $USEDTEST/fs$i + log_must $MKFILE 16M $mntpnt/fs$i/file$i + + if is_global_zone; then + log_must $ZFS create -V 16M $USEDTEST/vol$i + fi + + #usedbysnapshots + log_must $ZFS snapshot -r $USEDTEST@snap$i + + check_used $USEDTEST + + ((i = i + 1)) +done + +log_pass "Verify used is correct." + diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused_002_pos.ksh b/tests/sys/cddl/zfs/tests/snapused/snapused_002_pos.ksh new file mode 100644 index 00000000000..508fa963f7e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused_002_pos.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapused_002_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/snapused/snapused.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapused_002_pos +# +# DESCRIPTION: +# Verify usedbychildren is correct. +# +# STRATEGY: +# 1. Create a filesystem. +# 2. Create sub filesystem and make file in it. +# 3. Set reservation of the sub filesystem. +# 4. Create volume under it. +# 5. Snapshot it. +# 6. Check usedbychildren is correct. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-28) +# +# __stc_assertion_end +# +################################################################################ + +if ! usedby_supported ; then + log_unsupported "snapused property is not supported." +fi + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rR $USEDTEST +} + +log_assert "Verify usedbychildren is correct." +log_onexit cleanup + +log_must $ZFS create $USEDTEST +check_usedbychildren $USEDTEST + +typeset -i i=0 +typeset -i r_size=0 +mntpnt=$(get_prop mountpoint $USEDTEST) +while (( i < 5 )); do + ((r_size=(i+1)*16)) + + log_must $ZFS create $USEDTEST/fs$i + log_must $ZFS set reservation="$r_size"M $USEDTEST/fs$i + log_must $MKFILE 48M $mntpnt/fs$i/file$i + + if is_global_zone; then + log_must $ZFS create -V 32M $USEDTEST/vol$i + fi + + log_must $ZFS snapshot -r $USEDTEST@snap$i + + check_usedbychildren $USEDTEST + + ((i = i + 1)) +done + +log_pass "Verify usedbychildren is correct." + diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused_003_pos.ksh b/tests/sys/cddl/zfs/tests/snapused/snapused_003_pos.ksh new file mode 100644 index 00000000000..2873151eb46 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused_003_pos.ksh @@ -0,0 +1,101 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapused_003_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/snapused/snapused.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapused_003_pos +# +# DESCRIPTION: +# Verify usedbydataset is correct. +# +# STRATEGY: +# 1. Create a filesystem. +# 2. Make file in the filesystem. +# 3. Snapshot it. +# 4. Clone it and make file in the cloned filesystem. +# 5. Check usedbydataset is correct. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-28) +# +# __stc_assertion_end +# +################################################################################ + +if ! usedby_supported ; then + log_unsupported "snapused property is not supported." +fi + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rR $USEDTEST +} + +log_assert "Verify usedbydataset is correct." +log_onexit cleanup + +log_must $ZFS create $USEDTEST +check_usedbydataset $USEDTEST + +typeset -i i=0 +typeset -i r_size=0 +mntpnt=$(get_prop mountpoint $USEDTEST) +while (( i < 5 )); do + ((r_size=(i+1)*16)) + + log_must $MKFILE 16M $mntpnt/file$i + log_must $MKFILE "$r_size"M $mntpnt/file_var$i + log_must $ZFS snapshot -r $USEDTEST@snap$i + + log_must $ZFS clone $USEDTEST@snap$i $USEDTEST/cln$i + log_must $ZFS set is:cloned=yes $USEDTEST/cln$i + + mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i) + log_must $MKFILE 16M $mntpnt_cln/file_cln$i + log_must $MKFILE "$r_size"M $mntpnt_cln/file_cln_var$i + + check_usedbydataset $USEDTEST + + ((i = i + 1)) +done + +log_pass "Verify usedbydataset is correct." + diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused_004_pos.ksh b/tests/sys/cddl/zfs/tests/snapused/snapused_004_pos.ksh new file mode 100644 index 00000000000..7a6cbe38f8a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused_004_pos.ksh @@ -0,0 +1,114 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapused_004_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/snapused/snapused.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapused_004_pos +# +# DESCRIPTION: +# Verify usedbyrefreservation is correct. +# +# STRATEGY: +# 1. Create a filesystem. +# 2. Set refreservation of the filesystem. +# 3. Make file in the filesystem. +# 4. Create sub filesystem and make file in it. +# 5. Set refreservation of the sub filesystem. +# 6. Create volume under it. +# 7. Snapshot it. +# 8. Clone it and set refreservation of the cloned filesystem. +# 9. Makefile the cloned filesystem. +# 10. Check usedbyrefreservation is correct. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-28) +# +# __stc_assertion_end +# +################################################################################ + +if ! usedby_supported ; then + log_unsupported "snapused property is not supported." +fi + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rR $USEDTEST +} + +log_assert "Verify usedbyrefreservation is correct." +log_onexit cleanup + +log_must $ZFS create $USEDTEST +check_usedbyrefreservation $USEDTEST + +typeset -i i=0 +typeset -i r_size=0 +mntpnt=$(get_prop mountpoint $USEDTEST) +while (( i < 5 )); do + ((r_size=(i+1)*16)) + log_must $ZFS set refreservation="$r_size"M $USEDTEST + + log_must $MKFILE 16M $mntpnt/file$i + + log_must $ZFS create $USEDTEST/fs$i + log_must $ZFS set refreservation="$r_size"M $USEDTEST/fs$i + log_must $MKFILE 16M $mntpnt/fs$i/file$i + + if is_global_zone; then + log_must $ZFS create -V 16M $USEDTEST/vol$i + fi + + log_must $ZFS snapshot -r $USEDTEST@snap$i + + log_must $ZFS clone $USEDTEST@snap$i $USEDTEST/cln$i + + mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i) + log_must $ZFS set refreservation="$r_size"M $USEDTEST/cln$i + log_must $MKFILE 16M $mntpnt_cln/file_cln$i + + check_usedbyrefreservation $USEDTEST + + ((i = i + 1)) +done + +log_pass "Verify usedbyrefreservation is correct." + diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused_005_pos.ksh b/tests/sys/cddl/zfs/tests/snapused/snapused_005_pos.ksh new file mode 100644 index 00000000000..0a767b43d23 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused_005_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)snapused_005_pos.ksh 1.1 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/snapused/snapused.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: snapused_005_pos +# +# DESCRIPTION: +# Verify usedbysnapshots is correct. +# +# STRATEGY: +# 1. Create a filesystem. +# 2. Make file in the filesystem. +# 3. Snapshot it. +# 4. Check check_usedbysnapshots is correct. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2009-04-28) +# +# __stc_assertion_end +# +################################################################################ + +if ! usedby_supported ; then + log_unsupported "snapused property is not supported." +fi + +verify_runnable "both" + +function cleanup +{ + log_must $ZFS destroy -rR $USEDTEST +} + +log_assert "Verify usedbysnapshots is correct." +log_onexit cleanup + +log_must $ZFS create $USEDTEST +check_usedbysnapshots $USEDTEST + +typeset -i i=0 +typeset -i r_size=0 +mntpnt=$(get_prop mountpoint $USEDTEST) +while (( i < 5 )); do + ((r_size=(i+1)*16)) + + log_must $MKFILE "$r_size"M $mntpnt/file$i + + log_must $ZFS snapshot $USEDTEST@snap$i + check_usedbysnapshots $USEDTEST + + ((i = i + 1)) +done + +log_pass "Verify usedbysnapshots is correct." + diff --git a/tests/sys/cddl/zfs/tests/snapused/snapused_test.sh b/tests/sys/cddl/zfs/tests/snapused/snapused_test.sh new file mode 100755 index 00000000000..c13c11110e0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/snapused/snapused_test.sh @@ -0,0 +1,167 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case snapused_001_pos cleanup +snapused_001_pos_head() +{ + atf_set "descr" "Verify used is correct." + atf_set "require.progs" zfs +} +snapused_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapused_001_pos.ksh || atf_fail "Testcase failed" +} +snapused_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapused_002_pos cleanup +snapused_002_pos_head() +{ + atf_set "descr" "Verify usedbychildren is correct." + atf_set "require.progs" zfs +} +snapused_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapused_002_pos.ksh || atf_fail "Testcase failed" +} +snapused_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapused_003_pos cleanup +snapused_003_pos_head() +{ + atf_set "descr" "Verify usedbydataset is correct." + atf_set "require.progs" zfs +} +snapused_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapused_003_pos.ksh || atf_fail "Testcase failed" +} +snapused_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapused_004_pos cleanup +snapused_004_pos_head() +{ + atf_set "descr" "Verify usedbyrefreservation is correct." + atf_set "require.progs" zfs +} +snapused_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapused_004_pos.ksh || atf_fail "Testcase failed" +} +snapused_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case snapused_005_pos cleanup +snapused_005_pos_head() +{ + atf_set "descr" "Verify usedbysnapshots is correct." + atf_set "require.progs" zfs +} +snapused_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/snapused_005_pos.ksh || atf_fail "Testcase failed" +} +snapused_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/snapused.kshlib + . $(atf_get_srcdir)/snapused.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case snapused_001_pos + atf_add_test_case snapused_002_pos + atf_add_test_case snapused_003_pos + atf_add_test_case snapused_004_pos + atf_add_test_case snapused_005_pos +} diff --git a/tests/sys/cddl/zfs/tests/sparse/Makefile b/tests/sys/cddl/zfs/tests/sparse/Makefile new file mode 100644 index 00000000000..73647f2c95a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/sparse/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/sparse +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= sparse_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= sparse_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= sparse.cfg +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/sparse/cleanup.ksh b/tests/sys/cddl/zfs/tests/sparse/cleanup.ksh new file mode 100644 index 00000000000..26ce7c30a0b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/sparse/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/sparse/setup.ksh b/tests/sys/cddl/zfs/tests/sparse/setup.ksh new file mode 100644 index 00000000000..00289583e38 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/sparse/setup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + + +disk=${DISKS%% *} + +default_setup $disk diff --git a/tests/sys/cddl/zfs/tests/sparse/sparse.cfg b/tests/sys/cddl/zfs/tests/sparse/sparse.cfg new file mode 100644 index 00000000000..d44d0e6130b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/sparse/sparse.cfg @@ -0,0 +1,38 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)sparse.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE=testfile.${TESTCASE_ID} +export HOLES_FILESIZE=${HOLES_FILESIZE-"67108864"} # 64 Mb +export HOLES_BLKSIZE=${HOLES_BLKSIZE-"512"} +export HOLES_SEED=${HOLES_SEED-""} +export HOLES_FILEOFFSET=${HOLES_FILEOFFSET-""} +export HOLES_COUNT=${HOLES_COUNT-"16384"} # FILESIZE/BLKSIZE/8 +export STF_TIMEOUT=3600 diff --git a/tests/sys/cddl/zfs/tests/sparse/sparse_001_pos.ksh b/tests/sys/cddl/zfs/tests/sparse/sparse_001_pos.ksh new file mode 100644 index 00000000000..756570ea5c8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/sparse/sparse_001_pos.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)sparse_001_pos.ksh 1.3 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: sparse_001_pos +# +# DESCRIPTION: +# Holes in ZFS files work correctly. +# +# STRATEGY: +# 1. Open file +# 2. Write random blocks in random places +# 3. Read each block back to check for correctness. +# 4. Repeat steps 2 and 3 lots of times +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Ensure random blocks are read back correctly" + +options="" +options_display="default options" + +log_onexit cleanup + +[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " + +[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " + +[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " + +[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " + +[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " + +options="$options -r " + +[[ -n "$options" ]] && options_display=$options + +log_note "Invoking $FILE_TRUNC with: $options_display" +log_must $FILE_TRUNC $options $TESTDIR/$TESTFILE + +typeset dir=$(get_device_dir $DISKS) +verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir" + +log_pass "Random blocks have been read back correctly." diff --git a/tests/sys/cddl/zfs/tests/sparse/sparse_test.sh b/tests/sys/cddl/zfs/tests/sparse/sparse_test.sh new file mode 100755 index 00000000000..3470d1988a4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/sparse/sparse_test.sh @@ -0,0 +1,58 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case sparse_001_pos cleanup +sparse_001_pos_head() +{ + atf_set "descr" "Ensure random blocks are read back correctly" + atf_set "require.progs" zdb + atf_set "timeout" 3600 +} +sparse_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/sparse.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/sparse_001_pos.ksh || atf_fail "Testcase failed" +} +sparse_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/sparse.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case sparse_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/threadsappend/Makefile b/tests/sys/cddl/zfs/tests/threadsappend/Makefile new file mode 100644 index 00000000000..b09941dca50 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/threadsappend/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/threadsappend +FILESDIR=${TESTSDIR} +BINDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= threadsappend_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= threadsappend_001_pos.ksh +${PACKAGE}FILES+= threadsappend.cfg +${PACKAGE}FILES+= setup.ksh +PROG+= threadsappend +LIBADD+= pthread +MAN= + +.include diff --git a/tests/sys/cddl/zfs/tests/threadsappend/cleanup.ksh b/tests/sys/cddl/zfs/tests/threadsappend/cleanup.ksh new file mode 100644 index 00000000000..26ce7c30a0b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/threadsappend/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/threadsappend/setup.ksh b/tests/sys/cddl/zfs/tests/threadsappend/setup.ksh new file mode 100644 index 00000000000..805b20ce374 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/threadsappend/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup ${DISK} diff --git a/tests/sys/cddl/zfs/tests/threadsappend/threadsappend.c b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend.c new file mode 100644 index 00000000000..bd264cd66c5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend.c @@ -0,0 +1,135 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "@(#)threadsappend.c 1.3 07/05/25 SMI" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * The size of the output file, "go.out", should be 80*8192*2 = 1310720 + * + * $ cd /tmp; go; ls -l go.out + * done. + * -rwxr-xr-x 1 jdm staff 1310720 Apr 13 19:45 go.out + * $ cd /zfs; go; ls -l go.out + * done. + * -rwxr-xr-x 1 jdm staff 663552 Apr 13 19:45 go.out + * + * The file on zfs is short as it does not appear that zfs is making the + * implicit seek to EOF and the actual write atomic. From the SUSv3 + * interface spec, behavior is undefined if concurrent writes are performed + * from multi-processes to a single file. So I don't know if this is a + * standards violation, but I cannot find any such disclaimers in our + * man pages. This issue came up at a customer site in another context, and + * the suggestion was to open the file with O_APPEND, but that wouldn't + * help with zfs(see 4977529). Also see bug# 5031301. + */ + +static int outfd = 0; + +static void * +go(void *data) +{ + int i = 0, n = *(int *)data; + ssize_t ret = 0; + char buf[8192] = {0}; + (void) memset(buf, n, sizeof (buf)); + + for (i = 0; i < 80; i++) { + ret = write(outfd, buf, sizeof (buf)); + } + return (NULL); +} + +static void +usage() +{ + (void) fprintf(stderr, + "usage: zfs_threadsappend \n"); + exit(1); +} + +int +main(int argc, char **argv) +{ + pthread_t threads[2]; + int ret = 0; + long ncpus = 0; + int i; + + if (argc != 2) { + usage(); + } + + ncpus = sysconf(_SC_NPROCESSORS_ONLN); + if (ncpus < 0) { + (void) fprintf(stderr, + "Invalid return from sysconf(_SC_NPROCESSORS_ONLN)" + " : errno (decimal)=%d\n", errno); + exit(1); + } + if (ncpus < 2) { + (void) fprintf(stderr, + "Must execute this binary on a multi-processor system\n"); + exit(1); + } + + outfd = open(argv[optind++], O_RDWR|O_CREAT|O_APPEND|O_TRUNC, 0777); + if (outfd == -1) { + (void) fprintf(stderr, + "zfs_threadsappend: " + "open(%s, O_RDWR|O_CREAT|O_APPEND|O_TRUNC, 0777)" + " failed\n", argv[optind]); + perror("open"); + exit(1); + } + + for (i = 0; i < 2; i++) { + ret = pthread_create(&threads[i], NULL, go, (void *)&i); + if (ret != 0) { + (void) fprintf(stderr, + "zfs_threadsappend: thr_create(#%d) " + "failed error=%d\n", i+1, ret); + exit(1); + } + } + + for (i = 0; i < 2; i++) { + if (pthread_join(threads[i], NULL) != 0) + break; + } + + return (0); +} diff --git a/tests/sys/cddl/zfs/tests/threadsappend/threadsappend.cfg b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend.cfg new file mode 100644 index 00000000000..f679406f033 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)threadsappend.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE=testfile${TESTCASE_ID} diff --git a/tests/sys/cddl/zfs/tests/threadsappend/threadsappend_001_pos.ksh b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend_001_pos.ksh new file mode 100644 index 00000000000..16fd8191981 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend_001_pos.ksh @@ -0,0 +1,95 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)threadsappend_001_pos.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: threadsappend_001_pos +# +# DESCRIPTION: +# +# Ensure multiple threads performing write appends to the same ZFS +# file succeed. +# +# STRATEGY: +# 1) Verify this is a multi-processor system +# 2) Create multiple threads with each appending to a file +# 3) Verify that the resulting file is the expected size +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +log_assert "Ensure multiple threads performing write appends to the same" \ + "ZFS file succeed" + +# +# $FILE_SIZE is hardcoded into threadsappend.c and is the expected +# size of the file after all the threads have appended to it +# +typeset -i FILE_SIZE=1310720 + +# +# This test should be run on a multi-processor system because otherwise the FS +# will not be concurrently used by the threads +# +NCPUS=`sysctl -a | awk -F '"' '/cpu count="[0-9+]"/ {print $2; exit}'` +if [[ $? -ne 0 || -z $NCPUS || $NCPUS -le 1 ]]; then + log_unsupported \ + "This test should be executed on a multi-processor system." +fi + +# +# zfs_threadsappend tries to append to $TESTFILE using threads +# so that the resulting file is $FILE_SIZE bytes in size +# +log_must threadsappend ${TESTDIR}/${TESTFILE} + +# +# Check the size of the resulting file +# +SIZE=`$LS -l ${TESTDIR}/${TESTFILE} | $AWK '{print $5}'` +if [[ $SIZE -ne $FILE_SIZE ]]; then + log_fail "'The length of ${TESTDIR}/${TESTFILE}' doesnt equal 1310720." +fi + +log_pass "Multiple thread appends succeeded. File size as expected" diff --git a/tests/sys/cddl/zfs/tests/threadsappend/threadsappend_test.sh b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend_test.sh new file mode 100755 index 00000000000..e8a02094101 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/threadsappend/threadsappend_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case threadsappend_001_pos cleanup +threadsappend_001_pos_head() +{ + atf_set "descr" "Ensure multiple threads performing write appends to the sameZFS file succeed" +} +threadsappend_001_pos_body() +{ + export PATH=$(atf_get_srcdir):$PATH + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/threadsappend.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/threadsappend_001_pos.ksh || atf_fail "Testcase failed" +} +threadsappend_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/threadsappend.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case threadsappend_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/truncate/Makefile b/tests/sys/cddl/zfs/tests/truncate/Makefile new file mode 100644 index 00000000000..110abddbbbc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/truncate/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/truncate +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= truncate_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= truncate_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= truncate_002_pos.ksh +${PACKAGE}FILES+= truncate.cfg + +.include diff --git a/tests/sys/cddl/zfs/tests/truncate/cleanup.ksh b/tests/sys/cddl/zfs/tests/truncate/cleanup.ksh new file mode 100644 index 00000000000..26ce7c30a0b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/truncate/cleanup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/truncate/setup.ksh b/tests/sys/cddl/zfs/tests/truncate/setup.ksh new file mode 100644 index 00000000000..0108551c107 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/truncate/setup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +disk=${DISKS%% *} + +default_setup $disk diff --git a/tests/sys/cddl/zfs/tests/truncate/truncate.cfg b/tests/sys/cddl/zfs/tests/truncate/truncate.cfg new file mode 100644 index 00000000000..ed1c6ffa89c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/truncate/truncate.cfg @@ -0,0 +1,38 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)truncate.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE=testfile.${TESTCASE_ID} +export TRUNC_FILESIZE=${TRUNC_FILESIZE-"67108864"} # 64 Mb +export TRUNC_BLKSIZE=${TRUNC_BLKSIZE-"512"} +export TRUNC_SEED=${TRUNC_SEED-""} +export TRUNC_FILEOFFSET=${TRUNC_FILEOFFSET-""} +export TRUNC_COUNT=${TRUNC_COUNT-"16384"} # FILESIZE/BLKSIZE/8 +export STF_TIMEOUT=3600 diff --git a/tests/sys/cddl/zfs/tests/truncate/truncate_001_pos.ksh b/tests/sys/cddl/zfs/tests/truncate/truncate_001_pos.ksh new file mode 100644 index 00000000000..453c622bc1a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/truncate/truncate_001_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)truncate_001_pos.ksh 1.3 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: truncate_001_pos +# +# DESCRIPTION: +# Tests file truncation within ZFS. +# +# STRATEGY: +# 1. Open file +# 2. Write random blocks in random places +# 3. Truncate the file +# 4. Repeat steps 2 and 3 lots of times +# 5. Close the file. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/* +} + +log_assert "Ensure file with random blocks is truncated properly" + +options="" +options_display="default options" + +log_onexit cleanup + +[[ -n "$TRUNC_FILESIZE" ]] && options=" $options -f $TRUNC_FILESIZE " + +[[ -n "$TRUNC_BLKSIZE" ]] && options="$options -b $TRUNC_BLKSIZE " + +[[ -n "$TRUNC_COUNT" ]] && options="$options -c $TRUNC_COUNT " + +[[ -n "$TRUNC_SEED" ]] && options="$options -s $TRUNC_SEED " + +[[ -n "$TRUNC_FILEOFFSET" ]] && options="$options -o $TRUNC_FILEOFFSET " + +[[ -n "$options" ]] && options_display=$options + +log_note "Invoking $FILE_TRUNC with: $options_display" +log_must $FILE_TRUNC $options $TESTDIR/$TESTFILE + +typeset dir=$(get_device_dir $DISKS) +verify_filesys "$TESTPOOL" "$TESTPOOL/$TESTFS" "$dir" + +log_pass "Random blocks have been truncated properly." diff --git a/tests/sys/cddl/zfs/tests/truncate/truncate_002_pos.ksh b/tests/sys/cddl/zfs/tests/truncate/truncate_002_pos.ksh new file mode 100644 index 00000000000..9b96941200b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/truncate/truncate_002_pos.ksh @@ -0,0 +1,80 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)truncate_002_pos.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: truncate_002_pos +# +# DESCRIPTION: +# Tests file truncation within ZFS while a sync operation is in progress. +# +# STRATEGY: +# 1. Copy a file to ZFS filesystem +# 2. Copy /dev/null to same file on ZFS filesystem +# 3. Execute a sync command +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + [[ -e $TESTDIR ]] && log_must $RM -rf ${TESTDIR}/* +} + +log_assert "Ensure zeroed file gets written correctly during a sync operation" + +srcfilename="$STF_SUITE/include/libtest.kshlib" + +log_onexit cleanup + +log_note "Copying $srcfilename to $TESTFILE" +log_must $CP $srcfilename ${TESTDIR}/${TESTFILE} + +log_note "Copying /dev/null to $TESTFILE" +log_must $CP /dev/null ${TESTDIR}/${TESTFILE} + +log_note "Now 'sync' the filesystem" +(cd $TESTDIR; log_must $SYNC) + +log_pass "Successful truncation within ZFS while a sync operation is in progress." diff --git a/tests/sys/cddl/zfs/tests/truncate/truncate_test.sh b/tests/sys/cddl/zfs/tests/truncate/truncate_test.sh new file mode 100755 index 00000000000..3c50b0cdd6e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/truncate/truncate_test.sh @@ -0,0 +1,83 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case truncate_001_pos cleanup +truncate_001_pos_head() +{ + atf_set "descr" "Ensure file with random blocks is truncated properly" + atf_set "require.progs" zdb + atf_set "timeout" 3600 +} +truncate_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/truncate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/truncate_001_pos.ksh || atf_fail "Testcase failed" +} +truncate_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/truncate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case truncate_002_pos cleanup +truncate_002_pos_head() +{ + atf_set "descr" "Ensure zeroed file gets written correctly during a sync operation" + atf_set "timeout" 3600 +} +truncate_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/truncate.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/truncate_002_pos.ksh || atf_fail "Testcase failed" +} +truncate_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/truncate.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case truncate_001_pos + atf_add_test_case truncate_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/Makefile b/tests/sys/cddl/zfs/tests/txg_integrity/Makefile new file mode 100644 index 00000000000..a992db93b25 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/Makefile @@ -0,0 +1,26 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/txg_integrity +FILESDIR=${TESTSDIR} +BINDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= txg_integrity_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= txg_integrity_001_pos.ksh +${PACKAGE}FILES+= fsync_integrity_001_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= txg_integrity.cfg +PROGS+= txg_integrity +PROGS+= fsync_integrity +LIBADD+= pthread + +SRCS.fsync_integrity= fsync_integrity.c +SRCS.txg_integrity= txg_integrity.c + +.include diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/cleanup.ksh b/tests/sys/cddl/zfs/tests/txg_integrity/cleanup.ksh new file mode 100644 index 00000000000..5f0282b2035 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/cleanup.ksh @@ -0,0 +1,36 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2011 Spectra logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.0 10/20/11 SL" +# + +. ${STF_SUITE}/include/libtest.kshlib + +destroy_pool $TESTPOOL +$RM -rf $TESTDIR +$MDCONFIG -d -u $TESTCASE_ID diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/fsync_integrity.c b/tests/sys/cddl/zfs/tests/txg_integrity/fsync_integrity.c new file mode 100644 index 00000000000..0daba26579d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/fsync_integrity.c @@ -0,0 +1,517 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2013 Spectra Logic. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Verify the integrity of non-aligned writes to the same blocks within the same + * transaction group, where an fsync is issued by a non-final writer. + * + * This test verifies that the unoverride in the following sequence of events is + * handled correctly: + * + * 1) A new transaction group opens + * 2) A write is issued to a certain block + * 3) The writer fsyncs() that file + * 4) TBD module immediately writes that block, then places an override in the + * syncer's TBD data structure, indicating that it doesn't need to write that + * block when syncing. + * 5) Another write is issued to the same block, with different data. + * 6) TBD module unoverrides that block in the syncer's TBD data structure + * 7) The syncer writes that block + * + * Outline: + * Create a big zero-filled file. + * Create a bunch of different IO patterns. Each IO pattern consists of: + * * A partition of the file range into 64 different non-overlapping chunks. + * * A permutation of those chunks + * For each repetition: + * For each IO pattern: + * Create one binary semaphore per chunk, per (n-1) threads + * Create n threads. + * The first thread will write each chunk in order. It will post a + * semaphore after each write to indicate that it has completed + * writing that chunk. + * The second thread will pend on those semaphores in order. Each time it + * receives a semaphore, it will write a different pattern to that + * chunk. Then it will post a different semaphore to signal the next + * thread. + * The final thread will not post any semaphores + * Every even-numbered thread, starting with the first (0th), will fsync() + * the file after its write. The final thread, being odd-numbered, + * won't. + * Join all threads + * Read the entire file and verify that + * 1) Every write went to the correct location + * 2) The final thread's write is left in the file + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NUM_REPETITIONS 16 +#define CLUSTERSIZE (1 << 17) +#define NUM_CHUNKS 64 +#define FSIZE (64 * (CLUSTERSIZE)) //FSIZE may range from NUM_CHUNKS clusters to 8GB +#define USE_THREADS 1 +#define NUM_THREADS 8 + +typedef struct { + //partitions describes the boundaries between chunks. Each element is a + //fraction of the filesize in 1.31 fixed point format. So the boundary + //between chunk n and chunk n-1 is (FSIZE * partitions[n-1] / (1<<31) . + //partitions[-1] is understood to be 0 and partitions[NUM_CHUNKS] must be 1.0 + //partitions is sorted, of course. + //Partition boundaries must be dword aligned. Thus, in order to work with + //multiple values of FSIZE, partitions values must be aligned to multiples of + //8 / (NUM_CHUNKS * CLUSTERSIZE) = 1 / 524288 = 0x0.00002 + uint32_t partitions[NUM_CHUNKS]; + int permutation[NUM_CHUNKS]; //the order in which to write the chunks +} pattern_t; + +typedef struct { + int thread_num; + pattern_t* pat; +} thread_data_t; + + +/* Returns (via begin and end) the range of a chunk. Begin is inclusive, + * end is exclusive */ +void get_chunk_range(const pattern_t* pat, int chunk, uint32_t* begin, uint32_t* end){ + if (chunk == 0){ + *begin = 0; + } + else{ + *begin = (uint32_t)((uint64_t)FSIZE * (uint64_t)pat->partitions[chunk - 1] >> 31); + } + *end = (uint32_t)((uint64_t)FSIZE * (uint64_t)pat->partitions[chunk] >> 31); +} + + +/* The most basic, trivial IO pattern. Fully sequential, and the follower + * writes every other block */ +const pattern_t trivial_pattern = { + {0x2000000, 0x4000000, 0x6000000, 0x8000000, 0xa000000, 0xc000000, 0xe000000, 0x10000000, + 0x12000000, 0x14000000, 0x16000000, 0x18000000, 0x1a000000, 0x1c000000, 0x1e000000, 0x20000000, + 0x22000000, 0x24000000, 0x26000000, 0x28000000, 0x2a000000, 0x2c000000, 0x2e000000, 0x30000000, + 0x32000000, 0x34000000, 0x36000000, 0x38000000, 0x3a000000, 0x3c000000, 0x3e000000, 0x40000000, + 0x42000000, 0x44000000, 0x46000000, 0x48000000, 0x4a000000, 0x4c000000, 0x4e000000, 0x50000000, + 0x52000000, 0x54000000, 0x56000000, 0x58000000, 0x5a000000, 0x5c000000, 0x5e000000, 0x60000000, + 0x62000000, 0x64000000, 0x66000000, 0x68000000, 0x6a000000, 0x6c000000, 0x6e000000, 0x70000000, + 0x72000000, 0x74000000, 0x76000000, 0x78000000, 0x7a000000, 0x7c000000, 0x7e000000, 0x80000000}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}, +}; + +//The below patterns were randomly generated +const pattern_t pat0 = { + { 0x1eac000, 0x88a4000, 0xaffe000, 0xcdb7000, 0xd2d5000, 0xe16f000, 0xe499000, 0x11f71000, 0x1242d000, 0x12c07000, 0x143bc000, 0x1460a000, 0x15dd7000, 0x1700e000, 0x1be7e000, 0x1e14d000, 0x1e6ac000, 0x21097000, 0x24b74000, 0x27166000, 0x27669000, 0x30539000, 0x3218b000, 0x37591000, 0x37b60000, 0x39818000, 0x39d08000, 0x3c90e000, 0x3e54f000, 0x3fb99000, 0x42c8e000, 0x43a62000, 0x43f50000, 0x4c0c9000, 0x4c422000, 0x4c737000, 0x4d41e000, 0x4d738000, 0x4da71000, 0x4f4e8000, 0x508e3000, 0x51396000, 0x51ab5000, 0x52a02000, 0x54238000, 0x54d6a000, 0x55029000, 0x5584b000, 0x5c42c000, 0x5c4a7000, 0x5dac5000, 0x5fe4d000, 0x63f86000, 0x66ad0000, 0x67b3d000, 0x69ce5000, 0x6c179000, 0x6e79e000, 0x6f83f000, 0x71165000, 0x72bd9000, 0x7ac79000, 0x7dc94000, 0x80000000, }, + { 57, 16, 28, 25, 10, 59, 52, 46, 30, 6, 40, 36, 39, 9, 21, 51, 33, 45, 44, 19, 2, 50, 55, 5, 58, 13, 23, 0, 12, 53, 42, 32, 31, 48, 35, 61, 49, 54, 18, 24, 8, 41, 62, 4, 47, 17, 1, 3, 34, 14, 63, 22, 15, 26, 38, 56, 27, 60, 29, 11, 7, 43, 20, 37, }, +}; +const pattern_t pat1 = { + { 0x2b5000, 0x16db000, 0x5eb5000, 0x93a0000, 0xa7cb000, 0xa9e9000, 0xd144000, 0xe7c2000, 0xeb7d000, 0x10919000, 0x10cbd000, 0x11f85000, 0x17360000, 0x1760a000, 0x18eab000, 0x1ae6b000, 0x1c5f6000, 0x1df38000, 0x21bec000, 0x239d1000, 0x26b81000, 0x2747b000, 0x27a03000, 0x2b3cc000, 0x2cbf9000, 0x2ec0f000, 0x30a68000, 0x30bea000, 0x30c64000, 0x311af000, 0x35823000, 0x35d23000, 0x3b20e000, 0x405d8000, 0x414c8000, 0x43a91000, 0x44049000, 0x4ab4e000, 0x4ae21000, 0x4d293000, 0x511e5000, 0x516fc000, 0x52d77000, 0x57229000, 0x5da57000, 0x5dbe6000, 0x6070e000, 0x60fc0000, 0x64b24000, 0x67636000, 0x67658000, 0x6b040000, 0x6b28f000, 0x6e551000, 0x707c0000, 0x71b5c000, 0x72062000, 0x762a1000, 0x788a0000, 0x7a1e1000, 0x7b06a000, 0x7e04c000, 0x7f4cf000, 0x80000000, }, + { 45, 8, 55, 9, 21, 54, 41, 7, 6, 22, 31, 47, 23, 11, 48, 53, 0, 61, 63, 50, 17, 27, 12, 19, 10, 40, 14, 51, 39, 59, 2, 43, 18, 42, 52, 28, 16, 44, 3, 5, 15, 35, 58, 33, 57, 49, 34, 30, 46, 4, 37, 60, 32, 36, 25, 56, 24, 13, 20, 38, 29, 26, 62, 1, }, +}; +const pattern_t pat2 = { + { 0x912d000, 0xe610000, 0xf755000, 0x116df000, 0x128e5000, 0x1bd51000, 0x24e9a000, 0x27643000, 0x28cf4000, 0x292c9000, 0x2c907000, 0x2d389000, 0x2d941000, 0x2eb3f000, 0x30e94000, 0x31738000, 0x3343b000, 0x342ce000, 0x34d12000, 0x3536d000, 0x35e1a000, 0x35e4d000, 0x35fd5000, 0x3642b000, 0x3924d000, 0x392a5000, 0x3e531000, 0x3f0ee000, 0x3fdf8000, 0x41593000, 0x41c80000, 0x43959000, 0x43bc0000, 0x461c8000, 0x48922000, 0x49519000, 0x4f6fa000, 0x50274000, 0x508ae000, 0x536ed000, 0x54154000, 0x59894000, 0x5a666000, 0x5b0a6000, 0x5b9ff000, 0x5c109000, 0x5d8d0000, 0x5ddc5000, 0x5fcc5000, 0x63366000, 0x63adc000, 0x645b6000, 0x670eb000, 0x6b1b1000, 0x6c996000, 0x6ed2a000, 0x6ee4f000, 0x71fcd000, 0x734a3000, 0x76bdf000, 0x77b3f000, 0x7c65a000, 0x7d200000, 0x80000000, }, + { 31, 35, 36, 52, 27, 56, 40, 13, 51, 49, 43, 37, 62, 42, 24, 29, 48, 25, 7, 61, 22, 57, 11, 32, 2, 54, 41, 6, 55, 15, 20, 26, 63, 44, 12, 4, 19, 58, 60, 59, 47, 23, 30, 50, 53, 34, 9, 38, 45, 8, 28, 3, 16, 33, 5, 21, 1, 10, 46, 18, 0, 14, 39, 17, }, +}; +const pattern_t pat3 = { + { 0x553000, 0x19de000, 0x6a20000, 0x8a53000, 0x8ef9000, 0xc325000, 0x1132e000, 0x139fa000, 0x1426b000, 0x150ff000, 0x1bbc1000, 0x1e84c000, 0x1f43e000, 0x1f731000, 0x21ec8000, 0x231f4000, 0x23440000, 0x23466000, 0x260b6000, 0x286a7000, 0x29518000, 0x29e35000, 0x2fdb7000, 0x3089d000, 0x362e0000, 0x3c1f9000, 0x3df2d000, 0x3fce6000, 0x402f3000, 0x4117f000, 0x41e06000, 0x4374f000, 0x451e5000, 0x45a59000, 0x4956b000, 0x4960f000, 0x4a934000, 0x4bc6f000, 0x4d462000, 0x4eef8000, 0x4f609000, 0x50dc1000, 0x51022000, 0x54396000, 0x5641b000, 0x578f1000, 0x589cf000, 0x59093000, 0x5da6b000, 0x5fbf0000, 0x605a2000, 0x65428000, 0x65530000, 0x6705a000, 0x6db65000, 0x71cef000, 0x725a2000, 0x73bf5000, 0x75acb000, 0x76065000, 0x7614c000, 0x77aab000, 0x78f70000, 0x80000000, }, + { 15, 30, 31, 16, 49, 13, 55, 59, 4, 24, 26, 44, 17, 0, 18, 54, 10, 3, 46, 34, 29, 22, 45, 5, 38, 32, 39, 50, 48, 53, 12, 25, 35, 56, 51, 52, 1, 33, 43, 63, 47, 37, 23, 20, 60, 14, 11, 21, 8, 57, 27, 41, 6, 58, 62, 2, 19, 61, 28, 36, 40, 7, 9, 42, }, +}; +const pattern_t pat4 = { + { 0x425000, 0x8e8000, 0x4b90000, 0x883c000, 0x968e000, 0xbacc000, 0x10e59000, 0x125a1000, 0x12f00000, 0x14e7c000, 0x156de000, 0x192a1000, 0x1a2b9000, 0x1b4a0000, 0x1be9c000, 0x1d3bd000, 0x24242000, 0x2516b000, 0x2b88d000, 0x2b96a000, 0x2bcd3000, 0x2c5a9000, 0x2da74000, 0x2dba1000, 0x3097f000, 0x332ef000, 0x34525000, 0x36193000, 0x3725c000, 0x37e66000, 0x3d315000, 0x3e813000, 0x404ae000, 0x40c68000, 0x42f93000, 0x44b14000, 0x44b15000, 0x473b2000, 0x49048000, 0x4c794000, 0x50b60000, 0x52b3d000, 0x58c61000, 0x5b7d4000, 0x5ce71000, 0x5d21d000, 0x5d63e000, 0x5e00f000, 0x60e8b000, 0x66381000, 0x66c70000, 0x68430000, 0x707c2000, 0x71979000, 0x72681000, 0x74017000, 0x7721d000, 0x7a1be000, 0x7a2cd000, 0x7b225000, 0x7c311000, 0x7e03a000, 0x7e402000, 0x80000000, }, + { 52, 62, 28, 47, 51, 37, 31, 36, 4, 58, 26, 29, 16, 59, 57, 33, 22, 27, 49, 44, 19, 56, 34, 23, 5, 14, 45, 48, 21, 25, 18, 12, 43, 53, 60, 17, 46, 15, 63, 30, 42, 38, 41, 8, 39, 20, 1, 10, 54, 40, 32, 24, 9, 2, 35, 3, 7, 0, 61, 11, 13, 55, 6, 50, }, +}; +const pattern_t pat5 = { + { 0xae7000, 0x436e000, 0x81e1000, 0xb276000, 0xf8bf000, 0xfb26000, 0xfe7e000, 0x137ad000, 0x14b8e000, 0x157aa000, 0x1981a000, 0x1a32f000, 0x1bc9e000, 0x1def5000, 0x1e8ef000, 0x2068f000, 0x22692000, 0x22a6c000, 0x255bf000, 0x26977000, 0x27619000, 0x2977c000, 0x2ce0c000, 0x2e1ec000, 0x2e26c000, 0x31ce8000, 0x34e6c000, 0x365cd000, 0x37e87000, 0x385e3000, 0x3a7e2000, 0x3a9c7000, 0x41597000, 0x42e8a000, 0x453cc000, 0x454bf000, 0x4b24c000, 0x4ba54000, 0x4e307000, 0x4f059000, 0x55d5a000, 0x56277000, 0x56b90000, 0x5882d000, 0x5a2c5000, 0x5b369000, 0x5d442000, 0x5d671000, 0x5fdd0000, 0x60ce0000, 0x63713000, 0x64130000, 0x65973000, 0x67ad9000, 0x68764000, 0x68bb2000, 0x690d1000, 0x6a2c8000, 0x73e9f000, 0x74e75000, 0x77861000, 0x77ee5000, 0x7cddb000, 0x80000000, }, + { 42, 25, 15, 58, 32, 61, 30, 56, 48, 62, 38, 50, 7, 45, 16, 29, 12, 4, 41, 3, 27, 18, 57, 10, 51, 17, 21, 14, 35, 19, 44, 47, 49, 26, 59, 63, 28, 55, 20, 13, 5, 6, 37, 54, 40, 22, 23, 46, 11, 36, 34, 31, 2, 60, 9, 52, 24, 1, 53, 0, 39, 43, 8, 33, }, +}; +const pattern_t pat6 = { + { 0xad2000, 0x222f000, 0x64b4000, 0x6c66000, 0x6f35000, 0x9e50000, 0xe744000, 0xf129000, 0x101bb000, 0x11bf8000, 0x14b89000, 0x1691c000, 0x17a0d000, 0x1817a000, 0x1997a000, 0x1d736000, 0x1db33000, 0x1fdd8000, 0x21e56000, 0x2266c000, 0x22875000, 0x22b84000, 0x230ed000, 0x239c5000, 0x24e1a000, 0x275f5000, 0x29036000, 0x29f69000, 0x2e538000, 0x2efca000, 0x2f0bc000, 0x2f1bf000, 0x305cb000, 0x31ce7000, 0x345c4000, 0x35d4f000, 0x36e56000, 0x3ae9e000, 0x3cc27000, 0x40117000, 0x4299f000, 0x434c3000, 0x443d4000, 0x4552d000, 0x4a8a8000, 0x4cdea000, 0x51bd5000, 0x580c4000, 0x58381000, 0x59dc0000, 0x5ba7f000, 0x5d88b000, 0x5e0c4000, 0x5ee57000, 0x61f3f000, 0x63a4a000, 0x68a8a000, 0x68ec5000, 0x6937b000, 0x720be000, 0x72cf5000, 0x74fc8000, 0x76464000, 0x80000000, }, + { 31, 46, 36, 22, 63, 12, 51, 60, 13, 44, 41, 6, 11, 17, 42, 24, 16, 61, 20, 26, 35, 21, 29, 55, 50, 45, 62, 19, 54, 9, 30, 34, 53, 52, 10, 39, 0, 49, 48, 38, 40, 28, 23, 56, 2, 5, 4, 59, 14, 57, 3, 25, 43, 32, 27, 47, 8, 7, 37, 33, 1, 18, 58, 15, }, +}; +const pattern_t pat7 = { + { 0xd83000, 0x1597000, 0x245b000, 0x6a75000, 0x8fda000, 0x960e000, 0xd310000, 0xe6cd000, 0x1409a000, 0x15221000, 0x16059000, 0x1b3a4000, 0x1ceea000, 0x1ed1a000, 0x1ef0f000, 0x21723000, 0x21efc000, 0x24594000, 0x26d7f000, 0x28c4f000, 0x2fa89000, 0x304f0000, 0x30dbb000, 0x30de3000, 0x3365d000, 0x36dbc000, 0x3acb2000, 0x3e291000, 0x3f7da000, 0x41352000, 0x41a0f000, 0x435c8000, 0x4475a000, 0x47536000, 0x47726000, 0x4a81f000, 0x4be4e000, 0x4bf05000, 0x4c15b000, 0x515b4000, 0x52ef5000, 0x548cc000, 0x5692a000, 0x59ef2000, 0x5b97c000, 0x5c4f0000, 0x5d1b9000, 0x618ed000, 0x61bcc000, 0x61e07000, 0x639a3000, 0x65302000, 0x68041000, 0x6be56000, 0x721a3000, 0x72c99000, 0x740b9000, 0x7586d000, 0x75eca000, 0x76406000, 0x7b68a000, 0x7dd26000, 0x7ed55000, 0x80000000, }, + { 44, 57, 22, 35, 63, 11, 15, 49, 61, 40, 29, 20, 19, 42, 32, 12, 41, 6, 46, 60, 52, 5, 36, 10, 2, 8, 3, 33, 54, 39, 58, 48, 62, 7, 51, 34, 0, 1, 18, 9, 55, 31, 23, 38, 25, 21, 17, 24, 13, 50, 16, 14, 43, 53, 45, 28, 59, 37, 26, 30, 47, 27, 56, 4, }, +}; +const pattern_t pat8 = { + { 0x1b8000, 0x27eb000, 0x5a4d000, 0x6ecc000, 0xb52e000, 0xb70e000, 0xc6db000, 0xd83d000, 0xed51000, 0x13c59000, 0x13fef000, 0x142e1000, 0x192d0000, 0x1aa63000, 0x1e230000, 0x1f464000, 0x20de4000, 0x2234b000, 0x25459000, 0x27018000, 0x28263000, 0x29cc7000, 0x32227000, 0x32c63000, 0x34af0000, 0x37e27000, 0x3afc9000, 0x3c166000, 0x3df20000, 0x405bd000, 0x41273000, 0x45c39000, 0x471be000, 0x4758e000, 0x4b3fc000, 0x4c6b2000, 0x4c80f000, 0x4ccd6000, 0x4d9e0000, 0x4e07f000, 0x4eeda000, 0x541ae000, 0x58aa7000, 0x5a2c6000, 0x5a628000, 0x5ab94000, 0x5bddc000, 0x5d1d4000, 0x5e643000, 0x5f72f000, 0x64771000, 0x67bd4000, 0x6a28c000, 0x6c977000, 0x6cc4e000, 0x710c4000, 0x74b86000, 0x75cf7000, 0x77d4b000, 0x7870e000, 0x7c47c000, 0x7eb52000, 0x7fbea000, 0x80000000, }, + { 7, 29, 62, 8, 54, 38, 35, 45, 60, 55, 1, 40, 4, 19, 50, 63, 48, 51, 13, 27, 33, 39, 52, 46, 10, 9, 56, 2, 42, 43, 47, 44, 17, 5, 25, 6, 57, 23, 15, 58, 59, 22, 14, 26, 32, 61, 30, 0, 11, 12, 36, 24, 53, 49, 3, 20, 31, 28, 34, 18, 41, 21, 16, 37, }, +}; +const pattern_t pat9 = { + { 0x5b59000, 0xa6d7000, 0xbad3000, 0xdf91000, 0x115ad000, 0x13fde000, 0x17618000, 0x1b8e9000, 0x1e1b7000, 0x1e97d000, 0x21737000, 0x21a5e000, 0x24140000, 0x2558f000, 0x2647a000, 0x28257000, 0x285f6000, 0x2cb7a000, 0x2ebb1000, 0x30ae8000, 0x31543000, 0x315cb000, 0x31616000, 0x335ba000, 0x33ed6000, 0x35cf3000, 0x4162b000, 0x4409b000, 0x4629a000, 0x4b745000, 0x4c0ba000, 0x4cbc5000, 0x4dd97000, 0x4f34b000, 0x4f637000, 0x539d6000, 0x53f3d000, 0x56383000, 0x5642b000, 0x5a71f000, 0x5affa000, 0x5b486000, 0x5b8ef000, 0x60d88000, 0x61629000, 0x625cd000, 0x63326000, 0x6735e000, 0x67379000, 0x6a26a000, 0x6a281000, 0x6b997000, 0x6c50d000, 0x6cc6c000, 0x6f496000, 0x717ad000, 0x732ec000, 0x744dc000, 0x771e8000, 0x77cf0000, 0x79cad000, 0x7bb21000, 0x7e7b4000, 0x80000000, }, + { 35, 9, 46, 6, 29, 2, 3, 54, 55, 57, 41, 16, 44, 5, 0, 59, 10, 61, 22, 42, 47, 12, 14, 50, 39, 34, 21, 32, 25, 15, 26, 8, 38, 60, 28, 53, 62, 49, 58, 43, 36, 37, 52, 7, 19, 63, 17, 11, 45, 33, 23, 27, 24, 18, 48, 56, 31, 13, 51, 30, 4, 20, 40, 1, }, +}; +const pattern_t pat10 = { + { 0xa72000, 0x180a000, 0x6406000, 0x66df000, 0x83bb000, 0xa96f000, 0xd193000, 0x13b9b000, 0x13dae000, 0x16109000, 0x1853d000, 0x18887000, 0x19f0a000, 0x22151000, 0x229ba000, 0x26b58000, 0x2aaf4000, 0x2bf50000, 0x31a2e000, 0x31d4e000, 0x32196000, 0x3513a000, 0x36a2d000, 0x3746b000, 0x389ad000, 0x39d27000, 0x3dad3000, 0x3de55000, 0x3ea9b000, 0x3ec06000, 0x3f921000, 0x432d3000, 0x43bec000, 0x43dda000, 0x47b2b000, 0x4886e000, 0x4928e000, 0x49ad2000, 0x4d0df000, 0x4f40d000, 0x50959000, 0x54fa4000, 0x56091000, 0x5688d000, 0x5b7d8000, 0x5f6fd000, 0x601e4000, 0x64eaa000, 0x6752e000, 0x67fff000, 0x6a184000, 0x6ad7a000, 0x6adbc000, 0x6c434000, 0x6f451000, 0x6ffb4000, 0x707ee000, 0x71161000, 0x7146b000, 0x75dbf000, 0x77259000, 0x7acd4000, 0x7af71000, 0x80000000, }, + { 61, 38, 5, 23, 62, 11, 53, 9, 17, 45, 30, 29, 41, 60, 39, 21, 40, 19, 44, 33, 42, 50, 56, 28, 32, 46, 43, 20, 16, 3, 54, 8, 4, 26, 15, 34, 47, 12, 6, 27, 48, 0, 1, 2, 57, 59, 7, 58, 49, 35, 24, 37, 52, 63, 10, 55, 36, 13, 14, 25, 18, 22, 31, 51, }, +}; +const pattern_t pat11 = { + { 0x996000, 0xaff000, 0x199a000, 0x46f3000, 0x74c0000, 0x758d000, 0xcd09000, 0xe48c000, 0xe8de000, 0xf111000, 0xf87b000, 0x10b1c000, 0x15d63000, 0x17b21000, 0x182d3000, 0x19167000, 0x198ce000, 0x1bd47000, 0x1dff1000, 0x1edc0000, 0x1f890000, 0x20860000, 0x23207000, 0x29bd5000, 0x2ac0f000, 0x2e395000, 0x2e707000, 0x329de000, 0x3497f000, 0x3807f000, 0x38a94000, 0x40a19000, 0x4168e000, 0x42ca0000, 0x42de9000, 0x45194000, 0x464f2000, 0x4700f000, 0x47dbb000, 0x4dae7000, 0x50660000, 0x535a8000, 0x5546b000, 0x57b55000, 0x5860a000, 0x5a9ee000, 0x5b8d9000, 0x5c49f000, 0x5cb4d000, 0x5d28c000, 0x60dcd000, 0x62557000, 0x64b0c000, 0x654cb000, 0x65746000, 0x65e29000, 0x6648f000, 0x66c56000, 0x6999e000, 0x6a11c000, 0x6ca04000, 0x79e60000, 0x7edce000, 0x80000000, }, + { 16, 28, 2, 38, 10, 57, 21, 26, 61, 43, 46, 31, 56, 7, 47, 48, 58, 25, 63, 4, 59, 15, 32, 50, 1, 40, 53, 18, 17, 24, 29, 30, 55, 36, 49, 42, 41, 37, 23, 39, 6, 51, 33, 9, 45, 5, 35, 19, 44, 11, 34, 0, 27, 12, 60, 62, 20, 13, 22, 8, 14, 54, 3, 52, }, +}; +const pattern_t pat12 = { + { 0x513000, 0x1b72000, 0x1e27000, 0x3a63000, 0x1115c000, 0x158b4000, 0x1664f000, 0x1b667000, 0x1f838000, 0x21410000, 0x260c7000, 0x2cd8f000, 0x2ce37000, 0x2df16000, 0x2e59e000, 0x2e8eb000, 0x2ebd2000, 0x2f1d2000, 0x2fc42000, 0x30d00000, 0x31ef1000, 0x3301a000, 0x38097000, 0x38a1e000, 0x3d818000, 0x3e898000, 0x3f90f000, 0x47710000, 0x478bb000, 0x485ab000, 0x48e54000, 0x4cfe1000, 0x53a89000, 0x53d10000, 0x56308000, 0x56f3b000, 0x577f6000, 0x58734000, 0x5889b000, 0x58ad7000, 0x5923a000, 0x59aef000, 0x5dad3000, 0x5e32f000, 0x63b3a000, 0x665c9000, 0x68cde000, 0x69252000, 0x6a777000, 0x6a79a000, 0x6c1f0000, 0x6cb9a000, 0x6d319000, 0x6dc82000, 0x6dd4d000, 0x6e188000, 0x7184d000, 0x7206e000, 0x73980000, 0x740ad000, 0x75473000, 0x7614d000, 0x79b17000, 0x80000000, }, + { 4, 60, 10, 35, 6, 31, 5, 18, 53, 17, 20, 8, 56, 29, 7, 48, 40, 0, 12, 39, 2, 43, 15, 61, 42, 30, 50, 14, 49, 38, 34, 58, 24, 55, 33, 63, 28, 51, 59, 46, 11, 22, 45, 41, 13, 44, 23, 47, 3, 32, 16, 54, 26, 19, 25, 52, 27, 57, 36, 9, 37, 21, 62, 1, }, +}; +const pattern_t pat13 = { + { 0x351e000, 0x5917000, 0xa992000, 0xc471000, 0xc69c000, 0xc6ed000, 0xc919000, 0xd713000, 0xec14000, 0xfa31000, 0x17567000, 0x1d81a000, 0x1f3c8000, 0x215b5000, 0x26e41000, 0x2a2d4000, 0x2b750000, 0x2bea0000, 0x2c5ae000, 0x2ca2c000, 0x30a94000, 0x31074000, 0x314d3000, 0x31b1e000, 0x31de2000, 0x32062000, 0x33da5000, 0x37838000, 0x385ec000, 0x38740000, 0x387f9000, 0x38be6000, 0x3d2f7000, 0x3eaf5000, 0x40266000, 0x402f3000, 0x40fda000, 0x4a4bd000, 0x4b831000, 0x4bfc9000, 0x4ccaa000, 0x4ea43000, 0x50190000, 0x547c8000, 0x58cc6000, 0x58ea5000, 0x59de1000, 0x5c7f1000, 0x5f713000, 0x63f9a000, 0x6686d000, 0x675c1000, 0x6cccc000, 0x6e409000, 0x6fb6d000, 0x71a70000, 0x72f60000, 0x77bd9000, 0x79013000, 0x7a8d3000, 0x7b341000, 0x7d8f7000, 0x7fe43000, 0x80000000, }, + { 10, 52, 48, 8, 34, 4, 35, 19, 3, 17, 54, 45, 31, 38, 24, 44, 21, 36, 22, 11, 43, 40, 39, 26, 5, 30, 2, 7, 57, 12, 20, 32, 62, 15, 55, 14, 25, 58, 6, 33, 49, 9, 59, 27, 13, 63, 42, 61, 1, 51, 0, 50, 37, 47, 16, 18, 41, 56, 60, 46, 23, 28, 53, 29, }, +}; +const pattern_t pat14 = { + { 0xf8e000, 0x169a000, 0x3816000, 0x67a9000, 0x89f3000, 0xac97000, 0xc8da000, 0xf077000, 0x119f1000, 0x13902000, 0x19785000, 0x1ca7f000, 0x1f958000, 0x2027d000, 0x2251f000, 0x24661000, 0x25604000, 0x2b924000, 0x2be5f000, 0x2ec27000, 0x330a5000, 0x3349e000, 0x33a84000, 0x344fa000, 0x34514000, 0x37966000, 0x37f0b000, 0x37fcd000, 0x386d0000, 0x39600000, 0x39de4000, 0x3e601000, 0x3e7f1000, 0x42c61000, 0x48806000, 0x4d3d0000, 0x4f5ff000, 0x512c1000, 0x53fd4000, 0x59440000, 0x5b386000, 0x5e8a0000, 0x5fca3000, 0x6016c000, 0x61ca8000, 0x64915000, 0x66b99000, 0x67226000, 0x69b2f000, 0x6a473000, 0x6a590000, 0x6c844000, 0x6cb8c000, 0x713b5000, 0x7558a000, 0x75eab000, 0x76d15000, 0x77efe000, 0x78762000, 0x7bddc000, 0x7ce92000, 0x7dc44000, 0x7f54b000, 0x80000000, }, + { 54, 31, 48, 10, 51, 49, 55, 19, 38, 18, 44, 5, 17, 20, 16, 11, 9, 3, 42, 59, 63, 45, 25, 60, 57, 21, 40, 29, 0, 39, 26, 7, 53, 12, 13, 2, 58, 41, 22, 8, 14, 28, 46, 24, 27, 6, 52, 32, 56, 4, 30, 36, 15, 47, 23, 37, 43, 35, 50, 33, 61, 34, 1, 62, }, +}; +const pattern_t pat15 = { + { 0xe16000, 0xec6000, 0xf6b000, 0x634b000, 0x6896000, 0x91db000, 0xc2c8000, 0xe083000, 0xfd7f000, 0x10479000, 0x17740000, 0x18292000, 0x1aaca000, 0x1cb55000, 0x1d2be000, 0x222af000, 0x2cb03000, 0x2fabc000, 0x32034000, 0x35c0f000, 0x3c5ec000, 0x40908000, 0x4128e000, 0x44411000, 0x44bcd000, 0x4f0ac000, 0x5167b000, 0x5541c000, 0x581bc000, 0x584e5000, 0x588fb000, 0x593d3000, 0x5b25d000, 0x5dc99000, 0x60b35000, 0x60ffc000, 0x638e8000, 0x63cf8000, 0x64ee1000, 0x6523c000, 0x654a1000, 0x687bf000, 0x68bef000, 0x69826000, 0x69d90000, 0x6a622000, 0x6d1b9000, 0x6d1e1000, 0x6d886000, 0x6fe4a000, 0x6feac000, 0x720b2000, 0x734dc000, 0x73530000, 0x73f1e000, 0x7479c000, 0x76e33000, 0x786dc000, 0x79b40000, 0x79e49000, 0x7b66c000, 0x7b904000, 0x7c906000, 0x80000000, }, + { 6, 17, 62, 20, 61, 32, 22, 14, 28, 18, 3, 42, 63, 43, 46, 34, 29, 30, 35, 1, 37, 40, 10, 26, 5, 31, 15, 54, 8, 33, 9, 4, 39, 53, 23, 25, 41, 59, 12, 13, 60, 2, 7, 56, 58, 27, 11, 38, 36, 45, 47, 0, 57, 50, 48, 16, 51, 49, 55, 52, 44, 24, 19, 21, }, +}; +const pattern_t pat16 = { + { 0x596a000, 0x8644000, 0xa943000, 0xd59e000, 0x1062f000, 0x1082a000, 0x10c1b000, 0x10f9e000, 0x11e64000, 0x12e73000, 0x15ce7000, 0x16037000, 0x16d2e000, 0x17035000, 0x185ad000, 0x18d9b000, 0x19ac7000, 0x1b2fa000, 0x1cd6c000, 0x1d5f0000, 0x1f72c000, 0x20891000, 0x24bfa000, 0x25c1d000, 0x28e24000, 0x2a5f8000, 0x2e0ae000, 0x2fddf000, 0x3119d000, 0x332ee000, 0x3480a000, 0x34ea5000, 0x3534e000, 0x3538b000, 0x362e2000, 0x38f58000, 0x39ab0000, 0x3a519000, 0x3a62b000, 0x3b006000, 0x3d523000, 0x3e0f7000, 0x42366000, 0x42feb000, 0x44013000, 0x46b98000, 0x49794000, 0x4dce7000, 0x4f1f3000, 0x57ecd000, 0x5aaa2000, 0x5f419000, 0x61517000, 0x6797d000, 0x69a20000, 0x6a070000, 0x70575000, 0x75322000, 0x75a9e000, 0x79043000, 0x79875000, 0x7addc000, 0x7de88000, 0x80000000, }, + { 26, 25, 6, 50, 32, 53, 34, 27, 3, 16, 49, 28, 46, 38, 56, 4, 18, 24, 51, 36, 63, 5, 48, 13, 43, 55, 0, 62, 35, 7, 41, 21, 44, 60, 31, 39, 14, 8, 61, 58, 52, 23, 59, 33, 10, 37, 20, 30, 40, 22, 11, 54, 57, 1, 29, 47, 2, 17, 19, 45, 15, 9, 12, 42, }, +}; +const pattern_t pat17 = { + { 0x28ab000, 0x3ac8000, 0x3fe1000, 0x63a7000, 0x90fc000, 0xb3f2000, 0xd2f2000, 0xe032000, 0x12d4c000, 0x13135000, 0x14652000, 0x15331000, 0x1570c000, 0x1688e000, 0x16bc3000, 0x1cbe3000, 0x1fe0f000, 0x2517f000, 0x26c6b000, 0x2a284000, 0x2a4e2000, 0x2add5000, 0x2bd06000, 0x2ca3a000, 0x2eb11000, 0x324d1000, 0x35662000, 0x38695000, 0x38ce7000, 0x391ac000, 0x398f9000, 0x39949000, 0x401f3000, 0x457f0000, 0x45c6d000, 0x4b561000, 0x522fc000, 0x54ef0000, 0x559f8000, 0x562a7000, 0x56a04000, 0x57b68000, 0x59702000, 0x5ffc9000, 0x63a76000, 0x63c37000, 0x65d3e000, 0x67130000, 0x6a03a000, 0x6bcd6000, 0x6be96000, 0x6bf52000, 0x6fcd9000, 0x7038c000, 0x70a47000, 0x72881000, 0x72ed0000, 0x75035000, 0x75c11000, 0x77fa5000, 0x797c9000, 0x79813000, 0x7bbbb000, 0x80000000, }, + { 18, 15, 56, 5, 25, 47, 39, 55, 12, 14, 51, 33, 0, 7, 9, 44, 50, 31, 62, 59, 3, 35, 23, 17, 30, 60, 11, 24, 40, 20, 52, 2, 22, 8, 57, 42, 32, 54, 36, 48, 49, 13, 58, 10, 28, 63, 16, 41, 27, 21, 37, 4, 1, 29, 19, 6, 53, 45, 46, 38, 34, 43, 61, 26, }, +}; +const pattern_t pat18 = { + { 0x38d6000, 0x5379000, 0x5cae000, 0x5d20000, 0xa248000, 0xb4d0000, 0xd7c0000, 0xf731000, 0x116ae000, 0x151d2000, 0x1747d000, 0x1bfb6000, 0x1d758000, 0x2053d000, 0x24dda000, 0x25274000, 0x269c0000, 0x273e8000, 0x2a5d0000, 0x2ad34000, 0x3016b000, 0x30d1a000, 0x32960000, 0x34b3b000, 0x36e4f000, 0x37934000, 0x38c42000, 0x3c2d2000, 0x3d23d000, 0x3d89a000, 0x3dc85000, 0x3e9a7000, 0x3f25b000, 0x45bd1000, 0x48d94000, 0x4b126000, 0x4e17c000, 0x4f377000, 0x50908000, 0x51957000, 0x53410000, 0x5412c000, 0x55256000, 0x56b17000, 0x5707b000, 0x5bbe5000, 0x5d067000, 0x5e1c1000, 0x6380b000, 0x66009000, 0x68240000, 0x69fc4000, 0x6c327000, 0x6c5d2000, 0x6f69d000, 0x739c7000, 0x744bc000, 0x74cd8000, 0x787b8000, 0x78c61000, 0x7969d000, 0x79aae000, 0x7b032000, 0x80000000, }, + { 16, 48, 50, 60, 13, 39, 20, 4, 63, 18, 14, 30, 55, 8, 62, 37, 43, 41, 11, 0, 36, 33, 34, 49, 17, 58, 38, 22, 19, 5, 21, 12, 47, 25, 57, 61, 7, 3, 10, 23, 52, 24, 6, 53, 2, 26, 1, 31, 28, 46, 42, 9, 45, 29, 27, 54, 32, 56, 51, 44, 35, 59, 40, 15, }, +}; +const pattern_t pat19 = { + { 0x297d000, 0x34e0000, 0x7801000, 0x9664000, 0x96fa000, 0xbb9f000, 0xc192000, 0xc4a5000, 0xca74000, 0xcce8000, 0x173d8000, 0x1a8d8000, 0x1b299000, 0x1b52d000, 0x1e813000, 0x2185e000, 0x21abe000, 0x2b9a4000, 0x2c4b6000, 0x2fa27000, 0x343ba000, 0x356fd000, 0x37c6e000, 0x38365000, 0x3a9e4000, 0x3b599000, 0x4296b000, 0x43196000, 0x4381e000, 0x44783000, 0x47a75000, 0x4bd78000, 0x4d05d000, 0x4edb2000, 0x4eefd000, 0x4fecc000, 0x51f68000, 0x5252b000, 0x5439e000, 0x55fb3000, 0x5814f000, 0x5939d000, 0x60a78000, 0x62a86000, 0x633b0000, 0x64a68000, 0x64b62000, 0x66207000, 0x66540000, 0x67f90000, 0x68bf3000, 0x6a069000, 0x6d2ac000, 0x70c9f000, 0x71bab000, 0x724bc000, 0x783d8000, 0x7900e000, 0x79399000, 0x79763000, 0x7c8a8000, 0x7e680000, 0x7f6de000, 0x80000000, }, + { 14, 59, 60, 24, 18, 22, 62, 12, 45, 2, 32, 11, 25, 37, 13, 7, 50, 39, 56, 17, 47, 40, 29, 43, 15, 34, 4, 57, 31, 38, 21, 28, 36, 27, 42, 1, 23, 33, 5, 61, 44, 55, 8, 30, 10, 41, 19, 48, 16, 52, 49, 46, 54, 58, 6, 0, 51, 3, 26, 20, 53, 9, 35, 63, }, +}; +const pattern_t pat20 = { + { 0x8f7000, 0xa01000, 0x38e3000, 0x5299000, 0x6875000, 0x7f3e000, 0x827f000, 0x9413000, 0xca71000, 0xfb11000, 0x10beb000, 0x176be000, 0x1924f000, 0x1cfd6000, 0x1d20d000, 0x1ebb7000, 0x22c93000, 0x23601000, 0x2cf7a000, 0x2d3af000, 0x2e391000, 0x2f294000, 0x318ad000, 0x34ddd000, 0x365e4000, 0x3b8d2000, 0x3c0f8000, 0x3d2fd000, 0x3e431000, 0x3f0fe000, 0x4074e000, 0x40d1c000, 0x41936000, 0x4347b000, 0x452d7000, 0x486d3000, 0x4b47e000, 0x4b709000, 0x4c349000, 0x4ff13000, 0x50faa000, 0x51a07000, 0x52f30000, 0x55f29000, 0x57ad4000, 0x5909f000, 0x5a0f6000, 0x5de57000, 0x60d2f000, 0x625ff000, 0x6288e000, 0x65077000, 0x6a707000, 0x6a73f000, 0x6d720000, 0x6e390000, 0x6edc9000, 0x6ee78000, 0x77ac2000, 0x77ad3000, 0x7868f000, 0x79a1b000, 0x7aec6000, 0x80000000, }, + { 21, 56, 38, 11, 62, 9, 30, 47, 34, 23, 37, 16, 5, 49, 10, 43, 4, 45, 36, 7, 42, 1, 53, 57, 20, 59, 55, 50, 46, 39, 60, 27, 12, 31, 48, 25, 15, 22, 44, 52, 14, 33, 0, 29, 17, 18, 2, 32, 24, 19, 6, 41, 54, 8, 35, 26, 61, 3, 51, 13, 63, 28, 40, 58, }, +}; +const pattern_t pat21 = { + { 0x2a8e000, 0xa4bd000, 0xa935000, 0xcc05000, 0xdfe4000, 0xe014000, 0xff46000, 0x18c8c000, 0x199ec000, 0x19ce0000, 0x1f684000, 0x1ff5c000, 0x22d58000, 0x27651000, 0x280e5000, 0x2e2a4000, 0x2e432000, 0x2f96e000, 0x2f9c3000, 0x3343d000, 0x338bb000, 0x34032000, 0x34101000, 0x368c2000, 0x37b95000, 0x39492000, 0x39932000, 0x3b611000, 0x3c89e000, 0x40aa9000, 0x42358000, 0x4890e000, 0x495c9000, 0x4a79d000, 0x4c58e000, 0x4df9a000, 0x4f304000, 0x4fa4c000, 0x54d1d000, 0x58461000, 0x58f43000, 0x5a3d1000, 0x5a765000, 0x5c5c0000, 0x60488000, 0x60fad000, 0x613e5000, 0x61d61000, 0x62d17000, 0x641ff000, 0x67f8b000, 0x69c5d000, 0x6b931000, 0x6efd4000, 0x70333000, 0x70857000, 0x721f6000, 0x72f53000, 0x74450000, 0x746f7000, 0x76067000, 0x7774a000, 0x77ea6000, 0x80000000, }, + { 28, 51, 33, 2, 30, 55, 29, 17, 40, 48, 32, 9, 39, 1, 49, 50, 37, 43, 62, 11, 10, 26, 22, 6, 8, 7, 45, 47, 46, 42, 60, 5, 12, 56, 4, 23, 35, 25, 13, 16, 61, 54, 31, 63, 34, 19, 41, 59, 38, 24, 0, 58, 53, 44, 3, 18, 52, 20, 36, 27, 14, 21, 57, 15, }, +}; +const pattern_t pat22 = { + { 0x314d000, 0x4452000, 0x6673000, 0xab09000, 0xc80d000, 0x10eda000, 0x129c2000, 0x12f1f000, 0x13e9b000, 0x1450c000, 0x15aeb000, 0x1667c000, 0x190b2000, 0x19ac5000, 0x1c0ac000, 0x1c229000, 0x1ece8000, 0x1fc48000, 0x22abd000, 0x24268000, 0x2adce000, 0x2b809000, 0x30a11000, 0x31d08000, 0x36700000, 0x39e6a000, 0x3b84b000, 0x41e84000, 0x46301000, 0x4a326000, 0x50fda000, 0x5299a000, 0x56acf000, 0x57f66000, 0x586ab000, 0x58df5000, 0x591cc000, 0x59b91000, 0x59cbd000, 0x5b4d0000, 0x5cca7000, 0x5cfce000, 0x5d120000, 0x5d51a000, 0x5eaa0000, 0x5ebac000, 0x5f0e1000, 0x5f285000, 0x5f4d3000, 0x5ff61000, 0x60b51000, 0x61435000, 0x651fd000, 0x6b954000, 0x705aa000, 0x71a41000, 0x73ec7000, 0x75f92000, 0x76854000, 0x77cb9000, 0x782ca000, 0x7a2af000, 0x7eaa6000, 0x80000000, }, + { 16, 8, 5, 59, 4, 18, 26, 43, 33, 57, 6, 47, 56, 46, 10, 54, 52, 0, 50, 30, 39, 24, 38, 63, 28, 25, 49, 31, 55, 62, 3, 17, 23, 13, 37, 53, 34, 14, 44, 12, 19, 36, 27, 61, 51, 42, 41, 60, 45, 1, 7, 35, 21, 58, 20, 15, 2, 9, 22, 29, 48, 32, 40, 11, }, +}; +const pattern_t pat23 = { + { 0x47000, 0x680000, 0x176a000, 0x1db8000, 0x600e000, 0x808c000, 0x9e58000, 0xa82f000, 0xaebb000, 0xc938000, 0xd0eb000, 0xdc5e000, 0xe503000, 0x11e56000, 0x12dbd000, 0x14681000, 0x15200000, 0x18256000, 0x1be75000, 0x1d2a0000, 0x1ed67000, 0x27e8a000, 0x2bc39000, 0x2bf4b000, 0x2c94f000, 0x2d575000, 0x2d82e000, 0x2e440000, 0x2ecda000, 0x2fbc2000, 0x33ab0000, 0x360b8000, 0x39630000, 0x3a654000, 0x3d2b6000, 0x3eeff000, 0x41590000, 0x417ea000, 0x42ff9000, 0x4bca4000, 0x503b0000, 0x508e4000, 0x52a2e000, 0x535b6000, 0x54335000, 0x57412000, 0x57dc6000, 0x590d9000, 0x5fc0a000, 0x60552000, 0x60665000, 0x6168d000, 0x65b16000, 0x67328000, 0x6742d000, 0x68c88000, 0x6b802000, 0x6f6d2000, 0x7040e000, 0x77e31000, 0x79c71000, 0x7da4a000, 0x7e26b000, 0x80000000, }, + { 63, 50, 51, 33, 28, 35, 24, 14, 4, 23, 47, 11, 37, 41, 12, 55, 62, 32, 34, 30, 25, 43, 16, 0, 3, 49, 61, 15, 57, 46, 59, 44, 31, 27, 21, 53, 5, 2, 8, 56, 52, 22, 60, 40, 20, 1, 48, 18, 17, 19, 54, 29, 9, 38, 42, 6, 39, 45, 13, 10, 26, 58, 36, 7, }, +}; +const pattern_t pat24 = { + { 0x3890000, 0x3fd9000, 0x62d6000, 0x7df0000, 0x895c000, 0xab61000, 0xc23b000, 0x10ab3000, 0x1247c000, 0x13f00000, 0x16604000, 0x1a444000, 0x1c2c8000, 0x1c467000, 0x1d396000, 0x1e683000, 0x21080000, 0x2442a000, 0x27fea000, 0x282eb000, 0x28e2c000, 0x2a625000, 0x2b3b2000, 0x2bbd5000, 0x2c886000, 0x2cbe8000, 0x31518000, 0x35425000, 0x355f4000, 0x35d7a000, 0x3851d000, 0x396a6000, 0x3d10f000, 0x3d890000, 0x49238000, 0x4ab7e000, 0x4fadf000, 0x50603000, 0x5233a000, 0x53279000, 0x5586c000, 0x56968000, 0x58101000, 0x588b6000, 0x5bc19000, 0x5cc10000, 0x623f6000, 0x629f4000, 0x63176000, 0x63dcc000, 0x681d0000, 0x69c0e000, 0x6a9fa000, 0x6ae5e000, 0x6d2ba000, 0x6e422000, 0x73f94000, 0x77932000, 0x78b24000, 0x794c1000, 0x795d2000, 0x7ae08000, 0x7b3ce000, 0x80000000, }, + { 56, 47, 54, 62, 29, 43, 25, 59, 41, 7, 52, 63, 15, 21, 16, 14, 39, 17, 45, 11, 27, 24, 55, 31, 53, 4, 6, 2, 20, 23, 5, 37, 32, 58, 13, 51, 1, 8, 3, 57, 46, 30, 35, 49, 18, 40, 9, 22, 42, 38, 34, 0, 19, 33, 26, 60, 10, 48, 36, 61, 44, 12, 50, 28, }, +}; +const pattern_t pat25 = { + { 0xcb000, 0x22bf000, 0x2461000, 0x246b000, 0x5c6f000, 0x5fb4000, 0x69a9000, 0x718c000, 0x92e6000, 0xbb2e000, 0xd916000, 0xf3dc000, 0xf568000, 0x10246000, 0x12d53000, 0x14dfd000, 0x1598a000, 0x1956a000, 0x1b01b000, 0x1b3b8000, 0x1ce06000, 0x20bc5000, 0x21351000, 0x233b0000, 0x23f2b000, 0x24e41000, 0x29cca000, 0x2b5bd000, 0x2ba68000, 0x2bf7f000, 0x31a58000, 0x34570000, 0x39941000, 0x3b765000, 0x3cd13000, 0x3d251000, 0x3fa05000, 0x40745000, 0x45c68000, 0x4a282000, 0x4ad19000, 0x4b4aa000, 0x4ca18000, 0x4e0b8000, 0x4eb97000, 0x4f68b000, 0x4fca2000, 0x52466000, 0x52edf000, 0x5602a000, 0x57f60000, 0x5cc18000, 0x5cee3000, 0x5da37000, 0x5dba4000, 0x64b77000, 0x66e9f000, 0x68b9d000, 0x6aac9000, 0x6d873000, 0x6f7e6000, 0x71036000, 0x75a54000, 0x80000000, }, + { 1, 58, 13, 5, 62, 10, 49, 48, 19, 24, 54, 57, 20, 39, 35, 41, 28, 42, 6, 44, 34, 45, 55, 3, 2, 60, 38, 36, 30, 25, 7, 23, 53, 50, 61, 29, 40, 47, 22, 12, 27, 0, 52, 31, 8, 15, 37, 11, 46, 32, 4, 56, 17, 33, 26, 43, 51, 16, 9, 59, 63, 21, 14, 18, }, +}; +const pattern_t pat26 = { + { 0x1f4e000, 0x46f7000, 0x90a7000, 0xafe3000, 0xb2a8000, 0xb8b0000, 0xc480000, 0xc4e1000, 0xf03c000, 0xf075000, 0x14dbd000, 0x17728000, 0x1a146000, 0x1ab02000, 0x1af49000, 0x1be7a000, 0x1dc7a000, 0x1de5e000, 0x1f4f9000, 0x2092b000, 0x20a63000, 0x22937000, 0x22fe3000, 0x23e1c000, 0x28c46000, 0x294d6000, 0x2ad19000, 0x2b18b000, 0x2b233000, 0x2b685000, 0x2c792000, 0x2e6c2000, 0x2fa86000, 0x3320f000, 0x36f17000, 0x38406000, 0x38b1b000, 0x3a132000, 0x3b269000, 0x3cc43000, 0x3e2a2000, 0x3e3bb000, 0x3e83b000, 0x3ea14000, 0x4035d000, 0x4137f000, 0x4615b000, 0x50531000, 0x517c8000, 0x519e6000, 0x55ebc000, 0x594f8000, 0x5a732000, 0x5d2cb000, 0x5e409000, 0x5f394000, 0x5f3a8000, 0x60dc6000, 0x61373000, 0x6ebd6000, 0x6fd61000, 0x77161000, 0x7ce81000, 0x80000000, }, + { 61, 48, 12, 55, 3, 58, 51, 56, 15, 29, 54, 11, 31, 49, 40, 37, 7, 4, 23, 35, 25, 18, 27, 43, 6, 41, 17, 45, 52, 53, 47, 16, 42, 0, 30, 13, 38, 62, 1, 8, 21, 28, 57, 9, 60, 19, 44, 50, 14, 36, 22, 2, 32, 59, 34, 10, 63, 39, 5, 24, 33, 20, 46, 26, }, +}; +const pattern_t pat27 = { + { 0xa6a000, 0x4c7a000, 0x5183000, 0x8dda000, 0x9cbd000, 0xb860000, 0x10c24000, 0x12dda000, 0x147ab000, 0x14aa4000, 0x16c8f000, 0x17d5b000, 0x18b5c000, 0x1a163000, 0x1b0a1000, 0x24221000, 0x25ef8000, 0x267f1000, 0x268b7000, 0x26b07000, 0x273ad000, 0x27bc2000, 0x2856c000, 0x29896000, 0x2efeb000, 0x331a7000, 0x348e8000, 0x3707f000, 0x3f444000, 0x3fe2a000, 0x433b3000, 0x435d3000, 0x46d82000, 0x4a9d3000, 0x4c6cf000, 0x4ca36000, 0x4ec42000, 0x4f79c000, 0x53cd3000, 0x58c78000, 0x5d910000, 0x616cc000, 0x62800000, 0x65ded000, 0x68831000, 0x6b321000, 0x6cd46000, 0x6d0fa000, 0x6d2f9000, 0x6e353000, 0x6fd5e000, 0x706c5000, 0x7249f000, 0x75d6c000, 0x77528000, 0x783ad000, 0x79738000, 0x79bfe000, 0x79ee9000, 0x7b74a000, 0x7bb41000, 0x7bbeb000, 0x7bbfb000, 0x80000000, }, + { 61, 53, 12, 15, 26, 30, 32, 2, 16, 5, 39, 43, 20, 21, 49, 37, 11, 51, 18, 44, 31, 19, 24, 40, 1, 35, 50, 6, 57, 14, 46, 17, 22, 48, 29, 7, 34, 45, 10, 63, 23, 41, 54, 38, 4, 25, 42, 13, 56, 62, 36, 28, 33, 59, 55, 3, 9, 0, 58, 60, 47, 8, 52, 27, }, +}; +const pattern_t pat28 = { + { 0x439a000, 0x6860000, 0xd252000, 0x1105c000, 0x113c8000, 0x1429a000, 0x14922000, 0x15f32000, 0x1992f000, 0x1a1db000, 0x1a87c000, 0x1b260000, 0x1b292000, 0x1c253000, 0x1ea33000, 0x20bbc000, 0x215ae000, 0x25249000, 0x27c89000, 0x27e36000, 0x28bf2000, 0x29c27000, 0x2a575000, 0x2c6fa000, 0x31639000, 0x3184a000, 0x319c3000, 0x348a7000, 0x38aa8000, 0x39dd5000, 0x3a067000, 0x3c0dd000, 0x3cfd4000, 0x3ebb6000, 0x43259000, 0x46494000, 0x46fcb000, 0x4a050000, 0x4b5c4000, 0x4cff3000, 0x4edaa000, 0x4f025000, 0x542e1000, 0x55364000, 0x56338000, 0x56ef8000, 0x5711b000, 0x573d1000, 0x5943b000, 0x5b912000, 0x61ce2000, 0x65211000, 0x65dca000, 0x6dee2000, 0x6df30000, 0x7334d000, 0x73e76000, 0x7473a000, 0x75846000, 0x75fd0000, 0x77174000, 0x773e9000, 0x7a8db000, 0x80000000, }, + { 43, 11, 8, 56, 5, 22, 42, 55, 14, 32, 2, 47, 24, 51, 35, 25, 15, 58, 41, 27, 33, 37, 4, 36, 7, 53, 26, 48, 38, 19, 29, 28, 40, 10, 1, 46, 59, 63, 61, 62, 60, 30, 21, 39, 44, 57, 20, 18, 17, 54, 49, 52, 3, 12, 45, 13, 50, 9, 16, 23, 0, 6, 31, 34, }, +}; +const pattern_t pat29 = { + { 0x363000, 0x9bc000, 0x1907000, 0x41d5000, 0x5a6e000, 0x9f36000, 0xa3ee000, 0x14b98000, 0x1845c000, 0x188ea000, 0x1b297000, 0x1c024000, 0x1e1eb000, 0x1f3a4000, 0x2047f000, 0x2420a000, 0x28871000, 0x296dd000, 0x2c92c000, 0x2dd42000, 0x3444f000, 0x35b90000, 0x3683c000, 0x3d8ea000, 0x3fe6b000, 0x4200e000, 0x421cf000, 0x42a46000, 0x44463000, 0x44e61000, 0x45c82000, 0x485f8000, 0x48fe8000, 0x4a532000, 0x4a6fd000, 0x4c8f9000, 0x4dbd7000, 0x5052a000, 0x512bb000, 0x5281d000, 0x5315d000, 0x5a202000, 0x5a9fc000, 0x5c11a000, 0x6010b000, 0x62aa3000, 0x63d05000, 0x6774c000, 0x6776d000, 0x68105000, 0x699d5000, 0x69bc2000, 0x6b1b9000, 0x704d5000, 0x73d5c000, 0x73d94000, 0x78483000, 0x78c8c000, 0x78cc5000, 0x7ac8d000, 0x7ae00000, 0x7b597000, 0x7e6ab000, 0x80000000, }, + { 52, 40, 59, 29, 42, 34, 63, 44, 33, 37, 51, 23, 5, 36, 38, 43, 9, 4, 28, 55, 1, 6, 21, 26, 13, 24, 30, 15, 35, 17, 46, 20, 16, 10, 49, 48, 39, 62, 19, 14, 61, 27, 53, 2, 57, 58, 45, 7, 56, 50, 54, 25, 31, 11, 22, 47, 3, 0, 32, 12, 8, 41, 60, 18, }, +}; +const pattern_t pat30 = { + { 0x45c5000, 0x6bf3000, 0xc293000, 0xe470000, 0xe5b7000, 0x1256c000, 0x1444d000, 0x15699000, 0x16e86000, 0x1a4d5000, 0x1b803000, 0x1dcf9000, 0x1dd6f000, 0x1f57f000, 0x22879000, 0x263e9000, 0x29423000, 0x2a1a9000, 0x2a699000, 0x2c8fb000, 0x2d2e0000, 0x2ec5e000, 0x317a4000, 0x35a64000, 0x36967000, 0x37299000, 0x37c07000, 0x3b9bb000, 0x3c054000, 0x3ccbc000, 0x3d94a000, 0x3e2e9000, 0x3e7a4000, 0x40b98000, 0x44658000, 0x44738000, 0x44fe3000, 0x451d9000, 0x4536c000, 0x46df2000, 0x48855000, 0x503ce000, 0x53104000, 0x531fc000, 0x54c1b000, 0x56086000, 0x5642b000, 0x573a4000, 0x5887f000, 0x5a871000, 0x5c970000, 0x5e566000, 0x62b8f000, 0x642ce000, 0x65ee5000, 0x66db3000, 0x6727c000, 0x6a9a2000, 0x74a8f000, 0x7c29a000, 0x7cc57000, 0x7f221000, 0x7f28f000, 0x80000000, }, + { 29, 35, 8, 49, 30, 55, 27, 38, 58, 61, 0, 28, 15, 39, 5, 37, 32, 42, 46, 54, 12, 14, 1, 31, 59, 11, 47, 9, 13, 50, 2, 62, 60, 18, 20, 51, 23, 24, 53, 6, 25, 48, 41, 3, 33, 57, 44, 19, 22, 52, 4, 45, 10, 21, 56, 36, 17, 43, 7, 63, 16, 34, 26, 40, }, +}; +const pattern_t pat31 = { + { 0x143f000, 0x2068000, 0x328c000, 0x70a6000, 0x92a7000, 0x93dd000, 0xa3a8000, 0xbe51000, 0xbfc8000, 0xe353000, 0x1272f000, 0x143a4000, 0x16825000, 0x20bf8000, 0x20d9f000, 0x21e32000, 0x22426000, 0x2246b000, 0x22cea000, 0x25dc2000, 0x29324000, 0x29cd1000, 0x2aa44000, 0x2cd84000, 0x2dafb000, 0x2e74b000, 0x2f5b1000, 0x3a7a9000, 0x3bb38000, 0x3c11a000, 0x3c30a000, 0x3e2f1000, 0x4187b000, 0x42190000, 0x44e34000, 0x4d850000, 0x53ceb000, 0x540db000, 0x54937000, 0x5530a000, 0x5a111000, 0x5c280000, 0x5ef17000, 0x5fccf000, 0x64434000, 0x6498e000, 0x662c4000, 0x6a7e2000, 0x6b5a1000, 0x6c11f000, 0x6dd97000, 0x6ef1b000, 0x6f44e000, 0x7084f000, 0x73b53000, 0x7872c000, 0x78ed7000, 0x7935b000, 0x79bf9000, 0x7a6af000, 0x7b6fd000, 0x7bd42000, 0x7f233000, 0x80000000, }, + { 6, 25, 28, 44, 27, 43, 58, 33, 23, 21, 16, 48, 30, 26, 5, 20, 49, 38, 2, 45, 11, 61, 17, 0, 53, 13, 7, 52, 40, 31, 36, 4, 10, 8, 24, 22, 42, 63, 35, 60, 47, 29, 46, 19, 1, 3, 34, 55, 59, 14, 39, 12, 32, 50, 62, 54, 56, 51, 57, 15, 41, 18, 37, 9, }, +}; +const pattern_t* patterns[] = {&trivial_pattern, + &pat0, &pat1, &pat2, &pat3, &pat4, &pat5, &pat6, &pat7, + &pat8, &pat9, &pat10, &pat11, &pat12, &pat13, &pat14, &pat15, + &pat16, &pat17, &pat18, &pat19, &pat20, &pat21, &pat22, &pat23, + &pat24, &pat25, &pat26, &pat27, &pat28, &pat29, &pat30, &pat31}; + +//static variables used by the worker threads +static int outfd = 0; +static sem_t chunk_sems[NUM_THREADS - 1][NUM_CHUNKS]; + +static void +usage() +{ + (void) fprintf(stderr, "usage: fsync_integrity \n"); + exit(2); +} + + +/* Fills a buffer with a special marker. The marker contains information about + * the file offset where this buffer is supposed to go, and whether it will + * be written by a leader or a follower */ +static void +marker_fill(uint64_t* buf, int file_ofs, size_t len, int thread_num){ + int ofs; + uint32_t thread_mark = thread_num; + uint32_t final_mark = 0xe005b0ca; //"CABOOSE" in little endian + for (ofs = file_ofs; ofs < file_ofs + len; ofs += sizeof(uint64_t)){ + uint64_t mark = ((thread_num == (NUM_THREADS - 1) ? + (uint64_t)final_mark : (uint64_t)thread_mark) << (uint64_t)32) | + htonl(ofs & 0xFFFFFFFF); + int buf_idx = (ofs - file_ofs) / sizeof(uint64_t); + buf[buf_idx] = mark; + } +} + +static int +verify_file(int fd, const pattern_t* p_pat){ + int chunk_idx; + int good_data = 1; + int err = 0; + + for(chunk_idx=0; chunk_idx < NUM_CHUNKS; chunk_idx++){ + int i; + uint32_t chunk_start, chunk_end; + get_chunk_range(p_pat, chunk_idx, &chunk_start, &chunk_end); + size_t size = chunk_end - chunk_start; + uint64_t* desired_buf = malloc(size); + uint64_t* actual_buf = malloc(size); + marker_fill(desired_buf, chunk_start, size, NUM_THREADS - 1); + + //read the actual data from the file + if( read(fd, actual_buf, size) <= 0 ){ + perror("read"); + exit(1); + } + + //verify the data + for(i=0; i < size / sizeof(uint64_t); i++){ + int chunk_offset = sizeof(uint64_t) * i; + int file_offset = chunk_start + chunk_offset; + if (good_data && (actual_buf[i] != desired_buf[i])){ + fprintf(stderr, "fsync_integrity: miscompare at " + "chunk %i, chunk offset %lx, file offset %lx\n", + chunk_idx, chunk_offset, file_offset); + fprintf(stderr, "Expected %016lx, got %016lx\n", + desired_buf[i], actual_buf[i]); + err = 1; + good_data = 0; + } + else if (!good_data && (actual_buf[i] == desired_buf[i])) { + fprintf(stderr, "fsync_integrity: miscompare ends at " + "chunk %i, chunk offset %lx, file offset %lx\n", + chunk_idx, chunk_offset, file_offset); + good_data = 1; + } + } + free(desired_buf); + free(actual_buf); + } + + return (err); +} + +/* Writes a special marker to every byte within the chunk */ +static void +write_chunk(pattern_t* p_pat, int chunk_idx, int thread_num) +{ + uint32_t chunk_start, chunk_end; + get_chunk_range(p_pat, chunk_idx, &chunk_start, &chunk_end); + size_t size = chunk_end - chunk_start; + uint64_t* buf = malloc(size); + marker_fill(buf, chunk_start, size, thread_num); + pwrite(outfd, (void*)buf, size, chunk_start); + free(buf); +} + +static void +my_sync(int fd){ + if (fsync(fd)){ + perror("fsync"); + exit(1); + } +} + + +static void* +worker(void* args) +{ + int perm_idx, thread_num; + thread_data_t* data; + + data = (thread_data_t*)args; + thread_num = data->thread_num; + + for(perm_idx = 0; perm_idx < NUM_CHUNKS; perm_idx++) + { + int chunk_idx = data->pat->permutation[perm_idx]; + /* Acquire the semaphore, if necessary */ + if (thread_num > 0) { + if (-1 == sem_wait(&chunk_sems[thread_num - 1][chunk_idx])){ + perror("sem_wait"); + exit(1); + } + } + /* Write the data */ + write_chunk(data->pat, chunk_idx, thread_num); + /* Sync, if we are an even thread */ + if ((thread_num % 2) == 0) + my_sync(outfd); + /* Post the final semaphore, if necessary */ + if (thread_num < NUM_THREADS - 1) { + if (sem_post(&chunk_sems[thread_num][chunk_idx]) == -1){ + perror("sem_post"); + exit(1); + } + } + } + return 0; +} + + +int +main(int argc, char** argv) +{ + int rep; + int pat; + pthread_t threads[NUM_THREADS]; + thread_data_t thread_data[NUM_THREADS]; + + if (argc != 2){ + usage(); + } + + for(rep=0; rep < NUM_REPETITIONS; rep++){ + printf("Starting repetition %d\n", rep); + for(pat=0; pat < sizeof(patterns) / sizeof(patterns[0]); pat++){ + int i; + const pattern_t *pat_p = patterns[pat]; +/* pattern_t *pat_p = (void *)(uintptr_t)(const void *)patterns[pat];*/ + int sem_idx; + int ofs=0; + +/* printf("Starting on patterns[%d]\n" , pat);*/ + outfd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0644); + if (outfd == -1){ + perror("open"); + exit(1); + } + + //set the file size + if ( ftruncate(outfd, FSIZE)){ + perror("ftruncate"); + exit(1); + } + + //Zero-fill the file to avoid fragmentation, as recommended by mmap(2). + for(ofs=0; ofs < FSIZE; ofs+=CLUSTERSIZE){ + char buffer[CLUSTERSIZE]; + bzero(buffer, CLUSTERSIZE); + if ( -1 == write(outfd, buffer, CLUSTERSIZE)){ + perror("write"); + exit(1); + } + } + //Return the file pointer to the beginning prior to mmap + if (-1 == lseek(outfd, 0, SEEK_SET)){ + perror("lseek"); + } + + //Create the semaphores + for(i=0; i < NUM_THREADS - 1; i++) { + for(sem_idx=0; sem_idx < NUM_CHUNKS; sem_idx++){ + if (sem_init(&chunk_sems[i][sem_idx], 0, 0)){ + perror("sem_init"); + exit(1); + } + } + } + + //Create the worker threads + for(i=0; i < NUM_THREADS; i++) { + thread_data[i].pat = pat_p; + thread_data[i].thread_num = i; + if (pthread_create(&threads[i], NULL, worker, (void*)&thread_data[i])){ + perror("pthread_create"); + exit(1); + } + } + + //Join the threads + for(i=0; i < NUM_THREADS; i++) { + if (pthread_join(threads[i], NULL)){ + perror("pthread_join"); + exit(1); + } + } + + //destroy the semaphores + for(i=0; i < NUM_THREADS - 1; i++) { + for(sem_idx=0; sem_idx < NUM_CHUNKS; sem_idx++){ + if (sem_destroy(&chunk_sems[i][sem_idx])){ + perror("sem_destory"); + exit(1); + } + } + } + //printf("destroyed semaphores\n"); + + + //Verify the contents of the file. + if (verify_file(outfd, patterns[pat])) { + exit(1); + } + //printf("finished verify_file\n"); + + //close the file: + if (close(outfd)){ + perror("close"); + exit(1); + } + } + } + + return 0; +} diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/fsync_integrity_001_pos.ksh b/tests/sys/cddl/zfs/tests/txg_integrity/fsync_integrity_001_pos.ksh new file mode 100644 index 00000000000..d3324f9eb4a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/fsync_integrity_001_pos.ksh @@ -0,0 +1,83 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + +. ${STF_SUITE}/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: fsync_integrity_001_pos +# +# DESCRIPTION: +# +# Verify the integrity of non-aligned writes to the same blocks within the same +# transaction group, where an fsync is issued by a non-final writer. +# +# STRATEGY: + +# This test verifies that the unoverride in the following sequence of events is +# handled correctly: +# +# 1) A new transaction group opens +# 2) A write is issued to a certain block +# 3) The writer fsyncs() that file +# 4) TBD module immediately writes that block, then places an override in the +# syncer's TBD data structure, indicating that it doesn't need to write that +# block when syncing. +# 5) Another write is issued to the same block, with different data. +# 6) TBD module unoverrides that block in the syncer's TBD data structure +# 7) The syncer writes that block +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: BEGIN (2013-1-21) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +log_assert "Verify the integrity of non-aligned writes to the same blocks within the same transaction group, where an fsync is issued by a non-final writer." + +# Run the test program +fsync_integrity ${TESTDIR}/${TESTFILE} + +# Success is indicated by the return status +if [[ $? -ne 0 ]]; then + log_fail "Test failed to execute or file became corrupted" +else + log_pass +fi + + diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/make_patterns.py b/tests/sys/cddl/zfs/tests/txg_integrity/make_patterns.py new file mode 100644 index 00000000000..546eda1d346 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/make_patterns.py @@ -0,0 +1,59 @@ +#! /usr/bin/env python + +# $FreeBSD$ + +# Generate random IO patterns for the txg_integrity test +# We do this statically and embed the results into the code so that the +# Testing will be more repeatable compared to generating the tables at runtime + +import random + +CLUSTERSIZE = (1 << 16) +NUM_CHUNKS = 64 + + +def rand_partition(): + partitions = [] + while len(partitions) != NUM_CHUNKS: + # We don't want any duplicates, so we make a set and then check that + # its length is correct + partitions = sorted( + list( + set( + [random.randrange(0, + 2**31, + (2**31) * 8 / (NUM_CHUNKS * CLUSTERSIZE)) + for i in range(NUM_CHUNKS - 1)] + [2**31]))) + return partitions + + +def rand_permutation(): + perm = range(NUM_CHUNKS) + random.shuffle(perm) + return perm + + +def rand_follower_bitmap(): + bmp = 0 + chunks = random.sample(range(NUM_CHUNKS), NUM_CHUNKS / 2) + for chunk in chunks: + bmp |= (1 << chunk) + return bmp + + +def print_pattern(n): + print "const pattern_t pat%d = {" % n + print " {", + for p in rand_partition(): + print "%#x, " % p, + print " }," + print " {", + for p in rand_permutation(): + print "%d, " % p, + print " }," + print " %#x" % rand_follower_bitmap() + print "};" + + +for n in range(32): + print_pattern(n) diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/setup.ksh b/tests/sys/cddl/zfs/tests/txg_integrity/setup.ksh new file mode 100644 index 00000000000..36ca36cbfbc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/setup.ksh @@ -0,0 +1,49 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2011 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.0 10/20/11 SL" +# + +. ${STF_SUITE}/include/libtest.kshlib + +# For this test, we create an MD instead of using the defined DISKS. +# Data corrupts much more quickly on an MD. +# Make it small enough that we can tar up the entire pool for post-mortem +# analysis +log_must $MDCONFIG -a -t swap -s 1g -u $TESTCASE_ID + +log_must create_pool $TESTPOOL $TESTDEV +$RM -rf $TESTDIR +$MKDIR -p $TESTDIR + +log_must $ZFS create $TESTPOOL/$TESTFS +log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + +log_pass + + diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.c b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.c new file mode 100644 index 00000000000..3200fca3bc9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.c @@ -0,0 +1,609 @@ +/* + * 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 + * $FreeBSD$ + */ + +/* + * Copyright 2011-2012 Spectra Logic. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Verify the integrity of non-aligned writes to the same blocks that cross + * transaction groups. + * + * This test verifies that non-aligned writes are correctly committed to the + * file system, even adjacent transaction groups include writes to the same + * blocks. The test runs through multiple repetitions in an attempt to trigger + * race conditions. + * + * Outline: + * Create a 32MB file. + * Create a bunch of different IO patterns. Each IO pattern consists of: + * * A partition of the 32MB range into 64 different non-overlapping chunks. + * * A permutation of those chunks + * * A selection of 32 chunks that will be written by the follower. + * For each repetitions: + * For each IO pattern: + * For each phase (leader syncs and follower syncs): + * Create one binary semaphore per chunk. + * Create two threads, a leader and a follower thread. + * The leader thread will write each chunk in order. It will post a + * semaphore after each write to indicate that it has completed + * writing that chunk. If this is the "leader syncs" phase, it will + * call fsync() halfway through to force the closure of a transaction + * group. + * The follower will pend on those semaphores in order. Each time it + * receives a semaphore, it will write a different pattern to that + * chunk. If this is the "follower syncs" phase, it will call fsync() + * halfway through to force the closure of a transaction group. + * Join both threads + * Read the entire file and verify that + * 1) Every write went to the correct location + * 2) Each of the follower's writes overwrote the leader's. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NUM_REPETITIONS 15 +#define CLUSTERSIZE (1 << 16) +#define NUM_CHUNKS 64 +#define FSIZE (512 * (CLUSTERSIZE)) //FSIZE may range from NUM_CHUNKS clusters to 8GB +#define USE_THREADS 1 +#define USE_MMAP 0 + +typedef struct { + //partitions describes the boundaries between chunks. Each element is a + //fraction of the filesize in 1.31 fixed point format. So the boundary + //between chunk n and chunk n-1 is (FSIZE * partitions[n-1] / (1<<31) . + //partitions[-1] is understood to be 0 and partitions[NUM_CHUNKS] must be 1.0 + //partitions is sorted, of course. + //Partition boundaries must be dword aligned. Thus, in order to work with + //multiple values of FSIZE, partitions values must be aligned to multiples of + //8 / (NUM_CHUNKS * CLUSTERSIZE) = 1 / 524288 = 0x0.00002 + uint32_t partitions[NUM_CHUNKS]; + int permutation[NUM_CHUNKS]; //the order in which to write the chunks + //a bitmap of the chunks that should be written by the follower + //chunk 0 corresponds to bit 1, chunk 1 to bit 2, etc + uint64_t follower_chunks; +} pattern_t; + + +/* Returns (via begin and end) the range of a chunk. Begin is inclusive, + * end is exclusive */ +void get_chunk_range(const pattern_t* pat, int chunk, uint32_t* begin, uint32_t* end){ + if (chunk == 0){ + *begin = 0; + } + else{ + *begin = (uint32_t)((uint64_t)FSIZE * (uint64_t)pat->partitions[chunk - 1] >> 31); + } + *end = (uint32_t)((uint64_t)FSIZE * (uint64_t)pat->partitions[chunk] >> 31); +} + + +typedef enum{ + leader_syncs = 0, + follower_syncs, + NUM_PHASES +} phase_t; + +/* The most basic, trivial IO pattern. Fully sequential, and the follower + * writes every other block */ +const pattern_t trivial_pattern = { + {0x2000000, 0x4000000, 0x6000000, 0x8000000, 0xa000000, 0xc000000, 0xe000000, 0x10000000, + 0x12000000, 0x14000000, 0x16000000, 0x18000000, 0x1a000000, 0x1c000000, 0x1e000000, 0x20000000, + 0x22000000, 0x24000000, 0x26000000, 0x28000000, 0x2a000000, 0x2c000000, 0x2e000000, 0x30000000, + 0x32000000, 0x34000000, 0x36000000, 0x38000000, 0x3a000000, 0x3c000000, 0x3e000000, 0x40000000, + 0x42000000, 0x44000000, 0x46000000, 0x48000000, 0x4a000000, 0x4c000000, 0x4e000000, 0x50000000, + 0x52000000, 0x54000000, 0x56000000, 0x58000000, 0x5a000000, 0x5c000000, 0x5e000000, 0x60000000, + 0x62000000, 0x64000000, 0x66000000, 0x68000000, 0x6a000000, 0x6c000000, 0x6e000000, 0x70000000, + 0x72000000, 0x74000000, 0x76000000, 0x78000000, 0x7a000000, 0x7c000000, 0x7e000000, 0x80000000}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}, + 0x5555555555555555 +}; + +//The below patterns were randomly generated +const pattern_t pat0 = { + { 0x1eac000, 0x88a4000, 0xaffe000, 0xcdb7000, 0xd2d5000, 0xe16f000, 0xe499000, 0x11f71000, 0x1242d000, 0x12c07000, 0x143bc000, 0x1460a000, 0x15dd7000, 0x1700e000, 0x1be7e000, 0x1e14d000, 0x1e6ac000, 0x21097000, 0x24b74000, 0x27166000, 0x27669000, 0x30539000, 0x3218b000, 0x37591000, 0x37b60000, 0x39818000, 0x39d08000, 0x3c90e000, 0x3e54f000, 0x3fb99000, 0x42c8e000, 0x43a62000, 0x43f50000, 0x4c0c9000, 0x4c422000, 0x4c737000, 0x4d41e000, 0x4d738000, 0x4da71000, 0x4f4e8000, 0x508e3000, 0x51396000, 0x51ab5000, 0x52a02000, 0x54238000, 0x54d6a000, 0x55029000, 0x5584b000, 0x5c42c000, 0x5c4a7000, 0x5dac5000, 0x5fe4d000, 0x63f86000, 0x66ad0000, 0x67b3d000, 0x69ce5000, 0x6c179000, 0x6e79e000, 0x6f83f000, 0x71165000, 0x72bd9000, 0x7ac79000, 0x7dc94000, 0x80000000, }, + { 57, 16, 28, 25, 10, 59, 52, 46, 30, 6, 40, 36, 39, 9, 21, 51, 33, 45, 44, 19, 2, 50, 55, 5, 58, 13, 23, 0, 12, 53, 42, 32, 31, 48, 35, 61, 49, 54, 18, 24, 8, 41, 62, 4, 47, 17, 1, 3, 34, 14, 63, 22, 15, 26, 38, 56, 27, 60, 29, 11, 7, 43, 20, 37, }, + 0xa2f002a1a7795bbb +}; +const pattern_t pat1 = { + { 0x2b5000, 0x16db000, 0x5eb5000, 0x93a0000, 0xa7cb000, 0xa9e9000, 0xd144000, 0xe7c2000, 0xeb7d000, 0x10919000, 0x10cbd000, 0x11f85000, 0x17360000, 0x1760a000, 0x18eab000, 0x1ae6b000, 0x1c5f6000, 0x1df38000, 0x21bec000, 0x239d1000, 0x26b81000, 0x2747b000, 0x27a03000, 0x2b3cc000, 0x2cbf9000, 0x2ec0f000, 0x30a68000, 0x30bea000, 0x30c64000, 0x311af000, 0x35823000, 0x35d23000, 0x3b20e000, 0x405d8000, 0x414c8000, 0x43a91000, 0x44049000, 0x4ab4e000, 0x4ae21000, 0x4d293000, 0x511e5000, 0x516fc000, 0x52d77000, 0x57229000, 0x5da57000, 0x5dbe6000, 0x6070e000, 0x60fc0000, 0x64b24000, 0x67636000, 0x67658000, 0x6b040000, 0x6b28f000, 0x6e551000, 0x707c0000, 0x71b5c000, 0x72062000, 0x762a1000, 0x788a0000, 0x7a1e1000, 0x7b06a000, 0x7e04c000, 0x7f4cf000, 0x80000000, }, + { 45, 8, 55, 9, 21, 54, 41, 7, 6, 22, 31, 47, 23, 11, 48, 53, 0, 61, 63, 50, 17, 27, 12, 19, 10, 40, 14, 51, 39, 59, 2, 43, 18, 42, 52, 28, 16, 44, 3, 5, 15, 35, 58, 33, 57, 49, 34, 30, 46, 4, 37, 60, 32, 36, 25, 56, 24, 13, 20, 38, 29, 26, 62, 1, }, + 0xc88ca673fa160cbe +}; +const pattern_t pat2 = { + { 0x912d000, 0xe610000, 0xf755000, 0x116df000, 0x128e5000, 0x1bd51000, 0x24e9a000, 0x27643000, 0x28cf4000, 0x292c9000, 0x2c907000, 0x2d389000, 0x2d941000, 0x2eb3f000, 0x30e94000, 0x31738000, 0x3343b000, 0x342ce000, 0x34d12000, 0x3536d000, 0x35e1a000, 0x35e4d000, 0x35fd5000, 0x3642b000, 0x3924d000, 0x392a5000, 0x3e531000, 0x3f0ee000, 0x3fdf8000, 0x41593000, 0x41c80000, 0x43959000, 0x43bc0000, 0x461c8000, 0x48922000, 0x49519000, 0x4f6fa000, 0x50274000, 0x508ae000, 0x536ed000, 0x54154000, 0x59894000, 0x5a666000, 0x5b0a6000, 0x5b9ff000, 0x5c109000, 0x5d8d0000, 0x5ddc5000, 0x5fcc5000, 0x63366000, 0x63adc000, 0x645b6000, 0x670eb000, 0x6b1b1000, 0x6c996000, 0x6ed2a000, 0x6ee4f000, 0x71fcd000, 0x734a3000, 0x76bdf000, 0x77b3f000, 0x7c65a000, 0x7d200000, 0x80000000, }, + { 31, 35, 36, 52, 27, 56, 40, 13, 51, 49, 43, 37, 62, 42, 24, 29, 48, 25, 7, 61, 22, 57, 11, 32, 2, 54, 41, 6, 55, 15, 20, 26, 63, 44, 12, 4, 19, 58, 60, 59, 47, 23, 30, 50, 53, 34, 9, 38, 45, 8, 28, 3, 16, 33, 5, 21, 1, 10, 46, 18, 0, 14, 39, 17, }, + 0x51ac7692bd1a78d2 +}; +const pattern_t pat3 = { + { 0x553000, 0x19de000, 0x6a20000, 0x8a53000, 0x8ef9000, 0xc325000, 0x1132e000, 0x139fa000, 0x1426b000, 0x150ff000, 0x1bbc1000, 0x1e84c000, 0x1f43e000, 0x1f731000, 0x21ec8000, 0x231f4000, 0x23440000, 0x23466000, 0x260b6000, 0x286a7000, 0x29518000, 0x29e35000, 0x2fdb7000, 0x3089d000, 0x362e0000, 0x3c1f9000, 0x3df2d000, 0x3fce6000, 0x402f3000, 0x4117f000, 0x41e06000, 0x4374f000, 0x451e5000, 0x45a59000, 0x4956b000, 0x4960f000, 0x4a934000, 0x4bc6f000, 0x4d462000, 0x4eef8000, 0x4f609000, 0x50dc1000, 0x51022000, 0x54396000, 0x5641b000, 0x578f1000, 0x589cf000, 0x59093000, 0x5da6b000, 0x5fbf0000, 0x605a2000, 0x65428000, 0x65530000, 0x6705a000, 0x6db65000, 0x71cef000, 0x725a2000, 0x73bf5000, 0x75acb000, 0x76065000, 0x7614c000, 0x77aab000, 0x78f70000, 0x80000000, }, + { 15, 30, 31, 16, 49, 13, 55, 59, 4, 24, 26, 44, 17, 0, 18, 54, 10, 3, 46, 34, 29, 22, 45, 5, 38, 32, 39, 50, 48, 53, 12, 25, 35, 56, 51, 52, 1, 33, 43, 63, 47, 37, 23, 20, 60, 14, 11, 21, 8, 57, 27, 41, 6, 58, 62, 2, 19, 61, 28, 36, 40, 7, 9, 42, }, + 0x7d291499a7ecc986 +}; +const pattern_t pat4 = { + { 0x425000, 0x8e8000, 0x4b90000, 0x883c000, 0x968e000, 0xbacc000, 0x10e59000, 0x125a1000, 0x12f00000, 0x14e7c000, 0x156de000, 0x192a1000, 0x1a2b9000, 0x1b4a0000, 0x1be9c000, 0x1d3bd000, 0x24242000, 0x2516b000, 0x2b88d000, 0x2b96a000, 0x2bcd3000, 0x2c5a9000, 0x2da74000, 0x2dba1000, 0x3097f000, 0x332ef000, 0x34525000, 0x36193000, 0x3725c000, 0x37e66000, 0x3d315000, 0x3e813000, 0x404ae000, 0x40c68000, 0x42f93000, 0x44b14000, 0x44b15000, 0x473b2000, 0x49048000, 0x4c794000, 0x50b60000, 0x52b3d000, 0x58c61000, 0x5b7d4000, 0x5ce71000, 0x5d21d000, 0x5d63e000, 0x5e00f000, 0x60e8b000, 0x66381000, 0x66c70000, 0x68430000, 0x707c2000, 0x71979000, 0x72681000, 0x74017000, 0x7721d000, 0x7a1be000, 0x7a2cd000, 0x7b225000, 0x7c311000, 0x7e03a000, 0x7e402000, 0x80000000, }, + { 52, 62, 28, 47, 51, 37, 31, 36, 4, 58, 26, 29, 16, 59, 57, 33, 22, 27, 49, 44, 19, 56, 34, 23, 5, 14, 45, 48, 21, 25, 18, 12, 43, 53, 60, 17, 46, 15, 63, 30, 42, 38, 41, 8, 39, 20, 1, 10, 54, 40, 32, 24, 9, 2, 35, 3, 7, 0, 61, 11, 13, 55, 6, 50, }, + 0xd0e57ce640cdc726 +}; +const pattern_t pat5 = { + { 0xae7000, 0x436e000, 0x81e1000, 0xb276000, 0xf8bf000, 0xfb26000, 0xfe7e000, 0x137ad000, 0x14b8e000, 0x157aa000, 0x1981a000, 0x1a32f000, 0x1bc9e000, 0x1def5000, 0x1e8ef000, 0x2068f000, 0x22692000, 0x22a6c000, 0x255bf000, 0x26977000, 0x27619000, 0x2977c000, 0x2ce0c000, 0x2e1ec000, 0x2e26c000, 0x31ce8000, 0x34e6c000, 0x365cd000, 0x37e87000, 0x385e3000, 0x3a7e2000, 0x3a9c7000, 0x41597000, 0x42e8a000, 0x453cc000, 0x454bf000, 0x4b24c000, 0x4ba54000, 0x4e307000, 0x4f059000, 0x55d5a000, 0x56277000, 0x56b90000, 0x5882d000, 0x5a2c5000, 0x5b369000, 0x5d442000, 0x5d671000, 0x5fdd0000, 0x60ce0000, 0x63713000, 0x64130000, 0x65973000, 0x67ad9000, 0x68764000, 0x68bb2000, 0x690d1000, 0x6a2c8000, 0x73e9f000, 0x74e75000, 0x77861000, 0x77ee5000, 0x7cddb000, 0x80000000, }, + { 42, 25, 15, 58, 32, 61, 30, 56, 48, 62, 38, 50, 7, 45, 16, 29, 12, 4, 41, 3, 27, 18, 57, 10, 51, 17, 21, 14, 35, 19, 44, 47, 49, 26, 59, 63, 28, 55, 20, 13, 5, 6, 37, 54, 40, 22, 23, 46, 11, 36, 34, 31, 2, 60, 9, 52, 24, 1, 53, 0, 39, 43, 8, 33, }, + 0xc8b474decf8e9c40 +}; +const pattern_t pat6 = { + { 0xad2000, 0x222f000, 0x64b4000, 0x6c66000, 0x6f35000, 0x9e50000, 0xe744000, 0xf129000, 0x101bb000, 0x11bf8000, 0x14b89000, 0x1691c000, 0x17a0d000, 0x1817a000, 0x1997a000, 0x1d736000, 0x1db33000, 0x1fdd8000, 0x21e56000, 0x2266c000, 0x22875000, 0x22b84000, 0x230ed000, 0x239c5000, 0x24e1a000, 0x275f5000, 0x29036000, 0x29f69000, 0x2e538000, 0x2efca000, 0x2f0bc000, 0x2f1bf000, 0x305cb000, 0x31ce7000, 0x345c4000, 0x35d4f000, 0x36e56000, 0x3ae9e000, 0x3cc27000, 0x40117000, 0x4299f000, 0x434c3000, 0x443d4000, 0x4552d000, 0x4a8a8000, 0x4cdea000, 0x51bd5000, 0x580c4000, 0x58381000, 0x59dc0000, 0x5ba7f000, 0x5d88b000, 0x5e0c4000, 0x5ee57000, 0x61f3f000, 0x63a4a000, 0x68a8a000, 0x68ec5000, 0x6937b000, 0x720be000, 0x72cf5000, 0x74fc8000, 0x76464000, 0x80000000, }, + { 31, 46, 36, 22, 63, 12, 51, 60, 13, 44, 41, 6, 11, 17, 42, 24, 16, 61, 20, 26, 35, 21, 29, 55, 50, 45, 62, 19, 54, 9, 30, 34, 53, 52, 10, 39, 0, 49, 48, 38, 40, 28, 23, 56, 2, 5, 4, 59, 14, 57, 3, 25, 43, 32, 27, 47, 8, 7, 37, 33, 1, 18, 58, 15, }, + 0xe5172947f6d4e10a +}; +const pattern_t pat7 = { + { 0xd83000, 0x1597000, 0x245b000, 0x6a75000, 0x8fda000, 0x960e000, 0xd310000, 0xe6cd000, 0x1409a000, 0x15221000, 0x16059000, 0x1b3a4000, 0x1ceea000, 0x1ed1a000, 0x1ef0f000, 0x21723000, 0x21efc000, 0x24594000, 0x26d7f000, 0x28c4f000, 0x2fa89000, 0x304f0000, 0x30dbb000, 0x30de3000, 0x3365d000, 0x36dbc000, 0x3acb2000, 0x3e291000, 0x3f7da000, 0x41352000, 0x41a0f000, 0x435c8000, 0x4475a000, 0x47536000, 0x47726000, 0x4a81f000, 0x4be4e000, 0x4bf05000, 0x4c15b000, 0x515b4000, 0x52ef5000, 0x548cc000, 0x5692a000, 0x59ef2000, 0x5b97c000, 0x5c4f0000, 0x5d1b9000, 0x618ed000, 0x61bcc000, 0x61e07000, 0x639a3000, 0x65302000, 0x68041000, 0x6be56000, 0x721a3000, 0x72c99000, 0x740b9000, 0x7586d000, 0x75eca000, 0x76406000, 0x7b68a000, 0x7dd26000, 0x7ed55000, 0x80000000, }, + { 44, 57, 22, 35, 63, 11, 15, 49, 61, 40, 29, 20, 19, 42, 32, 12, 41, 6, 46, 60, 52, 5, 36, 10, 2, 8, 3, 33, 54, 39, 58, 48, 62, 7, 51, 34, 0, 1, 18, 9, 55, 31, 23, 38, 25, 21, 17, 24, 13, 50, 16, 14, 43, 53, 45, 28, 59, 37, 26, 30, 47, 27, 56, 4, }, + 0xc509d471a7ae3363 +}; +const pattern_t pat8 = { + { 0x1b8000, 0x27eb000, 0x5a4d000, 0x6ecc000, 0xb52e000, 0xb70e000, 0xc6db000, 0xd83d000, 0xed51000, 0x13c59000, 0x13fef000, 0x142e1000, 0x192d0000, 0x1aa63000, 0x1e230000, 0x1f464000, 0x20de4000, 0x2234b000, 0x25459000, 0x27018000, 0x28263000, 0x29cc7000, 0x32227000, 0x32c63000, 0x34af0000, 0x37e27000, 0x3afc9000, 0x3c166000, 0x3df20000, 0x405bd000, 0x41273000, 0x45c39000, 0x471be000, 0x4758e000, 0x4b3fc000, 0x4c6b2000, 0x4c80f000, 0x4ccd6000, 0x4d9e0000, 0x4e07f000, 0x4eeda000, 0x541ae000, 0x58aa7000, 0x5a2c6000, 0x5a628000, 0x5ab94000, 0x5bddc000, 0x5d1d4000, 0x5e643000, 0x5f72f000, 0x64771000, 0x67bd4000, 0x6a28c000, 0x6c977000, 0x6cc4e000, 0x710c4000, 0x74b86000, 0x75cf7000, 0x77d4b000, 0x7870e000, 0x7c47c000, 0x7eb52000, 0x7fbea000, 0x80000000, }, + { 7, 29, 62, 8, 54, 38, 35, 45, 60, 55, 1, 40, 4, 19, 50, 63, 48, 51, 13, 27, 33, 39, 52, 46, 10, 9, 56, 2, 42, 43, 47, 44, 17, 5, 25, 6, 57, 23, 15, 58, 59, 22, 14, 26, 32, 61, 30, 0, 11, 12, 36, 24, 53, 49, 3, 20, 31, 28, 34, 18, 41, 21, 16, 37, }, + 0x8b938ea7b599224d +}; +const pattern_t pat9 = { + { 0x5b59000, 0xa6d7000, 0xbad3000, 0xdf91000, 0x115ad000, 0x13fde000, 0x17618000, 0x1b8e9000, 0x1e1b7000, 0x1e97d000, 0x21737000, 0x21a5e000, 0x24140000, 0x2558f000, 0x2647a000, 0x28257000, 0x285f6000, 0x2cb7a000, 0x2ebb1000, 0x30ae8000, 0x31543000, 0x315cb000, 0x31616000, 0x335ba000, 0x33ed6000, 0x35cf3000, 0x4162b000, 0x4409b000, 0x4629a000, 0x4b745000, 0x4c0ba000, 0x4cbc5000, 0x4dd97000, 0x4f34b000, 0x4f637000, 0x539d6000, 0x53f3d000, 0x56383000, 0x5642b000, 0x5a71f000, 0x5affa000, 0x5b486000, 0x5b8ef000, 0x60d88000, 0x61629000, 0x625cd000, 0x63326000, 0x6735e000, 0x67379000, 0x6a26a000, 0x6a281000, 0x6b997000, 0x6c50d000, 0x6cc6c000, 0x6f496000, 0x717ad000, 0x732ec000, 0x744dc000, 0x771e8000, 0x77cf0000, 0x79cad000, 0x7bb21000, 0x7e7b4000, 0x80000000, }, + { 35, 9, 46, 6, 29, 2, 3, 54, 55, 57, 41, 16, 44, 5, 0, 59, 10, 61, 22, 42, 47, 12, 14, 50, 39, 34, 21, 32, 25, 15, 26, 8, 38, 60, 28, 53, 62, 49, 58, 43, 36, 37, 52, 7, 19, 63, 17, 11, 45, 33, 23, 27, 24, 18, 48, 56, 31, 13, 51, 30, 4, 20, 40, 1, }, + 0xfc4c41bb3d34a11d +}; +const pattern_t pat10 = { + { 0xa72000, 0x180a000, 0x6406000, 0x66df000, 0x83bb000, 0xa96f000, 0xd193000, 0x13b9b000, 0x13dae000, 0x16109000, 0x1853d000, 0x18887000, 0x19f0a000, 0x22151000, 0x229ba000, 0x26b58000, 0x2aaf4000, 0x2bf50000, 0x31a2e000, 0x31d4e000, 0x32196000, 0x3513a000, 0x36a2d000, 0x3746b000, 0x389ad000, 0x39d27000, 0x3dad3000, 0x3de55000, 0x3ea9b000, 0x3ec06000, 0x3f921000, 0x432d3000, 0x43bec000, 0x43dda000, 0x47b2b000, 0x4886e000, 0x4928e000, 0x49ad2000, 0x4d0df000, 0x4f40d000, 0x50959000, 0x54fa4000, 0x56091000, 0x5688d000, 0x5b7d8000, 0x5f6fd000, 0x601e4000, 0x64eaa000, 0x6752e000, 0x67fff000, 0x6a184000, 0x6ad7a000, 0x6adbc000, 0x6c434000, 0x6f451000, 0x6ffb4000, 0x707ee000, 0x71161000, 0x7146b000, 0x75dbf000, 0x77259000, 0x7acd4000, 0x7af71000, 0x80000000, }, + { 61, 38, 5, 23, 62, 11, 53, 9, 17, 45, 30, 29, 41, 60, 39, 21, 40, 19, 44, 33, 42, 50, 56, 28, 32, 46, 43, 20, 16, 3, 54, 8, 4, 26, 15, 34, 47, 12, 6, 27, 48, 0, 1, 2, 57, 59, 7, 58, 49, 35, 24, 37, 52, 63, 10, 55, 36, 13, 14, 25, 18, 22, 31, 51, }, + 0xbaba0d4f32308c7d +}; +const pattern_t pat11 = { + { 0x996000, 0xaff000, 0x199a000, 0x46f3000, 0x74c0000, 0x758d000, 0xcd09000, 0xe48c000, 0xe8de000, 0xf111000, 0xf87b000, 0x10b1c000, 0x15d63000, 0x17b21000, 0x182d3000, 0x19167000, 0x198ce000, 0x1bd47000, 0x1dff1000, 0x1edc0000, 0x1f890000, 0x20860000, 0x23207000, 0x29bd5000, 0x2ac0f000, 0x2e395000, 0x2e707000, 0x329de000, 0x3497f000, 0x3807f000, 0x38a94000, 0x40a19000, 0x4168e000, 0x42ca0000, 0x42de9000, 0x45194000, 0x464f2000, 0x4700f000, 0x47dbb000, 0x4dae7000, 0x50660000, 0x535a8000, 0x5546b000, 0x57b55000, 0x5860a000, 0x5a9ee000, 0x5b8d9000, 0x5c49f000, 0x5cb4d000, 0x5d28c000, 0x60dcd000, 0x62557000, 0x64b0c000, 0x654cb000, 0x65746000, 0x65e29000, 0x6648f000, 0x66c56000, 0x6999e000, 0x6a11c000, 0x6ca04000, 0x79e60000, 0x7edce000, 0x80000000, }, + { 16, 28, 2, 38, 10, 57, 21, 26, 61, 43, 46, 31, 56, 7, 47, 48, 58, 25, 63, 4, 59, 15, 32, 50, 1, 40, 53, 18, 17, 24, 29, 30, 55, 36, 49, 42, 41, 37, 23, 39, 6, 51, 33, 9, 45, 5, 35, 19, 44, 11, 34, 0, 27, 12, 60, 62, 20, 13, 22, 8, 14, 54, 3, 52, }, + 0x6458c1af941ce1f7 +}; +const pattern_t pat12 = { + { 0x513000, 0x1b72000, 0x1e27000, 0x3a63000, 0x1115c000, 0x158b4000, 0x1664f000, 0x1b667000, 0x1f838000, 0x21410000, 0x260c7000, 0x2cd8f000, 0x2ce37000, 0x2df16000, 0x2e59e000, 0x2e8eb000, 0x2ebd2000, 0x2f1d2000, 0x2fc42000, 0x30d00000, 0x31ef1000, 0x3301a000, 0x38097000, 0x38a1e000, 0x3d818000, 0x3e898000, 0x3f90f000, 0x47710000, 0x478bb000, 0x485ab000, 0x48e54000, 0x4cfe1000, 0x53a89000, 0x53d10000, 0x56308000, 0x56f3b000, 0x577f6000, 0x58734000, 0x5889b000, 0x58ad7000, 0x5923a000, 0x59aef000, 0x5dad3000, 0x5e32f000, 0x63b3a000, 0x665c9000, 0x68cde000, 0x69252000, 0x6a777000, 0x6a79a000, 0x6c1f0000, 0x6cb9a000, 0x6d319000, 0x6dc82000, 0x6dd4d000, 0x6e188000, 0x7184d000, 0x7206e000, 0x73980000, 0x740ad000, 0x75473000, 0x7614d000, 0x79b17000, 0x80000000, }, + { 4, 60, 10, 35, 6, 31, 5, 18, 53, 17, 20, 8, 56, 29, 7, 48, 40, 0, 12, 39, 2, 43, 15, 61, 42, 30, 50, 14, 49, 38, 34, 58, 24, 55, 33, 63, 28, 51, 59, 46, 11, 22, 45, 41, 13, 44, 23, 47, 3, 32, 16, 54, 26, 19, 25, 52, 27, 57, 36, 9, 37, 21, 62, 1, }, + 0x1a7a56b619472b96 +}; +const pattern_t pat13 = { + { 0x351e000, 0x5917000, 0xa992000, 0xc471000, 0xc69c000, 0xc6ed000, 0xc919000, 0xd713000, 0xec14000, 0xfa31000, 0x17567000, 0x1d81a000, 0x1f3c8000, 0x215b5000, 0x26e41000, 0x2a2d4000, 0x2b750000, 0x2bea0000, 0x2c5ae000, 0x2ca2c000, 0x30a94000, 0x31074000, 0x314d3000, 0x31b1e000, 0x31de2000, 0x32062000, 0x33da5000, 0x37838000, 0x385ec000, 0x38740000, 0x387f9000, 0x38be6000, 0x3d2f7000, 0x3eaf5000, 0x40266000, 0x402f3000, 0x40fda000, 0x4a4bd000, 0x4b831000, 0x4bfc9000, 0x4ccaa000, 0x4ea43000, 0x50190000, 0x547c8000, 0x58cc6000, 0x58ea5000, 0x59de1000, 0x5c7f1000, 0x5f713000, 0x63f9a000, 0x6686d000, 0x675c1000, 0x6cccc000, 0x6e409000, 0x6fb6d000, 0x71a70000, 0x72f60000, 0x77bd9000, 0x79013000, 0x7a8d3000, 0x7b341000, 0x7d8f7000, 0x7fe43000, 0x80000000, }, + { 10, 52, 48, 8, 34, 4, 35, 19, 3, 17, 54, 45, 31, 38, 24, 44, 21, 36, 22, 11, 43, 40, 39, 26, 5, 30, 2, 7, 57, 12, 20, 32, 62, 15, 55, 14, 25, 58, 6, 33, 49, 9, 59, 27, 13, 63, 42, 61, 1, 51, 0, 50, 37, 47, 16, 18, 41, 56, 60, 46, 23, 28, 53, 29, }, + 0x8eb1b741cb9906f4 +}; +const pattern_t pat14 = { + { 0xf8e000, 0x169a000, 0x3816000, 0x67a9000, 0x89f3000, 0xac97000, 0xc8da000, 0xf077000, 0x119f1000, 0x13902000, 0x19785000, 0x1ca7f000, 0x1f958000, 0x2027d000, 0x2251f000, 0x24661000, 0x25604000, 0x2b924000, 0x2be5f000, 0x2ec27000, 0x330a5000, 0x3349e000, 0x33a84000, 0x344fa000, 0x34514000, 0x37966000, 0x37f0b000, 0x37fcd000, 0x386d0000, 0x39600000, 0x39de4000, 0x3e601000, 0x3e7f1000, 0x42c61000, 0x48806000, 0x4d3d0000, 0x4f5ff000, 0x512c1000, 0x53fd4000, 0x59440000, 0x5b386000, 0x5e8a0000, 0x5fca3000, 0x6016c000, 0x61ca8000, 0x64915000, 0x66b99000, 0x67226000, 0x69b2f000, 0x6a473000, 0x6a590000, 0x6c844000, 0x6cb8c000, 0x713b5000, 0x7558a000, 0x75eab000, 0x76d15000, 0x77efe000, 0x78762000, 0x7bddc000, 0x7ce92000, 0x7dc44000, 0x7f54b000, 0x80000000, }, + { 54, 31, 48, 10, 51, 49, 55, 19, 38, 18, 44, 5, 17, 20, 16, 11, 9, 3, 42, 59, 63, 45, 25, 60, 57, 21, 40, 29, 0, 39, 26, 7, 53, 12, 13, 2, 58, 41, 22, 8, 14, 28, 46, 24, 27, 6, 52, 32, 56, 4, 30, 36, 15, 47, 23, 37, 43, 35, 50, 33, 61, 34, 1, 62, }, + 0xa13fa3d92bcc578 +}; +const pattern_t pat15 = { + { 0xe16000, 0xec6000, 0xf6b000, 0x634b000, 0x6896000, 0x91db000, 0xc2c8000, 0xe083000, 0xfd7f000, 0x10479000, 0x17740000, 0x18292000, 0x1aaca000, 0x1cb55000, 0x1d2be000, 0x222af000, 0x2cb03000, 0x2fabc000, 0x32034000, 0x35c0f000, 0x3c5ec000, 0x40908000, 0x4128e000, 0x44411000, 0x44bcd000, 0x4f0ac000, 0x5167b000, 0x5541c000, 0x581bc000, 0x584e5000, 0x588fb000, 0x593d3000, 0x5b25d000, 0x5dc99000, 0x60b35000, 0x60ffc000, 0x638e8000, 0x63cf8000, 0x64ee1000, 0x6523c000, 0x654a1000, 0x687bf000, 0x68bef000, 0x69826000, 0x69d90000, 0x6a622000, 0x6d1b9000, 0x6d1e1000, 0x6d886000, 0x6fe4a000, 0x6feac000, 0x720b2000, 0x734dc000, 0x73530000, 0x73f1e000, 0x7479c000, 0x76e33000, 0x786dc000, 0x79b40000, 0x79e49000, 0x7b66c000, 0x7b904000, 0x7c906000, 0x80000000, }, + { 6, 17, 62, 20, 61, 32, 22, 14, 28, 18, 3, 42, 63, 43, 46, 34, 29, 30, 35, 1, 37, 40, 10, 26, 5, 31, 15, 54, 8, 33, 9, 4, 39, 53, 23, 25, 41, 59, 12, 13, 60, 2, 7, 56, 58, 27, 11, 38, 36, 45, 47, 0, 57, 50, 48, 16, 51, 49, 55, 52, 44, 24, 19, 21, }, + 0xef2ebd111c482f52 +}; +const pattern_t pat16 = { + { 0x596a000, 0x8644000, 0xa943000, 0xd59e000, 0x1062f000, 0x1082a000, 0x10c1b000, 0x10f9e000, 0x11e64000, 0x12e73000, 0x15ce7000, 0x16037000, 0x16d2e000, 0x17035000, 0x185ad000, 0x18d9b000, 0x19ac7000, 0x1b2fa000, 0x1cd6c000, 0x1d5f0000, 0x1f72c000, 0x20891000, 0x24bfa000, 0x25c1d000, 0x28e24000, 0x2a5f8000, 0x2e0ae000, 0x2fddf000, 0x3119d000, 0x332ee000, 0x3480a000, 0x34ea5000, 0x3534e000, 0x3538b000, 0x362e2000, 0x38f58000, 0x39ab0000, 0x3a519000, 0x3a62b000, 0x3b006000, 0x3d523000, 0x3e0f7000, 0x42366000, 0x42feb000, 0x44013000, 0x46b98000, 0x49794000, 0x4dce7000, 0x4f1f3000, 0x57ecd000, 0x5aaa2000, 0x5f419000, 0x61517000, 0x6797d000, 0x69a20000, 0x6a070000, 0x70575000, 0x75322000, 0x75a9e000, 0x79043000, 0x79875000, 0x7addc000, 0x7de88000, 0x80000000, }, + { 26, 25, 6, 50, 32, 53, 34, 27, 3, 16, 49, 28, 46, 38, 56, 4, 18, 24, 51, 36, 63, 5, 48, 13, 43, 55, 0, 62, 35, 7, 41, 21, 44, 60, 31, 39, 14, 8, 61, 58, 52, 23, 59, 33, 10, 37, 20, 30, 40, 22, 11, 54, 57, 1, 29, 47, 2, 17, 19, 45, 15, 9, 12, 42, }, + 0xb19913245ddeb436 +}; +const pattern_t pat17 = { + { 0x28ab000, 0x3ac8000, 0x3fe1000, 0x63a7000, 0x90fc000, 0xb3f2000, 0xd2f2000, 0xe032000, 0x12d4c000, 0x13135000, 0x14652000, 0x15331000, 0x1570c000, 0x1688e000, 0x16bc3000, 0x1cbe3000, 0x1fe0f000, 0x2517f000, 0x26c6b000, 0x2a284000, 0x2a4e2000, 0x2add5000, 0x2bd06000, 0x2ca3a000, 0x2eb11000, 0x324d1000, 0x35662000, 0x38695000, 0x38ce7000, 0x391ac000, 0x398f9000, 0x39949000, 0x401f3000, 0x457f0000, 0x45c6d000, 0x4b561000, 0x522fc000, 0x54ef0000, 0x559f8000, 0x562a7000, 0x56a04000, 0x57b68000, 0x59702000, 0x5ffc9000, 0x63a76000, 0x63c37000, 0x65d3e000, 0x67130000, 0x6a03a000, 0x6bcd6000, 0x6be96000, 0x6bf52000, 0x6fcd9000, 0x7038c000, 0x70a47000, 0x72881000, 0x72ed0000, 0x75035000, 0x75c11000, 0x77fa5000, 0x797c9000, 0x79813000, 0x7bbbb000, 0x80000000, }, + { 18, 15, 56, 5, 25, 47, 39, 55, 12, 14, 51, 33, 0, 7, 9, 44, 50, 31, 62, 59, 3, 35, 23, 17, 30, 60, 11, 24, 40, 20, 52, 2, 22, 8, 57, 42, 32, 54, 36, 48, 49, 13, 58, 10, 28, 63, 16, 41, 27, 21, 37, 4, 1, 29, 19, 6, 53, 45, 46, 38, 34, 43, 61, 26, }, + 0x710633dc35c17b71 +}; +const pattern_t pat18 = { + { 0x38d6000, 0x5379000, 0x5cae000, 0x5d20000, 0xa248000, 0xb4d0000, 0xd7c0000, 0xf731000, 0x116ae000, 0x151d2000, 0x1747d000, 0x1bfb6000, 0x1d758000, 0x2053d000, 0x24dda000, 0x25274000, 0x269c0000, 0x273e8000, 0x2a5d0000, 0x2ad34000, 0x3016b000, 0x30d1a000, 0x32960000, 0x34b3b000, 0x36e4f000, 0x37934000, 0x38c42000, 0x3c2d2000, 0x3d23d000, 0x3d89a000, 0x3dc85000, 0x3e9a7000, 0x3f25b000, 0x45bd1000, 0x48d94000, 0x4b126000, 0x4e17c000, 0x4f377000, 0x50908000, 0x51957000, 0x53410000, 0x5412c000, 0x55256000, 0x56b17000, 0x5707b000, 0x5bbe5000, 0x5d067000, 0x5e1c1000, 0x6380b000, 0x66009000, 0x68240000, 0x69fc4000, 0x6c327000, 0x6c5d2000, 0x6f69d000, 0x739c7000, 0x744bc000, 0x74cd8000, 0x787b8000, 0x78c61000, 0x7969d000, 0x79aae000, 0x7b032000, 0x80000000, }, + { 16, 48, 50, 60, 13, 39, 20, 4, 63, 18, 14, 30, 55, 8, 62, 37, 43, 41, 11, 0, 36, 33, 34, 49, 17, 58, 38, 22, 19, 5, 21, 12, 47, 25, 57, 61, 7, 3, 10, 23, 52, 24, 6, 53, 2, 26, 1, 31, 28, 46, 42, 9, 45, 29, 27, 54, 32, 56, 51, 44, 35, 59, 40, 15, }, + 0xb53f1e4266db260c +}; +const pattern_t pat19 = { + { 0x297d000, 0x34e0000, 0x7801000, 0x9664000, 0x96fa000, 0xbb9f000, 0xc192000, 0xc4a5000, 0xca74000, 0xcce8000, 0x173d8000, 0x1a8d8000, 0x1b299000, 0x1b52d000, 0x1e813000, 0x2185e000, 0x21abe000, 0x2b9a4000, 0x2c4b6000, 0x2fa27000, 0x343ba000, 0x356fd000, 0x37c6e000, 0x38365000, 0x3a9e4000, 0x3b599000, 0x4296b000, 0x43196000, 0x4381e000, 0x44783000, 0x47a75000, 0x4bd78000, 0x4d05d000, 0x4edb2000, 0x4eefd000, 0x4fecc000, 0x51f68000, 0x5252b000, 0x5439e000, 0x55fb3000, 0x5814f000, 0x5939d000, 0x60a78000, 0x62a86000, 0x633b0000, 0x64a68000, 0x64b62000, 0x66207000, 0x66540000, 0x67f90000, 0x68bf3000, 0x6a069000, 0x6d2ac000, 0x70c9f000, 0x71bab000, 0x724bc000, 0x783d8000, 0x7900e000, 0x79399000, 0x79763000, 0x7c8a8000, 0x7e680000, 0x7f6de000, 0x80000000, }, + { 14, 59, 60, 24, 18, 22, 62, 12, 45, 2, 32, 11, 25, 37, 13, 7, 50, 39, 56, 17, 47, 40, 29, 43, 15, 34, 4, 57, 31, 38, 21, 28, 36, 27, 42, 1, 23, 33, 5, 61, 44, 55, 8, 30, 10, 41, 19, 48, 16, 52, 49, 46, 54, 58, 6, 0, 51, 3, 26, 20, 53, 9, 35, 63, }, + 0x64f54c0a0deae9ab +}; +const pattern_t pat20 = { + { 0x8f7000, 0xa01000, 0x38e3000, 0x5299000, 0x6875000, 0x7f3e000, 0x827f000, 0x9413000, 0xca71000, 0xfb11000, 0x10beb000, 0x176be000, 0x1924f000, 0x1cfd6000, 0x1d20d000, 0x1ebb7000, 0x22c93000, 0x23601000, 0x2cf7a000, 0x2d3af000, 0x2e391000, 0x2f294000, 0x318ad000, 0x34ddd000, 0x365e4000, 0x3b8d2000, 0x3c0f8000, 0x3d2fd000, 0x3e431000, 0x3f0fe000, 0x4074e000, 0x40d1c000, 0x41936000, 0x4347b000, 0x452d7000, 0x486d3000, 0x4b47e000, 0x4b709000, 0x4c349000, 0x4ff13000, 0x50faa000, 0x51a07000, 0x52f30000, 0x55f29000, 0x57ad4000, 0x5909f000, 0x5a0f6000, 0x5de57000, 0x60d2f000, 0x625ff000, 0x6288e000, 0x65077000, 0x6a707000, 0x6a73f000, 0x6d720000, 0x6e390000, 0x6edc9000, 0x6ee78000, 0x77ac2000, 0x77ad3000, 0x7868f000, 0x79a1b000, 0x7aec6000, 0x80000000, }, + { 21, 56, 38, 11, 62, 9, 30, 47, 34, 23, 37, 16, 5, 49, 10, 43, 4, 45, 36, 7, 42, 1, 53, 57, 20, 59, 55, 50, 46, 39, 60, 27, 12, 31, 48, 25, 15, 22, 44, 52, 14, 33, 0, 29, 17, 18, 2, 32, 24, 19, 6, 41, 54, 8, 35, 26, 61, 3, 51, 13, 63, 28, 40, 58, }, + 0x786427ef60db40f4 +}; +const pattern_t pat21 = { + { 0x2a8e000, 0xa4bd000, 0xa935000, 0xcc05000, 0xdfe4000, 0xe014000, 0xff46000, 0x18c8c000, 0x199ec000, 0x19ce0000, 0x1f684000, 0x1ff5c000, 0x22d58000, 0x27651000, 0x280e5000, 0x2e2a4000, 0x2e432000, 0x2f96e000, 0x2f9c3000, 0x3343d000, 0x338bb000, 0x34032000, 0x34101000, 0x368c2000, 0x37b95000, 0x39492000, 0x39932000, 0x3b611000, 0x3c89e000, 0x40aa9000, 0x42358000, 0x4890e000, 0x495c9000, 0x4a79d000, 0x4c58e000, 0x4df9a000, 0x4f304000, 0x4fa4c000, 0x54d1d000, 0x58461000, 0x58f43000, 0x5a3d1000, 0x5a765000, 0x5c5c0000, 0x60488000, 0x60fad000, 0x613e5000, 0x61d61000, 0x62d17000, 0x641ff000, 0x67f8b000, 0x69c5d000, 0x6b931000, 0x6efd4000, 0x70333000, 0x70857000, 0x721f6000, 0x72f53000, 0x74450000, 0x746f7000, 0x76067000, 0x7774a000, 0x77ea6000, 0x80000000, }, + { 28, 51, 33, 2, 30, 55, 29, 17, 40, 48, 32, 9, 39, 1, 49, 50, 37, 43, 62, 11, 10, 26, 22, 6, 8, 7, 45, 47, 46, 42, 60, 5, 12, 56, 4, 23, 35, 25, 13, 16, 61, 54, 31, 63, 34, 19, 41, 59, 38, 24, 0, 58, 53, 44, 3, 18, 52, 20, 36, 27, 14, 21, 57, 15, }, + 0x615a5f41d4c3d653 +}; +const pattern_t pat22 = { + { 0x314d000, 0x4452000, 0x6673000, 0xab09000, 0xc80d000, 0x10eda000, 0x129c2000, 0x12f1f000, 0x13e9b000, 0x1450c000, 0x15aeb000, 0x1667c000, 0x190b2000, 0x19ac5000, 0x1c0ac000, 0x1c229000, 0x1ece8000, 0x1fc48000, 0x22abd000, 0x24268000, 0x2adce000, 0x2b809000, 0x30a11000, 0x31d08000, 0x36700000, 0x39e6a000, 0x3b84b000, 0x41e84000, 0x46301000, 0x4a326000, 0x50fda000, 0x5299a000, 0x56acf000, 0x57f66000, 0x586ab000, 0x58df5000, 0x591cc000, 0x59b91000, 0x59cbd000, 0x5b4d0000, 0x5cca7000, 0x5cfce000, 0x5d120000, 0x5d51a000, 0x5eaa0000, 0x5ebac000, 0x5f0e1000, 0x5f285000, 0x5f4d3000, 0x5ff61000, 0x60b51000, 0x61435000, 0x651fd000, 0x6b954000, 0x705aa000, 0x71a41000, 0x73ec7000, 0x75f92000, 0x76854000, 0x77cb9000, 0x782ca000, 0x7a2af000, 0x7eaa6000, 0x80000000, }, + { 16, 8, 5, 59, 4, 18, 26, 43, 33, 57, 6, 47, 56, 46, 10, 54, 52, 0, 50, 30, 39, 24, 38, 63, 28, 25, 49, 31, 55, 62, 3, 17, 23, 13, 37, 53, 34, 14, 44, 12, 19, 36, 27, 61, 51, 42, 41, 60, 45, 1, 7, 35, 21, 58, 20, 15, 2, 9, 22, 29, 48, 32, 40, 11, }, + 0x828366dbf1f83654 +}; +const pattern_t pat23 = { + { 0x47000, 0x680000, 0x176a000, 0x1db8000, 0x600e000, 0x808c000, 0x9e58000, 0xa82f000, 0xaebb000, 0xc938000, 0xd0eb000, 0xdc5e000, 0xe503000, 0x11e56000, 0x12dbd000, 0x14681000, 0x15200000, 0x18256000, 0x1be75000, 0x1d2a0000, 0x1ed67000, 0x27e8a000, 0x2bc39000, 0x2bf4b000, 0x2c94f000, 0x2d575000, 0x2d82e000, 0x2e440000, 0x2ecda000, 0x2fbc2000, 0x33ab0000, 0x360b8000, 0x39630000, 0x3a654000, 0x3d2b6000, 0x3eeff000, 0x41590000, 0x417ea000, 0x42ff9000, 0x4bca4000, 0x503b0000, 0x508e4000, 0x52a2e000, 0x535b6000, 0x54335000, 0x57412000, 0x57dc6000, 0x590d9000, 0x5fc0a000, 0x60552000, 0x60665000, 0x6168d000, 0x65b16000, 0x67328000, 0x6742d000, 0x68c88000, 0x6b802000, 0x6f6d2000, 0x7040e000, 0x77e31000, 0x79c71000, 0x7da4a000, 0x7e26b000, 0x80000000, }, + { 63, 50, 51, 33, 28, 35, 24, 14, 4, 23, 47, 11, 37, 41, 12, 55, 62, 32, 34, 30, 25, 43, 16, 0, 3, 49, 61, 15, 57, 46, 59, 44, 31, 27, 21, 53, 5, 2, 8, 56, 52, 22, 60, 40, 20, 1, 48, 18, 17, 19, 54, 29, 9, 38, 42, 6, 39, 45, 13, 10, 26, 58, 36, 7, }, + 0xd8456d32bb91872e +}; +const pattern_t pat24 = { + { 0x3890000, 0x3fd9000, 0x62d6000, 0x7df0000, 0x895c000, 0xab61000, 0xc23b000, 0x10ab3000, 0x1247c000, 0x13f00000, 0x16604000, 0x1a444000, 0x1c2c8000, 0x1c467000, 0x1d396000, 0x1e683000, 0x21080000, 0x2442a000, 0x27fea000, 0x282eb000, 0x28e2c000, 0x2a625000, 0x2b3b2000, 0x2bbd5000, 0x2c886000, 0x2cbe8000, 0x31518000, 0x35425000, 0x355f4000, 0x35d7a000, 0x3851d000, 0x396a6000, 0x3d10f000, 0x3d890000, 0x49238000, 0x4ab7e000, 0x4fadf000, 0x50603000, 0x5233a000, 0x53279000, 0x5586c000, 0x56968000, 0x58101000, 0x588b6000, 0x5bc19000, 0x5cc10000, 0x623f6000, 0x629f4000, 0x63176000, 0x63dcc000, 0x681d0000, 0x69c0e000, 0x6a9fa000, 0x6ae5e000, 0x6d2ba000, 0x6e422000, 0x73f94000, 0x77932000, 0x78b24000, 0x794c1000, 0x795d2000, 0x7ae08000, 0x7b3ce000, 0x80000000, }, + { 56, 47, 54, 62, 29, 43, 25, 59, 41, 7, 52, 63, 15, 21, 16, 14, 39, 17, 45, 11, 27, 24, 55, 31, 53, 4, 6, 2, 20, 23, 5, 37, 32, 58, 13, 51, 1, 8, 3, 57, 46, 30, 35, 49, 18, 40, 9, 22, 42, 38, 34, 0, 19, 33, 26, 60, 10, 48, 36, 61, 44, 12, 50, 28, }, + 0x3e9c5e14d18c9e65 +}; +const pattern_t pat25 = { + { 0xcb000, 0x22bf000, 0x2461000, 0x246b000, 0x5c6f000, 0x5fb4000, 0x69a9000, 0x718c000, 0x92e6000, 0xbb2e000, 0xd916000, 0xf3dc000, 0xf568000, 0x10246000, 0x12d53000, 0x14dfd000, 0x1598a000, 0x1956a000, 0x1b01b000, 0x1b3b8000, 0x1ce06000, 0x20bc5000, 0x21351000, 0x233b0000, 0x23f2b000, 0x24e41000, 0x29cca000, 0x2b5bd000, 0x2ba68000, 0x2bf7f000, 0x31a58000, 0x34570000, 0x39941000, 0x3b765000, 0x3cd13000, 0x3d251000, 0x3fa05000, 0x40745000, 0x45c68000, 0x4a282000, 0x4ad19000, 0x4b4aa000, 0x4ca18000, 0x4e0b8000, 0x4eb97000, 0x4f68b000, 0x4fca2000, 0x52466000, 0x52edf000, 0x5602a000, 0x57f60000, 0x5cc18000, 0x5cee3000, 0x5da37000, 0x5dba4000, 0x64b77000, 0x66e9f000, 0x68b9d000, 0x6aac9000, 0x6d873000, 0x6f7e6000, 0x71036000, 0x75a54000, 0x80000000, }, + { 1, 58, 13, 5, 62, 10, 49, 48, 19, 24, 54, 57, 20, 39, 35, 41, 28, 42, 6, 44, 34, 45, 55, 3, 2, 60, 38, 36, 30, 25, 7, 23, 53, 50, 61, 29, 40, 47, 22, 12, 27, 0, 52, 31, 8, 15, 37, 11, 46, 32, 4, 56, 17, 33, 26, 43, 51, 16, 9, 59, 63, 21, 14, 18, }, + 0x7bae8ea344ec83e +}; +const pattern_t pat26 = { + { 0x1f4e000, 0x46f7000, 0x90a7000, 0xafe3000, 0xb2a8000, 0xb8b0000, 0xc480000, 0xc4e1000, 0xf03c000, 0xf075000, 0x14dbd000, 0x17728000, 0x1a146000, 0x1ab02000, 0x1af49000, 0x1be7a000, 0x1dc7a000, 0x1de5e000, 0x1f4f9000, 0x2092b000, 0x20a63000, 0x22937000, 0x22fe3000, 0x23e1c000, 0x28c46000, 0x294d6000, 0x2ad19000, 0x2b18b000, 0x2b233000, 0x2b685000, 0x2c792000, 0x2e6c2000, 0x2fa86000, 0x3320f000, 0x36f17000, 0x38406000, 0x38b1b000, 0x3a132000, 0x3b269000, 0x3cc43000, 0x3e2a2000, 0x3e3bb000, 0x3e83b000, 0x3ea14000, 0x4035d000, 0x4137f000, 0x4615b000, 0x50531000, 0x517c8000, 0x519e6000, 0x55ebc000, 0x594f8000, 0x5a732000, 0x5d2cb000, 0x5e409000, 0x5f394000, 0x5f3a8000, 0x60dc6000, 0x61373000, 0x6ebd6000, 0x6fd61000, 0x77161000, 0x7ce81000, 0x80000000, }, + { 61, 48, 12, 55, 3, 58, 51, 56, 15, 29, 54, 11, 31, 49, 40, 37, 7, 4, 23, 35, 25, 18, 27, 43, 6, 41, 17, 45, 52, 53, 47, 16, 42, 0, 30, 13, 38, 62, 1, 8, 21, 28, 57, 9, 60, 19, 44, 50, 14, 36, 22, 2, 32, 59, 34, 10, 63, 39, 5, 24, 33, 20, 46, 26, }, + 0x465275bfa2868e8b +}; +const pattern_t pat27 = { + { 0xa6a000, 0x4c7a000, 0x5183000, 0x8dda000, 0x9cbd000, 0xb860000, 0x10c24000, 0x12dda000, 0x147ab000, 0x14aa4000, 0x16c8f000, 0x17d5b000, 0x18b5c000, 0x1a163000, 0x1b0a1000, 0x24221000, 0x25ef8000, 0x267f1000, 0x268b7000, 0x26b07000, 0x273ad000, 0x27bc2000, 0x2856c000, 0x29896000, 0x2efeb000, 0x331a7000, 0x348e8000, 0x3707f000, 0x3f444000, 0x3fe2a000, 0x433b3000, 0x435d3000, 0x46d82000, 0x4a9d3000, 0x4c6cf000, 0x4ca36000, 0x4ec42000, 0x4f79c000, 0x53cd3000, 0x58c78000, 0x5d910000, 0x616cc000, 0x62800000, 0x65ded000, 0x68831000, 0x6b321000, 0x6cd46000, 0x6d0fa000, 0x6d2f9000, 0x6e353000, 0x6fd5e000, 0x706c5000, 0x7249f000, 0x75d6c000, 0x77528000, 0x783ad000, 0x79738000, 0x79bfe000, 0x79ee9000, 0x7b74a000, 0x7bb41000, 0x7bbeb000, 0x7bbfb000, 0x80000000, }, + { 61, 53, 12, 15, 26, 30, 32, 2, 16, 5, 39, 43, 20, 21, 49, 37, 11, 51, 18, 44, 31, 19, 24, 40, 1, 35, 50, 6, 57, 14, 46, 17, 22, 48, 29, 7, 34, 45, 10, 63, 23, 41, 54, 38, 4, 25, 42, 13, 56, 62, 36, 28, 33, 59, 55, 3, 9, 0, 58, 60, 47, 8, 52, 27, }, + 0x5ba5aa760ec14c3e +}; +const pattern_t pat28 = { + { 0x439a000, 0x6860000, 0xd252000, 0x1105c000, 0x113c8000, 0x1429a000, 0x14922000, 0x15f32000, 0x1992f000, 0x1a1db000, 0x1a87c000, 0x1b260000, 0x1b292000, 0x1c253000, 0x1ea33000, 0x20bbc000, 0x215ae000, 0x25249000, 0x27c89000, 0x27e36000, 0x28bf2000, 0x29c27000, 0x2a575000, 0x2c6fa000, 0x31639000, 0x3184a000, 0x319c3000, 0x348a7000, 0x38aa8000, 0x39dd5000, 0x3a067000, 0x3c0dd000, 0x3cfd4000, 0x3ebb6000, 0x43259000, 0x46494000, 0x46fcb000, 0x4a050000, 0x4b5c4000, 0x4cff3000, 0x4edaa000, 0x4f025000, 0x542e1000, 0x55364000, 0x56338000, 0x56ef8000, 0x5711b000, 0x573d1000, 0x5943b000, 0x5b912000, 0x61ce2000, 0x65211000, 0x65dca000, 0x6dee2000, 0x6df30000, 0x7334d000, 0x73e76000, 0x7473a000, 0x75846000, 0x75fd0000, 0x77174000, 0x773e9000, 0x7a8db000, 0x80000000, }, + { 43, 11, 8, 56, 5, 22, 42, 55, 14, 32, 2, 47, 24, 51, 35, 25, 15, 58, 41, 27, 33, 37, 4, 36, 7, 53, 26, 48, 38, 19, 29, 28, 40, 10, 1, 46, 59, 63, 61, 62, 60, 30, 21, 39, 44, 57, 20, 18, 17, 54, 49, 52, 3, 12, 45, 13, 50, 9, 16, 23, 0, 6, 31, 34, }, + 0x6236b5e97869acb +}; +const pattern_t pat29 = { + { 0x363000, 0x9bc000, 0x1907000, 0x41d5000, 0x5a6e000, 0x9f36000, 0xa3ee000, 0x14b98000, 0x1845c000, 0x188ea000, 0x1b297000, 0x1c024000, 0x1e1eb000, 0x1f3a4000, 0x2047f000, 0x2420a000, 0x28871000, 0x296dd000, 0x2c92c000, 0x2dd42000, 0x3444f000, 0x35b90000, 0x3683c000, 0x3d8ea000, 0x3fe6b000, 0x4200e000, 0x421cf000, 0x42a46000, 0x44463000, 0x44e61000, 0x45c82000, 0x485f8000, 0x48fe8000, 0x4a532000, 0x4a6fd000, 0x4c8f9000, 0x4dbd7000, 0x5052a000, 0x512bb000, 0x5281d000, 0x5315d000, 0x5a202000, 0x5a9fc000, 0x5c11a000, 0x6010b000, 0x62aa3000, 0x63d05000, 0x6774c000, 0x6776d000, 0x68105000, 0x699d5000, 0x69bc2000, 0x6b1b9000, 0x704d5000, 0x73d5c000, 0x73d94000, 0x78483000, 0x78c8c000, 0x78cc5000, 0x7ac8d000, 0x7ae00000, 0x7b597000, 0x7e6ab000, 0x80000000, }, + { 52, 40, 59, 29, 42, 34, 63, 44, 33, 37, 51, 23, 5, 36, 38, 43, 9, 4, 28, 55, 1, 6, 21, 26, 13, 24, 30, 15, 35, 17, 46, 20, 16, 10, 49, 48, 39, 62, 19, 14, 61, 27, 53, 2, 57, 58, 45, 7, 56, 50, 54, 25, 31, 11, 22, 47, 3, 0, 32, 12, 8, 41, 60, 18, }, + 0xa3cfc2e527b1c191 +}; +const pattern_t pat30 = { + { 0x45c5000, 0x6bf3000, 0xc293000, 0xe470000, 0xe5b7000, 0x1256c000, 0x1444d000, 0x15699000, 0x16e86000, 0x1a4d5000, 0x1b803000, 0x1dcf9000, 0x1dd6f000, 0x1f57f000, 0x22879000, 0x263e9000, 0x29423000, 0x2a1a9000, 0x2a699000, 0x2c8fb000, 0x2d2e0000, 0x2ec5e000, 0x317a4000, 0x35a64000, 0x36967000, 0x37299000, 0x37c07000, 0x3b9bb000, 0x3c054000, 0x3ccbc000, 0x3d94a000, 0x3e2e9000, 0x3e7a4000, 0x40b98000, 0x44658000, 0x44738000, 0x44fe3000, 0x451d9000, 0x4536c000, 0x46df2000, 0x48855000, 0x503ce000, 0x53104000, 0x531fc000, 0x54c1b000, 0x56086000, 0x5642b000, 0x573a4000, 0x5887f000, 0x5a871000, 0x5c970000, 0x5e566000, 0x62b8f000, 0x642ce000, 0x65ee5000, 0x66db3000, 0x6727c000, 0x6a9a2000, 0x74a8f000, 0x7c29a000, 0x7cc57000, 0x7f221000, 0x7f28f000, 0x80000000, }, + { 29, 35, 8, 49, 30, 55, 27, 38, 58, 61, 0, 28, 15, 39, 5, 37, 32, 42, 46, 54, 12, 14, 1, 31, 59, 11, 47, 9, 13, 50, 2, 62, 60, 18, 20, 51, 23, 24, 53, 6, 25, 48, 41, 3, 33, 57, 44, 19, 22, 52, 4, 45, 10, 21, 56, 36, 17, 43, 7, 63, 16, 34, 26, 40, }, + 0xf2ae48cdd4d05e58 +}; +const pattern_t pat31 = { + { 0x143f000, 0x2068000, 0x328c000, 0x70a6000, 0x92a7000, 0x93dd000, 0xa3a8000, 0xbe51000, 0xbfc8000, 0xe353000, 0x1272f000, 0x143a4000, 0x16825000, 0x20bf8000, 0x20d9f000, 0x21e32000, 0x22426000, 0x2246b000, 0x22cea000, 0x25dc2000, 0x29324000, 0x29cd1000, 0x2aa44000, 0x2cd84000, 0x2dafb000, 0x2e74b000, 0x2f5b1000, 0x3a7a9000, 0x3bb38000, 0x3c11a000, 0x3c30a000, 0x3e2f1000, 0x4187b000, 0x42190000, 0x44e34000, 0x4d850000, 0x53ceb000, 0x540db000, 0x54937000, 0x5530a000, 0x5a111000, 0x5c280000, 0x5ef17000, 0x5fccf000, 0x64434000, 0x6498e000, 0x662c4000, 0x6a7e2000, 0x6b5a1000, 0x6c11f000, 0x6dd97000, 0x6ef1b000, 0x6f44e000, 0x7084f000, 0x73b53000, 0x7872c000, 0x78ed7000, 0x7935b000, 0x79bf9000, 0x7a6af000, 0x7b6fd000, 0x7bd42000, 0x7f233000, 0x80000000, }, + { 6, 25, 28, 44, 27, 43, 58, 33, 23, 21, 16, 48, 30, 26, 5, 20, 49, 38, 2, 45, 11, 61, 17, 0, 53, 13, 7, 52, 40, 31, 36, 4, 10, 8, 24, 22, 42, 63, 35, 60, 47, 29, 46, 19, 1, 3, 34, 55, 59, 14, 39, 12, 32, 50, 62, 54, 56, 51, 57, 15, 41, 18, 37, 9, }, + 0xc8cbea4e3899aca5 +}; +const pattern_t* patterns[] = {&trivial_pattern, + &pat0, &pat1, &pat2, &pat3, &pat4, &pat5, &pat6, &pat7, + &pat8, &pat9, &pat10, &pat11, &pat12, &pat13, &pat14, &pat15, + &pat16, &pat17, &pat18, &pat19, &pat20, &pat21, &pat22, &pat23, + &pat24, &pat25, &pat26, &pat27, &pat28, &pat29, &pat30, &pat31}; + +//static variables used by the worker threads +static int outfd = 0; +static sem_t chunk_sems[NUM_CHUNKS]; +static phase_t phase; +#if USE_MMAP +static void* p_file; +#endif + +static void +usage() +{ + (void) fprintf(stderr, "usage: txg_integrity \n"); + exit(2); +} + + +/* Fills a buffer with a special marker. The marker contains information about + * the file offset where this buffer is supposed to go, and whether it will + * be written by a leader or a follower */ +static void +marker_fill(uint64_t* buf, int file_ofs, size_t len, int is_follower){ + int ofs; + uint32_t lead_mark = 0x4441454c; //"LEAD" in little endian + uint32_t follow_mark = 0x4c4c4f46; //"FOLL" in little endian + for (ofs = file_ofs; ofs < file_ofs + len; ofs += sizeof(uint64_t)){ + uint64_t mark = ((is_follower ? + (uint64_t)follow_mark : (uint64_t)lead_mark) << (uint64_t)32) | + htonl((ofs & 0xFFFFFFFF)); + int buf_idx = (ofs - file_ofs) / sizeof(uint64_t); + buf[buf_idx] = mark; + } +} + +static int +verify_file(int fd, const pattern_t* p_pat){ + int chunk_idx; + int good_data = 1; + int err = 0; + + for(chunk_idx=0; chunk_idx < NUM_CHUNKS; chunk_idx++){ + int i; + uint32_t chunk_start, chunk_end; + get_chunk_range(p_pat, chunk_idx, &chunk_start, &chunk_end); + size_t size = chunk_end - chunk_start; + uint64_t* desired_buf = malloc(size); + uint64_t* actual_buf = malloc(size); + if ((1 << chunk_idx) & p_pat->follower_chunks){ + marker_fill(desired_buf, chunk_start, size, 1); + } + else{ + marker_fill(desired_buf, chunk_start, size, 0); + } + + //read the actual data from the file + if( read(fd, actual_buf, size) <= 0 ){ + perror("read"); + exit(1); + } + + //verify the data + for(i=0; i < size / sizeof(uint64_t); i++){ + int chunk_offset = sizeof(uint64_t) * i; + int file_offset = chunk_start + chunk_offset; + if (good_data && (actual_buf[i] != desired_buf[i])){ + fprintf(stderr, "txg_integrity: miscompare at " + "chunk %i, chunk offset %lx, file offset %lx\n", + chunk_idx, chunk_offset, file_offset); + fprintf(stderr, "Expected %16lx, got %16lx\n", + desired_buf[i], actual_buf[i]); + err = 1; + good_data = 0; + } + else if (!good_data && (actual_buf[i] == desired_buf[i])) { + fprintf(stderr, "txg_integrity: miscompare ends at " + "chunk %i, chunk offset %lx, file offset %lx\n", + chunk_idx, chunk_offset, file_offset); + good_data = 1; + } + } + free(desired_buf); + free(actual_buf); + } + + return (err); +} + +/* Writes a special marker to every byte within the chunk */ +static void +write_chunk(pattern_t* p_pat, int chunk_idx, int is_follower) +{ + uint32_t chunk_start, chunk_end; + get_chunk_range(p_pat, chunk_idx, &chunk_start, &chunk_end); + size_t size = chunk_end - chunk_start; + uint64_t* buf = malloc(size); + marker_fill(buf, chunk_start, size, is_follower); +#if USE_MMAP + memcpy((void*)( (char*)p_file + chunk_start ), (void*)buf, size); +#else + pwrite(outfd, (void*)buf, size, chunk_start); +#endif + free(buf); +} + +static void +my_sync(int fd){ + //FreeBSD's msync(2) recommends that msync is obsolete and fsync should + //be used instead, even for memory-mapped files + if (fsync(fd)){ + perror("fsync"); + exit(1); + } +} + +static void* +follower(void* data) +{ + int perm_idx; + pattern_t* p_pat = (pattern_t*)data; +/* printf("Follower started\n");*/ + for(perm_idx = 0; perm_idx < NUM_CHUNKS; perm_idx++) + { + int chunk_idx = p_pat->permutation[perm_idx]; + if (perm_idx == NUM_CHUNKS / 2 && phase == follower_syncs){ +/* printf("about to sync in follower\n");*/ + my_sync(outfd); + } + + if ( (1 << chunk_idx) & p_pat->follower_chunks){ +/* printf("about to pend on semaphore\n");*/ +#if USE_THREADS + if (-1 == sem_wait(&chunk_sems[chunk_idx])){ + perror("sem_wait"); + exit(1); + } +#endif +/* printf("about to write chunk in follower\n");*/ + write_chunk(p_pat, chunk_idx, 1); + } + } + return 0; +} + +static void* +leader(void* data) +{ + int perm_idx; + pattern_t* p_pat = (pattern_t*)data; +/* printf("Leader started\n");*/ + for(perm_idx = 0; perm_idx < NUM_CHUNKS; perm_idx++) + { + int chunk_idx = p_pat->permutation[perm_idx]; + if (perm_idx == NUM_CHUNKS / 2 && phase == leader_syncs){ + //printf("about to sync in leader\n"); + my_sync(outfd); + } + //printf("about to write chunk in leader\n"); + write_chunk(p_pat, chunk_idx, 0); + //printf("about to post semaphore\n"); +#if USE_THREADS + if (sem_post(&chunk_sems[chunk_idx]) == -1){ + perror("sem_post"); + exit(1); + } +#endif + } + return 0; +} + +int +main(int argc, char** argv) +{ + int rep; + int pat; +#if USE_THREADS + pthread_t leader_th, follower_th; +#endif + + if (argc != 2){ + usage(); + } + + //follower_chunks bitmap must have enough space to represent every chunk + assert(NUM_CHUNKS <= 8 * sizeof(((pattern_t*) 0)->follower_chunks)); + + for(rep=0; rep < NUM_REPETITIONS; rep++){ + printf("Starting repetition %d\n", rep); + for(pat=0; pat < sizeof(patterns) / sizeof(patterns[0]); pat++){ + void *pat_p = (void *)(uintptr_t)(const void *)patterns[pat]; + for(phase=leader_syncs; phase < NUM_PHASES; phase++){ + int sem_idx; + int ofs=0; + +/* printf("Starting on patterns[%d]\n" , pat);*/ + outfd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0644); + if (outfd == -1){ + perror("open"); + exit(1); + } + + //set the file size + if ( ftruncate(outfd, FSIZE)){ + perror("ftruncate"); + exit(1); + } + + //Zero-fill the file to avoid fragmentation, as recommended by mmap(2). + for(ofs=0; ofs < FSIZE; ofs+=CLUSTERSIZE){ + char buffer[CLUSTERSIZE]; + bzero(buffer, CLUSTERSIZE); + if ( -1 == write(outfd, buffer, CLUSTERSIZE)){ + perror("write"); + exit(1); + } + } + //Return the file pointer to the beginning prior to mmap + if (-1 == lseek(outfd, 0, SEEK_SET)){ + perror("lseek"); + } + +#if USE_MMAP + //mmap the file + p_file = mmap(0, FSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, outfd, 0); + if (p_file == MAP_FAILED){ + perror("mmap"); + exit(1); + } +#endif +#if USE_THREADS + //Create the semaphores + for(sem_idx=0; sem_idx < NUM_CHUNKS; sem_idx++){ + if (sem_init(&chunk_sems[sem_idx], 0, 0)){ + perror("sem_init"); + exit(1); + } + } + + //Create the worker threads + if (pthread_create(&follower_th, NULL, follower, pat_p)){ + perror("pthread_create follower"); + exit(1); + } + if (pthread_create(&leader_th, NULL, leader, pat_p)){ + perror("pthread_create leader"); + exit(1); + } + + //Join the threads + if (pthread_join(leader_th, NULL)){ + perror("pthread_join leader"); + exit(1); + } +/* printf("Joined leader\n");*/ + if (pthread_join(follower_th, NULL)){ + perror("pthread_join follower"); + exit(1); + } +/* printf("Joined follower\n");*/ + + //destroy the semaphores + for(sem_idx=0; sem_idx < NUM_CHUNKS; sem_idx++){ + if (sem_destroy(&chunk_sems[sem_idx])){ + perror("sem_destory"); + exit(1); + } + } + //printf("destroyed semaphores\n"); +#else + leader(pat_p); follower(pat_p); +#endif + +#if USE_MMAP + //unmap the file prior to verifying it + if (msync(p_file, 0, 0)){ + perror("msync"); + exit(1); + } + //printf("finished msync\n"); + + if (munmap(p_file, FSIZE)){ + perror("munmap"); + exit(1); + } + //printf("finished munmap\n"); +#endif + + //Verify the contents of the file. + if (verify_file(outfd, patterns[pat])) { + exit(1); + } + //printf("finished verify_file\n"); + + //close the file: + if (close(outfd)){ + perror("close"); + exit(1); + } + } + } + } + + return 0; +} diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.cfg b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.cfg new file mode 100644 index 00000000000..0ceef29a323 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.cfg @@ -0,0 +1,34 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2011 Spectra logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)transaction_group_integrity.cfg 1.0 10/20/11 SL" +# + +export TESTFILE=testfile${TESTCASE_ID} +export DISK="/dev/md${TESTCASE_ID}" +export TESTDEV=${DISK} diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.d b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.d new file mode 100644 index 00000000000..5436f15dd0e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity.d @@ -0,0 +1,117 @@ +#!/usr/sbin/dtrace -s + +/* This D script attempts to verify whether a single dbuf is being held by + * multiple transaction groups at the time it is fixed up. The purpose is + * to verify whether the txg_integrity test exercises the kernel code paths + * that we want it to. + * XXX this is a work in progress. It is not yet usable + * + * $FreeBSD$ + */ + +/* zfs:kernel:dbuf_fix_old_data:entry +{ + printf("entry"); +}*/ + +dtrace:::BEGIN +{ + dmu_write_uio_dnode_size = 0; + dmu_write_uio_dnode_loffset = 0; + dmu_write_uio_dnode_numbufs = 0; + dbuf_dirty_size = 0; + dbuf_dirty_offset = 0; + uio_stats2_refcount = 0, + uio_stats2_dirtycnt = 0, + dbuf_dirty_entry_refcount = 0; + dbuf_dirty_entry_dirtycnt = 0; + dbuf_dirty_refcount = 0; + dbuf_dirty_dirtycnt = 0; + ge2TrackerName[0] = ""; + ge2TrackerCount[0] = 0; +} + +zfs:kernel:dbuf_fix_old_data:db_get_spa +{ + /*printf("db_get_spa");*/ + /* stack(); */ + printf("uio_stats: size=%d\tloffset=%x\tnumbufs=%d\n\trefcount(holds)=%d\tdirtycnt=%d\n", + dmu_write_uio_dnode_size , + dmu_write_uio_dnode_loffset, + dmu_write_uio_dnode_numbufs , + uio_stats2_refcount, + uio_stats2_dirtycnt); + printf("dbuf_dirty stats: size=%d\toffset=%x\n\tentry: refcount(holds)=%d\tdirtycnt=%d\n\texit: refcount(holds)=%d\tdirtycnt=%d\n", + dbuf_dirty_size, + dbuf_dirty_offset, + dbuf_dirty_entry_refcount, + dbuf_dirty_entry_dirtycnt, + dbuf_dirty_refcount, + dbuf_dirty_dirtycnt); + printf("DR_TXG=%d\tDB address = %x\n", args[0], (long long)args[1]); + printf("ge2Tracker entry: name=%s\tcount=%d", ge2TrackerName[(long long)args[1]], ge2TrackerCount[(long long)args[1]]); + exit(0); +} + +zfs:kernel:dbuf_dirty:entry +{ + dbuf_dirty_size = args[0]; + dbuf_dirty_offset = args[1]; + dbuf_dirty_entry_refcount = args[2]; + dbuf_dirty_entry_dirtycnt = args[3]; +} + + +zfs2:kernel:dmu_write_uio_dnode:uio_stats +{ + dmu_write_uio_dnode_size = args[0]; + dmu_write_uio_dnode_loffset = args[1]; + dmu_write_uio_dnode_numbufs = args[2]; + printf("uio_stats: size=%d\tloffset=%x\tnumbufs=%d", args[0], args[1], args[2]); +} + +zfs2:kernel:dmu_write_uio_dnode:uio_stats_two +{ + uio_stats2_refcount = args[0]; + uio_stats2_dirtycnt = args[1]; + printf("uio_stats2: refcount=%d\tdirtycnt=%d\tdb=%x", args[0], args[1], (long long)args[2]); +} + +zfs2:kernel:dmu_write_uio_dnode:uio_stats_three +{ + printf("uio_stats3: io_txg=%d", args[0]); +} + +zfs:kernel:dbuf_dirty:no_db_nofill +{ + dbuf_dirty_refcount = args[0]; + dbuf_dirty_dirtycnt = args[1]; +} + +/* refcount:kernel::ge2 +{ + stack(); +} */ + +zfs:kernel:dbuf_hold_impl:ge2 +{ + ge2TrackerName[(long long)args[0]] = "dbuf_hold_impl"; + ge2TrackerCount[(long long)args[0]] = args[1]; + printf(">= 2: db=%x\trc=%d", (long long)args[0], args[1]); + /* stack(); */ + /* ustack(10); */ +} + +/* zfs:kernel:dbuf_add_ref:ge2 +{ + ge2TrackerName[(long long)args[0]] = "dbuf_add_ref"; + ge2TrackerCount[(long long)args[0]] = args[1]; +} */ + +/* zfs2:kernel:dmu_bonus_hold:ge2 +{ + ge2TrackerName[(long long)args[0]] = "dmu_bonus_hold"; + ge2TrackerCount[(long long)args[0]] = args[1]; +}*/ + + diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity_001_pos.ksh b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity_001_pos.ksh new file mode 100644 index 00000000000..3f2ae69f91f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity_001_pos.ksh @@ -0,0 +1,74 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2011 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + +. ${STF_SUITE}/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: transaction_group_integrity_001_pos +# +# DESCRIPTION: +# +# Verify the integrity of non-aligned writes to the same blocks that cross +# transaction groups. +# +# STRATEGY: +# This test verifies that non-aligned writes are correctly committed to the +# file system, even adjacent transaction groups include writes to the same +# blocks. The test runs through multiple repetitions in an attempt to trigger +# race conditions. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: BEGIN (2011-10-20) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +log_assert "Ensure that non-aligned writes to the same blocks that cross" \ + "transaction groups do not corrupt the file." + +# Run the test program +txg_integrity ${TESTDIR}/${TESTFILE} + +# Success is indicated by the return status +if [[ $? -ne 0 ]]; then + log_fail "Test failed to execute or file became corrupted" +else + log_pass "Multiple unaligned writes from multiple transactions groups succeeded" +fi + + diff --git a/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity_test.sh b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity_test.sh new file mode 100755 index 00000000000..375fb41312c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/txg_integrity/txg_integrity_test.sh @@ -0,0 +1,113 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case txg_integrity_001_pos cleanup +txg_integrity_001_pos_head() +{ + atf_set "descr" "Ensure that non-aligned writes to the same blocks that cross transaction groups do not corrupt the file." + atf_set "timeout" 1800 +} +txg_integrity_001_pos_body() +{ + export PATH=$(atf_get_srcdir):$PATH + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/txg_integrity.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/txg_integrity_001_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +txg_integrity_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/txg_integrity.cfg + + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case fsync_integrity_001_pos cleanup +fsync_integrity_001_pos_head() +{ + atf_set "descr" "Verify the integrity of non-aligned writes to the same blocks within the same transaction group, where an fsync is issued by a non-final writer." + atf_set "timeout" 1800 +} +fsync_integrity_001_pos_body() +{ + export PATH=$(atf_get_srcdir):$PATH + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/txg_integrity.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/fsync_integrity_001_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +fsync_integrity_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/txg_integrity.cfg + export DISK="/dev/md${TESTCASE_ID}" + export TESTDEV=${DISK}p1 + + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case txg_integrity_001_pos + atf_add_test_case fsync_integrity_001_pos +} + + +save_artifacts() +{ + # If ARTIFACTS_DIR is defined, save test artifacts for + # post-mortem analysis + if [[ -n $ARTIFACTS_DIR ]]; then + TC_ARTIFACTS_DIR=${ARTIFACTS_DIR}/sys/cddl/zfs/tests/txg_integrity/$(atf_get ident) + mkdir -p $TC_ARTIFACTS_DIR + cp -a $TESTDIR/$TESTFILE $TC_ARTIFACTS_DIR + bzip2 $TC_ARTIFACTS_DIR/$TESTFILE + # Now export the pool and tar up the entire thing + zpool export $TESTPOOL + dd if=$TESTDEV bs=131072 of=$TC_ARTIFACTS_DIR/pool + bzip2 $TC_ARTIFACTS_DIR/pool + # Reimport it so that the cleanup script will work + zpool import $TESTPOOL + fi +} diff --git a/tests/sys/cddl/zfs/tests/userquota/Makefile b/tests/sys/cddl/zfs/tests/userquota/Makefile new file mode 100644 index 00000000000..e7042269959 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/Makefile @@ -0,0 +1,34 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/userquota +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= userquota_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= groupspace_001_pos.ksh +${PACKAGE}FILES+= userquota_common.kshlib +${PACKAGE}FILES+= userquota_010_pos.ksh +${PACKAGE}FILES+= userquota_001_pos.ksh +${PACKAGE}FILES+= userquota_009_pos.ksh +${PACKAGE}FILES+= userquota_008_pos.ksh +${PACKAGE}FILES+= userquota_004_pos.ksh +${PACKAGE}FILES+= userquota_005_neg.ksh +${PACKAGE}FILES+= userspace_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= userquota_011_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= userquota_002_pos.ksh +${PACKAGE}FILES+= userquota_006_pos.ksh +${PACKAGE}FILES+= userquota_012_neg.ksh +${PACKAGE}FILES+= groupspace_002_pos.ksh +${PACKAGE}FILES+= userquota_003_pos.ksh +${PACKAGE}FILES+= userquota_007_pos.ksh +${PACKAGE}FILES+= userquota.cfg +${PACKAGE}FILES+= userspace_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/userquota/cleanup.ksh b/tests/sys/cddl/zfs/tests/userquota/cleanup.ksh new file mode 100644 index 00000000000..fd13711b399 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/cleanup.ksh @@ -0,0 +1,41 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 09/08/06 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +if ! is_userquota_supported; then + log_unsupported "userquota is not supported in this system." +fi + +log_must clean_user_group + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/userquota/groupspace_001_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/groupspace_001_pos.ksh new file mode 100644 index 00000000000..6ac57c5aab9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/groupspace_001_pos.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)groupspace_001_pos.ksh 1.2 09/08/06 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: groupspace_001_pos +# +# DESCRIPTION: +# Check the zfs groupspace with all parameters +# +# +# STRATEGY: +# 1. set zfs groupquota to a fs +# 2. write some data to the fs with specified user and group +# 3. use zfs groupspace with all possible parameters to check the result +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + if datasetexists $snap_fs; then + log_must $ZFS destroy $snap_fs + fi + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the zfs groupspace with all possible parameters" + +set -A params -- "-h" "--help" "-n" "-H" "-p" "-o type,name,used,quota" \ + "-o name,used,quota" "-o used,quota" "-o used" "-o quota" \ + "-s type" "-s name" "-s used" "-s quota" \ + "-S type" "-S name" "-S used" "-S quota" \ + "-t posixuser" "-t posixgroup" "-t all" + +if check_version "5.11" ; then + set -A params -- "${params[@]}" "-i" "-t smbuser" "-t smbgroup" +fi + +typeset snap_fs=$QFS@snap + +log_must $ZFS set groupquota@$QGROUP=500m $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 $MKFILE 50m $QFILE + +$SYNC + +log_must $ZFS snapshot $snap_fs + +for param in "${params[@]}"; do + log_must eval "$ZFS groupspace $param $QFS >/dev/null 2>&1" + log_must eval "$ZFS groupspace $param $snap_fs >/dev/null 2>&1" +done + +log_pass "Check the zfs groupspace with all possible parameters" diff --git a/tests/sys/cddl/zfs/tests/userquota/groupspace_002_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/groupspace_002_pos.ksh new file mode 100644 index 00000000000..31548f964e4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/groupspace_002_pos.ksh @@ -0,0 +1,93 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)groupspace_002_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: groupspace_002_pos +# +# DESCRIPTION: +# Check the user used and groupspace size in zfs groupspace +# +# +# STRATEGY: +# 1. set zfs groupquota to a fs +# 2. write some data to the fs with specified user and size +# 3. use zfs groupspace to check the used size and quota size +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + if datasetexists $snapfs; then + log_must $ZFS destroy $snapfs + fi + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the zfs groupspace used and quota" + +log_must $ZFS set groupquota@$QGROUP=500m $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 $TRUNCATE -s 100m $QFILE + +$SYNC + +typeset snapfs=$QFS@snap + +log_must $ZFS snapshot $snapfs + +log_must eval "$ZFS groupspace $QFS >/dev/null 2>&1" +log_must eval "$ZFS groupspace $snapfs >/dev/null 2>&1" + +for fs in "$QFS" "$snapfs"; do + log_note "check the quota size in zfs groupspace $fs" + log_must eval "$ZFS groupspace $fs | $GREP $QGROUP | $GREP 500M" + + log_note "check the user used size in zfs groupspace $fs" + log_must eval "$ZFS groupspace $fs | $GREP $QGROUP | $GREP 100M" +done + +log_pass "Check the zfs groupspace used and quota pass as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/setup.ksh b/tests/sys/cddl/zfs/tests/userquota/setup.ksh new file mode 100644 index 00000000000..f96519dc2d3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/setup.ksh @@ -0,0 +1,48 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +verify_runnable "both" + +if ! is_userquota_supported; then + log_unsupported "userquota is not supported in this system." +fi + +log_must clean_user_group + +log_must add_group $QGROUP +log_must add_user $QGROUP $QUSER1 +log_must add_user $QGROUP $QUSER2 + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota.cfg b/tests/sys/cddl/zfs/tests/userquota/userquota.cfg new file mode 100644 index 00000000000..c73bfea2ebf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota.cfg @@ -0,0 +1,48 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota.cfg 1.1 09/06/22 SMI" +# + +export QUSER1=quser1 +export QUSER2=quser2 + +export QGROUP=qgroup +export QGROUP1=qgroup1 +export QGROUP1=qgroup2 + +export UQUOTA_SIZE=1000000 +export GQUOTA_SIZE=4000000 + +export QFS=$TESTPOOL/$TESTFS +export QFILE=$TESTDIR/qf.${TESTCASE_ID} +export OFILE=$TESTDIR/of.${TESTCASE_ID} + +export SNAP_QUOTA=100m +export TEST_QUOTA=88888 + diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_001_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_001_pos.ksh new file mode 100644 index 00000000000..c8fdc316c78 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_001_pos.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_001_pos.ksh 1.1 09/06/22 SMI" +# +################################################################################ +# +# +# __stc_assertion_start +# +# ID: userquota_001_pos +# +# DESCRIPTION: +# Check the basic function of the userquota and groupquota +# +# +# STRATEGY: +# 1. Set userquota and overwrite the quota size +# 2. The write operation should fail with Disc quota exceeded +# 3. Set groupquota and overwrite the quota size +# 4. The write operation should fail with Disc quota exceeded +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "If write operation overwrite {user|group}quota size, it will fail" + +mkmount_writable $QFS +log_note "Check the userquota@$QUSER1" +log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS +log_must user_run $QUSER1 $TRUNCATE -s UQUOTA_SIZE $QFILE +$SYNC +log_mustnot user_run $QUSER1 $TRUNCATE -s 1 $OFILE +cleanup_quota + +log_note "Check the groupquota@$QGROUP" +log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 $TRUNCATE -s $GQUOTA_SIZE $QFILE +$SYNC +log_mustnot user_run $TRUNCATE -s 1 $OFILE + +cleanup_quota + +log_pass "Write operation overwrite {user|group}quota size, it as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_002_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_002_pos.ksh new file mode 100644 index 00000000000..401584a00b9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_002_pos.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_002_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_002_pos +# +# DESCRIPTION: +# the userquota and groupquota can be set during zpool or zfs creation" +# +# +# STRATEGY: +# 1. Set userquota and groupquota via "zpool -O or zfs create -o" +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +verify_runnable "global" + +function cleanup +{ + destroy_pool $TESTPOOL1 + + if [[ -f $pool_vdev ]]; then + $RM -f $pool_vdev + fi +} + +log_onexit cleanup + +log_assert \ + "the userquota and groupquota can be set during zpool,zfs creation" + +typeset pool_vdev=$TMPDIR/pool_dev.${TESTCASE_ID} + +log_must create_vdevs $pool_vdev +destroy_pool $TESTPOOL1 + +log_must $ZPOOL create -O userquota@$QUSER1=$UQUOTA_SIZE \ + -O groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1 $pool_vdev + +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL1 > /dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL1 "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL1 "$GQUOTA_SIZE" + +log_must $ZFS create -o userquota@$QUSER1=$UQUOTA_SIZE \ + -o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL1/fs + +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL1 > /dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL1/fs "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL1/fs "$GQUOTA_SIZE" + +log_pass \ + "the userquota and groupquota can be set during zpool,zfs creation" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_003_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_003_pos.ksh new file mode 100644 index 00000000000..c007ed960c9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_003_pos.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_003_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_003_pos +# +# DESCRIPTION: +# Check the basic function of set/get userquota and groupquota on fs +# +# +# STRATEGY: +# 1. Set userquota on fs and check the zfs get +# 2. Set groupquota on fs and check the zfs get +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the basic function of set/get userquota and groupquota on fs" + +log_note "Check the set|get userquota@$QUSER1 and groupquota@QGROUP" +log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS +log_must check_quota "userquota@$QUSER1" $QFS "$UQUOTA_SIZE" + +log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS +log_must check_quota "groupquota@$QGROUP" $QFS "$GQUOTA_SIZE" + +log_pass "Check the basic function of set/get userquota on fs passed as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_004_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_004_pos.ksh new file mode 100644 index 00000000000..431c5c343df --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_004_pos.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_004_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_004_pos +# +# DESCRIPTION: +# Check the basic function user|group used +# +# +# STRATEGY: +# 1. Write some data to fs by normal user and check the user|group used +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the basic function of {user|group} used" + +typeset user_used=$(get_value "userused@$QUSER1" $QFS) +typeset group_used=$(get_value "groupused@$QGROUP" $QFS) + +if [[ $user_used != 0 ]]; then + log_fail "FAIL: userused should be 0" +fi +if [[ $group_used != 0 ]]; then + log_fail "FAIL: groupused should be 0" +fi + +mkmount_writable $QFS +log_must user_run $QUSER1 $TRUNCATE -s 100m $QFILE +$SYNC + +user_used=$(get_value "userused@$QUSER1" $QFS) +group_used=$(get_value "groupused@$QGROUP" $QFS) + +if [[ $user_used != "100M" ]]; then + log_note "user $QUSER1 used is $user_used" + log_fail "userused for user $QUSER1 expected to be 50.0M, not $user_used" +fi + +if [[ $user_used != $group_used ]]; then + log_note "user $QUSER1 used is $user_used" + log_note "group $QGROUP used is $group_used" + log_fail "FAIL: userused should equal to groupused" +fi + +log_pass "Check the basic function of {user|group}used pass as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_005_neg.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_005_neg.ksh new file mode 100644 index 00000000000..f6a7a4d3aff --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_005_neg.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_005_neg.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_005_neg +# +# DESCRIPTION: +# Check the invalid parameter of zfs set user|group quota +# +# +# STRATEGY: +# 1. check the invalid zfs set user|group quota to fs +# 1. check the valid zfs set user|group quota to snapshots +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + if datasetexists $snap_fs; then + log_must $ZFS destroy $snap_fs + fi + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the invalid parameter of zfs set user|group quota" +typeset snap_fs=$QFS@snap + +log_must $ZFS snapshot $snap_fs + +set -A no_users "mms1234" "ss@#" "root-122" +for user in "${no_users[@]}"; do + log_mustnot $ID $user + log_mustnot $ZFS set userquota@$user=100m $QFS +done + +log_note "can set all numberic id even that id is not existed" +log_must $ZFS set userquota@12345678=100m $QFS +log_mustnot $ZFS set userquota@12345678=100m $snap_fs + +set -A sizes "100mfsd" "m0.12m" "GGM" "-1234-m" "123m-m" + +for size in "${sizes[@]}"; do + log_note "can not set user quota with invalid size parameter" + log_mustnot $ZFS set userquota@root=$size $QFS +done + +log_note "can not set user quota to snapshot $snap_fs" +log_mustnot $ZFS set userquota@root=100m $snap_fs + + +set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "@@@@" +for group in "${no_groups[@]}"; do + log_mustnot eval "$GREP $group /etc/group" + log_mustnot $ZFS set groupquota@$group=100m $QFS +done + +log_note "can not set group quota with invalid size parameter" +log_mustnot $ZFS set groupquota@root=100msfsd $QFS + +log_note "can not set group quota to snapshot $snap_fs" +log_mustnot $ZFS set groupquota@root=100m $snap_fs + +log_pass "Check the invalid parameter of zfs set user|group quota pas as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_006_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_006_pos.ksh new file mode 100644 index 00000000000..b4cca662ecd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_006_pos.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_006_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_006_pos +# +# DESCRIPTION: +# Check the invalid parameter of zfs get user|group quota +# +# +# STRATEGY: +# 1. check the invalid zfs get user|group quota to fs +# 2. check the valid zfs get user|group quota to snapshots +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + if datasetexists $snap_fs; then + log_must $ZFS destroy $snap_fs + fi + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the invalid parameter of zfs get user|group quota" +typeset snap_fs=$QFS@snap + +log_must $ZFS snapshot $snap_fs + +set -A no_users "mms1234" "ss@#" "root-122" "1234" +for user in "${no_users[@]}"; do + log_mustnot eval "$ID $user >/dev/null 2>&1" + log_must eval "$ZFS get userquota@$user $QFS >/dev/null 2>&1" + log_must eval "$ZFS get userquota@$user $snap_fs >/dev/null 2>&1" +done + +set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "1234" +for group in "${no_groups[@]}"; do + log_mustnot eval "$GROUPDEL $group > /dev/null 2>&1" + log_must eval "$ZFS get groupquota@$group $QFS >/dev/null 2>&1" + log_must eval "$ZFS get groupquota@$group $snap_fs >/dev/null 2>&1" +done + +log_pass "Check the invalid parameter of zfs get user|group quota pass as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_007_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_007_pos.ksh new file mode 100644 index 00000000000..aa585fa4000 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_007_pos.ksh @@ -0,0 +1,89 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_007_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_007_pos +# +# DESCRIPTION: +# +# userquota/groupquota can be set beyond the fs quota +# userquota/groupquota can be set at a smaller size than its current usage. +# +# STRATEGY: +# 1. set quota to a fs and set a larger size of userquota and groupquota +# 2. write some data to the fs and set a smaller userquota and groupquota +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + log_must cleanup_quota + log_must $ZFS set quota=none $QFS +} + +log_onexit cleanup + +log_assert "Check set user|group quota to larger than the quota size of a fs" + +log_must $ZFS set quota=200m $QFS +log_must $ZFS set userquota@$QUSER1=500m $QFS +log_must $ZFS set groupquota@$QGROUP=600m $QFS + +log_must $ZFS get userquota@$QUSER1 $QFS +log_must $ZFS get groupquota@$QGROUP $QFS + +log_note "write some data to the $QFS" +mkmount_writable $QFS +log_must user_run $QUSER1 $MKFILE 100m $QFILE +$SYNC + +log_note "set user|group quota at a smaller size than it current usage" +log_must $ZFS set userquota@$QUSER1=90m $QFS +log_must $ZFS set groupquota@$QGROUP=90m $QFS + +log_must $ZFS get userquota@$QUSER1 $QFS +log_must $ZFS get groupquota@$QGROUP $QFS + +log_pass "set user|group quota to larger than quota size of a fs pass as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_008_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_008_pos.ksh new file mode 100644 index 00000000000..2c20ce3e671 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_008_pos.ksh @@ -0,0 +1,74 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_008_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_008_pos +# +# DESCRIPTION: +# +# zfs get all does not print out userquota/groupquota +# +# STRATEGY: +# 1. set userquota and groupquota to a fs +# 2. check zfs get all fs +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check zfs get all will not print out user|group quota" + +log_must $ZFS set userquota@$QUSER1=50m $QFS +log_must $ZFS set groupquota@$QGROUP=100m $QFS + +log_mustnot $ZFS get all $QFS | $GREP userquota +log_mustnot $ZFS get all $QFS | $GREP groupquota + +log_pass "zfs get all will not print out user|group quota" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_009_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_009_pos.ksh new file mode 100644 index 00000000000..bdc262fdcc9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_009_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_009_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_009_pos +# +# DESCRIPTION: +# Check user|group quota to snapshot that: +# 1) can not set user|group quota to snapshot directly +# 2) snapshot can inherit the parent fs's user|groupquota +# 3) the user|group quota will not change even the parent fs's quota changed. +# +# +# STRATEGY: +# 1. create a snapshot of a fs +# 2. set the user|group quota to snapshot and expect fail +# 3. set user|group quota to fs and check the snapshot +# 4. re-set user|group quota to fs and check the snapshot's value +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + if datasetexists $snap_fs; then + log_must $ZFS destroy $snap_fs + fi + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the snapshot's user|group quota" +typeset snap_fs=$QFS@snap + + +log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS +log_must check_quota "userquota@$QUSER1" $QFS "$UQUOTA_SIZE" + +log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS +log_must check_quota "groupquota@$QGROUP" $QFS "$GQUOTA_SIZE" + +log_must $ZFS snapshot $snap_fs + +log_note "check the snapshot $snap_fs user|group quota" +log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE" + +log_note "set userquota and groupquota to $snap_fs which will fail" +log_mustnot $ZFS set userquota@$QUSER1=$SNAP_QUOTA $snap_fs +log_mustnot $ZFS set groupquota@$QGROUP=$SNAP_QUOTA $snap_fs + +log_note "change the parent's userquota and groupquota" +log_must $ZFS set userquota@$QUSER1=$TEST_QUOTA $QFS +log_must $ZFS set groupquota@$QGROUP=$TEST_QUOTA $QFS + +log_must check_quota "userquota@$QUSER1" $QFS $TEST_QUOTA +log_must check_quota "groupquota@$QGROUP" $QFS $TEST_QUOTA + +log_note "check the snapshot $snap_fs userquota and groupquota" +log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE" + +log_pass "Check the snapshot's user|group quota pass as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_010_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_010_pos.ksh new file mode 100644 index 00000000000..10a72244e60 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_010_pos.ksh @@ -0,0 +1,88 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_010_pos.ksh 1.1 09/06/22 SMI" +# +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_010_pos +# +# DESCRIPTION: +# Check userquota and groupquota be overwrited at same time +# +# +# STRATEGY: +# 1. Set userquota and groupquota to a fs +# 2. write to exceed the userquota size to check the result +# 3. write to exceed the groupquota size to check the result +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + cleanup_quota +} + +log_onexit cleanup + +log_assert "overwrite any of the {user|group}quota size, it will fail" + +log_note "overwrite to $QFS to make it exceed userquota" +log_must $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $QFS +log_must $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $QFS + +mkmount_writable $QFS +log_must user_run $QUSER1 $MKFILE $UQUOTA_SIZE $QFILE +$SYNC + +log_must eval "$ZFS get -p userused@$QUSER1 $QFS >/dev/null 2>&1" +log_must eval "$ZFS get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1" + +log_mustnot user_run $QUSER1 $MKFILE 1 $OFILE + +log_must $RM -f $QFILE + +log_note "overwrite to $QFS to make it exceed userquota" +log_mustnot user_run $QUSER1 $MKFILE $GQUOTA_SIZE $QFILE + +log_must eval "$ZFS get -p userused@$QUSER1 $QFS >/dev/null 2>&1" +log_must eval "$ZFS get -p groupused@$GROUPUSED $QFS >/dev/null 2>&1" + +log_pass "overwrite any of the {user|group}quota size, it fail as expect" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_011_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_011_pos.ksh new file mode 100644 index 00000000000..73754f85d12 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_011_pos.ksh @@ -0,0 +1,141 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_011_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_011_pos +# +# DESCRIPTION: +# the userquota and groupquota will not change during zfs actions, such as +# snapshot,clone,rename,upgrade,send,receive. +# +# +# STRATEGY: +# 1. Create a pool, and create fs with preset user,group quota +# 2. Check set user|group quota via zfs snapshot|clone|list -o +# 3. Check the user|group quota can not change during zfs rename|upgrade|promote +# 4. Check the user|group quota can not change during zfs clone +# 5. Check the user|group quota can not change during zfs send/receive +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + for ds in $TESTPOOL/fs $TESTPOOL/fs-rename $TESTPOOL/fs-clone; do + if datasetexists $ds; then + log_must $ZFS destroy -rRf $ds + fi + done +} + +log_onexit cleanup + +log_assert \ + "the userquota and groupquota can't change during zfs actions" + +cleanup + +log_must $ZFS create -o userquota@$QUSER1=$UQUOTA_SIZE \ + -o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL/fs + +log_must $ZFS snapshot $TESTPOOL/fs@snap +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs@snap "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs@snap "$GQUOTA_SIZE" + + +log_note "clone fs gets its parent's userquota/groupquota initially" +log_must $ZFS clone -o userquota@$QUSER1=$UQUOTA_SIZE \ + -o groupquota@$QGROUP=$GQUOTA_SIZE \ + $TESTPOOL/fs@snap $TESTPOOL/fs-clone + +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE" + +log_must eval "$ZFS list -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL/fs-clone >/dev/null 2>&1" + +log_note "zfs promote can not change the previously set user|group quota" +log_must $ZFS promote $TESTPOOL/fs-clone + +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE" + +log_note "zfs send receive can not change the previously set user|group quota" +log_must $ZFS send $TESTPOOL/fs-clone@snap | $ZFS receive $TESTPOOL/fs-rev + +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rev "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rev "$GQUOTA_SIZE" + +log_note "zfs rename can not change the previously set user|group quota" +log_must $ZFS rename $TESTPOOL/fs-rev $TESTPOOL/fs-rename + +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE" + +log_note "zfs upgrade can not change the previously set user|group quota" +log_must $ZFS upgrade $TESTPOOL/fs-rename + +log_must eval "$ZFS list -r -o userquota@$QUSER1,groupquota@$QGROUP \ + $TESTPOOL >/dev/null 2>&1" + +log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE" +log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE" + +log_pass \ + "the userquota and groupquota can't change during zfs actions" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_012_neg.ksh b/tests/sys/cddl/zfs/tests/userquota/userquota_012_neg.ksh new file mode 100644 index 00000000000..0f093933cde --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_012_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_012_neg.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userquota_012_neg +# +# DESCRIPTION: +# userquota and groupquota can not be set against snapshot +# +# +# STRATEGY: +# 1. Set userquota on snap and check the zfs get +# 2. Set groupquota on snap and check the zfs get +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + cleanup_quota + + if datasetexists $snap_fs; then + log_must $ZFS destroy $snap_fs + fi +} + +log_onexit cleanup + +typeset snap_fs=$QFS@snap +log_assert "Check set userquota and groupquota on snapshot" + +log_note "Check can not set user|group quuota on snapshot" +log_must $ZFS snapshot $snap_fs + +log_mustnot $ZFS set userquota@$QUSER1=$UQUOTA_SIZE $snap_fs + +log_mustnot $ZFS set groupquota@$QGROUP=$GQUOTA_SIZE $snap_fs + +log_pass "Check set userquota and groupquota on snapshot" +t" diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_common.kshlib b/tests/sys/cddl/zfs/tests/userquota/userquota_common.kshlib new file mode 100644 index 00000000000..ff85e46c953 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_common.kshlib @@ -0,0 +1,147 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userquota_common.kshlib 1.1 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota.cfg + + +# +# Check if the test box support userquota or not. +# +function is_userquota_supported +{ + if ! fs_prop_exist "userquota@..."; then + return 1 + fi + + return 0 +} + +# +# reset the userquota and groupquota and delete temporary files +# +function cleanup_quota +{ + if datasetexists $QFS; then + log_must $ZFS set userquota@$QUSER1=none $QFS + log_must $ZFS set userquota@$QUSER2=none $QFS + log_must $ZFS set groupquota@$QGROUP=none $QFS + recovery_writable $QFS + fi + + [[ -f $QFILE ]] && log_must $RM -f $QFILE + [[ -f $OFILE ]] && log_must $RM -f $OFILE + + return 0 +} + +# +# delete user and group that created during the test +# +function clean_user_group +{ + for usr in $QUSER1 $QUSER2; do + log_must del_user $usr + done + + log_must del_group $QGROUP + + return 0 +} + +# +# make the $QFS's mountpoint writable for all users +# +function mkmount_writable +{ + typeset fs=$1 + typeset mntp=$(get_prop mountpoint $fs) + log_must $CHMOD 0777 $mntp +} + +# +# recovery the directory permission for $QFS +# +function recovery_writable +{ + typeset fs=$1 + typeset mntp=$(get_prop mountpoint $fs) + log_must $CHMOD 0755 $mntp +} + +# +# run command as specific user +# +function user_run +{ + typeset user=$1 + typeset group=$($GROUPS $user) + + shift + + eval \$RUNWATTR -u \$user -g \$group \"$@\" > /dev/null 2>&1 + return $? +} + +# +# check the quota value of a specific FS +# +function check_quota +{ + typeset fs=$2 + typeset prop=$1 + typeset expected=$3 + typeset value=$(get_prop $prop $fs) + + if (( $value != $expected )); then + return 1 + fi +} + +# +# zfs get prop, which return raw value not -p value. +# +function get_value # property dataset +{ + typeset prop_val + typeset prop=$1 + typeset dataset=$2 + + prop_val=$($ZFS get -H -o value $prop $dataset 2>/dev/null) + if [[ $? -ne 0 ]]; then + log_note "Unable to get $prop property for dataset " \ + "$dataset" + return 1 + fi + + $ECHO $prop_val + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/userquota/userquota_test.sh b/tests/sys/cddl/zfs/tests/userquota/userquota_test.sh new file mode 100755 index 00000000000..918d41c8a61 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userquota_test.sh @@ -0,0 +1,464 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case groupspace_001_pos cleanup +groupspace_001_pos_head() +{ + atf_set "descr" "Check the zfs groupspace with all possible parameters" + atf_set "require.progs" zfs runwattr +} +groupspace_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/groupspace_001_pos.ksh || atf_fail "Testcase failed" +} +groupspace_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case groupspace_002_pos cleanup +groupspace_002_pos_head() +{ + atf_set "descr" "Check the zfs groupspace used and quota" + atf_set "require.progs" zfs runwattr +} +groupspace_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/groupspace_002_pos.ksh || atf_fail "Testcase failed" +} +groupspace_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_001_pos cleanup +userquota_001_pos_head() +{ + atf_set "descr" "If write operation overwrite {user|group}quota size, it will fail" + atf_set "require.progs" zfs runwattr +} +userquota_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_001_pos.ksh || atf_fail "Testcase failed" +} +userquota_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_002_pos cleanup +userquota_002_pos_head() +{ + atf_set "descr" "the userquota and groupquota can be set during zpool,zfs creation" + atf_set "require.progs" zpool zfs +} +userquota_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_002_pos.ksh || atf_fail "Testcase failed" +} +userquota_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_003_pos cleanup +userquota_003_pos_head() +{ + atf_set "descr" "Check the basic function of set/get userquota and groupquota on fs" + atf_set "require.progs" zfs +} +userquota_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_003_pos.ksh || atf_fail "Testcase failed" +} +userquota_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_004_pos cleanup +userquota_004_pos_head() +{ + atf_set "descr" "Check the basic function of {user|group} used" + atf_set "require.progs" runwattr +} +userquota_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_004_pos.ksh || atf_fail "Testcase failed" +} +userquota_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_005_neg cleanup +userquota_005_neg_head() +{ + atf_set "descr" "Check the invalid parameter of zfs set user|group quota" + atf_set "require.progs" zfs +} +userquota_005_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_005_neg.ksh || atf_fail "Testcase failed" +} +userquota_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_006_pos cleanup +userquota_006_pos_head() +{ + atf_set "descr" "Check the invalid parameter of zfs get user|group quota" + atf_set "require.progs" zfs +} +userquota_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_006_pos.ksh || atf_fail "Testcase failed" +} +userquota_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_007_pos cleanup +userquota_007_pos_head() +{ + atf_set "descr" "Check set user|group quota to larger than the quota size of a fs" + atf_set "require.progs" zfs runwattr +} +userquota_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_007_pos.ksh || atf_fail "Testcase failed" +} +userquota_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_008_pos cleanup +userquota_008_pos_head() +{ + atf_set "descr" "Check zfs get all will not print out user|group quota" + atf_set "require.progs" zfs +} +userquota_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_008_pos.ksh || atf_fail "Testcase failed" +} +userquota_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_009_pos cleanup +userquota_009_pos_head() +{ + atf_set "descr" "Check the snapshot's user|group quota" + atf_set "require.progs" zfs +} +userquota_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_009_pos.ksh || atf_fail "Testcase failed" +} +userquota_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_010_pos cleanup +userquota_010_pos_head() +{ + atf_set "descr" "overwrite any of the {user|group}quota size, it will fail" + atf_set "require.progs" zfs runwattr +} +userquota_010_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_010_pos.ksh || atf_fail "Testcase failed" +} +userquota_010_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_011_pos cleanup +userquota_011_pos_head() +{ + atf_set "descr" "the userquota and groupquota can't change during zfs actions" + atf_set "require.progs" zfs +} +userquota_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_011_pos.ksh || atf_fail "Testcase failed" +} +userquota_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userquota_012_neg cleanup +userquota_012_neg_head() +{ + atf_set "descr" "Check set userquota and groupquota on snapshot" + atf_set "require.progs" zfs +} +userquota_012_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userquota_012_neg.ksh || atf_fail "Testcase failed" +} +userquota_012_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userspace_001_pos cleanup +userspace_001_pos_head() +{ + atf_set "descr" "Check the zfs userspace with all possible parameters" + atf_set "require.progs" zfs runwattr +} +userspace_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userspace_001_pos.ksh || atf_fail "Testcase failed" +} +userspace_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case userspace_002_pos cleanup +userspace_002_pos_head() +{ + atf_set "descr" "Check the zfs userspace used and quota" + atf_set "require.progs" zfs runwattr +} +userspace_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/userspace_002_pos.ksh || atf_fail "Testcase failed" +} +userspace_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/userquota_common.kshlib + . $(atf_get_srcdir)/userquota.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case groupspace_001_pos + atf_add_test_case groupspace_002_pos + atf_add_test_case userquota_001_pos + atf_add_test_case userquota_002_pos + atf_add_test_case userquota_003_pos + atf_add_test_case userquota_004_pos + atf_add_test_case userquota_005_neg + atf_add_test_case userquota_006_pos + atf_add_test_case userquota_007_pos + atf_add_test_case userquota_008_pos + atf_add_test_case userquota_009_pos + atf_add_test_case userquota_010_pos + atf_add_test_case userquota_011_pos + atf_add_test_case userquota_012_neg + atf_add_test_case userspace_001_pos + atf_add_test_case userspace_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/userquota/userspace_001_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userspace_001_pos.ksh new file mode 100644 index 00000000000..0a7cebfeb9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userspace_001_pos.ksh @@ -0,0 +1,98 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userspace_001_pos.ksh 1.2 09/08/06 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userspace_001_pos +# +# DESCRIPTION: +# Check the zfs userspace with all parameters +# +# +# STRATEGY: +# 1. set zfs userspace to a fs +# 2. write some data to the fs with specified user +# 3. use zfs userspace with all possible parameters to check the result +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + if datasetexists $snap_fs; then + log_must $ZFS destroy $snap_fs + fi + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the zfs userspace with all possible parameters" + +set -A params -- "-h" "--help" "-n" "-H" "-p" "-o type,name,used,quota" \ + "-o name,used,quota" "-o used,quota" "-o used" "-o quota" \ + "-s type" "-s name" "-s used" "-s quota" \ + "-S type" "-S name" "-S used" "-S quota" \ + "-t posixuser" "-t posixgroup" "-t all" + +if check_version "5.11" ; then + set -A params -- "${params[@]}" "-i" "-t smbuser" "-t smbgroup" +fi + +typeset snap_fs=$QFS@snap + +log_must $ZFS set userquota@$QUSER1=100m $QFS +mkmount_writable $QFS +log_must user_run $QUSER1 $MKFILE 50m $QFILE +$SYNC + +log_must $ZFS snapshot $snap_fs + +for param in "${params[@]}"; do + log_must eval "$ZFS userspace $param $QFS >/dev/null 2>&1" + log_must eval "$ZFS userspace $param $snap_fs >/dev/null 2>&1" +done + +log_pass "zfs userspace with all possible parameters pass as expect" + diff --git a/tests/sys/cddl/zfs/tests/userquota/userspace_002_pos.ksh b/tests/sys/cddl/zfs/tests/userquota/userspace_002_pos.ksh new file mode 100644 index 00000000000..2e5fed2e9e4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/userquota/userspace_002_pos.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)userspace_002_pos.ksh 1.1 09/06/22 SMI" +# + +################################################################################ +# +# __stc_assertion_start +# +# ID: userspace_002_pos +# +# DESCRIPTION: +# Check the user used size and quota in zfs userspace +# +# +# STRATEGY: +# 1. set zfs userquota to a fs +# 2. write some data to the fs with specified user and size +# 3. use zfs userspace to check the used size and quota size +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2009-04-16) +# +# __stc_assertion_end +# +############################################################################### + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/userquota/userquota_common.kshlib + +function cleanup +{ + if datasetexists $snapfs; then + log_must $ZFS destroy $snapfs + fi + + log_must cleanup_quota +} + +log_onexit cleanup + +log_assert "Check the zfs userspace used and quota" + +log_must $ZFS set userquota@$QUSER1=100m $QFS + +mkmount_writable $QFS + +log_must user_run $QUSER1 $MKFILE 50m $QFILE +$SYNC + +typeset snapfs=$QFS@snap + +log_must $ZFS snapshot $snapfs + +log_must eval "$ZFS userspace $QFS >/dev/null 2>&1" +log_must eval "$ZFS userspace $snapfs >/dev/null 2>&1" + +for fs in "$QFS" "$snapfs"; do + log_note "check the quota size in zfs userspace $fs" + log_must eval "$ZFS userspace $fs | $GREP $QUSER1 | $GREP 100M" + + log_note "check the user used size in zfs userspace $fs" + log_must eval "$ZFS userspace $fs | $GREP $QUSER1 | $GREP 50.0M" +done + +log_pass "Check the zfs userspace used and quota" diff --git a/tests/sys/cddl/zfs/tests/utils_test/Makefile b/tests/sys/cddl/zfs/tests/utils_test/Makefile new file mode 100644 index 00000000000..bbb4b7abe2a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/Makefile @@ -0,0 +1,27 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/utils_test +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= utils_test_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= utils_test_007_pos.ksh +${PACKAGE}FILES+= utils_test_003_pos.ksh +${PACKAGE}FILES+= utils_test_006_pos.ksh +${PACKAGE}FILES+= utils_test_002_pos.ksh +${PACKAGE}FILES+= utils_test.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= utils_test_004_pos.ksh +${PACKAGE}FILES+= utils_test_008_pos.ksh +${PACKAGE}FILES+= utils_test.cfg +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= utils_test_009_pos.ksh +${PACKAGE}FILES+= utils_test_005_pos.ksh +${PACKAGE}FILES+= utils_test_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/utils_test/cleanup.ksh b/tests/sys/cddl/zfs/tests/utils_test/cleanup.ksh new file mode 100644 index 00000000000..606fc7ac601 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/cleanup.ksh @@ -0,0 +1,33 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/utils_test/setup.ksh b/tests/sys/cddl/zfs/tests/utils_test/setup.ksh new file mode 100644 index 00000000000..7c575654194 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/setup.ksh @@ -0,0 +1,33 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib + +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test.cfg b/tests/sys/cddl/zfs/tests/utils_test/utils_test.cfg new file mode 100644 index 00000000000..2a354115130 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test.cfg @@ -0,0 +1,41 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test.cfg 1.3 08/08/15 SMI" +# + +export TESTSNAP=testsnap${TESTCASE_ID} +export TESTCLCT=testclct${TESTCASE_ID} +export TESTFILE=testfile${TESTCASE_ID} + +export WRITE_COUNT=20 +export BLOCKSZ=8192 +export DATA=0 +export NUM_FILES=10 + +export DISK=${DISKS%% *} diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test.kshlib b/tests/sys/cddl/zfs/tests/utils_test/utils_test.kshlib new file mode 100644 index 00000000000..f6df7a0678c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test.kshlib @@ -0,0 +1,30 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test.kshlib 1.2 07/01/09 SMI" +# diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_001_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_001_pos.ksh new file mode 100644 index 00000000000..2758378052c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_001_pos.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_001_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_001_pos +# +# DESCRIPTION: +# Ensure that the clri(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS directory with a number of files. +# 2. Run clri against the raw device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Ensure that the clri(1M) utility fails on a ZFS file system." + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA + +inode=`$LS -i $TESTDIR/$TESTFILE.0 | $AWK '{print $1}'` +log_mustnot $CLRI /dev/rdsk/$DISK $inode +log_mustnot $CLRI -F zfs /dev/rdsk/$DISK $inode + +log_pass "clri(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_002_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_002_pos.ksh new file mode 100644 index 00000000000..734b619c6f8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_002_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_002_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_002_pos +# +# DESCRIPTION: +# Ensure that the labelit(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS file system with some files. +# 2. Run labelit(1M) against the device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + ismounted $TESTPOOL/$TESTFS + (( $? != 0 )) && \ + log_must $ZFS mount $TESTPOOL/$TESTFS + + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Ensure that the labelit(1M) utility fails on a ZFS file system." + +test_requires LABELIT + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA + +log_must $ZFS unmount $TESTDIR + +log_mustnot $LABELIT /dev/rdsk/${DISK}s0 mfiles ${DISK}s0 + +log_pass "labelit(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_003_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_003_pos.ksh new file mode 100644 index 00000000000..169e8d59f60 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_003_pos.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_003_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_003_pos +# +# DESCRIPTION: +# Ensure that the fsdb(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS directory with a number of files. +# 2. Run fsdb against the raw device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Ensure that the fsdb(1M) utility fails on a ZFS file system." + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA +inode_num=`$LS -li $TESTDIR/$TESTFILE.0 | $AWK '{print $1}'` +[[ -z $inode_num ]] && \ + log_fail "Failed to determine inode of file: $TESTDIR/$TESTFILE.0" + +log_mustnot $ECHO ":inode $inode_num" | $FSDB ${DISK}a + +log_pass "fsdb(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_004_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_004_pos.ksh new file mode 100644 index 00000000000..960134c30cc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_004_pos.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_004_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_004_pos +# +# DESCRIPTION: +# Ensure that the quotaon(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Enable a quota on a ZFS file system. +# 2. Run quotaon against the device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Ensure that the quotaon(1M) utility fails on a ZFS file system." + +log_must $ZFS set quota=1099511627776 $TESTPOOL/$TESTFS +log_must $TOUCH $TESTDIR/quotas +log_mustnot $QUOTAON ${DISK}a + +log_pass "quotaon(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_005_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_005_pos.ksh new file mode 100644 index 00000000000..5501b5bceba --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_005_pos.ksh @@ -0,0 +1,75 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_005_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_005_pos +# +# DESCRIPTION: +# Ensure that the ff(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS file system with some files. +# 2. Run ff(1M) against the device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +test_requires FF + +log_assert "Ensure that the ff(1M) utility fails on a ZFS file system." + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA + +log_mustnot $FF -F zfs /dev/rdsk/${DISK}s0 + +log_pass "ff(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_006_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_006_pos.ksh new file mode 100644 index 00000000000..c78fe5abb18 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_006_pos.ksh @@ -0,0 +1,79 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_006_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_006_pos +# +# DESCRIPTION: +# Ensure that the fsirand(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS file system with some files. +# 2. Run fsirand(1M) against the device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + ismounted $TESTPOOL/$TESTFS + (( $? != 0 )) && \ + log_must $ZFS mount $TESTPOOL/$TESTFS + + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Ensure that the fsirand(1M) utility fails on a ZFS file system." + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA + +log_must $ZFS unmount $TESTDIR + +log_mustnot $FSIRAND /dev/rdsk/${DISK}s0 + +log_pass "fsirand(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_007_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_007_pos.ksh new file mode 100644 index 00000000000..34b8fa29b3d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_007_pos.ksh @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_007_pos.ksh 1.4 09/01/12 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_007_pos +# +# DESCRIPTION: +# Ensure that the fstyp(8) utility succeeds on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS file system with some files. +# 2. Run fstyp(8) against the device. +# 3. Ensure it passes +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + ismounted $TESTPOOL/$TESTFS + (( $? != 0 )) && \ + log_must $ZFS mount $TESTPOOL/$TESTFS + + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Ensure that the fstyp(8) utility succeeds on a ZFS file system." + +test_requires FSTYP + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA + +log_must $ZFS unmount $TESTDIR + +log_must $FSTYP -u $DISK +detected_filesystem=$( $FSTYP -u $DISK ) +if [ "$detected_filesystem" != "zfs" ]; then + log_fail "fstyp(8) detected $detected_filesystem instead of zfs" +fi + +log_pass "fstyp(8) returned successfully." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_008_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_008_pos.ksh new file mode 100644 index 00000000000..37d25725bba --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_008_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_008_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_008_pos +# +# DESCRIPTION: +# Ensure that the ncheck(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS file system with some files. +# 2. Run ncheck(1M) against the device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + ismounted $TESTPOOL/$TESTFS + (( $? != 0 )) && \ + log_must $ZFS mount $TESTPOOL/$TESTFS + + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +test_requires NCHECK + +log_assert "Ensure that the ncheck(1M) utility fails on a ZFS file system." + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA + +log_must $ZFS unmount $TESTDIR + +log_mustnot $NCHECK /dev/rdsk/${DISK}s0 + +log_pass "ncheck(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_009_pos.ksh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_009_pos.ksh new file mode 100644 index 00000000000..5ac8601ef65 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_009_pos.ksh @@ -0,0 +1,73 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)utils_test_009_pos.ksh 1.2 07/01/09 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/utils_test/utils_test.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: utils_test_009_pos +# +# DESCRIPTION: +# Ensure that the tunefs(1M) utility fails on a ZFS file system. +# +# STRATEGY: +# 1. Populate a ZFS file system with some files. +# 2. Run tunefs(1M) against the device. +# 3. Ensure it fails. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Ensure that the tunefs(1M) utility fails on a ZFS file system." + +populate_dir $TESTDIR/$TESTFILE $NUM_FILES $WRITE_COUNT $BLOCKSZ $DATA + +log_mustnot $TUNEFS -m 80 /dev/dsk/${DISK}s0 + +log_pass "tunefs(1M) returned an error as expected." diff --git a/tests/sys/cddl/zfs/tests/utils_test/utils_test_test.sh b/tests/sys/cddl/zfs/tests/utils_test/utils_test_test.sh new file mode 100755 index 00000000000..82fe2bbbd03 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/utils_test/utils_test_test.sh @@ -0,0 +1,276 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case utils_test_001_pos cleanup +utils_test_001_pos_head() +{ + atf_set "descr" "Ensure that the clri(1M) utility fails on a ZFS file system." + atf_set "require.progs" clri +} +utils_test_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_001_pos.ksh || atf_fail "Testcase failed" +} +utils_test_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_002_pos cleanup +utils_test_002_pos_head() +{ + atf_set "descr" "Ensure that the labelit(1M) utility fails on a ZFS file system." + atf_set "require.progs" zfs labelit +} +utils_test_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_002_pos.ksh || atf_fail "Testcase failed" +} +utils_test_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_003_pos cleanup +utils_test_003_pos_head() +{ + atf_set "descr" "Ensure that the fsdb(1M) utility fails on a ZFS file system." + atf_set "require.progs" fsdb +} +utils_test_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_003_pos.ksh || atf_fail "Testcase failed" +} +utils_test_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_004_pos cleanup +utils_test_004_pos_head() +{ + atf_set "descr" "Ensure that the quotaon(1M) utility fails on a ZFS file system." + atf_set "require.progs" zfs quotaon +} +utils_test_004_pos_body() +{ + atf_expect_fail "FreeBSD's quotaon utility exits 0 even when you supply a nonexistent filesystem" + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_004_pos.ksh || atf_fail "Testcase failed" +} +utils_test_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_005_pos cleanup +utils_test_005_pos_head() +{ + atf_set "descr" "Ensure that the ff(1M) utility fails on a ZFS file system." + atf_set "require.progs" ff +} +utils_test_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_005_pos.ksh || atf_fail "Testcase failed" +} +utils_test_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_006_pos cleanup +utils_test_006_pos_head() +{ + atf_set "descr" "Ensure that the fsirand(1M) utility fails on a ZFS file system." + atf_set "require.progs" zfs fsirand +} +utils_test_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_006_pos.ksh || atf_fail "Testcase failed" +} +utils_test_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_007_pos cleanup +utils_test_007_pos_head() +{ + atf_set "descr" "Ensure that the fstyp(1M) utility succeeds on a ZFS file system." + atf_set "require.progs" zfs fstyp +} +utils_test_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_007_pos.ksh || atf_fail "Testcase failed" +} +utils_test_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_008_pos cleanup +utils_test_008_pos_head() +{ + atf_set "descr" "Ensure that the ncheck(1M) utility fails on a ZFS file system." + atf_set "require.progs" zfs ncheck +} +utils_test_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_008_pos.ksh || atf_fail "Testcase failed" +} +utils_test_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case utils_test_009_pos cleanup +utils_test_009_pos_head() +{ + atf_set "descr" "Ensure that the tunefs(1M) utility fails on a ZFS file system." + atf_set "require.progs" tunefs +} +utils_test_009_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/utils_test_009_pos.ksh || atf_fail "Testcase failed" +} +utils_test_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/utils_test.kshlib + . $(atf_get_srcdir)/utils_test.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case utils_test_001_pos + atf_add_test_case utils_test_002_pos + atf_add_test_case utils_test_003_pos + atf_add_test_case utils_test_004_pos + atf_add_test_case utils_test_005_pos + atf_add_test_case utils_test_006_pos + atf_add_test_case utils_test_007_pos + atf_add_test_case utils_test_008_pos + atf_add_test_case utils_test_009_pos +} diff --git a/tests/sys/cddl/zfs/tests/write_dirs/Makefile b/tests/sys/cddl/zfs/tests/write_dirs/Makefile new file mode 100644 index 00000000000..d38228b7ce2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/write_dirs/Makefile @@ -0,0 +1,19 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/write_dirs +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= write_dirs_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= write_dirs.cfg +${PACKAGE}FILES+= write_dirs_002_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= write_dirs_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/write_dirs/cleanup.ksh b/tests/sys/cddl/zfs/tests/write_dirs/cleanup.ksh new file mode 100644 index 00000000000..239cc31ba33 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/write_dirs/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +destroy_pool $TESTPOOL +log_must wipe_partition_table $DISKS +log_must $RM -rf $TESTDIR +log_pass diff --git a/tests/sys/cddl/zfs/tests/write_dirs/setup.ksh b/tests/sys/cddl/zfs/tests/write_dirs/setup.ksh new file mode 100644 index 00000000000..fcaed25610a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/write_dirs/setup.ksh @@ -0,0 +1,41 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.4 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +DISK=${DISKS%% *} + +wipe_partition_table $DISK +log_must set_partition $PARTITION "" $SIZE $DISK + +default_setup "$DISK"p"$PARTITION" diff --git a/tests/sys/cddl/zfs/tests/write_dirs/write_dirs.cfg b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs.cfg new file mode 100644 index 00000000000..fddca0dfb65 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs.cfg @@ -0,0 +1,36 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)write_dirs.cfg 1.3 08/08/15 SMI" +# + +export TESTFILE=testfile${TESTCASE_ID} +export STF_TIMEOUT=1200 + +export SIZE="1gb" +export PARTITION=1 diff --git a/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_001_pos.ksh b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_001_pos.ksh new file mode 100644 index 00000000000..0dde726922a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_001_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)write_dirs_001_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +########################################################################### +# +# __stc_assertion_start +# +# ID: write_dirs_001_pos +# +# DESCRIPTION: +# Create as many directories with 50 big files each until the file system +# is full. The zfs file system should be stable and works well. +# +# STRATEGY: +# 1. Create a pool & dateset +# 2. Make directories in the zfs file system +# 3. Create 50 big files in each directories +# 4. Test case exit when the disk is full. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for file in `$FIND $TESTDIR -type f`; do + $CAT /dev/null > $file + done + log_must $SYNC + log_must $RM -rf $TESTDIR/* +} + +typeset -i retval=0 +log_assert "Creating directories with 50 big files in each, until file system "\ + "is full." + +log_onexit cleanup + +typeset -i bytes=8192 +typeset -i num_writes=300000 +typeset -i dirnum=50 +typeset -i filenum=50 + +fill_fs "" $dirnum $filenum $bytes $num_writes +retval=$? +if (( retval == 28 )); then + log_note "No space left on device." +elif (( retval != 0 )); then + log_fail "Unexpected exit: $retval" +fi + +log_pass "Write big files in a directory succeeded." diff --git a/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_002_pos.ksh b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_002_pos.ksh new file mode 100644 index 00000000000..7dccbda6773 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_002_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)write_dirs_002_pos.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +########################################################################### +# +# __stc_assertion_start +# +# ID: write_dirs_002_pos +# +# DESCRIPTION: +# Create as many directories with 5000 files each until the file system +# is full. The zfs file system should be work well and stable. +# +# STRATEGY: +# 1. Create a pool & dateset +# 2. Make directories in the zfs file system +# 3. Create 5000 files in each directories +# 4. Test case exit when the disk is full +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "both" + +function cleanup +{ + for file in `$FIND $TESTDIR -type f`; do + $CAT /dev/null > $file + done + log_must $SYNC + log_must $RM -rf $TESTDIR/* +} + +typeset -i retval=0 + +log_assert "Creating directories with 5000 files in each, until file system " \ + "is full." + +log_onexit cleanup + +typeset -i bytes=8192 +typeset -i num_writes=20 +typeset -i dirnum=50 +typeset -i filenum=5000 + +fill_fs "" $dirnum $filenum $bytes $num_writes +retval=$? +if (( retval == 28 )); then + log_note "No space left on device." +elif (( retval != 0 )); then + log_fail "Unexpected exit: $retval" +fi + +log_pass "Create many files in a directory succeeded." diff --git a/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_test.sh b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_test.sh new file mode 100755 index 00000000000..1028070f699 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/write_dirs/write_dirs_test.sh @@ -0,0 +1,84 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case write_dirs_001_pos cleanup +write_dirs_001_pos_head() +{ + atf_set "descr" "Creating directories with 50 big files in each, until file systemis full." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +write_dirs_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/write_dirs.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/write_dirs_001_pos.ksh || atf_fail "Testcase failed" +} +write_dirs_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/write_dirs.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case write_dirs_002_pos cleanup +write_dirs_002_pos_head() +{ + atf_set "descr" "Creating directories with 5000 files in each, until file systemis full." + atf_set "require.progs" zpool + atf_set "timeout" 1200 +} +write_dirs_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/write_dirs.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/write_dirs_002_pos.ksh || atf_fail "Testcase failed" +} +write_dirs_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/write_dirs.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case write_dirs_001_pos + atf_add_test_case write_dirs_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/xattr/Makefile b/tests/sys/cddl/zfs/tests/xattr/Makefile new file mode 100644 index 00000000000..4bff449c591 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/Makefile @@ -0,0 +1,31 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/xattr +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= xattr_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= xattr_002_neg.ksh +${PACKAGE}FILES+= xattr_012_pos.ksh +${PACKAGE}FILES+= xattr_013_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= xattr_003_neg.ksh +${PACKAGE}FILES+= xattr_007_neg.ksh +${PACKAGE}FILES+= xattr_common.kshlib +${PACKAGE}FILES+= xattr.cfg +${PACKAGE}FILES+= xattr_006_pos.ksh +${PACKAGE}FILES+= xattr_011_pos.ksh +${PACKAGE}FILES+= xattr_010_neg.ksh +${PACKAGE}FILES+= xattr_009_neg.ksh +${PACKAGE}FILES+= xattr_008_pos.ksh +${PACKAGE}FILES+= xattr_004_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= xattr_005_pos.ksh +${PACKAGE}FILES+= xattr_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/xattr/cleanup.ksh b/tests/sys/cddl/zfs/tests/xattr/cleanup.ksh new file mode 100644 index 00000000000..7f0267376e5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/cleanup.ksh @@ -0,0 +1,43 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/05/29 SMI" +# + +# $FreeBSD$ + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/tests/xattr/xattr.cfg + +del_user $ZFS_USER + +if [ "${USES_NIS}" == "true" ] +then + $SVCADM enable svc:/network/nis/client:default +fi + +$RM $TMPDIR/zfs-xattr-test-user.txt +$RM $TMPDIR/zfs-xattr-test-nis.txt + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/xattr/setup.ksh b/tests/sys/cddl/zfs/tests/xattr/setup.ksh new file mode 100644 index 00000000000..0e2b96d5b18 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/setup.ksh @@ -0,0 +1,62 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.2 07/05/29 SMI" +# + +# $FreeBSD$ + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/tests/xattr/xattr.cfg + +# if we're running NIS, turn it off until we clean up +# (it can cause useradd to take a long time, hitting our TIMEOUT) +$SVCS svc:/network/nis/client:default | $GREP online > /dev/null +if [ $? -eq 0 ] +then + $SVCADM disable -t svc:/network/nis/client:default + USES_NIS=true +fi + +# Make sure we use a brand new user for this +while [ -z "${FOUND}" ] +do + COUNT=0 + USER_EXISTS=$( $GREP $ZFS_USER /etc/passwd ) + if [ ! -z "${USER_EXISTS}" ] + then + ZFS_USER="${ZFS_USER}${COUNT}" + COUNT=$(( $COUNT + 1 )) + else + FOUND="true" + fi +done + +log_must add_user $ZFS_GROUP $ZFS_USER + +$ECHO $ZFS_USER > $TMPDIR/zfs-xattr-test-user.txt +$ECHO $USES_NIS > $TMPDIR/zfs-xattr-test-nis.txt + +DISK=${DISKS%% *} +default_setup $DISK diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr.cfg b/tests/sys/cddl/zfs/tests/xattr/xattr.cfg new file mode 100644 index 00000000000..b2404d91ff4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr.cfg @@ -0,0 +1,54 @@ +#!/bin/ksh -p +# vim: filetype=sh +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr.cfg 1.3 08/08/15 SMI" +# + +# $FreeBSD$ + +# a variable we set during setup to indicate whether we need to +# re-enable the nis/client during cleanup. +USES_NIS=false + +# A username we can create for the course of the zfs xattr +# testing (modified by setup if it already exists) +ZFS_USER=zxtr +ZFS_GROUP=staff + +# These variables may also have been tweaked by the setup script +# Let's import them if necessary. +if [ -f $TMPDIR/zfs-xattr-test-nis.txt ] +then + USES_NIS=$($CAT $TMPDIR/zfs-xattr-test-nis.txt) +fi + +if [ -f $TMPDIR/zfs-xattr-test-user.txt ] +then + ZFS_USER=$($CAT $TMPDIR/zfs-xattr-test-user.txt) +fi + +export ZFS_USER +export ZFS_GROUP +export USES_NIS diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_001_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_001_pos.ksh new file mode 100644 index 00000000000..f955b15bf1b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_001_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_001_pos.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_001_pos +# +# DESCRIPTION: +# +# Creating, reading and writing xattrs on ZFS filesystems works as expected +# +# STRATEGY: +# 1. Create an xattr on a ZFS-based file using runat +# 2. Read an empty xattr directory +# 3. Write the xattr using runat and cat +# 3. Read the xattr using runat +# 4. Delete the xattr +# 5. List the xattr namespace successfully, checking for deletion +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-05) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + if [ -f $TESTDIR/myfile.${TESTCASE_ID} ] + then + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} + fi +} + +log_assert "Create/read/write/append of xattrs works" +log_onexit cleanup + +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd +verify_write_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd +delete_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd + +log_pass "Create/read/write of xattrs works" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_002_neg.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_002_neg.ksh new file mode 100644 index 00000000000..371234109ad --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_002_neg.ksh @@ -0,0 +1,70 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_002_neg.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_002_neg +# +# DESCRIPTION: +# +# Trying to read a non-existent xattr should fail. +# +# STRATEGY: +# 1. Create a file +# 2. Try to read a non-existent xattr, check that an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-12-05) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} + +} + +log_assert "A read of a non-existent xattr fails" +log_onexit cleanup + +# create a file +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +log_mustnot eval "$CAT $TESTDIR/myfile.${TESTCASE_ID} not-here.txt > /dev/null 2>&1" + +log_pass "A read of a non-existent xattr fails" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_003_neg.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_003_neg.ksh new file mode 100644 index 00000000000..7023c86888d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_003_neg.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_003_neg.ksh 1.2 07/05/29 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_003_neg +# +# DESCRIPTION: +# +# Attempting to read an xattr on a file for which we have no permissions +# should fail. +# +# STRATEGY: +# 1. Create a file, and set an with an xattr +# 2. Set the octal file permissions to 000 on the file. +# 3. Check that we're unable to read the xattr as a non-root user +# 4. Check that we're unable to write an xattr as a non-root user +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-05) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} + +} + +log_assert "read/write xattr on a file with no permissions fails" +log_onexit cleanup + +test_requires RUNAT + +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +log_must $CHMOD 000 $TESTDIR/myfile.${TESTCASE_ID} +log_mustnot $RUNWATTR -u $ZFS_USER -g $ZFS_GROUP \ + "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $CAT passwd" + +log_mustnot $RUNWATTR -u $ZFS_USER -g $ZFS_GROUP \ + "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $CP /etc/passwd ." + +log_pass "read/write xattr on a file with no permissions fails" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_004_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_004_pos.ksh new file mode 100644 index 00000000000..de8ead8e850 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_004_pos.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_004_pos.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_004_pos +# +# DESCRIPTION: +# +# Creating files on ufs and tmpfs, and copying those files to ZFS with +# appropriate cp flags, the xattrs will still be readable. +# +# STRATEGY: +# 1. Create files in ufs and tmpfs with xattrs +# 2. Copy those files to zfs +# 3. Ensure the xattrs can be read and written +# 4. Do the same in reverse. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-05) +# +# __stc_assertion_end +# +################################################################################ + +# we need to be able to create zvols to hold our test +# ufs filesystem. +verify_runnable "global" + +# Make sure we clean up properly +function cleanup { + + if [ $( ismounted $TMPDIR/ufs.${TESTCASE_ID} ufs ) ] + then + log_must $UMOUNT $TMPDIR/ufs.${TESTCASE_ID} + log_must $RM -rf $TMPDIR/ufs.${TESTCASE_ID} + fi +} + +log_assert "Files from ufs,tmpfs with xattrs copied to zfs retain xattr info." +log_onexit cleanup + +test_requires RUNAT + +# Create a UFS file system that we can work in +log_must $ZFS create -V128m $TESTPOOL/$TESTFS/zvol +log_must eval "$ECHO y | $NEWFS /dev/zvol/dsk/$TESTPOOL/$TESTFS/zvol > /dev/null 2>&1" + +log_must $MKDIR $TMPDIR/ufs.${TESTCASE_ID} +log_must $MOUNT /dev/zvol/dsk/$TESTPOOL/$TESTFS/zvol $TMPDIR/ufs.${TESTCASE_ID} + +# Create files in ufs and tmpfs, and set some xattrs on them. +log_must $TOUCH $TMPDIR/ufs.${TESTCASE_ID}/ufs-file.${TESTCASE_ID} +log_must $TOUCH $TMPDIR/tmpfs-file.${TESTCASE_ID} + +log_must $RUNAT $TMPDIR/ufs.${TESTCASE_ID}/ufs-file.${TESTCASE_ID} $CP /etc/passwd . +log_must $RUNAT $TMPDIR/tmpfs-file.${TESTCASE_ID} $CP /etc/group . + +# copy those files to ZFS +log_must $CP -@ $TMPDIR/ufs.${TESTCASE_ID}/ufs-file.${TESTCASE_ID} $TESTDIR +log_must $CP -@ $TMPDIR/tmpfs-file.${TESTCASE_ID} $TESTDIR + +# ensure the xattr information has been copied correctly +log_must $RUNAT $TESTDIR/ufs-file.${TESTCASE_ID} $DIFF passwd /etc/passwd +log_must $RUNAT $TESTDIR/tmpfs-file.${TESTCASE_ID} $DIFF group /etc/group + +log_must $UMOUNT $TMPDIR/ufs.${TESTCASE_ID} +log_pass "Files from ufs,tmpfs with xattrs copied to zfs retain xattr info." diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_005_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_005_pos.ksh new file mode 100644 index 00000000000..d9886278bd0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_005_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_005_pos.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_005_pos +# +# DESCRIPTION: +# read/write/create/delete xattr on a clone filesystem +# +# +# STRATEGY: +# 1. Create an xattr on a filesystem +# 2. Snapshot the filesystem and clone it +# 3. Verify the xattr can still be read, written, deleted +# 4. Verify we can create new xattrs on new files created on the clone +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-13) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $ZFS destroy $TESTPOOL/$TESTFS/clone + log_must $ZFS destroy $TESTPOOL/$TESTFS@snapshot1 + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} +} + +log_assert "read/write/create/delete xattr on a clone filesystem" +log_onexit cleanup + +# create a file, and an xattr on it +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +# snapshot & clone the filesystem +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snapshot1 +log_must $ZFS clone $TESTPOOL/$TESTFS@snapshot1 $TESTPOOL/$TESTFS/clone +log_must $ZFS set mountpoint=$TESTDIR/clone $TESTPOOL/$TESTFS/clone + +# check for the xattrs on the clone +verify_xattr $TESTDIR/clone/myfile.${TESTCASE_ID} passwd /etc/passwd + +# check we can create xattrs on the clone +create_xattr $TESTDIR/clone/myfile.${TESTCASE_ID} foo /etc/passwd +delete_xattr $TESTDIR/clone/myfile.${TESTCASE_ID} foo + +# delete the original dataset xattr +delete_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd + +# verify it's still there on the clone +verify_xattr $TESTDIR/clone/myfile.${TESTCASE_ID} passwd /etc/passwd +delete_xattr $TESTDIR/clone/myfile.${TESTCASE_ID} passwd + +log_pass "read/write/create/delete xattr on a clone filesystem" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_006_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_006_pos.ksh new file mode 100644 index 00000000000..4a1422fc873 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_006_pos.ksh @@ -0,0 +1,77 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_006_pos.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_006_pos +# +# DESCRIPTION: +# Xattrs present on a file in a snapshot should be visible. +# +# STRATEGY: +# 1. Create a file and give it an xattr +# 2. Take a snapshot of the filesystem +# 3. Verify that we can take a snapshot of it. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-05) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $ZFS destroy $TESTPOOL/$TESTFS@snap + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} + +} + +log_assert "read xattr on a snapshot" +log_onexit cleanup + +# create a file, and an xattr on it +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +# snapshot the filesystem +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap + +# check for the xattr on the snapshot +verify_xattr $TESTDIR/$(get_snapdir_name)/snap/myfile.${TESTCASE_ID} passwd /etc/passwd + +log_pass "read xattr on a snapshot" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_007_neg.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_007_neg.ksh new file mode 100644 index 00000000000..991e692db35 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_007_neg.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_007_neg.ksh 1.2 08/02/27 SMI" +# +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +# $FreeBSD$ + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_007_neg +# +# DESCRIPTION: +# Creating and writing xattrs on files in snapshot directories fails. Also, +# we shouldn't be able to list the xattrs of files in snapshots who didn't have +# xattrs when the snapshot was created (the xattr namespace wouldn't have been +# created yet, and snapshots are read-only) See fsattr(5) for more details. +# +# STRATEGY: +# 1. Create a file and add an xattr to it. +# 2. Create another file, but don't add an xattr to it. +# 3. Snapshot the filesystem +# 4. Verify we're unable to alter the xattr on the first file +# 5. Verify we're unable to list the xattrs on the second file +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-13) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + log_must $ZFS destroy $TESTPOOL/$TESTFS@snap + log_must $RM $TESTDIR/myfile2.${TESTCASE_ID} + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} + log_must $RM $TMPDIR/output.${TESTCASE_ID} + [[ -e $TMPDIR/expected_output.${TESTCASE_ID} ]] && log_must $RM \ + $TMPDIR/expected_output.${TESTCASE_ID} + +} + +log_assert "create/write xattr on a snapshot fails" +log_onexit cleanup + +# create a file, and an xattr on it +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +# create another file that doesn't have an xattr +log_must $TOUCH $TESTDIR/myfile2.${TESTCASE_ID} + +# snapshot the filesystem +log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap + +# we shouldn't be able to alter the first file's xattr +log_mustnot eval " $RUNAT $TESTDIR/$(get_snapdir_name)/snap/myfile.${TESTCASE_ID} \ + $CP /etc/passwd . >$TMPDIR/output.${TESTCASE_ID} 2>&1" +log_must $GREP -i Read-only $TMPDIR/output.${TESTCASE_ID} + +if check_version "5.10" +then + # we shouldn't be able to list xattrs at all on the second file + log_mustnot eval " $RUNAT $TESTDIR/$(get_snapdir_name)/snap/myfile2.${TESTCASE_ID} \ + $LS >$TMPDIR/output.${TESTCASE_ID} 2>&1" + log_must $GREP -i Read-only $TMPDIR/output.${TESTCASE_ID} +else + log_must eval "$RUNAT $TESTDIR/$(get_snapdir_name)/snap/myfile2.${TESTCASE_ID} \ + $LS >$TMPDIR/output.${TESTCASE_ID} 2>&1" + create_expected_output $TMPDIR/expected_output.${TESTCASE_ID} SUNWattr_ro \ + SUNWattr_rw + log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected_output.${TESTCASE_ID} +fi +log_pass "create/write xattr on a snapshot fails" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_008_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_008_pos.ksh new file mode 100644 index 00000000000..ea590c84e9a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_008_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_008_pos.ksh 1.2 08/02/27 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_008_pos +# +# DESCRIPTION: +# We verify that the special . and .. dirs work as expected for xattrs. +# +# STRATEGY: +# 1. Create a file and an xattr on that file +# 2. List the . directory, verifying the output +# 3. Verify we're unable to list the ../ directory +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-05) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + typeset file + + for file in $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID} \ + $TESTDIR/myfile.${TESTCASE_ID} ; do + log_must $RM -f $file + done +} + +log_assert "special . and .. dirs work as expected for xattrs" +log_onexit cleanup + +test_requires RUNAT + +# create a file, and an xattr on it +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +if check_version "5.10" +then + # listing the directory . should show one file + OUTPUT=$($RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS .) + if [ "$OUTPUT" != "passwd" ] + then + log_fail "Listing the . directory doesn't show \"passwd\" as expected." + fi + # list the directory . long form + log_must eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS -a . > $TMPDIR/output.${TESTCASE_ID}" + # create a file that should be the same as the command above + create_expected_output $TMPDIR/expected-output.${TESTCASE_ID} . .. passwd + # compare them + log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID} +else + # listing the directory . + log_must eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS . > $TMPDIR/output.${TESTCASE_ID}" + create_expected_output $TMPDIR/expected-output.${TESTCASE_ID} \ + SUNWattr_ro SUNWattr_rw passwd + log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID} + # list the directory . long form + log_must eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS -a . > $TMPDIR/output.${TESTCASE_ID}" + create_expected_output $TMPDIR/expected-output.${TESTCASE_ID} . .. \ + SUNWattr_ro SUNWattr_rw passwd + log_must $DIFF $TMPDIR/output.${TESTCASE_ID} $TMPDIR/expected-output.${TESTCASE_ID} +fi + +# list the directory .. expecting one file +OUTPUT=$($RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS ..) +if [ "$OUTPUT" != ".." ] +then + log_fail "Listing the .. directory doesn't show \"..\" as expected." +fi + +# verify we can't list ../ +log_mustnot eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LS ../ > /dev/null 2>&1" + +log_pass "special . and .. dirs work as expected for xattrs" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_009_neg.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_009_neg.ksh new file mode 100644 index 00000000000..96f9ba1fd40 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_009_neg.ksh @@ -0,0 +1,78 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_009_neg.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_009_neg +# +# DESCRIPTION: +# links between xattr and normal file namespace fail +# +# STRATEGY: +# 1. Create a file and add an xattr to it (to ensure the namespace exists) +# 2. Verify we're unable to create a symbolic link +# 3. Verify we're unable to create a hard link +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-13) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} + +} + +log_assert "links between xattr and normal file namespace fail" +log_onexit cleanup + +test_requires RUNAT + +# create a file, and an xattr on it +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +# Try to create a soft link from the xattr namespace to the default namespace +log_mustnot $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LN -s /etc/passwd foo + +# Try to create a hard link from the xattr namespace to the default namespace +log_mustnot $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $LN /etc/passwd foo + +log_pass "links between xattr and normal file namespace fail" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_010_neg.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_010_neg.ksh new file mode 100644 index 00000000000..0b11ccdd357 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_010_neg.ksh @@ -0,0 +1,82 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_010_neg.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_010_neg +# +# DESCRIPTION: +# Verify that mkdir and various mknods fail inside the xattr namespace +# +# STRATEGY: +# 1. Create a file and add an xattr to it (to ensure the namespace exists) +# 2. Verify that mkdir fails inside the xattr namespace +# 3. Verify that various mknods fails inside the xattr namespace +# +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-13) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} +} + +log_assert "mkdir, mknod fail" +log_onexit cleanup + +test_requires RUNAT + +# create a file, and an xattr on it +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +# Try to create directory in the xattr namespace +log_mustnot $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $MKDIR foo + +# Try to create a range of different filetypes in the xattr namespace +log_mustnot $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $MKNOD block b 888 888 + +log_mustnot $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $MKNOD char c + +log_mustnot $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $MKNOD fifo p + +log_pass "mkdir, mknod fail" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_011_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_011_pos.ksh new file mode 100644 index 00000000000..1ea0826a665 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_011_pos.ksh @@ -0,0 +1,203 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_011_pos.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_011_pos +# +# DESCRIPTION: +# +# Basic applications work with xattrs: cpio cp find mv pax tar +# +# STRATEGY: +# 1. For each application +# 2. Create an xattr and archive/move/copy/find files with xattr support +# 3. Also check that when appropriate flag is not used, the xattr +# doesn't get copied +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-15) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} +} + +log_assert "Basic applications work with xattrs: cpio cp find mv pax tar" +log_onexit cleanup + +test_requires RUNAT + +# Create a file, and set an xattr on it. This file is used in several of the +# test scenarios below. +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + + +# For the archive applications below (tar, cpio, pax) +# we create two archives, one with xattrs, one without +# and try various cpio options extracting the archives +# with and without xattr support, checking for correct behaviour + + +log_note "Checking cpio" +log_must $TOUCH $TESTDIR/cpio.${TESTCASE_ID} +create_xattr $TESTDIR/cpio.${TESTCASE_ID} passwd /etc/passwd +$ECHO $TESTDIR/cpio.${TESTCASE_ID} | $CPIO -o@ > $TMPDIR/xattr.${TESTCASE_ID}.cpio +$ECHO $TESTDIR/cpio.${TESTCASE_ID} | $CPIO -o > $TMPDIR/noxattr.${TESTCASE_ID}.cpio + +# we should have no xattr here +log_must $CPIO -iu < $TMPDIR/xattr.${TESTCASE_ID}.cpio +log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" + +# we should have an xattr here +log_must $CPIO -iu@ < $TMPDIR/xattr.${TESTCASE_ID}.cpio +log_must eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" + +# we should have no xattr here +log_must $CPIO -iu < $TMPDIR/noxattr.${TESTCASE_ID}.cpio +log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" + +# we should have no xattr here +log_must $CPIO -iu@ < $TMPDIR/noxattr.${TESTCASE_ID}.cpio +log_mustnot eval "$RUNAT $TESTDIR/cpio.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/cpio.${TESTCASE_ID} $TMPDIR/xattr.${TESTCASE_ID}.cpio $TMPDIR/noxattr.${TESTCASE_ID}.cpio + + + +log_note "Checking cp" +# check that with the right flag, the xattr is preserved +log_must $CP -@ $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID} +compare_xattrs $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID} passwd +log_must $RM $TESTDIR/myfile2.${TESTCASE_ID} + +# without the right flag, there should be no xattr +log_must $CP $TESTDIR/myfile.${TESTCASE_ID} $TESTDIR/myfile2.${TESTCASE_ID} +log_mustnot eval "$RUNAT $TESTDIR/myfile2.${TESTCASE_ID} $LS passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/myfile2.${TESTCASE_ID} + + + +log_note "Checking find" +# create a file without xattrs, and check that find -xattr only finds +# our test file that has an xattr. +log_must $MKDIR $TESTDIR/noxattrs +log_must $TOUCH $TESTDIR/noxattrs/no-xattr + +$FIND $TESTDIR -xattr | $GREP myfile.${TESTCASE_ID} +if [ $? -ne 0 ] +then + log_fail "find -xattr didn't find our file that had an xattr." +fi +$FIND $TESTDIR -xattr | $GREP no-xattr +if [ $? -eq 0 ] +then + log_fail "find -xattr found a file that didn't have an xattr." +fi +log_must $RM -rf $TESTDIR/noxattrs + + + +log_note "Checking mv" +# mv doesn't have any flags to preserve/ommit xattrs - they're +# always moved. +log_must $TOUCH $TESTDIR/mvfile.${TESTCASE_ID} +create_xattr $TESTDIR/mvfile.${TESTCASE_ID} passwd /etc/passwd +log_must $MV $TESTDIR/mvfile.${TESTCASE_ID} $TESTDIR/mvfile2.${TESTCASE_ID} +verify_xattr $TESTDIR/mvfile2.${TESTCASE_ID} passwd /etc/passwd +log_must $RM $TESTDIR/mvfile2.${TESTCASE_ID} + + +log_note "Checking pax" +log_must $TOUCH $TESTDIR/pax.${TESTCASE_ID} +create_xattr $TESTDIR/pax.${TESTCASE_ID} passwd /etc/passwd +log_must $PAX -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.${TESTCASE_ID} +log_must $PAX -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.${TESTCASE_ID} +log_must $RM $TESTDIR/pax.${TESTCASE_ID} + +# we should have no xattr here +log_must $PAX -r -f $TESTDIR/noxattr.pax +log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/pax.${TESTCASE_ID} + +# we should have no xattr here +log_must $PAX -r@ -f $TESTDIR/noxattr.pax +log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/pax.${TESTCASE_ID} + + +# we should have an xattr here +log_must $PAX -r@ -f $TESTDIR/xattr.pax +verify_xattr $TESTDIR/pax.${TESTCASE_ID} passwd /etc/passwd +log_must $RM $TESTDIR/pax.${TESTCASE_ID} + +# we should have no xattr here +log_must $PAX -r -f $TESTDIR/xattr.pax +log_mustnot eval "$RUNAT $TESTDIR/pax.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/pax.${TESTCASE_ID} $TESTDIR/noxattr.pax $TESTDIR/xattr.pax + + +log_note "Checking tar" +log_must $TOUCH $TESTDIR/tar.${TESTCASE_ID} +create_xattr $TESTDIR/tar.${TESTCASE_ID} passwd /etc/passwd +log_must $TAR cf $TESTDIR/noxattr.tar $TESTDIR/tar.${TESTCASE_ID} +log_must $TAR c@f $TESTDIR/xattr.tar $TESTDIR/tar.${TESTCASE_ID} +log_must $RM $TESTDIR/tar.${TESTCASE_ID} + +# we should have no xattr here +log_must $TAR xf $TESTDIR/xattr.tar +log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/tar.${TESTCASE_ID} + +# we should have an xattr here +log_must $TAR x@f $TESTDIR/xattr.tar +verify_xattr $TESTDIR/tar.${TESTCASE_ID} passwd /etc/passwd +log_must $RM $TESTDIR/tar.${TESTCASE_ID} + +# we should have no xattr here +log_must $TAR xf $TESTDIR/noxattr.tar +log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/tar.${TESTCASE_ID} + +# we should have no xattr here +log_must $TAR x@f $TESTDIR/noxattr.tar +log_mustnot eval "$RUNAT $TESTDIR/tar.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_must $RM $TESTDIR/tar.${TESTCASE_ID} $TESTDIR/noxattr.tar $TESTDIR/xattr.tar diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_012_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_012_pos.ksh new file mode 100644 index 00000000000..c355d386207 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_012_pos.ksh @@ -0,0 +1,119 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_012_pos.ksh 1.2 08/02/27 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_012_pos +# +# DESCRIPTION: +# xattr file sizes count towards normal disk usage +# +# STRATEGY: +# 1. Create a file, and check pool and filesystem usage +# 2. Create a 200mb xattr in that file +# 3. Check pool and filesystem usage, to ensure it reflects the size +# of the xattr +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-15) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} +} + +function get_pool_size { + poolname=$1 + psize=$( $ZPOOL list -H -o used $poolname ) + if [[ $psize == *[mM] ]] + then + returnvalue=$($ECHO $psize | $SED -e 's/m//g' -e 's/M//g') + returnvalue=$(( returnvalue * 1024 )) + else + returnvalue=$($ECHO $psize | $SED -e 's/k//g' -e 's/K//g') + fi + print $returnvalue +} + +log_assert "xattr file sizes count towards normal disk usage" +log_onexit cleanup + +test_requires RUNAT + +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} + +POOL_SIZE=0 +NEW_POOL_SIZE=0 + +if is_global_zone +then + # get pool and filesystem sizes. Since we're starting with an empty + # pool, the usage should be small - a few k. + POOL_SIZE=$(get_pool_size $TESTPOOL) +fi + +FS_SIZE=$( $ZFS get -p -H -o value used $TESTPOOL/$TESTFS ) + +log_must $RUNAT $TESTDIR/myfile.${TESTCASE_ID} $MKFILE 200m xattr + +#Make sure the newly created file is counted into zpool usage +log_must $SYNC + +# now check to see if our pool disk usage has increased +if is_global_zone +then + NEW_POOL_SIZE=$(get_pool_size $TESTPOOL) + if (( $NEW_POOL_SIZE <= $POOL_SIZE )) + then + log_fail "The new pool size $NEW_POOL_SIZE was less \ + than or equal to the old pool size $POOL_SIZE." + fi + +fi + +# also make sure our filesystem usage has increased +NEW_FS_SIZE=$( $ZFS get -p -H -o value used $TESTPOOL/$TESTFS ) +if (( $NEW_FS_SIZE <= $FS_SIZE )) +then + log_fail "The new filesystem size $NEW_FS_SIZE was less \ + than or equal to the old filesystem size $FS_SIZE." +fi + +log_pass "xattr file sizes count towards normal disk usage" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_013_pos.ksh b/tests/sys/cddl/zfs/tests/xattr/xattr_013_pos.ksh new file mode 100644 index 00000000000..468705a6499 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_013_pos.ksh @@ -0,0 +1,104 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_013_pos.ksh 1.1 07/02/06 SMI" +# + +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/xattr/xattr_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: xattr_013_pos +# +# DESCRIPTION: +# The noxattr mount option functions as expected +# +# STRATEGY: +# 1. Create a file on a filesystem and add an xattr to it +# 2. Unmount the filesystem, and mount it -o noxattr +# 3. Verify that the xattr cannot be read and new files +# cannot have xattrs set on them. +# 4. Unmount and mount the filesystem normally +# 5. Verify that xattrs can be set and accessed again +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-15) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $RM $TESTDIR/myfile.${TESTCASE_ID} +} + + +log_assert "The noxattr mount option functions as expected" +log_onexit cleanup + +test_requires RUNAT + +$ZFS set 2>&1 | $GREP xattr > /dev/null +if [ $? -ne 0 ] +then + log_unsupported "noxattr mount option not supported on this release." +fi + +log_must $TOUCH $TESTDIR/myfile.${TESTCASE_ID} +create_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +log_must $UMOUNT $TESTDIR +log_must $ZFS mount -o noxattr $TESTPOOL/$TESTFS + +# check that we can't perform xattr operations +log_mustnot eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +log_mustnot eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $RM passwd > /dev/null 2>&1" +log_mustnot eval "$RUNAT $TESTDIR/myfile.${TESTCASE_ID} $CP /etc/passwd . > /dev/null 2>&1" + +log_must $TOUCH $TESTDIR/new.${TESTCASE_ID} +log_mustnot eval "$RUNAT $TESTDIR/new.${TESTCASE_ID} $CP /etc/passwd . > /dev/null 2>&1" +log_mustnot eval "$RUNAT $TESTDIR/new.${TESTCASE_ID} $RM passwd > /dev/null 2>&1" + +# now mount the filesystem again as normal +log_must $UMOUNT $TESTDIR +log_must $ZFS mount $TESTPOOL/$TESTFS + +# we should still have an xattr on the first file +verify_xattr $TESTDIR/myfile.${TESTCASE_ID} passwd /etc/passwd + +# there should be no xattr on the file we created while the fs was mounted +# -o noxattr +log_mustnot eval "$RUNAT $TESTDIR/new.${TESTCASE_ID} $CAT passwd > /dev/null 2>&1" +create_xattr $TESTDIR/new.${TESTCASE_ID} passwd /etc/passwd + +log_pass "The noxattr mount option functions as expected" diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_common.kshlib b/tests/sys/cddl/zfs/tests/xattr/xattr_common.kshlib new file mode 100644 index 00000000000..f9feedba219 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_common.kshlib @@ -0,0 +1,108 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)xattr_common.kshlib 1.3 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# a function that takes a file, then creates and verifies +# an xattr on that file. The xattr_contents is the file +# that should appear in the xattr namespace. +function create_xattr { # filename xattr_name xattr_contents + typeset FILE=$1 + typeset XATTR_NAME=$2 + typeset XATTR_CONTENTS=$3 + + # read any empty xattr on that file + log_must $RUNAT $FILE $LS + # create the xattr + log_must $RUNAT $FILE $CP $XATTR_CONTENTS $XATTR_NAME + + verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS +} + +# a function that compares the a single xattr between two files +# and checks to see if their contents are identical +function compare_xattrs { # filename1 filename2 xattr_name + typeset FILE1=$1 + typeset FILE2=$2 + typeset XATTR_NAME=$3 + + $RUNAT $FILE1 $CAT $XATTR_NAME > $TMPDIR/file1.${TESTCASE_ID} + $RUNAT $FILE2 $CAT $XATTR_NAME > $TMPDIR/file2.${TESTCASE_ID} + + log_must $DIFF $TMPDIR/file1.${TESTCASE_ID} $TMPDIR/file2.${TESTCASE_ID} + log_must $RM $TMPDIR/file1.${TESTCASE_ID} $TMPDIR/file2.${TESTCASE_ID} +} + +function verify_xattr { # filename xattr_name xattr_contents + typeset FILE=$1 + typeset XATTR_NAME=$2 + typeset XATTR_CONTENTS=$3 + + # read the xattr, writing it to a temp file + log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 2>&1" + log_must $DIFF $XATTR_CONTENTS $TMPDIR/$XATTR_NAME.${TESTCASE_ID} + $RM $TMPDIR/$XATTR_NAME.${TESTCASE_ID} +} + +function delete_xattr { # filename xattr_name + typeset FILE=$1 + typeset XATTR_NAME=$2 + + # delete the xattr + log_must $RUNAT $FILE $RM $XATTR_NAME + log_mustnot eval "$RUNAT $FILE $LS $XATTR_NAME > /dev/null 2>&1" +} + +# not sure about this : really this should be testing write/append +function verify_write_xattr { # filename xattr_name + typeset FILE=$1 + typeset XATTR_NAME=$2 + + log_must eval "$RUNAT $FILE $DD if=/etc/passwd of=$XATTR_NAME" + log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 2>&1" + log_must $DD if=/etc/passwd of=$TMPDIR/passwd_dd.${TESTCASE_ID} + log_must $DIFF $TMPDIR/passwd_dd.${TESTCASE_ID} $TMPDIR/$XATTR_NAME.${TESTCASE_ID} + log_must $RM $TMPDIR/passwd_dd.${TESTCASE_ID} $TMPDIR/$XATTR_NAME.${TESTCASE_ID} +} + +# this function is to create the expected output +function create_expected_output { # expected_output_file contents_of_the_output + typeset FILE=$1 + shift + if [[ -f $FILE ]]; then + log_must $RM $FILE + fi + + for line in $@ + do + log_must eval "$ECHO $line >> $FILE" + done + } diff --git a/tests/sys/cddl/zfs/tests/xattr/xattr_test.sh b/tests/sys/cddl/zfs/tests/xattr/xattr_test.sh new file mode 100755 index 00000000000..7f7106a3468 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/xattr/xattr_test.sh @@ -0,0 +1,370 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case xattr_001_pos cleanup +xattr_001_pos_head() +{ + atf_set "descr" "Create/read/write/append of xattrs works" + atf_set "require.progs" svcadm svcs +} +xattr_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_001_pos.ksh || atf_fail "Testcase failed" +} +xattr_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_002_neg cleanup +xattr_002_neg_head() +{ + atf_set "descr" "A read of a non-existent xattr fails" + atf_set "require.progs" svcadm svcs +} +xattr_002_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_002_neg.ksh || atf_fail "Testcase failed" +} +xattr_002_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_003_neg cleanup +xattr_003_neg_head() +{ + atf_set "descr" "read/write xattr on a file with no permissions fails" + atf_set "require.progs" svcs svcadm runat runwattr +} +xattr_003_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_003_neg.ksh || atf_fail "Testcase failed" +} +xattr_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_004_pos cleanup +xattr_004_pos_head() +{ + atf_set "descr" "Files from ufs,tmpfs with xattrs copied to zfs retain xattr info." + atf_set "require.progs" zfs svcadm runat svcs +} +xattr_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_004_pos.ksh || atf_fail "Testcase failed" +} +xattr_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_005_pos cleanup +xattr_005_pos_head() +{ + atf_set "descr" "read/write/create/delete xattr on a clone filesystem" + atf_set "require.progs" zfs svcadm svcs +} +xattr_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_005_pos.ksh || atf_fail "Testcase failed" +} +xattr_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_006_pos cleanup +xattr_006_pos_head() +{ + atf_set "descr" "read xattr on a snapshot" + atf_set "require.progs" zfs svcadm svcs +} +xattr_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_006_pos.ksh || atf_fail "Testcase failed" +} +xattr_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_007_neg cleanup +xattr_007_neg_head() +{ + atf_set "descr" "create/write xattr on a snapshot fails" + atf_set "require.progs" zfs svcadm runat svcs +} +xattr_007_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_007_neg.ksh || atf_fail "Testcase failed" +} +xattr_007_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_008_pos cleanup +xattr_008_pos_head() +{ + atf_set "descr" "special . and .. dirs work as expected for xattrs" + atf_set "require.progs" svcadm runat svcs +} +xattr_008_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_008_pos.ksh || atf_fail "Testcase failed" +} +xattr_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_009_neg cleanup +xattr_009_neg_head() +{ + atf_set "descr" "links between xattr and normal file namespace fail" + atf_set "require.progs" svcadm runat svcs +} +xattr_009_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_009_neg.ksh || atf_fail "Testcase failed" +} +xattr_009_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_010_neg cleanup +xattr_010_neg_head() +{ + atf_set "descr" "mkdir, mknod fail" + atf_set "require.progs" svcadm runat svcs +} +xattr_010_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_010_neg.ksh || atf_fail "Testcase failed" +} +xattr_010_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_011_pos cleanup +xattr_011_pos_head() +{ + atf_set "descr" "Basic applications work with xattrs: cpio cp find mv pax tar" + atf_set "require.progs" pax svcadm runat svcs +} +xattr_011_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_011_pos.ksh || atf_fail "Testcase failed" +} +xattr_011_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_012_pos cleanup +xattr_012_pos_head() +{ + atf_set "descr" "xattr file sizes count towards normal disk usage" + atf_set "require.progs" svcadm zfs runat zpool svcs +} +xattr_012_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_012_pos.ksh || atf_fail "Testcase failed" +} +xattr_012_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case xattr_013_pos cleanup +xattr_013_pos_head() +{ + atf_set "descr" "The noxattr mount option functions as expected" + atf_set "require.progs" zfs svcadm runat svcs +} +xattr_013_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/xattr_013_pos.ksh || atf_fail "Testcase failed" +} +xattr_013_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/xattr_common.kshlib + . $(atf_get_srcdir)/xattr.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case xattr_001_pos + atf_add_test_case xattr_002_neg + atf_add_test_case xattr_003_neg + atf_add_test_case xattr_004_pos + atf_add_test_case xattr_005_pos + atf_add_test_case xattr_006_pos + atf_add_test_case xattr_007_neg + atf_add_test_case xattr_008_pos + atf_add_test_case xattr_009_neg + atf_add_test_case xattr_010_neg + atf_add_test_case xattr_011_pos + atf_add_test_case xattr_012_pos + atf_add_test_case xattr_013_pos +} diff --git a/tests/sys/cddl/zfs/tests/zfsd/Makefile b/tests/sys/cddl/zfs/tests/zfsd/Makefile new file mode 100644 index 00000000000..6bdbae7886a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/Makefile @@ -0,0 +1,38 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zfsd +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zfsd_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= hotspare_cleanup.ksh +${PACKAGE}FILES+= hotspare_setup.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zfsd.cfg +${PACKAGE}FILES+= zfsd.kshlib +${PACKAGE}FILES+= zfsd_autoreplace_001_neg.ksh +${PACKAGE}FILES+= zfsd_autoreplace_002_pos.ksh +${PACKAGE}FILES+= zfsd_autoreplace_003_pos.ksh +${PACKAGE}FILES+= zfsd_degrade_001_pos.ksh +${PACKAGE}FILES+= zfsd_degrade_002_pos.ksh +${PACKAGE}FILES+= zfsd_fault_001_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_001_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_002_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_003_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_004_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_005_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_006_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_007_pos.ksh +${PACKAGE}FILES+= zfsd_hotspare_008_neg.ksh +${PACKAGE}FILES+= zfsd_import_001_pos.ksh +${PACKAGE}FILES+= zfsd_replace_001_pos.ksh +${PACKAGE}FILES+= zfsd_replace_002_pos.ksh +${PACKAGE}FILES+= zfsd_replace_003_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zfsd/cleanup.ksh b/tests/sys/cddl/zfs/tests/zfsd/cleanup.ksh new file mode 100644 index 00000000000..3d1869c9e93 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/cleanup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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) 2012,2013 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# $FreeBSD$ + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/include/libgnop.kshlib + +# Rotate logs now, because this test can generate a great volume of log entries +newsyslog + +default_cleanup_noexit +destroy_gnops ${DISKS} +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/hotspare_cleanup.ksh b/tests/sys/cddl/zfs/tests/zfsd/hotspare_cleanup.ksh new file mode 100644 index 00000000000..cd6c35800f6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/hotspare_cleanup.ksh @@ -0,0 +1,47 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2013 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +# + +# This is the cleanup script for ZFSD tests that are based on the hotspare +# framework. It is almost identical to tests/hotspare/cleanup.ksh, +# but does not restart ZFSD. + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +verify_runnable "global" + +log_must cleanup_devices_all + +log_pass + + diff --git a/tests/sys/cddl/zfs/tests/zfsd/hotspare_setup.ksh b/tests/sys/cddl/zfs/tests/zfsd/hotspare_setup.ksh new file mode 100644 index 00000000000..341e541badf --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/hotspare_setup.ksh @@ -0,0 +1,45 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2013 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +# + +# This is the setup script for ZFSD tests that are based on the hotspare +# framework. It is almost identical to tests/hotspare/setup.ksh, +# but does not stop ZFSD. + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +verify_runnable "global" + +log_must cleanup_devices_all + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/setup.ksh b/tests/sys/cddl/zfs/tests/zfsd/setup.ksh new file mode 100644 index 00000000000..78792c6c886 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/setup.ksh @@ -0,0 +1,34 @@ +#!/usr/local/bin/ksh93 -p +# +# 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) 2012,2013 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# $FreeBSD$ + +. ${STF_SUITE}/include/libtest.kshlib + +# Rotate logs now, because this test can generate a great volume of log entries +newsyslog + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd.cfg b/tests/sys/cddl/zfs/tests/zfsd/zfsd.cfg new file mode 100644 index 00000000000..d515d44c404 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd.cfg @@ -0,0 +1,32 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright (c) 2012,2013 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# + +export TESTFILE=testfile.${TESTCASE_ID} +export STF_TIMEOUT=300 diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib b/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib new file mode 100644 index 00000000000..4a7f9b09e18 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib @@ -0,0 +1,85 @@ +#!/usr/local/bin/ksh93 -p +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + +# Common routines used by multiple zfsd tests + +function wait_for_pool_dev_state_change +{ + typeset -i timeout=$1 + typeset disk=$2 + typeset state=$3 + + log_note "Waiting up to $timeout seconds for $disk to become $state ..." + for ((; $timeout > 0; timeout=$timeout-1)); do + check_state $TESTPOOL "$disk" "$state" + [ $? -eq 0 ] && return + $SLEEP 1 + done + log_must $ZPOOL status $TESTPOOL + log_fail "ERROR: Disk $disk not marked as $state in $TESTPOOL" +} + +function wait_for_pool_removal +{ + typeset -i timeout=$1 + wait_for_pool_dev_state_change $timeout $REMOVAL_DISK "REMOVED|UNAVAIL" +} + +function wait_until_scrubbed +{ + typeset pool=$1 + + while is_pool_scrubbing $pool; do + log_note "$pool still scrubbing..." + $SLEEP 1 + done +} + +function corrupt_pool_vdev +{ + typeset pool=$1 + typeset vdev=$2 + typeset file=$3 + + # do some IO on the pool + log_must $DD if=/dev/zero of=$file bs=1024k count=64 + $FSYNC $file + + # scribble on the underlying file to corrupt the vdev + log_must $DD if=/dev/urandom of=$vdev bs=1024k count=64 conv=notrunc + + # Scrub the pool to detect the corruption + log_must $ZPOOL scrub $pool + wait_until_scrubbed $pool + + # ZFSD can take up to 60 seconds to degrade an array in response to + # errors (though it's usually faster). + wait_for_pool_dev_state_change 60 $vdev DEGRADED +} diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_001_neg.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_001_neg.ksh new file mode 100644 index 00000000000..9e811d06f94 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_001_neg.ksh @@ -0,0 +1,95 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_007_pos.ksh 1.0 12/08/10 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib +. $STF_SUITE/include/libgnop.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_autoreplace_001_neg +# +# DESCRIPTION: +# In a pool without the autoreplace property unset, a vdev will not be +# replaced by physical path +# +# STRATEGY: +# 1. Create 1 storage pool without hot spares +# 2. Remove a vdev +# 4. Create a new vdev with the same physical path as the first one +# 9. Verify that it does not get added to the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2013-02-4) +# +# __stc_assertion_end +# +############################################################################### + +log_assert "A pool without the autoreplace property set will not replace disks by physical path" + +function verify_assertion +{ + # 9. Verify that it does not get added to the pool + for ((timeout=0; timeout<4; timeout=$timeout+1)); do + log_mustnot check_state $TESTPOOL $REMOVAL_DISK "ONLINE" + $SLEEP 5 + done +} + +typeset PHYSPATH="some_physical_path" +typeset REMOVAL_DISK=$DISK0 +typeset REMOVAL_NOP=${DISK0}.nop +typeset NEW_DISK=$DISK4 +typeset NEW_NOP=${DISK4}.nop +typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}" +typeset ALLDISKS="${DISK0} ${DISK1} ${DISK2} ${DISK3}" +typeset ALLNOPS=${ALLDISKS//~(E)([[:space:]]+|$)/.nop\1} +set -A MY_KEYWORDS "mirror" "raidz1" "raidz2" +ensure_zfsd_running +log_must create_gnops $OTHER_DISKS +for keyword in "${MY_KEYWORDS[@]}" ; do + log_must create_gnop $REMOVAL_DISK $PHYSPATH + log_must create_pool $TESTPOOL $keyword $ALLNOPS + log_must $ZPOOL set autoreplace=on $TESTPOOL + + log_must destroy_gnop $REMOVAL_DISK + log_must create_gnop $NEW_DISK $PHYSPATH + verify_assertion + destroy_pool "$TESTPOOL" + log_must destroy_gnop $NEW_DISK +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_002_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_002_pos.ksh new file mode 100644 index 00000000000..64be3c05503 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_002_pos.ksh @@ -0,0 +1,92 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_007_pos.ksh 1.0 12/08/10 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib +. $STF_SUITE/include/libgnop.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_autoreplace_002_pos +# +# DESCRIPTION: +# In a pool with the autoreplace property set, a vdev will be +# replaced by physical path +# +# STRATEGY: +# 1. Create 1 storage pool without hot spares +# 2. Remove a vdev +# 4. Create a new vdev with the same physical path as the first one +# 9. Verify that it does get added to the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2013-02-4) +# +# __stc_assertion_end +# +############################################################################### + +log_assert "A pool with the autoreplace property will replace disks by physical path" + +function verify_assertion +{ + wait_for_pool_dev_state_change 20 $NEW_DISK ONLINE +} + + +typeset PHYSPATH="some_physical_path" +typeset REMOVAL_DISK=$DISK0 +typeset REMOVAL_NOP=${DISK0}.nop +typeset NEW_DISK=$DISK4 +typeset NEW_NOP=${DISK4}.nop +typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}" +typeset ALLDISKS="${DISK0} ${DISK1} ${DISK2} ${DISK3}" +typeset ALLNOPS=${ALLDISKS//~(E)([[:space:]]+|$)/.nop\1} +set -A MY_KEYWORDS "mirror" "raidz1" "raidz2" +ensure_zfsd_running +log_must create_gnops $OTHER_DISKS +for keyword in "${MY_KEYWORDS[@]}" ; do + log_must create_gnop $REMOVAL_DISK $PHYSPATH + log_must create_pool $TESTPOOL $keyword $ALLNOPS + log_must $ZPOOL set autoreplace=on $TESTPOOL + + log_must destroy_gnop $REMOVAL_DISK + log_must create_gnop $NEW_DISK $PHYSPATH + verify_assertion + destroy_pool "$TESTPOOL" + log_must destroy_gnop $NEW_DISK +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_003_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_003_pos.ksh new file mode 100644 index 00000000000..beb2a100c35 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_autoreplace_003_pos.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib +. $STF_SUITE/include/libgnop.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_autoreplace_003_pos +# +# DESCRIPTION: +# In a pool with the autoreplace property set, a vdev will be +# replaced by physical path even if a spare is already active for that +# vdev +# +# STRATEGY: +# 1. Create 1 storage pool with a hot spare +# 2. Remove a vdev +# 3. Wait for the hotspare to fully resilver +# 4. Create a new vdev with the same physical path as the first one +# 10. Verify that it does get added to the pool. +# 11. Verify that the hotspare gets removed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2013-05-13) +# +# __stc_assertion_end +# +############################################################################### + +log_assert "A pool with the autoreplace property will replace disks by physical path, even if a spare is active" + +function verify_assertion +{ + # Verify that the replacement disk gets added to the pool + wait_for_pool_dev_state_change 20 $NEW_DISK ONLINE + + # Wait for resilvering to complete + wait_until_resilvered + + # Check that the spare is deactivated + wait_for_pool_dev_state_change 20 "$SPARE_DISK" "AVAIL" +} + + +typeset PHYSPATH="some_physical_path" +typeset REMOVAL_DISK=$DISK0 +typeset REMOVAL_NOP=${DISK0}.nop +typeset NEW_DISK=$DISK4 +typeset NEW_NOP=${DISK4}.nop +typeset SPARE_DISK=${DISK5} +typeset SPARE_NOP=${DISK5}.nop +typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}" +typeset OTHER_NOPS=${OTHER_DISKS//~(E)([[:space:]]+|$)/.nop\1} +set -A MY_KEYWORDS "mirror" "raidz1" "raidz2" +ensure_zfsd_running +log_must create_gnops $OTHER_DISKS $SPARE_DISK +for keyword in "${MY_KEYWORDS[@]}" ; do + log_must create_gnop $REMOVAL_DISK $PHYSPATH + log_must create_pool $TESTPOOL $keyword $REMOVAL_NOP $OTHER_NOPS spare $SPARE_NOP + log_must $ZPOOL set autoreplace=on $TESTPOOL + + log_must destroy_gnop $REMOVAL_DISK + log_must create_gnop $NEW_DISK $PHYSPATH + verify_assertion + destroy_pool "$TESTPOOL" + log_must destroy_gnop $NEW_DISK +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_degrade_001_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_degrade_001_pos.ksh new file mode 100644 index 00000000000..246d012465e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_degrade_001_pos.ksh @@ -0,0 +1,90 @@ +#!/usr/local/bin/ksh93 -p +# +# 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) 2012,2013 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_degrade_001_pos +# +# DESCRIPTION: +# If a vdev experiences checksum errors, it will become degraded. +# +# +# STRATEGY: +# 1. Create a storage pool. Only use the file vdevs because it is easy to +# generate checksum errors on them. +# 2. Mostly fill the pool with data. +# 3. Corrupt it by DDing to the underlying vdev +# 4. Verify that the vdev becomes DEGRADED. +# 5. ONLINE it and verify that it resilvers and joins the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2012-08-09) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +VDEV0=${TMPDIR}/file0.${TESTCASE_ID} +VDEV1=${TMPDIR}/file1.${TESTCASE_ID} +VDEVS="${VDEV0} ${VDEV1}" +TESTFILE=/$TESTPOOL/testfile +VDEV_SIZE=192m + + +function cleanup +{ + destroy_pool $TESTPOOL + $RM -f $VDEVS +} + +log_assert "ZFS will degrade a vdev that produces checksum errors" + +log_onexit cleanup + +log_must create_vdevs $VDEV0 $VDEV1 +ensure_zfsd_running +for type in "raidz" "mirror"; do + log_note "Testing raid type $type" + + create_pool $TESTPOOL $type ${VDEVS} + corrupt_pool_vdev $TESTPOOL $VDEV1 $TESTFILE + destroy_pool $TESTPOOL +done + +cleanup +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_degrade_002_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_degrade_002_pos.ksh new file mode 100644 index 00000000000..962bbaf2f53 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_degrade_002_pos.ksh @@ -0,0 +1,102 @@ +#!/usr/local/bin/ksh93 -p +# +# 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) 2012-2014 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_degrade_002_pos +# +# DESCRIPTION: +# If an active hotspare experiences checksum errors, it will become degraded. +# +# +# STRATEGY: +# 1. Create a storage pool with a hotspare. Only use the file vdevs because +# it is easy to generate checksum errors on them. +# 2. fault a vdev to active the hotspare +# 3. Mostly fill the pool with data. +# 4. Corrupt it by DDing to the hotspare's underlying file. +# 5. Verify that the hotspare becomes DEGRADED. +# 6. ONLINE it and verify that it resilvers and joins the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2014-05-13) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +VDEV0=${TMPDIR}/file0.${TESTCASE_ID} +VDEV1=${TMPDIR}/file1.${TESTCASE_ID} +SPARE_VDEV=${TMPDIR}/file2.${TESTCASE_ID} +BASIC_VDEVS="${VDEV0} ${VDEV1}" +VDEVS="${BASIC_VDEVS} ${SPARE_VDEV}" +TESTFILE=/$TESTPOOL/testfile +VDEV_SIZE=192m + + +function cleanup +{ + destroy_pool $TESTPOOL + $RM -f $VDEVS +} + +log_assert "ZFS will degrade a spare vdev that produces checksum errors" + +log_onexit cleanup + +ensure_zfsd_running +log_must create_vdevs $VDEV0 $VDEV1 $SPARE_VDEV + +for type in "mirror" "raidz"; do + log_note "Testing raid type $type" + + create_pool $TESTPOOL $type ${BASIC_VDEVS} spare ${SPARE_VDEV} + + # Activate the hotspare + $ZINJECT -d ${VDEV0} -A fault $TESTPOOL + + # ZFSD can take up to 60 seconds to replace a failed device + # (though it's usually faster). + wait_for_pool_dev_state_change 60 $SPARE_VDEV INUSE + + corrupt_pool_vdev $TESTPOOL $SPARE_VDEV $TESTFILE + destroy_pool $TESTPOOL +done + +cleanup +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_fault_001_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_fault_001_pos.ksh new file mode 100644 index 00000000000..5dfc8e9a9d1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_fault_001_pos.ksh @@ -0,0 +1,163 @@ +#!/usr/local/bin/ksh93 -p +# +# 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) 2012,2013 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_fault_001_pos +# +# DESCRIPTION: +# If a vdev experiences IO errors, it will become faulted. +# +# +# STRATEGY: +# 1. Create a storage pool. Only use the da driver (FreeBSD's SCSI disk +# driver) because it has a special interface for simulating IO errors. +# 2. Inject IO errors while doing IO to the pool. +# 3. Verify that the vdev becomes FAULTED. +# 4. ONLINE it and verify that it resilvers and joins the pool. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2012-08-09) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + # Disable error injection, if still active + sysctl kern.cam.da.$TMPDISKNUM.error_inject=0 > /dev/null + + if poolexists $TESTPOOL; then + # We should not get here if the test passed. Print the output + # of zpool status to assist in debugging. + $ZPOOL status + # Clear out artificially generated errors and destroy the pool + $ZPOOL clear $TESTPOOL + destroy_pool $TESTPOOL + fi +} + +log_assert "ZFS will fault a vdev that produces IO errors" + +log_onexit cleanup +ensure_zfsd_running + +# Make sure that at least one of the disks is using the da driver, and use +# that disk for inject errors +typeset TMPDISK="" +for d in $DISKS +do + b=`basename $d` + if test ${b%%[0-9]*} == da + then + TMPDISK=$b + TMPDISKNUM=${b##da} + break + fi +done +if test -z $TMPDISK +then + log_unsupported "This test requires at least one disk to use the da driver" +fi + + +for type in "raidz" "mirror"; do + log_note "Testing raid type $type" + + # Create a pool on the supplied disks + create_pool $TESTPOOL $type $DISKS + log_must $ZFS create $TESTPOOL/$TESTFS + + # Cause some IO errors writing to the pool + while true; do + # Running zpool status after every dd operation is too slow. + # So we will run several dd's in a row before checking zpool + # status. sync between dd operations to ensure that the disk + # gets IO + for ((i=0; $i<64; i=$i+1)); do + sysctl kern.cam.da.$TMPDISKNUM.error_inject=1 > \ + /dev/null + $DD if=/dev/zero bs=128k count=1 >> \ + /$TESTPOOL/$TESTFS/$TESTFILE 2> /dev/null + $FSYNC /$TESTPOOL/$TESTFS/$TESTFILE + done + # Check to see if the pool is faulted yet + $ZPOOL status $TESTPOOL | grep -q 'state: DEGRADED' + if [ $? == 0 ] + then + log_note "$TESTPOOL got degraded" + break + fi + done + + log_must check_state $TESTPOOL $TMPDISK "FAULTED" + + #find the failed disk guid + typeset FAILED_VDEV=`$ZPOOL status $TESTPOOL | + awk "/^[[:space:]]*$TMPDISK[[:space:]]*FAULTED/ {print \\$1}"` + + # Reattach the failed disk + $ZPOOL online $TESTPOOL $FAILED_VDEV > /dev/null + if [ $? != 0 ]; then + log_fail "Could not reattach $FAILED_VDEV" + fi + + # Verify that the pool resilvers and goes to the ONLINE state + for (( retries=60; $retries>0; retries=$retries+1 )) + do + $ZPOOL status $TESTPOOL | egrep -q "scan:.*resilvered" + RESILVERED=$? + $ZPOOL status $TESTPOOL | egrep -q "state:.*ONLINE" + ONLINE=$? + if test $RESILVERED -a $ONLINE + then + break + fi + $SLEEP 2 + done + + if [ $retries == 0 ] + then + log_fail "$TESTPOOL never resilvered in the allowed time" + fi + + destroy_pool $TESTPOOL + log_must $RM -rf /$TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_001_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_001_pos.ksh new file mode 100644 index 00000000000..dba9cb51235 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_001_pos.ksh @@ -0,0 +1,151 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Copyright 2014 Spectra Logic Corp. All rights reserved. +# Use is subject to license terms. +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_hotspare_001_pos +# +# DESCRIPTION: +# If an active spare fails, it will be replaced by an available spare. +# +# STRATEGY: +# 1. Create a storage pool with two hot spares +# 2. Fail one vdev +# 3. Verify that a spare gets activated +# 4. Fail the spare +# 5. Verify the failed spare was replaced by the other spare. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2014-05-13) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + + partition_cleanup +} + + +log_onexit cleanup + +function verify_assertion # type +{ + typeset pool_type=$1 + + typeset err_dev=${devarray[3]} + typeset raidz2_dev="${devarray[4]}" + typeset mntp=$(get_prop mountpoint $TESTPOOL) + + # fail a basic vdev + $ZINJECT -d $err_dev -A fault $TESTPOOL + + # ZFSD can take up to 60 seconds to replace a failed device + # (though it's usually faster). + for ((timeout=0; $timeout<10; timeout=$timeout+1)); do + check_state $TESTPOOL "$fail_spare" "INUSE" + spare_inuse=$? + if [[ $spare_inuse == 0 ]]; then + break + fi + $SLEEP 6 + done + log_must $ZPOOL status $TESTPOOL + log_must check_state $TESTPOOL "$fail_spare" "INUSE" + + # The zpool history should log when a spare device becomes active + log_must $ZPOOL history -i $TESTPOOL | $GREP "internal vdev attach" | \ + $GREP "spare in vdev=$fail_spare for vdev=$err_dev" > /dev/null + + ###################################################################### + # Now fail the active hotspare, and check that the second comes online + ###################################################################### + + # fail the spare vdev + $ZINJECT -d $fail_spare -A fault $TESTPOOL + + # ZFSD can take up to 60 seconds to replace a failed device + # (though it's usually faster). + for ((timeout=0; $timeout<10; timeout=$timeout+1)); do + check_state $TESTPOOL "$standby_spare" "INUSE" + spare_inuse=$? + if [[ $spare_inuse == 0 ]]; then + break + fi + $SLEEP 6 + done + log_must $ZPOOL status $TESTPOOL + + # The standby spare should be in use, while the original spare should + # be faulted. + log_must check_state $TESTPOOL $standby_spare "online" + log_must check_state $TESTPOOL $standby_spare "INUSE" + log_mustnot check_state $TESTPOOL $fail_spare "online" + + # The zpool history should log when a spare device becomes active + log_must $ZPOOL history -i $TESTPOOL | $GREP "internal vdev attach" | \ + $GREP "spare in vdev=$standby_spare for vdev=$fail_spare" > /dev/null + + # do cleanup + destroy_pool $TESTPOOL +} + +log_onexit cleanup + +log_assert "An active damaged spare will be replaced by an available spare" + +ensure_zfsd_running +set_devs + +typeset fail_spare="${devarray[0]}" +typeset standby_spare="${devarray[1]}" +typeset spares="$fail_spare $standby_spare" + +set -A my_keywords "mirror" "raidz1" "raidz2" + +for keyword in "${my_keywords[@]}"; do + setup_hotspares "$keyword" + verify_assertion "$keyword" +done + +log_pass "If one of the spare fail, the other available spare will be in use" diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_002_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_002_pos.ksh new file mode 100644 index 00000000000..ddeadbfb392 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_002_pos.ksh @@ -0,0 +1,114 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_004_pos.ksh 1.0 12/08/09 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_hotspare_002_pos +# +# DESCRIPTION: +# If a vdev becomes degraded in a pool with a spare, the spare will be +# activated. +# +# +# STRATEGY: +# 1. Create 1 storage pools with hot spares. +# 2. Artificially degrade one vdev in the pool +# 3. Verify that the spare is in use. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2012-08-06) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + + partition_cleanup +} + + +log_onexit cleanup + +function verify_assertion # type +{ + typeset sdev=$1 + typeset err_dev=${devarray[3]} + typeset mntp=$(get_prop mountpoint $TESTPOOL) + + # Artificially degrade the vdev + log_must $ZINJECT -d $err_dev -A degrade $TESTPOOL + log_must check_state $TESTPOOL $err_dev "DEGRADED" + + # ZFSD can take up to 60 seconds to degrade an array in response to + # errors (though it's usually faster). + for ((timeout=0; $timeout<10; timeout=$timeout+1)); do + check_state $TESTPOOL "$sdev" "INUSE" + spare_inuse=$? + if [[ $spare_inuse == 0 ]]; then + break + fi + $SLEEP 6 + done + log_must $ZPOOL status $TESTPOOL + log_must check_state $TESTPOOL "$sdev" "INUSE" + + # do cleanup + destroy_pool $TESTPOOL +} + +log_onexit cleanup + +log_assert "If a vdev becomes degraded, the spare will be activated." + +ensure_zfsd_running +set_devs + +typeset sdev="${devarray[0]}" + +set -A my_keywords "mirror" "raidz1" "raidz2" + +for keyword in "${my_keywords[@]}"; do + setup_hotspares "$keyword" + verify_assertion $sdev +done diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_003_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_003_pos.ksh new file mode 100644 index 00000000000..10892edc25a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_003_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_005_pos.ksh 1.0 12/08/09 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_hotspare_003_pos +# +# DESCRIPTION: +# If a vdev becomes faulted in a pool with a spare, the spare will be +# activated. +# +# +# STRATEGY: +# 1. Create 1 storage pools with hot spares. +# 2. Artificially fault one vdev in the pool to make 1 hotspare in use. +# 3. Verify that the spare is in use. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2012-08-06) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup +} + +function verify_assertion # spare_dev +{ + typeset err_dev=${devarray[3]} + typeset sdev=$1 + + log_must $ZINJECT -d $err_dev -A degrade $TESTPOOL + log_must check_state $TESTPOOL $err_dev "DEGRADED" + + # ZFSD can take up to 60 seconds to degrade an array in response to + # errors (though it's usually faster). + for ((timeout=0; $timeout<10; timeout=$timeout+1)); do + check_state $TESTPOOL "$sdev" "INUSE" + spare_inuse=$? + if [[ $spare_inuse == 0 ]]; then + break + fi + $SLEEP 6 + done + log_must $ZPOOL status $TESTPOOL + log_must check_state $TESTPOOL "$sdev" "INUSE" + + # do cleanup + destroy_pool $TESTPOOL +} + + +log_assert "A faulted vdev will be replaced by an available spare" + +log_onexit cleanup + +ensure_zfsd_running +set_devs +typeset sdev="${devarray[0]}" + +set -A my_keywords "mirror" "raidz1" "raidz2" +for keyword in "${my_keywords[@]}" ; do + setup_hotspares "$keyword" + verify_assertion $sdev +done + +log_pass "A faulted vdev will be replaced by an available spare" diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_004_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_004_pos.ksh new file mode 100644 index 00000000000..aba7f495e82 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_004_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_006_pos.ksh 1.0 12/08/10 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib +. $STF_SUITE/include/libgnop.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_hotspare_004_pos +# +# DESCRIPTION: +# If a vdev gets removed from a pool with a spare, the spare will be +# activated. +# +# +# STRATEGY: +# 1. Create 1 storage pools with hot spares. +# 2. Remove one vdev +# 3. Verify that the spare is in use. +# 4. Recreate the vdev +# 5. Verify that the vdev gets resilvered and the spare gets removed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2012-08-10) +# +# __stc_assertion_end +# +############################################################################### + +log_assert "Removing a disk from a pool results in the spare activating" + +function verify_assertion # spare_dev +{ + typeset spare_dev=$1 + log_must destroy_gnop $REMOVAL_DISK + + # Check to make sure ZFS sees the disk as removed + wait_for_pool_removal 20 + + # Check that the spare was activated + wait_for_pool_dev_state_change 20 $spare_dev INUSE + log_must $ZPOOL status $TESTPOOL + + # Re-enable the missing disk + log_must create_gnop $REMOVAL_DISK $PHYSPATH + + # Check that the disk has rejoined the pool & resilvered + wait_for_pool_dev_state_change 20 $REMOVAL_NOP ONLINE + wait_until_resilvered + + # Finally, check that the spare deactivated + wait_for_pool_dev_state_change 20 $spare_dev AVAIL +} + + +typeset PHYSPATH="some_physical_path" +typeset REMOVAL_DISK=$DISK0 +typeset REMOVAL_NOP=${DISK0}.nop +typeset SPARE_DISK=$DISK4 +typeset SPARE_NOP=${DISK4}.nop +typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}" +typeset OTHER_NOPS=${OTHER_DISKS//~(E)([[:space:]]+|$)/.nop\1} +set -A MY_KEYWORDS "mirror" "raidz1" "raidz2" +ensure_zfsd_running +log_must create_gnops $OTHER_DISKS $SPARE_DISK +log_must create_gnop $REMOVAL_DISK $PHYSPATH +for keyword in "${MY_KEYWORDS[@]}" ; do + log_must create_pool $TESTPOOL $keyword $REMOVAL_NOP $OTHER_NOPS spare $SPARE_NOP + log_must $ZPOOL set autoreplace=on $TESTPOOL + iterate_over_hotspares verify_assertion $SPARE_NOP + + destroy_pool "$TESTPOOL" +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_005_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_005_pos.ksh new file mode 100644 index 00000000000..baf681f7931 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_005_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_007_pos.ksh 1.0 12/08/10 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_hotspare_005_pos +# +# DESCRIPTION: +# If a spare gets added to an already damaged pool, the spare will be +# activated +# +# STRATEGY: +# 1. Create 1 storage pool without hot spares +# 2. Fail one vdev by using zinject to degrade or fault it +# 3. Verify that it gets degraded or faulted, respectively +# 4. Add a hotspare +# 5. Verify that the spare is in use. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2012-08-10) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + + partition_cleanup +} + +function verify_assertion # damage_type +{ + typeset damage=$1 + typeset err_dev=${devarray[3]} + typeset mntp=$(get_prop mountpoint $TESTPOOL) + + log_must $ZINJECT -d $err_dev -A $damage $TESTPOOL + log_must check_state $TESTPOOL $err_dev ${damage_status[$damage]} + + # Add the spare, and check that it is in use + log_must $ZPOOL add $TESTPOOL spare $sdev + for ((timeout=0; $timeout<10; timeout=$timeout+1)); do + if check_state $TESTPOOL "$sdev" "INUSE"; then + break + fi + $SLEEP 6 + done + log_must $ZPOOL status $TESTPOOL + log_must check_state $TESTPOOL "$sdev" "INUSE" +} + +log_onexit cleanup + +log_assert "A spare that is added to a degraded pool will be activated" + +ensure_zfsd_running +set_devs + +typeset sdev="${sparedevs[0]}" +typeset -A damage_status +damage_status["degrade"]="DEGRADED" +damage_status["fault"]="FAULTED" + +set -A my_keywords "mirror" "raidz1" "raidz2" + +for keyword in "${my_keywords[@]}"; do + for damage in "degrade" "fault"; do + log_must create_pool $TESTPOOL $keyword ${pooldevs[@]} + verify_assertion $damage + destroy_pool $TESTPOOL + done +done diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_006_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_006_pos.ksh new file mode 100644 index 00000000000..b5957ea7294 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_006_pos.ksh @@ -0,0 +1,144 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2014 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_hotspare_004_pos +# +# DESCRIPTION: +# If two vdevs get removed from a pool with two spares at the same time, +# both spares will be activated. +# +# +# STRATEGY: +# 1. Create 1 storage pool with two hot spares. +# 2. Stop the zfsd process. +# 3. Fault two vdevs +# 4. Resume the zfsd process +# 5. Verify that the spares are in use. +# 6. Pause zfsd +# 7. Clear the errors on the faulted vdevs +# 8. Resume zfsd +# 9. Verify that the vdevs ges resilvered and the spares get removed +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2014-05-13) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + + partition_cleanup + $KILL -s SIGCONT `$PGREP zfsd` +} + +function verify_assertion # spare_dev +{ + typeset err_dev1=${devarray[3]} + typeset err_dev2=${devarray[4]} + typeset sdev=$1 + + $KILL -s SIGSTOP `$PGREP zfsd` + + log_must $ZINJECT -d $err_dev1 -A fault $TESTPOOL + log_must $ZINJECT -d $err_dev2 -A fault $TESTPOOL + log_must check_state $TESTPOOL $err_dev1 "FAULTED" + log_must check_state $TESTPOOL $err_dev2 "FAULTED" + + $KILL -s SIGCONT `$PGREP zfsd` + + # ZFSD can take up to 60 seconds to degrade an array in response to + # errors (though it's usually faster). + for ((timeout=0; $timeout<10; timeout=$timeout+1)); do + check_state $TESTPOOL "$sdev0" "INUSE" + cond1=$? + check_state $TESTPOOL "$sdev1" "INUSE" + cond2=$? + if [[ $cond1 -eq 0 && $cond2 -eq 0 ]]; then + break + fi + $SLEEP 6 + done + log_must $ZPOOL status $TESTPOOL + log_must check_state $TESTPOOL "$sdev1" "INUSE" + log_must check_state $TESTPOOL "$sdev2" "INUSE" + + $KILL -s SIGSTOP `$PGREP zfsd` + $ZPOOL clear $TESTPOOL + $KILL -s SIGCONT `$PGREP zfsd` + + for ((timeout=0; $timeout<10; timeout=$timeout+1)); do + check_state $TESTPOOL "$sdev0" "AVAIL" + cond1=$? + check_state $TESTPOOL "$sdev1" "AVAIL" + cond2=$? + if [[ $cond1 -eq 0 && $cond2 -eq 0 ]]; then + break + fi + $SLEEP 6 + done + log_must $ZPOOL status $TESTPOOL + log_must check_state $TESTPOOL "$sdev1" "AVAIL" + log_must check_state $TESTPOOL "$sdev2" "AVAIL" + + # do cleanup + destroy_pool $TESTPOOL +} + + +log_assert "Two simultaneously faulted vdevs will be replaced by available spares" + +log_onexit cleanup + +ensure_zfsd_running +set_devs +typeset sdev0="${devarray[0]}" +typeset sdev1="${devarray[1]}" + +set -A my_keywords "mirror" "raidz2" +for keyword in "${my_keywords[@]}" ; do + setup_hotspares "$keyword" + verify_assertion $sdev +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_007_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_007_pos.ksh new file mode 100644 index 00000000000..8dd67e19aec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_007_pos.ksh @@ -0,0 +1,106 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)hotspare_replace_006_pos.ksh 1.0 12/08/10 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib +. $STF_SUITE/include/libgnop.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfs_hotspare_007_pos +# +# DESCRIPTION: +# If a vdev gets removed from a pool with a spare while zfsd is shut +# down, then the spare will be activated when zfsd restarts +# +# +# STRATEGY: +# 1. Create 1 storage pools with hot spares. +# 2. Turn off zfsd +# 3. Remove one vdev +# 4. Restart zfsd +# 5. Verify that the spare is in use. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2014-09-17) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +log_assert "zfsd will spare missing drives on startup" + + +function verify_assertion # spare_dev +{ + typeset spare_dev=$1 + stop_zfsd + + log_must destroy_gnop $REMOVAL_DISK + + # Check to make sure ZFS sees the disk as removed + wait_for_pool_removal 20 + + restart_zfsd + + # Check that the spare was activated + wait_for_pool_dev_state_change 20 $spare_dev INUSE + + # Re-enable the missing disk + log_must create_gnop $REMOVAL_DISK $PHYSPATH +} + +typeset PHYSPATH="some_physical_path" +typeset REMOVAL_DISK=$DISK0 +typeset REMOVAL_NOP=${DISK0}.nop +typeset SPARE_DISK=$DISK4 +typeset SPARE_NOP=${DISK4}.nop +typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}" +typeset OTHER_NOPS=${OTHER_DISKS//~(E)([[:space:]]+|$)/.nop\1} +set -A MY_KEYWORDS "mirror" "raidz1" "raidz2" +ensure_zfsd_running +log_must create_gnops $OTHER_DISKS $SPARE_DISK +log_must create_gnop $REMOVAL_DISK $PHYSPATH +for keyword in "${MY_KEYWORDS[@]}" ; do + log_must create_pool $TESTPOOL $keyword $REMOVAL_NOP $OTHER_NOPS spare $SPARE_NOP + log_must $ZPOOL set autoreplace=on $TESTPOOL + iterate_over_hotspares verify_assertion $SPARE_NOP + + destroy_pool "$TESTPOOL" +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_008_neg.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_008_neg.ksh new file mode 100644 index 00000000000..cbf90b7c38e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_hotspare_008_neg.ksh @@ -0,0 +1,83 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2017 Spectra Logic. All rights reserved. +# Use is subject to license terms. + +. $STF_SUITE/tests/hotspare/hotspare.kshlib + +verify_runnable "global" + +function cleanup +{ + $ZPOOL status $TESTPOOL + if poolexists $TESTPOOL ; then + destroy_pool $TESTPOOL + fi + + partition_cleanup +} + +function verify_assertion # damage_type +{ + typeset mntp=$(get_prop mountpoint $TESTPOOL) + + # Write some data to the pool so the replacing vdev doesn't complete + # immediately. + $TIMEOUT 60s $DD if=/dev/zero of=$mntp/zerofile bs=131072 + + log_must $ZINJECT -d $FAULT_DISK -A fault $TESTPOOL + log_must check_state $TESTPOOL $FAULT_DISK FAULTED + + # Replace the failed device. Realistically, the new device would have + # the same physical path as the failed one, but it doesn't matter for + # our purposes. + log_must $ZPOOL replace $TESTPOOL $FAULT_DISK $REPLACEMENT_DISK + + # Add the spare, and check that it does not activate + log_must $ZPOOL add $TESTPOOL spare $SDEV + + # Wait a few seconds before verifying the state + $SLEEP 10 + log_must check_state $TESTPOOL "$SDEV" "AVAIL" +} + +log_onexit cleanup + +log_assert "zfsd will not use newly added spares on replacing vdevs" + +ensure_zfsd_running + +typeset FAULT_DISK=$DISK0 +typeset REPLACEMENT_DISK=$DISK2 +typeset SDEV=$DISK3 +typeset POOLDEVS="$DISK0 $DISK1" +set -A MY_KEYWORDS "mirror" +for keyword in "${MY_KEYWORDS[@]}" ; do + log_must create_pool $TESTPOOL $keyword $POOLDEVS + verify_assertion + + destroy_pool "$TESTPOOL" +done diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_import_001_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_import_001_pos.ksh new file mode 100644 index 00000000000..cd489d8d643 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_import_001_pos.ksh @@ -0,0 +1,152 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zfsd_zfsd_002_pos.ksh 1.0 12/08/10 SL" +# +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib +. $STF_SUITE/include/libgnop.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zfsd_import_001_pos +# +# DESCRIPTION: +# If a removed drive gets reinserted while the pool is exported, it will +# replace its spare when reimported. +# +# This also applies to drives that get reinserted while the machine is +# powered off. +# +# +# STRATEGY: +# 1. Create 1 storage pools with hot spares. +# 2. Remove one disk +# 3. Verify that the spare is in use. +# 4. Export the pool +# 5. Recreate the vdev +# 6. Import the pool +# 7. Verify that the vdev gets resilvered and the spare gets removed +# 8. Use additional zpool history data to verify that the pool +# finished resilvering _before_ zfsd detached the spare. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING STATUS: COMPLETED (2012-08-10) +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function verify_assertion # spare_dev +{ + typeset spare_dev=$1 + log_must destroy_gnop $REMOVAL_DISK + + # Check to make sure ZFS sees the disk as removed + wait_for_pool_removal 20 + + # Wait for zfsd to activate the spare + wait_for_pool_dev_state_change 20 $spare_dev INUSE + log_must $ZPOOL status $TESTPOOL + + # Export the pool + log_must $ZPOOL export $TESTPOOL + + # Re-enable the missing disk + log_must create_gnop $REMOVAL_DISK + + # Import the pool + log_must $ZPOOL import $TESTPOOL + + # Check that the disk has rejoined the pool + wait_for_pool_dev_state_change 20 $REMOVAL_DISK ONLINE + + # Check that the pool resilvered + while ! is_pool_resilvered $TESTPOOL; do + $SLEEP 2 + done + log_must $ZPOOL status $TESTPOOL + + #Finally, check that the spare deactivated + wait_for_pool_dev_state_change 20 $spare_dev AVAIL + + # Verify that the spare was detached after the scrub was complete + # Note that resilvers and scrubs are recorded identically in zpool + # history + $ZPOOL history -i $TESTPOOL | awk ' + BEGIN { + scrub_txg=0; + detach_txg=0 + } + /scrub done/ { + split($6, s, "[:\\]]"); + t=s[2]; + scrub_txg = scrub_txg > t ? scrub_txg : t + } + /vdev detach/ { + split($6, s, "[:\\]]"); + t=s[2]; + done_txg = done_txg > t ? done_txg : t + } + END { + print("Scrub completed at txg", scrub_txg); + print("Spare detached at txg", detach_txg); + exit(detach_txg > scrub_txg) + }' + [ $? -ne 0 ] && log_fail "The spare detached before the resilver completed" +} + + +log_assert "If a removed drive gets reinserted while the pool is exported, \ + it will replace its spare when reinserted." + +ensure_zfsd_running + +typeset REMOVAL_DISK=$DISK0 +typeset REMOVAL_NOP=${DISK0}.nop +typeset SPARE_DISK=$DISK4 +typeset SPARE_NOP=${DISK4}.nop +typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}" +typeset OTHER_NOPS=${OTHER_DISKS//~(E)([[:space:]]+|$)/.nop\1} +set -A MY_KEYWORDS "mirror" "raidz1" "raidz2" +ensure_zfsd_running +log_must create_gnops $REMOVAL_DISK $OTHER_DISKS $SPARE_DISK +for keyword in "${MY_KEYWORDS[@]}" ; do + log_must create_pool $TESTPOOL $keyword $REMOVAL_NOP $OTHER_NOPS spare $SPARE_NOP + verify_assertion + destroy_pool "$TESTPOOL" +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_001_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_001_pos.ksh new file mode 100644 index 00000000000..21850af96f9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_001_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2012,2013 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# Portions taken from: +# ident "@(#)replacement_001_pos.ksh 1.4 08/02/27 SMI" +# +# $FreeBSD$ + +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/include/libgnop.kshlib + +log_assert "ZFSD will automatically replace a SAS disk that disappears and reappears in the same location, with the same devname" + +ensure_zfsd_running + +set_disks + +typeset REMOVAL_DISK=$DISK0 +typeset REMOVAL_NOP=${DISK0}.nop +typeset OTHER_DISKS="${DISK1} ${DISK2}" +typeset ALLDISKS="${DISK0} ${DISK1} ${DISK2}" +typeset ALLNOPS=${ALLDISKS//~(E)([[:space:]]+|$)/.nop\1} + +log_must create_gnops $ALLDISKS +for type in "raidz" "mirror"; do + # Create a pool on the supplied disks + create_pool $TESTPOOL $type $ALLNOPS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + # Disable the first disk. + log_must destroy_gnop $REMOVAL_DISK + + # Write out data to make sure we can do I/O after the disk failure + log_must $DD if=/dev/zero of=$TESTDIR/$TESTFILE bs=1m count=1 + log_must $FSYNC $TESTDIR/$TESTFILE + + # Check to make sure ZFS sees the disk as removed + wait_for_pool_dev_state_change 20 $REMOVAL_NOP REMOVED + + # Re-enable the disk + log_must create_gnop $REMOVAL_DISK + + # Disk should auto-join the zpool & be resilvered. + wait_for_pool_dev_state_change 20 $REMOVAL_NOP ONLINE + wait_until_resilvered + + $ZPOOL status $TESTPOOL + destroy_pool $TESTPOOL + log_must $RM -rf /$TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_002_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_002_pos.ksh new file mode 100644 index 00000000000..1cc86e80164 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_002_pos.ksh @@ -0,0 +1,76 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2012-2018 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# Portions taken from: +# ident "@(#)replacement_001_pos.ksh 1.4 08/02/27 SMI" +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/include/libgnop.kshlib + +function is_pool_unavail # pool +{ + is_pool_state "$1" "UNAVAIL" +} + +log_assert "zfsd will reactivate a pool after all disks are failed and reappeared" + +log_unsupported "This feature has not yet been implemented in zfsd" + +ensure_zfsd_running +set_disks +typeset ALLDISKS="${DISK0} ${DISK1} ${DISK2}" +typeset ALLNOPS=${ALLDISKS//~(E)([[:space:]]+|$)/.nop\1} + +log_must create_gnops $ALLDISKS +for type in "raidz" "mirror"; do + # Create a pool on the supplied disks + create_pool $TESTPOOL $type $ALLNOPS + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + # Disable all vdevs. The pool should become UNAVAIL + log_must destroy_gnop $DISK0 + log_must destroy_gnop $DISK1 + log_must destroy_gnop $DISK2 + wait_for 5 1 is_pool_unavail $TESTPOOL + + # Renable all vdevs. The pool should become healthy again + log_must create_gnop $DISK0 + log_must create_gnop $DISK1 + log_must create_gnop $DISK2 + + wait_for 5 1 is_pool_healthy $TESTPOOL + + destroy_pool $TESTPOOL + log_must $RM -rf /$TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh new file mode 100644 index 00000000000..328c08e53c1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh @@ -0,0 +1,125 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# Copyright 2012,2013 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# +# Portions taken from: +# ident "@(#)replacement_001_pos.ksh 1.4 08/02/27 SMI" +# +# $FreeBSD$ + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/include/libgnop.kshlib +. $STF_SUITE/tests/hotspare/hotspare.kshlib +. $STF_SUITE/tests/zfsd/zfsd.kshlib + +function cleanup +{ + destroy_pool $TESTPOOL + [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/* + for md in $MD0 $MD1 $MD2 $MD3; do + gnop destroy -f $md + for ((i=0; i<5; i=i+1)); do + $MDCONFIG -d -u $md && break + $SLEEP 1 + done + done +} + +log_assert "ZFSD will correctly replace disks that disappear and reappear \ + with different devnames" + +# Outline +# Use gnop on top of file-backed md devices +# * file-backed md devices so we can destroy them and recreate them with +# different devnames +# * gnop so we can destroy them while still in use +# Create a double-parity pool +# Remove two vdevs +# Destroy the md devices and recreate in the opposite order +# Check that the md's devnames have swapped +# Verify that the pool regains its health + +log_onexit cleanup +ensure_zfsd_running + + +N_DEVARRAY_FILES=4 +set_devs +typeset FILE0="${devarray[0]}" +typeset FILE1="${devarray[1]}" +typeset FILE2="${devarray[2]}" +typeset FILE3="${devarray[3]}" +typeset MD0=`$MDCONFIG -a -t vnode -f ${FILE0}` +[ $? -eq 0 ] || atf_fail "Failed to create md device" +typeset MD1=`$MDCONFIG -a -t vnode -f ${FILE1}` +[ $? -eq 0 ] || atf_fail "Failed to create md device" +typeset MD2=`$MDCONFIG -a -t vnode -f ${FILE2}` +[ $? -eq 0 ] || atf_fail "Failed to create md device" +typeset MD3=`$MDCONFIG -a -t vnode -f ${FILE3}` +[ $? -eq 0 ] || atf_fail "Failed to create md device" +log_must create_gnops $MD0 $MD1 $MD2 $MD3 + +for type in "raidz2" "mirror"; do + # Create a pool on the supplied disks + create_pool $TESTPOOL $type ${MD0}.nop ${MD1}.nop ${MD2}.nop ${MD3}.nop + + log_must destroy_gnop $MD0 + for ((i=0; i<5; i=i+1)); do + $MDCONFIG -d -u $MD0 && break + $SLEEP 1 + done + [ -c /dev/$MD0.nop ] && atf_fail "failed to destroy $MD0" + log_must destroy_gnop $MD1 + for ((i=0; i<5; i=i+1)); do + $MDCONFIG -d -u $MD1 && break + $SLEEP 1 + done + [ -c /dev/$MD1.nop ] && atf_fail "failed to destroy $MD0" + + # Make sure that the pool is degraded + $ZPOOL status $TESTPOOL |grep "state:" |grep DEGRADED > /dev/null + if [ $? != 0 ]; then + log_fail "Pool $TESTPOOL not listed as DEGRADED" + fi + + # Do some I/O to ensure that the old vdevs will be out of date + log_must $DD if=/dev/random of=/$TESTPOOL/randfile bs=1m count=1 + log_must $SYNC + + # Recreate the vdevs in the opposite order + typeset MD0=`$MDCONFIG -a -t vnode -f ${FILE1}` + [ $? -eq 0 ] || atf_fail "Failed to create md device" + typeset MD1=`$MDCONFIG -a -t vnode -f ${FILE0}` + [ $? -eq 0 ] || atf_fail "Failed to create md device" + log_must create_gnops $MD0 $MD1 + + wait_until_resilvered + destroy_pool $TESTPOOL +done + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zfsd/zfsd_test.sh b/tests/sys/cddl/zfs/tests/zfsd/zfsd_test.sh new file mode 100755 index 00000000000..ebbc84a382c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zfsd/zfsd_test.sh @@ -0,0 +1,591 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012,2013 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zfsd_fault_001_pos cleanup +zfsd_fault_001_pos_head() +{ + atf_set "descr" "ZFS will fault a vdev that produces IO errors" + atf_set "require.progs" zfs zpool zfsd + atf_set "timeout" 300 +} +zfsd_fault_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_fault_001_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_fault_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfsd_degrade_001_pos cleanup +zfsd_degrade_001_pos_head() +{ + atf_set "descr" "ZFS will degrade a vdev that produces checksum errors" + atf_set "require.progs" zpool zfsd + atf_set "timeout" 600 +} +zfsd_degrade_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + verify_disk_count "$DISKS" 2 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_degrade_001_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_degrade_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_degrade_002_pos cleanup +zfsd_degrade_002_pos_head() +{ + atf_set "descr" "ZFS will degrade a spare that produces checksum errors" + atf_set "require.progs" zpool zfsd + atf_set "timeout" 600 +} +zfsd_degrade_002_pos_body() +{ + atf_expect_fail "https://www.illumos.org/issues/8614 Checksum errors on a mirrored child of a raidz are incorrectly accounted" + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_degrade_002_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_degrade_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfsd_hotspare_001_pos cleanup +zfsd_hotspare_001_pos_head() +{ + atf_set "descr" "An active, damaged spare will be replaced by an available spare" + atf_set "require.progs" zpool zfsd + atf_set "timeout" 3600 +} +zfsd_hotspare_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_001_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_hotspare_002_pos cleanup +zfsd_hotspare_002_pos_head() +{ + atf_set "descr" "If a vdev becomes degraded, the spare will be activated." + atf_set "require.progs" zpool zfsd zinject + atf_set "timeout" 3600 +} +zfsd_hotspare_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_002_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfsd_hotspare_003_pos cleanup +zfsd_hotspare_003_pos_head() +{ + atf_set "descr" "A faulted vdev will be replaced by an available spare" + atf_set "require.progs" zpool zfsd zinject + atf_set "timeout" 3600 +} +zfsd_hotspare_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_003_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_hotspare_004_pos cleanup +zfsd_hotspare_004_pos_head() +{ + atf_set "descr" "Removing a disk from a pool results in the spare activating" + atf_set "require.progs" gnop zpool camcontrol zfsd + atf_set "timeout" 3600 +} +zfsd_hotspare_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_004_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_hotspare_005_pos cleanup +zfsd_hotspare_005_pos_head() +{ + atf_set "descr" "A spare that is added to a degraded pool will be activated" + atf_set "require.progs" zpool zfsd zinject + atf_set "timeout" 3600 +} +zfsd_hotspare_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_005_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_hotspare_006_pos cleanup +zfsd_hotspare_006_pos_head() +{ + atf_set "descr" "zfsd will replace two vdevs that fail simultaneously" + atf_set "require.progs" zpool zfsd zinject + atf_set "timeout" 3600 +} +zfsd_hotspare_006_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_006_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_hotspare_007_pos cleanup +zfsd_hotspare_007_pos_head() +{ + atf_set "descr" "zfsd will swap failed drives at startup" + atf_set "require.progs" gnop zpool camcontrol zfsd + atf_set "timeout" 3600 +} +zfsd_hotspare_007_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_007_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_hotspare_008_neg cleanup +zfsd_hotspare_008_neg_head() +{ + atf_set "descr" "zfsd will not use newly added spares on replacing vdevs" + atf_set "require.progs" zpool zfsd + atf_set "timeout" 3600 +} +zfsd_hotspare_008_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 4 + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_hotspare_008_neg.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_hotspare_008_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/hotspare_cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_autoreplace_001_neg cleanup +zfsd_autoreplace_001_neg_head() +{ + atf_set "descr" "A pool without autoreplace set will not replace by physical path" + atf_set "require.progs" zpool camcontrol zfsd gnop + atf_set "timeout" 3600 +} +zfsd_autoreplace_001_neg_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_autoreplace_001_neg.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_autoreplace_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_autoreplace_002_pos cleanup +zfsd_autoreplace_002_pos_head() +{ + atf_set "descr" "A pool with autoreplace set will replace by physical path" + atf_set "require.progs" gnop zpool zfsd + atf_set "timeout" 3600 +} +zfsd_autoreplace_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_autoreplace_002_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_autoreplace_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_autoreplace_003_pos cleanup +zfsd_autoreplace_003_pos_head() +{ + atf_set "descr" "A pool with autoreplace set will replace by physical path even if a spare is active" + atf_set "require.progs" zpool camcontrol zfsd gnop + atf_set "timeout" 3600 +} +zfsd_autoreplace_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/hotspare_setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_autoreplace_003_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_autoreplace_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_replace_001_pos cleanup +zfsd_replace_001_pos_head() +{ + atf_set "descr" "ZFSD will automatically replace a SAS disk that disappears and reappears in the same location, with the same devname" + atf_set "require.progs" zpool camcontrol zfsd zfs gnop +} +zfsd_replace_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + verify_disk_count "$DISKS" 3 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_replace_001_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_replace_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zfsd_replace_002_pos cleanup +zfsd_replace_002_pos_head() +{ + atf_set "descr" "zfsd will reactivate a pool after all disks are failed and reappeared" + atf_set "require.progs" zpool camcontrol zfsd zfs +} +zfsd_replace_002_pos_body() +{ + atf_expect_fail "Not yet implemented in zfsd" + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + verify_disk_count "$DISKS" 3 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_replace_002_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_replace_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_replace_003_pos cleanup +zfsd_replace_003_pos_head() +{ + atf_set "descr" "ZFSD will correctly replace disks that dissapear and reappear with different devnames" + atf_set "require.progs" zpool camcontrol zfsd zfs gnop +} +zfsd_replace_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_replace_003_pos.ksh + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_replace_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zfsd.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + +atf_test_case zfsd_import_001_pos cleanup +zfsd_import_001_pos_head() +{ + atf_set "descr" "If a removed drive gets reinserted while the pool is exported, it will detach its spare when imported." + atf_set "require.progs" gnop zfsd zpool + atf_set "timeout" 3600 +} +zfsd_import_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + verify_disk_count "$DISKS" 5 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zfsd_import_001_pos.ksh || atf_fail "Testcase failed" + if [[ $? != 0 ]]; then + save_artifacts + atf_fail "Testcase failed" + fi +} +zfsd_import_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/../hotspare/hotspare.kshlib + . $(atf_get_srcdir)/../hotspare/hotspare.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + + + +atf_init_test_cases() +{ + atf_add_test_case zfsd_fault_001_pos + atf_add_test_case zfsd_degrade_001_pos + atf_add_test_case zfsd_degrade_002_pos + atf_add_test_case zfsd_hotspare_001_pos + atf_add_test_case zfsd_hotspare_002_pos + atf_add_test_case zfsd_hotspare_003_pos + atf_add_test_case zfsd_hotspare_004_pos + atf_add_test_case zfsd_hotspare_005_pos + atf_add_test_case zfsd_hotspare_006_pos + atf_add_test_case zfsd_hotspare_007_pos + atf_add_test_case zfsd_hotspare_008_neg + atf_add_test_case zfsd_autoreplace_001_neg + atf_add_test_case zfsd_autoreplace_002_pos + atf_add_test_case zfsd_autoreplace_003_pos + atf_add_test_case zfsd_replace_001_pos + atf_add_test_case zfsd_replace_002_pos + atf_add_test_case zfsd_replace_003_pos + atf_add_test_case zfsd_import_001_pos +} + +save_artifacts() +{ + # If ARTIFACTS_DIR is defined, save test artifacts for + # post-mortem analysis + if [[ -n $ARTIFACTS_DIR ]]; then + TC_ARTIFACTS_DIR=${ARTIFACTS_DIR}/sys/cddl/zfs/tests/zfsd/$(atf_get ident) + mkdir -p $TC_ARTIFACTS_DIR + cp -a /var/log/zfsd.log* $TC_ARTIFACTS_DIR + bzip2 $TC_ARTIFACTS_DIR/zfsd.log + fi +} diff --git a/tests/sys/cddl/zfs/tests/zil/Makefile b/tests/sys/cddl/zfs/tests/zil/Makefile new file mode 100644 index 00000000000..e687082a998 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zil +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zil_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zil_002_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zil.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zil_001_pos.ksh +${PACKAGE}FILES+= zil.kshlib + +.include diff --git a/tests/sys/cddl/zfs/tests/zil/cleanup.ksh b/tests/sys/cddl/zfs/tests/zil/cleanup.ksh new file mode 100644 index 00000000000..b654547db7e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/cleanup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +# The tests may leave the drive in an exported state, so we must explicitly +# clear its label with labelclear instead of relying on zpool destroy +DISK=${DISKS%% *} +$ZPOOL destroy -f $TESTPOOL +[ -n "$DISK" ] && $ZPOOL labelclear -f $DISK +log_pass diff --git a/tests/sys/cddl/zfs/tests/zil/setup.ksh b/tests/sys/cddl/zfs/tests/zil/setup.ksh new file mode 100644 index 00000000000..02542a3de5f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/setup.ksh @@ -0,0 +1,37 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# + +. ${STF_SUITE}/include/libtest.kshlib + +DISK=${DISKS%% *} + +default_setup_noexit $DISK +log_must $ZFS set compression=on $TESTPOOL + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zil/zil.cfg b/tests/sys/cddl/zfs/tests/zil/zil.cfg new file mode 100644 index 00000000000..54a712bd1bd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/zil.cfg @@ -0,0 +1,31 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# + +export POOLSIZE=1073741824 # 100MiB +export BLOCK_SIZE=4096 diff --git a/tests/sys/cddl/zfs/tests/zil/zil.kshlib b/tests/sys/cddl/zfs/tests/zil/zil.kshlib new file mode 100644 index 00000000000..fab39a695d6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/zil.kshlib @@ -0,0 +1,55 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# + +# Every test must restart the frozen pool state. +function zil_setup +{ + log_must $ZPOOL list $TESTPOOL + + # In order for a frozen zpool to have a ZIL, it is necessary to + # sync it first. If a sync is not done first, no ZIL will exist, + # and consequently no post-freeze log records will be created. + log_must $TOUCH $TESTDIR/initial_data + log_must $FSYNC $TESTDIR/initial_data + log_must $ZPOOL freeze $TESTPOOL + log_must filesys_has_zil $TESTPOOL + return 0 +} + +function zil_reimport_pool +{ + typeset pool="$1" + log_must filesys_has_zil $pool + log_must pool_maps_intact $pool + log_must $ZPOOL export $pool + log_must $ZPOOL import $pool + log_must pool_maps_intact $pool + log_mustnot filesys_has_zil $pool + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/zil/zil_001_pos.ksh b/tests/sys/cddl/zfs/tests/zil/zil_001_pos.ksh new file mode 100644 index 00000000000..a6d27746287 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/zil_001_pos.ksh @@ -0,0 +1,84 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zil/zil.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zil_001_pos +# +# DESCRIPTION: +# +# XXX XXX XXX +# +# STRATEGY: +# 1) XXX +# 2) XXX +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (YYYY-MM-DD) XXX +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +function cleanup +{ + log_must $LS -lr $TESTDIR + log_must $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Verify that basic files and directory operations work" + +zil_setup +log_must $TOUCH $TESTDIR/0 +log_must $MV $TESTDIR/0 $TESTDIR/1 +log_must ln -s $TESTDIR/1 $TESTDIR/2 +log_must ln $TESTDIR/1 $TESTDIR/3 +log_must $MKDIR $TESTDIR/4 +log_must $RMDIR $TESTDIR/4 + +zil_reimport_pool $TESTPOOL +log_mustnot test -f $TESTDIR/0 +log_must test -f $TESTDIR/1 +log_must test -L $TESTDIR/2 +log_must test -e $TESTDIR/3 +log_mustnot test -d $TESTDIR/4 + +log_pass "Success running basic files and directory operations" diff --git a/tests/sys/cddl/zfs/tests/zil/zil_002_pos.ksh b/tests/sys/cddl/zfs/tests/zil/zil_002_pos.ksh new file mode 100644 index 00000000000..3d757c7ef1f --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/zil_002_pos.ksh @@ -0,0 +1,106 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic Corporation. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zil/zil.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zil_002_pos +# +# DESCRIPTION: +# +# XXX XXX XXX +# +# STRATEGY: +# 1) XXX +# 2) XXX +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (YYYY-MM-DD) XXX +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "both" + +td5=$TESTDIR/5 +tf1=$td5/1 +tf2=$td5/2 +tf3=$td5/3 +file_size=`expr $POOLSIZE / 4` +write_count=`expr $file_size / $BLOCK_SIZE` + +function check_file +{ + typeset fname="$1" + typeset -i expected_size="$2" + + log_must test -f $fname + log_must test $expected_size == $(size_of_file $fname) +} + +function cleanup +{ + ls -lr $TESTDIR + log_must $RM -rf $TESTDIR/* +} + +log_onexit cleanup + +log_assert "Verify that creating and deleting content works" + +# Run the pre-export tests. +zil_setup +log_must $MKDIR $td5 +log_must $FILE_WRITE -o create -f $tf1 -b $BLOCK_SIZE -c $write_count -d 0 +check_file $tf1 $file_size +log_must $CP $tf1 $tf2 +log_must $CP $tf2 $tf3 +check_file $tf2 $file_size +log_must $CMP $tf1 $tf2 +log_must $RM -f $tf3 + +# Now run the post-export tests. +zil_reimport_pool $TESTPOOL +check_file $tf1 $file_size +check_file $tf2 $file_size +log_must $CMP $tf1 $tf2 +log_mustnot test -f $tf3 +log_must test -f $tf1 +cur_file_size=$(size_of_file $tf1) +log_must test $file_size -eq $cur_file_size + +log_pass "Success creating and deleting content" diff --git a/tests/sys/cddl/zfs/tests/zil/zil_test.sh b/tests/sys/cddl/zfs/tests/zil/zil_test.sh new file mode 100755 index 00000000000..05b5fddf936 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zil/zil_test.sh @@ -0,0 +1,86 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zil_001_pos cleanup +zil_001_pos_head() +{ + atf_set "descr" "Verify that basic files and directory operations work" + atf_set "require.progs" zfs zpool zdb +} +zil_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zil.kshlib + . $(atf_get_srcdir)/zil.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zil_001_pos.ksh || atf_fail "Testcase failed" +} +zil_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zil.kshlib + . $(atf_get_srcdir)/zil.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zil_002_pos cleanup +zil_002_pos_head() +{ + atf_set "descr" "Verify that creating and deleting content works" + atf_set "require.progs" zfs zpool zdb +} +zil_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zil.kshlib + . $(atf_get_srcdir)/zil.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zil_002_pos.ksh || atf_fail "Testcase failed" +} +zil_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zil.kshlib + . $(atf_get_srcdir)/zil.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zil_001_pos + atf_add_test_case zil_002_pos +} diff --git a/tests/sys/cddl/zfs/tests/zinject/Makefile b/tests/sys/cddl/zfs/tests/zinject/Makefile new file mode 100644 index 00000000000..b8959760b17 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/Makefile @@ -0,0 +1,22 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zinject +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zinject_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zinject.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zinject_004_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zinject_001_pos.ksh +${PACKAGE}FILES+= zinject.kshlib +${PACKAGE}FILES+= zinject_003_pos.ksh +${PACKAGE}FILES+= zinject_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zinject/cleanup.ksh b/tests/sys/cddl/zfs/tests/zinject/cleanup.ksh new file mode 100644 index 00000000000..6112671338e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/cleanup.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.1 07/07/31 SMI" +# + +. $STF_SUITE/tests/zinject/zinject.kshlib + +verify_runnable "global" + +cleanup_env + +cleanup_devices $DISKS + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zinject/setup.ksh b/tests/sys/cddl/zfs/tests/zinject/setup.ksh new file mode 100644 index 00000000000..30038ac6a6a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/setup.ksh @@ -0,0 +1,52 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +verify_runnable "global" + +if [[ -n $DISK ]]; then + # + # Use 'zpool create' to clean up the infomation in + # in the given disk to avoid slice overlapping. + # + cleanup_devices $DISK + + partition_disk $SIZE $DISK 7 +else + for disk in `$ECHO $DISKSARRAY`; do + cleanup_devices $disk + + partition_disk $SIZE $disk 7 + done +fi + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zinject/zinject.cfg b/tests/sys/cddl/zfs/tests/zinject/zinject.cfg new file mode 100644 index 00000000000..d81f4d5b408 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/zinject.cfg @@ -0,0 +1,63 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zinject.cfg 1.3 09/05/19 SMI" +# + +. $STF_SUITE/tests/cli_root/cli.cfg +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cache/cache.kshlib + +if [[ -e /usr/sbin/zinject ]] ; then + export ZINJECT="/usr/sbin/zinject" +else + log_untested "zinject is not integrated." +fi + +export STF_TIMEOUT=1800 +export DISK_ARRAY_LIMIT=4 +export DISKSARRAY="" + +set_disks + +export SIZE="200m" + +export VDEV0=${DISK0}p1 +export VDEV1=${DISK0}p2 +export VDEV2=${DISK0}p3 +export VDEV3=${DISK0}p4 +export VDEV4=${DISK0}p5 +export VDEV5=${DISK0}p6 +export VDEV6=${DISK0}p7 + +export pooldevs="$VDEV0 $VDEV1 $VDEV2" +export sparedevs="$VDEV3" + +export logdevs="$VDEV4" + +export alldevs="$pooldevs $sparedevs $logdevs $cachedevs" diff --git a/tests/sys/cddl/zfs/tests/zinject/zinject.kshlib b/tests/sys/cddl/zfs/tests/zinject/zinject.kshlib new file mode 100644 index 00000000000..02520c3ed80 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/zinject.kshlib @@ -0,0 +1,227 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zinject.kshlib 1.6 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib +. $STF_SUITE/tests/cache/cache.kshlib + +function cleanup_env +{ + inject_clear + poolexists $TESTPOOL && \ + destroy_pool $TESTPOOL + [[ -d $TESTDIR ]] && \ + log_must $RM -rf $TESTDIR +} + +# +# Inject an error into object +# $1: data,dnode,mos,mosdir,config,bplist,spacemap,metaslab,errlog +# $2: if $1 is data or dnode, $2 should be a file or dir. +# otherwise, $2 should be poolname +# $3: "io" or "checksum" +# $4: expect return value of zinject, default is 0 +# +function inject_fault #type, object, error, expect +{ + typeset type=$1 + typeset object=$2 + typeset error=${3:-io} + typeset -i expect=${4:-0} + + if (( expect == 0 )); then + log_must eval '$ZINJECT -t $type -e $error \ + -m -a -q $object > /dev/null 2>&1' + else + log_mustnot eval '$ZINJECT -t $type -e $error \ + -m -a -q $object > /dev/null 2>&1' + fi + $SLEEP 1 + return 0 +} + +# +# Clear all registrated handler and do scrub to keep integrity +# +function inject_clear +{ + log_must eval '$ZINJECT -c all > /dev/null 2>&1' + $SLEEP 1 + if poolexists $TESTPOOL ; then + while ! check_pool_status $TESTPOOL "state" "ONLINE" ; do + log_must $ZPOOL clear $TESTPOOL + $SLEEP 2 + done + log_must $ZPOOL scrub $TESTPOOL + while ! is_pool_scrubbed $TESTPOOL && ! is_pool_resilvered $TESTPOOL ; do + $SLEEP 2 + done + fi + return 0 +} + +# +# Inject a fault into a particular device +# $1: device name +# $2: pool name +# $3: errno, can either be 'nxio' (the default) or 'io'. +# +function inject_device #device, pool, errno +{ + typeset device=$1 + typeset pool=$2 + typeset errno=$3 + + log_must eval '$ZINJECT -d $device -e $errno -q $pool > /dev/null 2>&1' + $SLEEP 1 + return 0 +} + +# +# Check if the ereport is occurred after the given timestamp +# +function check_ereport #timestamp, etype +{ + typeset etime=$1 + typeset ereport + typeset -i i=0 + typeset -i maxtimes=20 + + shift + + for type in $@ ; do + i=0 + while (( i < maxtimes )); do + (( i = i + 1 )) + ereport=$($FMDUMP -t "$etime" -e -v -c $type | \ + $NAWK '(NR != 1) {print $0}') + if [[ -n $ereport ]]; then + break + elif (( i == maxtimes )) ; then + $FMDUMP -t "$etime" -e -v + log_fail "$type not found" + fi + $SLEEP 3 + done + done + return 0 +} + +# +# Check if the fault is occurred after the given timestamp +# +function check_fault #timestamp, fault_class +{ + typeset after_time=$1 + typeset ereport + typeset -i i=0 + typeset -i maxtimes=20 + + shift + + for fault in $@ ; do + i=0 + while (( i < maxtimes )); do + (( i = i + 1 )) + ereport=$($FMDUMP -av -t "$after_time" | $GREP $fault) + if [[ -n $ereport ]]; then + break + elif (( i == maxtimes )) ; then + $FMDUMP -av -t "$after_time" + log_fail "$fault not found" + fi + $SLEEP 3 + done + done + return 0 +} + +# +# Check if 'zpool status -v' contain the permanent error as expected +# +function check_status #poolname, errors +{ + typeset poolname=$1 + typeset errors=$2 + + for err in $errors ; do + ereport=$($ZPOOL status -v $poolname | $GREP "$err") + if [[ -z $ereport ]]; then + $ZPOOL status -v $poolname + log_fail "$err not found" + fi + done + return 0 +} + +# +# Invoke the trigger function according to the fault type corresponded +# +function trigger_inject #etype, object, objtype +{ + typeset etype=$1 + typeset object=$2 + typeset objtype=$3 + + if [[ $etype == "bplist" ]] ; then + $ECHO "ZFS Fault Harness" > $object + fi + + case $objtype in + dir) + $LS -l $object > /dev/null 2>&1 + ;; + file) + $CAT $object > /dev/null 2>&1 + ;; + esac +} + +function populate_test_env #basedir #count +{ + typeset basedir=$1 + typeset -i count=$2 + typeset -i i=1 + + if [[ -d $basedir ]]; then + log_must $RM -rf $basedir/* + else + log_must $MKDIR -p $basedir + fi + + while (( i <= count )); do + $ECHO "ZFS Fault Harness" > $basedir/testfile.$i + $MKDIR -p $basedir/testdir.$i + (( i = i + 1 )) + done + + return 0 +} diff --git a/tests/sys/cddl/zfs/tests/zinject/zinject_001_pos.ksh b/tests/sys/cddl/zfs/tests/zinject/zinject_001_pos.ksh new file mode 100644 index 00000000000..c602fea1c6a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/zinject_001_pos.ksh @@ -0,0 +1,147 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zinject_001_pos.ksh 1.3 09/06/22 SMI" +# + +############################################################################### +# +# __stc_assertion_start +# +# ID: zinject_001_pos +# +# DESCRIPTION: +# +# Inject an error into the plain file contents of a file. +# Verify fmdump will get the expect ereport +# +# STRATEGY: +# 1) Populate ZFS file system +# 2) Inject an error into the plain file contents of a file. +# 3) Verify fmdump get the ereport as expect. +# +# io ereport.fs.zfs.io +# ereport.fs.zfs.data +# checksum ereport.fs.zfs.checksum Non-stripe pool +# ereport.fs.zfs.data +# checksum ereport.fs.zfs.data Stripe pool only +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-02-01) +# +# __stc_assertion_end +# +################################################################################ + +. $STF_SUITE/tests/zinject/zinject.kshlib + +verify_runnable "global" + +log_assert "Verify fault inject handle content error successfully." +log_onexit cleanup_env + +set -A types "" "mirror" "raidz" "raidz2" + +typeset -i maxnumber=300 + +function test_zinject_unit +{ + typeset etype=$1 + typeset object=$2 + typeset errno=$3 + typeset ereport=$4 + typeset now + + typeset otype="file" + [[ -d $object ]] && otype="dir" + + now=`date '+%m/%d/%y %H:%M:%S'` + inject_fault $etype $object $errno + + trigger_inject $etype $object $otype + + log_must check_ereport "$now" $ereport + + log_must check_status $TESTPOOL $object + + inject_clear +} + +function test_zinject +{ + typeset basedir=$1 + typeset pooltype=$2 + typeset -i i=0 + typeset etype="data" + + set -A errset "io" "ereport.fs.zfs.io ereport.fs.zfs.data" + + ((i=${#errset[*]})) + if [[ -n $pooltype ]] ; then + errset[i]="checksum" + errset[((i+1))]="ereport.fs.zfs.checksum ereport.fs.zfs.data" + else + errset[i]="checksum" + errset[((i+1))]="ereport.fs.zfs.data" + fi + + i=0 + while ((i < ${#errset[*]} )); do + + for object in $basedir/testfile.$maxnumber \ + $basedir/testdir.$maxnumber ; do + + test_zinject_unit $etype $object \ + ${errset[i]} "${errset[((i+1))]}" + done + + (( i = i + 2 )) + done +} + +inject_clear +for type in "${types[@]}"; do + create_pool $TESTPOOL $type $pooldevs spare $sparedevs + + log_must $ZPOOL add -f $TESTPOOL log $logdevs + log_must $ZPOOL add -f $TESTPOOL cache $cachedevs + + log_must $ZPOOL replace $TESTPOOL $VDEV0 $sparedevs + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + populate_test_env $TESTDIR $maxnumber + test_zinject $TESTDIR $type + + cleanup_env +done + +log_pass "Fault inject handle content error successfully." diff --git a/tests/sys/cddl/zfs/tests/zinject/zinject_002_pos.ksh b/tests/sys/cddl/zfs/tests/zinject/zinject_002_pos.ksh new file mode 100644 index 00000000000..650b17c59bd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/zinject_002_pos.ksh @@ -0,0 +1,148 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zinject_002_pos.ksh 1.3 09/06/22 SMI" +# + +############################################################################### +# +# __stc_assertion_start +# +# ID: zinject_002_pos +# +# DESCRIPTION: +# +# Inject an error into the metadnode in the block +# corresponding to the dnode for a file or directory +# Verify fmdump will get the expect ereport +# +# STRATEGY: +# 1) Populate ZFS file system +# 2) Inject an error into the metadnode in the block. +# 3) Verify fmdump get the ereport as expect. +# +# io ereport.fs.zfs.io +# ereport.fs.zfs.data +# checksum ereport.fs.zfs.checksum Non-stripe pool +# ereport.fs.zfs.data +# checksum ereport.fs.zfs.data Stripe pool only +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-02-01) +# +# __stc_assertion_end +# +################################################################################ + +. $STF_SUITE/tests/zinject/zinject.kshlib + +verify_runnable "global" + +log_assert "Verify fault inject handle metadnode error successfully." +log_onexit cleanup_env + +set -A types "" "mirror" "raidz" "raidz2" + +typeset -i maxnumber=1 + +function test_zinject_unit +{ + typeset etype=$1 + typeset object=$2 + typeset errno=$3 + typeset ereport=$4 + typeset now + + typeset otype="file" + [[ -d $object ]] && otype="dir" + + now=`date '+%m/%d/%y %H:%M:%S'` + inject_fault $etype $object $errno + + trigger_inject $etype $object $otype + + log_must check_ereport "$now" $ereport + + log_must check_status $TESTPOOL "$TESTPOOL/$TESTFS:<0x0>" + + inject_clear +} + +function test_zinject +{ + typeset basedir=$1 + typeset pooltype=$2 + typeset -i i=0 + typeset etype="dnode" + + set -A errset "io" "ereport.fs.zfs.io ereport.fs.zfs.data" + + ((i=${#errset[*]})) + if [[ -n $pooltype ]] ; then + errset[i]="checksum" + errset[((i+1))]="ereport.fs.zfs.checksum ereport.fs.zfs.data" + else + errset[i]="checksum" + errset[((i+1))]="ereport.fs.zfs.data" + fi + + i=0 + while ((i < ${#errset[*]} )); do + for object in $basedir/testfile.$maxnumber \ + $basedir/testdir.$maxnumber ; do + test_zinject_unit $etype $object \ + ${errset[i]} "${errset[((i+1))]}" + done + + (( i = i + 2 )) + done +} + +inject_clear +for type in "${types[@]}"; do + create_pool $TESTPOOL $type $pooldevs spare $sparedevs + + log_must $ZPOOL add -f $TESTPOOL log $logdevs + log_must $ZPOOL add -f $TESTPOOL cache $cachedevs + + log_must $ZPOOL replace $TESTPOOL $VDEV0 $sparedevs + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + populate_test_env $TESTDIR/safe_dir 64 + populate_test_env $TESTDIR/bad_dir $maxnumber + + test_zinject $TESTDIR/bad_dir $type + + cleanup_env +done + +log_pass "Fault inject handle metadnode error successfully." diff --git a/tests/sys/cddl/zfs/tests/zinject/zinject_003_pos.ksh b/tests/sys/cddl/zfs/tests/zinject/zinject_003_pos.ksh new file mode 100644 index 00000000000..7ffe4cd960b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/zinject_003_pos.ksh @@ -0,0 +1,144 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zinject_003_pos.ksh 1.3 09/06/22 SMI" +# + +############################################################################### +# +# __stc_assertion_start +# +# ID: zinject_003_pos +# +# DESCRIPTION: +# +# Inject an error into the first metadnode in the block +# Verify the filesystem unmountable since dnode be injected. +# +# STRATEGY: +# 1) Populate ZFS file system +# 2) Inject an error into the first metadnode in the block. +# 3) Verify the filesystem unmountable, +# and 'zpool status -v' will display the error as expect. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-02-01) +# +# __stc_assertion_end +# +################################################################################ + +. $STF_SUITE/tests/zinject/zinject.kshlib + +verify_runnable "global" + +log_assert "Verify fault inject handle into first metadnode " \ + "cause filesystem unmountable." +log_onexit cleanup_env + +set -A types "" "mirror" "raidz" "raidz2" + +typeset -i maxnumber=1 + +function test_zinject_unit +{ + typeset etype=$1 + typeset object=$2 + typeset errno=$3 + typeset ereport=$4 + typeset now + + typeset otype="file" + [[ -d $object ]] && otype="dir" + + now=`date '+%m/%d/%y %H:%M:%S'` + inject_fault $etype $object $errno 1 + + unmounted $TESTPOOL/$TESTFS || \ + log_fail "$TESTPOOL/$TESTFS mount unexpected." + + log_must check_status $TESTPOOL "$TESTPOOL/$TESTFS:<0x0>" + + inject_clear + + log_must $ZFS mount -a +} + +function test_zinject +{ + typeset basedir=$1 + typeset pooltype=$2 + typeset -i i=0 + typeset etype="dnode" + + set -A errset "io" "ereport.fs.zfs.io ereport.fs.zfs.data" + + ((i=${#errset[*]})) + if [[ -n $pooltype ]] ; then + errset[i]="checksum" + errset[((i+1))]="ereport.fs.zfs.checksum ereport.fs.zfs.data" + else + errset[i]="checksum" + errset[((i+1))]="ereport.fs.zfs.data" + fi + + i=0 + while ((i < ${#errset[*]} )); do + for object in $basedir/testfile.$maxnumber \ + $basedir/testdir.$maxnumber ; do + test_zinject_unit $etype $object \ + ${errset[i]} "${errset[((i+1))]}" + done + + (( i = i + 2 )) + done +} + +inject_clear +for type in "${types[@]}"; do + create_pool $TESTPOOL $type $pooldevs spare $sparedevs + + log_must $ZPOOL add -f $TESTPOOL log $logdevs + log_must $ZPOOL add -f $TESTPOOL cache $cachedevs + + log_must $ZPOOL replace $TESTPOOL $VDEV0 $sparedevs + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + populate_test_env $TESTDIR/bad_dir $maxnumber + + test_zinject $TESTDIR/bad_dir $type + + cleanup_env +done + +log_pass "Fault inject handle into first metadnode " \ + "cause filesystem unmountable." diff --git a/tests/sys/cddl/zfs/tests/zinject/zinject_004_pos.ksh b/tests/sys/cddl/zfs/tests/zinject/zinject_004_pos.ksh new file mode 100644 index 00000000000..c149466466d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/zinject_004_pos.ksh @@ -0,0 +1,130 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zinject_004_pos.ksh 1.6 09/06/22 SMI" +# + +############################################################################### +# +# __stc_assertion_start +# +# ID: zinject_004_pos +# +# DESCRIPTION: +# +# Inject an error into the device of a pool. +# Verify fmdump will get the expect ereport, +# and the fault class of "fault.fs.zfs.vdev.io" be generated. +# +# STRATEGY: +# 1) Populate ZFS file system +# 2) Inject an error into the device of the pool. +# 3) Verify fmdump get the ereport as expected. +# +# nxio ereport.fs.zfs.probe_failure +# io ereport.fs.zfs.probe_failure +# 4) Verify the fault class of "fault.fs.zfs.vdev.io" be generated. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-05-31) +# +# __stc_assertion_end +# +################################################################################ + +. $STF_SUITE/tests/zinject/zinject.kshlib + +verify_runnable "global" + +log_assert "Verify fault inject handle device error successfully." +log_onexit cleanup_env + +set -A types "mirror" "raidz" "raidz2" + +typeset -i maxnumber=1 + +function test_zinject +{ + typeset basedir=$1 + typeset -i i=0 + typeset etype="device" + typeset fclass="fault.fs.zfs.vdev.io" + + set -A errset \ + "nxio" "ereport.fs.zfs.probe_failure" \ + "io" "ereport.fs.zfs.probe_failure" + + set -A alldevarray $alldevs + + for device in $(random_string alldevarray 1); do + i=0 + while ((i < ${#errset[*]} )); do + now=`date '+%m/%d/%y %H:%M:%S'` + inject_device $device $TESTPOOL ${errset[i]} + + trigger_inject $etype $basedir/testfile.$maxnumber "file" + log_must check_ereport "$now" ${errset[((i+1))]} + log_must check_fault "$now" $fclass + + inject_clear + + now=`date '+%m/%d/%y %H:%M:%S'` + inject_device $device $TESTPOOL ${errset[i]} + + trigger_inject $etype $basedir/testdir.$maxnumber "dir" + log_must check_ereport "$now" ${errset[((i+1))]} + log_must check_fault "$now" $fclass + + inject_clear + + (( i = i + 2 )) + done + done +} + +inject_clear +for type in "${types[@]}"; do + create_pool $TESTPOOL $type $pooldevs spare $sparedevs + + log_must $ZPOOL add -f $TESTPOOL log $logdevs + log_must $ZPOOL add -f $TESTPOOL cache $cachedevs + + log_must $ZPOOL replace $TESTPOOL $VDEV0 $sparedevs + log_must $ZFS create $TESTPOOL/$TESTFS + log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS + + populate_test_env $TESTDIR $maxnumber + test_zinject $TESTDIR + + cleanup_env +done + +log_pass "Fault inject handle device error successfully." diff --git a/tests/sys/cddl/zfs/tests/zinject/zinject_test.sh b/tests/sys/cddl/zfs/tests/zinject/zinject_test.sh new file mode 100755 index 00000000000..30788deccc8 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zinject/zinject_test.sh @@ -0,0 +1,140 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zinject_001_pos cleanup +zinject_001_pos_head() +{ + atf_set "descr" "Verify fault inject handle content error successfully." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +zinject_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zinject_001_pos.ksh || atf_fail "Testcase failed" +} +zinject_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zinject_002_pos cleanup +zinject_002_pos_head() +{ + atf_set "descr" "Verify fault inject handle metadnode error successfully." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +zinject_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zinject_002_pos.ksh || atf_fail "Testcase failed" +} +zinject_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zinject_003_pos cleanup +zinject_003_pos_head() +{ + atf_set "descr" "Verify fault inject handle into first metadnodecause filesystem unmountable." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +zinject_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zinject_003_pos.ksh || atf_fail "Testcase failed" +} +zinject_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zinject_004_pos cleanup +zinject_004_pos_head() +{ + atf_set "descr" "Verify fault inject handle device error successfully." + atf_set "require.progs" zfs zpool + atf_set "timeout" 1800 +} +zinject_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zinject_004_pos.ksh || atf_fail "Testcase failed" +} +zinject_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zinject.kshlib + . $(atf_get_srcdir)/zinject.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zinject_001_pos + atf_add_test_case zinject_002_pos + atf_add_test_case zinject_003_pos + atf_add_test_case zinject_004_pos +} diff --git a/tests/sys/cddl/zfs/tests/zones/Makefile b/tests/sys/cddl/zfs/tests/zones/Makefile new file mode 100644 index 00000000000..7c44fc58abc --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/Makefile @@ -0,0 +1,23 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zones +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zones_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zones.cfg +${PACKAGE}FILES+= zones_005_pos.ksh +${PACKAGE}FILES+= zones_001_pos.ksh +${PACKAGE}FILES+= zones_004_pos.ksh +${PACKAGE}FILES+= zones_common.kshlib +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zones_002_pos.ksh +${PACKAGE}FILES+= zones_003_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zones/cleanup.ksh b/tests/sys/cddl/zfs/tests/zones/cleanup.ksh new file mode 100644 index 00000000000..1543ad77380 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/cleanup.ksh @@ -0,0 +1,66 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.5 09/05/19 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib + +verify_runnable "both" + +if ! is_global_zone ; then + default_cleanup +fi + +# Zone installs that may have been interrupted can leave the system in +# an odd state, lots of processes hanging around that will block +# our attempts to delete the zone. Remove these first. +for program in zoneadm lucreatezone lupi_zones lupi_bebasic pkginstall +do + $PKILL -9 $program +done + +# Zone installs that may have been interrupted can leave the system +# with lofs mounts from our test pool. Unmount these. +FS=$($MOUNT | $GREP $TESTPOOL | $AWK '{print $1}') + +for fs in $FS +do + $UMOUNT -f $fs +done + +for zone in $ZONE $ZONE2 $ZONE3 $ZONE4 ; do + $ZONEADM -z $zone list > /dev/null 2>&1 + if (( $? == 0 )) ; then + $ZONEADM -z $zone halt > /dev/null 2>&1 + $ZONEADM -z $zone uninstall -F > /dev/null 2>&1 + $ZONECFG -z $zone delete -F > /dev/null 2>&1 + fi +done + +default_cleanup diff --git a/tests/sys/cddl/zfs/tests/zones/setup.ksh b/tests/sys/cddl/zfs/tests/zones/setup.ksh new file mode 100644 index 00000000000..0f8bf47ff9b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/setup.ksh @@ -0,0 +1,65 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/tests/zones/zones_common.kshlib + +verify_runnable "both" +check_version "5.11" +if [ $? -eq 1 ] +then + log_unsupported "ZFS zone clone tests unsupported on this release." +fi + +if ! is_global_zone ; then + log_pass +fi + +DISK=${DISKS%% *} +default_setup_noexit $DISK + +# create a zone on ZFS +create_zone $ZONE /$TESTPOOL +install_zone $ZONE + +log_must $MKDIR -p -m 0700 /$TESTPOOL/simple_dir + +# create a normal zone - again on ZFS, but with the zonepath +# being a simple directory, rather than a top-level filesystem. +# We also create this as a branded zone. +create_zone $ZONE2 /$TESTPOOL/simple_dir SUNWsn1 +install_zone $ZONE2 + +# Now make sure those zones are visible +log_must eval "$ZONEADM -z $ZONE list > /dev/null 2>&1" +log_must eval "$ZONEADM -z $ZONE2 list > /dev/null 2>&1" + +log_pass "Setup created zones $ZONE and $ZONE2" diff --git a/tests/sys/cddl/zfs/tests/zones/zones.cfg b/tests/sys/cddl/zfs/tests/zones/zones.cfg new file mode 100644 index 00000000000..e887b75dd24 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones.cfg @@ -0,0 +1,83 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zones.cfg 1.5 08/08/15 SMI" +# + +# Variables we'll use to name our zones +# The first two zones are created by setup, +# then destroyed in zones_004_pos - or cleanup. +ZONE="${ZONE:=zone}" +ZONE2="${ZONE2:=zonetwo}" + +# These zones are created and destroyed by zones_003_pos - or cleanup. +ZONE3="${ZONE3:=zonethree}" +ZONE4="${ZONE4:=zonefour}" + +# A function which runs through a loop, adding a different characters +# to the stem passed as $1, to make sure we have a unique name that +# doesn't clash with an existing zone name. Once we've found a unique +# name, we echo that to stdout. +# +function find_unique_zonename { # initial name of zone + + NAME=$1 + COUNT=0 + while [ -z "$FOUND" ] + do + NAME="${NAME}${COUNT}" + $ZONEADM -z $NAME list > /dev/null 2>&1 + if [ $? -eq 1 ] + then + FOUND=true + fi + COUNT=$(( $COUNT + 1 )) + done + echo $NAME +} + +# Need a longer timeout for zone installation +export STF_TIMEOUT=3600 + +# Make sure that multiple sourcing of this script doesn't change the zone name +if [ -z "${RUNCONFIG}" ] +then + ZONE=$(find_unique_zonename $ZONE) + ZONE2=$(find_unique_zonename $ZONE2) + ZONE3=$(find_unique_zonename $ZONE3) + ZONE4=$(find_unique_zonename $ZONE4) + + log_note "zones.cfg gave us new zone names $ZONE,$ZONE2,$ZONE3,$ZONE4" + + export ZONE + export ZONE2 + export ZONE3 + export ZONE4 + + export RUNCONFIG="true" +fi diff --git a/tests/sys/cddl/zfs/tests/zones/zones_001_pos.ksh b/tests/sys/cddl/zfs/tests/zones/zones_001_pos.ksh new file mode 100644 index 00000000000..bfa979e246e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones_001_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zones_001_pos.ksh 1.3 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zones_001_pos +# +# DESCRIPTION: +# +# The zone created by the default zones setup should have ZFS zvols, +# datasets and filesystems present. +# +# STRATEGY: +# 1. For each ZFS object type +# 2. Perform a basic sanity check for that object in the local zone. +# 3. Check that the top level dataset is read only. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-10-18) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "local" + + +log_assert "Local zone contains ZFS datasets as expected." + + +# check to see if our zvol exists: +if [ ! -b /dev/zvol/dsk/zonepool/zone_zvol ] +then + log_fail "block device /dev/zvol/dsk/zonepool/zone_zvol not found!" +fi + +if [ ! -c /dev/zvol/rdsk/zonepool/zone_zvol ] +then + log_fail "char device /dev/zvol/rdsk/zonepool/zone_zvol not found!" +fi + +# check to see if the device appears sane - create a UFS filesystem on it. +$ECHO y | $NEWFS /dev/zvol/rdsk/zonepool/zone_zvol > /dev/null + +if [ $? -ne 0 ] +then + log_fail "Failed to create UFS filesystem on a zvol in the zone!" +fi + +$MKDIR /ufs.${TESTCASE_ID} +log_must $MOUNT /dev/zvol/dsk/zonepool/zone_zvol /ufs.${TESTCASE_ID} +log_must $UMOUNT /ufs.${TESTCASE_ID} +$RM -rf /ufs.${TESTCASE_ID} + + +# Next check to see if the datasets exist as expected. +for dataset in 0 1 2 3 4 +do + DATASET=zonepool/zonectr${dataset} + if [ ! -d /${DATASET} ] + then + log_note "Missing zone dataset ${DATASET}!" + fi + log_must $ZFS create ${DATASET}/fs + if [ ! -d /${DATASET}/fs ] + then + log_fail "ZFS create failed to create child dataset of ${DATASET}" + fi + log_must $ZFS destroy ${DATASET}/fs +done + +# Next check to see that the root dataset is readonly +log_mustnot $ZFS create zonepool/fs +log_mustnot $ZFS mount zonepool + +log_pass "Local zone contains ZFS datasets as expected." + diff --git a/tests/sys/cddl/zfs/tests/zones/zones_002_pos.ksh b/tests/sys/cddl/zfs/tests/zones/zones_002_pos.ksh new file mode 100644 index 00000000000..2fef9368016 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones_002_pos.ksh @@ -0,0 +1,81 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zones_002_pos.ksh 1.2 07/01/09 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/tests/zones/zones_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zones_002_pos +# +# DESCRIPTION: +# +# A zone created where the zonepath parent dir is the top level of a ZFS +# file system has a new ZFS filesystem created for it. +# +# STRATEGY: +# 1. The setup script should have created the zone. +# 2. Verify that a new ZFS filesystem has been created. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A ZFS fs is created when the parent dir of zonepath is a ZFS fs." + +# check to see if our zone exists: +if [ ! -d /$TESTPOOL/$ZONE ] +then + log_fail "Zone dir in /$TESTPOOL/$ZONE not found!" +fi + +if [ ! -d /$TESTPOOL/simple_dir/$ZONE2 ] +then + log_fail "Zone dir /$TESTPOOL/simple_dir/$ZONE2 not found!" +fi + +# we should have a new ZFS fs for the zone +log_must eval "$ZFS list $TESTPOOL/$ZONE > /dev/null" + +# we should not have a new ZFS fs for the non-ZFS zone. +log_mustnot eval "$ZFS list $TESTPOOL/simple_dir/$ZONE2 > /dev/null" + +log_pass "A ZFS fs is created when the parent dir of zonepath is a ZFS fs." diff --git a/tests/sys/cddl/zfs/tests/zones/zones_003_pos.ksh b/tests/sys/cddl/zfs/tests/zones/zones_003_pos.ksh new file mode 100644 index 00000000000..cf81284f053 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones_003_pos.ksh @@ -0,0 +1,133 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zones_003_pos.ksh 1.3 08/11/03 SMI" +# + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/tests/zones/zones_common.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zones_003_pos +# +# DESCRIPTION: +# +# Zone cloning via ZFS snapshots works as expected. +# We can clone zones where the zonepath is the top level of a ZFS filesystem +# using snapshots. Where the zone is not at the top level of a ZFS filesystem, +# cloning the zone uses the normal method of copying the files when +# performing the clone operation. +# +# STRATEGY: +# 1. The setup script should have created the zone. +# 2. Clone a zone-on-ZFS +# 3. Verify that ZFS snapshots were taken and used for the clone and that +# the new zone is indeed a clone (in the ZFS sense) +# 4. Clone a normal zone & verify that no snapshots were taken. +# 5. Clone a zone-on-ZFS, but specify the "copy" method & verify that no +# snapshots were taken. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-12) +# +# __stc_assertion_end +# +################################################################################ + +function cleanup { + + log_must $ZONEADM -z $ZONE3 uninstall -F + log_must $ZONECFG -z $ZONE3 delete -F + + log_must $ZONEADM -z $ZONE4 uninstall -F + log_must $ZONECFG -z $ZONE4 delete -F +} + + +verify_runnable "global" +log_onexit cleanup + +log_assert "Zone cloning via ZFS snapshots works as expected." + + +# Make sure our zones exist: +if [ ! -d /$TESTPOOL/$ZONE ] +then + log_fail "Zone dir in /$TESTPOOL/$ZONE not found!" +fi + +if [ ! -d /$TESTPOOL/simple_dir/$ZONE2 ] +then + log_fail "Zone dir /$TESTPOOL/simple_dir/$ZONE2 not found!" +fi + + +create_zone $ZONE3 /$TESTPOOL +create_zone $ZONE4 /$TESTPOOL/simple_dir + +# Create a new zone3 based on cloning our zone +log_note "Cloning ZFS rooted zone" +log_must $ZONEADM -z $ZONE3 clone $ZONE + +# Make sure our snapshot and the new filesystem is there +log_must snapexists $TESTPOOL/$ZONE@SUNWzone1 +log_must datasetexists $TESTPOOL/$ZONE3 + +# verify that it is in fact a clone: +ORIGIN=$($ZFS get -H -o value origin $TESTPOOL/$ZONE3) +if [ "$ORIGIN" != "$TESTPOOL/$ZONE@SUNWzone1" ] +then + log_fail "$ZONE3 does not appear to have been ZFS cloned from $ZONE" +fi + +# Now uninstall that zone & the snapshot it was cloned from +log_must $ZONEADM -z $ZONE3 uninstall -F +log_must $ZONECFG -z $ZONE3 delete -F + +# Again create a new zone3, but clone the non-ZFS-rooted zone2 +# A snapshot should not have been created this time, but a new filesys +# should still be created. +create_zone $ZONE3 /$TESTPOOL SUNWsn1 +log_note "Cloning non-ZFS rooted zone2" +log_must $ZONEADM -z $ZONE3 clone $ZONE2 +log_mustnot snapexists $TESTPOOL/$ZONE2@SUNWzone1 +log_must datasetexists $TESTPOOL/$ZONE3 + +# Finally, clone a zone using the old copy method, where +# a snapshot should not be taken. +log_note "Cloning ZFS rooted zone using copy method" +log_must $ZONEADM -z $ZONE4 clone -m copy $ZONE +log_mustnot snapexists $TESTPOOl/$ZONE@SUNWzone1 + +log_pass "Zone cloning via ZFS snapshots works as expected." diff --git a/tests/sys/cddl/zfs/tests/zones/zones_004_pos.ksh b/tests/sys/cddl/zfs/tests/zones/zones_004_pos.ksh new file mode 100644 index 00000000000..e9ebac3bf8c --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones_004_pos.ksh @@ -0,0 +1,91 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zones_004_pos.ksh 1.3 09/05/19 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zones_004_pos +# +# DESCRIPTION: +# +# Deleting a zone, where the zonepath parent dir is the top level of a ZFS +# file system, causes that underlying filesystem to be deleted. Deleting +# the non-ZFS zone does not delete any filesystems. +# +# STRATEGY: +# 1. The setup script should have created the zone. +# 2. Delete our ZFS rooted zone, verify the filesystem has been deleted. +# 3. Delete our non-ZFS rooted zone, the zonepath dir should still exist. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-11) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "A ZFS fs is destroyed when the zone it was created for is deleted." + +# Make sure our zones exist: +if [ ! -d /$TESTPOOL/$ZONE ] +then + log_fail "Zone dir in /$TESTPOOL/$ZONE not found!" +fi + +if [ ! -d /$TESTPOOL/simple_dir/$ZONE2 ] +then + log_fail "Zone dir /$TESTPOOL/simple_dir/$ZONE2 not found!" +fi + + +# delete our ZFS rooted zone +log_must $ZONEADM -z $ZONE uninstall -F +log_must $ZONECFG -z $ZONE delete -F +log_mustnot eval "$ZFS list $TESTPOOL/$ZONE > /dev/null 2>&1" + +# delete our non-ZFS rooted zone +log_must $ZONEADM -z $ZONE2 uninstall -F +log_must $ZONECFG -z $ZONE2 delete -F +if [ ! -d /$TESTPOOL/simple_dir ] +then + log_fail "On deleting $ZONE2, the dir above zonepath was destroyed!" +fi + + +log_pass "A ZFS fs is destroyed when the zone it was created for is deleted." diff --git a/tests/sys/cddl/zfs/tests/zones/zones_005_pos.ksh b/tests/sys/cddl/zfs/tests/zones/zones_005_pos.ksh new file mode 100644 index 00000000000..a60a104b742 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones_005_pos.ksh @@ -0,0 +1,72 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zones_005_pos.ksh 1.1 07/05/25 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zones_005_pos +# +# DESCRIPTION: +# +# Pool properties can be read but can't be set within a zone +# +# STRATEGY: +# 1. Verify we can read pool properties in a zone +# 2. Verify we can't set a pool property in a zone +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2007-04-03) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "local" + +log_assert "Pool properties can be read but can't be set within a zone" + +log_must $ZPOOL get all zonepool +log_must $ZPOOL get bootfs zonepool +log_mustnot $ZPOOL set boofs=zonepool zonepool + +# verify that the property hasn't been set. +log_must eval "$ZPOOL get bootfs zonepool > $TMPDIR/output.${TESTCASE_ID}" +log_must $GREP "zonepool bootfs -" $TMPDIR/output.${TESTCASE_ID} + +$RM $TMPDIR/output.${TESTCASE_ID} + +log_pass "Pool properties can be read but can't be set within a zone" diff --git a/tests/sys/cddl/zfs/tests/zones/zones_common.kshlib b/tests/sys/cddl/zfs/tests/zones/zones_common.kshlib new file mode 100644 index 00000000000..e9c478451ec --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones_common.kshlib @@ -0,0 +1,70 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zones_common.kshlib 1.3 07/03/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zones/zones.cfg + +# a simple zone creation function +function create_zone { # $ZONENAME $ZONEPATH $BRAND (optional) + ZNAME=$1 + ZPATH=$2 + BRAND=$3 + + if [ ! -z $BRAND ] + then + # The SUNWsn1 brand only works on debug kernels for sparc, so we + # check for a known symbol to see if that's there. + $ECHO "logmap_logscan_debug/p" | $MDB -k > /dev/null 2>&1 + if [ $? -eq 1 ] + then + BRAND="" + else + BRAND="-t $BRAND " + fi + fi + + # create a zone config file + $CAT > $TMPDIR/zone.${TESTCASE_ID}.cfg < /dev/null + $RM $TMPDIR/zone.${TESTCASE_ID}.cfg +} + +function install_zone { # $ZONENAME + ZNAME=$1 + log_note "Installing $ZNAME. This may take some time." + log_must $ZONEADM -z $ZNAME install > /dev/null +} diff --git a/tests/sys/cddl/zfs/tests/zones/zones_test.sh b/tests/sys/cddl/zfs/tests/zones/zones_test.sh new file mode 100755 index 00000000000..6bf9e290d64 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zones/zones_test.sh @@ -0,0 +1,167 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zones_001_pos cleanup +zones_001_pos_head() +{ + atf_set "descr" "Local zone contains ZFS datasets as expected." + atf_set "require.progs" zfs zoneadm zonecfg + atf_set "timeout" 3600 +} +zones_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zones_001_pos.ksh || atf_fail "Testcase failed" +} +zones_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zones_002_pos cleanup +zones_002_pos_head() +{ + atf_set "descr" "A ZFS fs is created when the parent dir of zonepath is a ZFS fs." + atf_set "require.progs" zfs zoneadm zonecfg + atf_set "timeout" 3600 +} +zones_002_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zones_002_pos.ksh || atf_fail "Testcase failed" +} +zones_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zones_003_pos cleanup +zones_003_pos_head() +{ + atf_set "descr" "Zone cloning via ZFS snapshots works as expected." + atf_set "require.progs" zfs zoneadm zonecfg + atf_set "timeout" 3600 +} +zones_003_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zones_003_pos.ksh || atf_fail "Testcase failed" +} +zones_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zones_004_pos cleanup +zones_004_pos_head() +{ + atf_set "descr" "A ZFS fs is destroyed when the zone it was created for is deleted." + atf_set "require.progs" zfs zoneadm zonecfg + atf_set "timeout" 3600 +} +zones_004_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zones_004_pos.ksh || atf_fail "Testcase failed" +} +zones_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zones_005_pos cleanup +zones_005_pos_head() +{ + atf_set "descr" "Pool properties can be read but can't be set within a zone" + atf_set "require.progs" zpool zonecfg zoneadm + atf_set "timeout" 3600 +} +zones_005_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zones_005_pos.ksh || atf_fail "Testcase failed" +} +zones_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zones_common.kshlib + . $(atf_get_srcdir)/zones.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zones_001_pos + atf_add_test_case zones_002_pos + atf_add_test_case zones_003_pos + atf_add_test_case zones_004_pos + atf_add_test_case zones_005_pos +} diff --git a/tests/sys/cddl/zfs/tests/zvol/Makefile b/tests/sys/cddl/zfs/tests/zvol/Makefile new file mode 100644 index 00000000000..ade9c7284bd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/Makefile @@ -0,0 +1,17 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zvol +FILESDIR=${TESTSDIR} + +${PACKAGE}FILES+= zvol.cfg +${PACKAGE}FILES+= zvol_common.kshlib + +TESTS_SUBDIRS+= zvol_ENOSPC +TESTS_SUBDIRS+= zvol_swap +TESTS_SUBDIRS+= zvol_misc +TESTS_SUBDIRS+= zvol_cli + +.include diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol.cfg b/tests/sys/cddl/zfs/tests/zvol/zvol.cfg new file mode 100644 index 00000000000..725ba6741d3 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol.cfg @@ -0,0 +1,39 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol.cfg 1.4 08/08/15 SMI" +# + +export DISK=${DISKS%% *} + +export TESTVOL=testvol${TESTCASE_ID} +export TESTFILE=testfile${TESTCASE_ID} +export TESTSNAP=testsnap${TESTCASE_ID} +export VOLSIZE=2g +export DATA=0 +export ENOSPC=28 diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/Makefile b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/Makefile new file mode 100644 index 00000000000..8cb5e128de1 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zvol/zvol_ENOSPC +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zvol_ENOSPC_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zvol_ENOSPC_001_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zvol_ENOSPC.cfg +${PACKAGE}FILES+= cleanup.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/cleanup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/cleanup.ksh new file mode 100644 index 00000000000..5ab2b991459 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/cleanup.ksh @@ -0,0 +1,39 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)cleanup.ksh 1.3 08/11/03 SMI" +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +default_zvol_cleanup + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/setup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/setup.ksh new file mode 100644 index 00000000000..f097553e9a7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/setup.ksh @@ -0,0 +1,43 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +default_zvol_setup $DISK $VOLSIZE + +log_must $NEWFS /dev/zvol/$TESTPOOL/$TESTVOL +log_must $MKDIR $TESTDIR +log_must $MOUNT /dev/zvol/$TESTPOOL/$TESTVOL $TESTDIR + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC.cfg b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC.cfg new file mode 100644 index 00000000000..76e127cc05a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_ENOSPC.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/zvol/zvol.cfg + +export BLOCKSZ=$(( 1024 * 1024 )) +export NUM_WRITES=40 diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos.ksh new file mode 100644 index 00000000000..e14925f177b --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC_001_pos.ksh @@ -0,0 +1,82 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)zvol_ENOSPC_001_pos.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_ENOSPC_001_pos +# +# DESCRIPTION: +# A zvol volume will return ENOSPC when the underlying pool runs out of +# space. +# +# STRATEGY: +# 1. Create a pool +# 2. Create a zvol volume +# 3. Create a ufs file system ontop of the zvol +# 4. Mount the ufs file system +# 5. Fill volume until ENOSPC is returned +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + # unmounting the UFS filesystem can take more than 60s, and Kyua has a + # hardcoded 60s limit for the cleanup phase. So we must unmount the + # filesystem here rather than cleanup.ksh. + ismounted $TESTDIR ufs && log_must $UMOUNT -f $TESTDIR + $RMDIR $TESTDIR +} + +log_assert "A zvol volume will return ENOSPC when the underlying pool " \ + "runs out of space." + +log_onexit cleanup + +typeset -i fn=0 +typeset -i retval=0 + +log_mustbe ENOSPC fill_fs $TESTDIR -1 50 $BLOCKSZ $NUM_WRITES + +log_pass "ENOSPC was returned as expected" diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC_test.sh b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC_test.sh new file mode 100755 index 00000000000..49ee93d59d2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_ENOSPC/zvol_ENOSPC_test.sh @@ -0,0 +1,56 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zvol_ENOSPC_001_pos cleanup +zvol_ENOSPC_001_pos_head() +{ + atf_set "descr" "A zvol volume will return ENOSPC when the underlying poolruns out of space." +} +zvol_ENOSPC_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_ENOSPC.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_ENOSPC_001_pos.ksh || atf_fail "Testcase failed" +} +zvol_ENOSPC_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_ENOSPC.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zvol_ENOSPC_001_pos +} diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/Makefile b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/Makefile new file mode 100644 index 00000000000..5ed650abc37 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/Makefile @@ -0,0 +1,20 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zvol/zvol_cli +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zvol_cli_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zvol_cli_003_neg.ksh +${PACKAGE}FILES+= zvol_cli_002_pos.ksh +${PACKAGE}FILES+= zvol_cli.cfg +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zvol_cli_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/cleanup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/cleanup.ksh new file mode 100644 index 00000000000..5ace55491b7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/cleanup.ksh @@ -0,0 +1,39 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +default_zvol_cleanup + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/setup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/setup.ksh new file mode 100644 index 00000000000..30af5161eae --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/setup.ksh @@ -0,0 +1,39 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +default_zvol_setup $DISK $VOLSIZE + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli.cfg b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli.cfg new file mode 100644 index 00000000000..e93a348dbcb --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli.cfg @@ -0,0 +1,35 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_cli.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/zvol/zvol.cfg + +export LONGPNAME="poolname50charslong_012345678901234567890123456789" +export LONGVOLNAME="volumename50charslong_0123456789012345678901234567" diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_001_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_001_pos.ksh new file mode 100644 index 00000000000..babd0df0cf5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_001_pos.ksh @@ -0,0 +1,75 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)zvol_cli_001_pos.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_cli_001_pos +# +# DESCRIPTION: +# Executing well-formed 'zfs list' commands should return success +# +# STRATEGY: +# 1. Create an array of valid options. +# 2. Execute each element in the array. +# 3. Verify success is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A args "list" "list -r" \ + "list $TESTPOOL/$TESTVOL" "list -r $TESTPOOL/$TESTVOL" \ + "list -H $TESTPOOL/$TESTVOL" "list -Hr $TESTPOOL/$TESTVOL" \ + "list -rH $TESTPOOL/$TESTVOL" "list -o name $TESTPOOL/$TESTVOL" \ + "list -r -o name $TESTPOOL/$TESTVOL" "list -H -o name $TESTPOOL/$TESTVOL" \ + "list -rH -o name $TESTPOOL/$TESTVOL" + +log_assert "Executing well-formed 'zfs list' commands should return success" + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_must eval "$ZFS ${args[i]} > /dev/null" + ((i = i + 1)) +done + +log_pass "Executing zfs list on volume works as expected" diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_002_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_002_pos.ksh new file mode 100644 index 00000000000..f6f3f73b5d5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_002_pos.ksh @@ -0,0 +1,74 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)zvol_cli_002_pos.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_cli_002_pos +# +# DESCRIPTION: +# Creating a volume with a 50 letter name should work. +# +# STRATEGY: +# 1. Using a very long name, create a zvol +# 2. Verify volume exists +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + datasetexists $TESTPOOL/$LONGVOLNAME && \ + $ZFS destroy $TESTPOOL/$LONGVOLNAME +} + +log_onexit cleanup + +log_assert "Creating a volume a 50 letter name should work." + +log_must $ZFS create -V $VOLSIZE $TESTPOOL/$LONGVOLNAME + +datasetexists $TESTPOOL/$LONGVOLNAME || \ + log_fail "Couldn't find long volume name" + +log_pass "Created a 50-letter zvol volume name" diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_003_neg.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_003_neg.ksh new file mode 100644 index 00000000000..8ad7d3aa0a7 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_003_neg.ksh @@ -0,0 +1,73 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)zvol_cli_003_neg.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_cli_003_neg +# +# DESCRIPTION: +# Try each ZFS volume sub-command without parameters to make sure +# it returns an error. +# +# STRATEGY: +# 1. Create an array of parameters +# 2. For each parameter in the array, execute the sub-command +# 3. Verify an error is returned. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +set -A args "" "create -V" "create -V $TESTPOOL" \ + "create -V $TESTPOOL/$TESTVOL@" "create -V blah" "destroy" + +log_assert "Try each ZFS volume sub-command without parameters to make sure" \ + " it returns an error." + +typeset -i i=0 +while (( $i < ${#args[*]} )); do + log_mustnot $ZFS ${args[i]} + (( i = i + 1 )) +done + +log_pass "Badly formed ZFS volume sub-commands fail as expected." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_test.sh b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_test.sh new file mode 100755 index 00000000000..75dd29376f9 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_cli/zvol_cli_test.sh @@ -0,0 +1,107 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zvol_cli_001_pos cleanup +zvol_cli_001_pos_head() +{ + atf_set "descr" "Executing well-formed 'zfs list' commands should return success" + atf_set "require.progs" zfs +} +zvol_cli_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_cli.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_cli_001_pos.ksh || atf_fail "Testcase failed" +} +zvol_cli_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_cli.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_cli_002_pos cleanup +zvol_cli_002_pos_head() +{ + atf_set "descr" "Creating a volume a 50 letter name should work." + atf_set "require.progs" zfs +} +zvol_cli_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_cli.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_cli_002_pos.ksh || atf_fail "Testcase failed" +} +zvol_cli_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_cli.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_cli_003_neg cleanup +zvol_cli_003_neg_head() +{ + atf_set "descr" "Try each ZFS volume sub-command without parameters to make sure it returns an error." + atf_set "require.progs" zfs +} +zvol_cli_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_cli.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_cli_003_neg.ksh || atf_fail "Testcase failed" +} +zvol_cli_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_cli.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zvol_cli_001_pos + atf_add_test_case zvol_cli_002_pos + atf_add_test_case zvol_cli_003_neg +} diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_common.kshlib b/tests/sys/cddl/zfs/tests/zvol/zvol_common.kshlib new file mode 100644 index 00000000000..b31916b8be2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_common.kshlib @@ -0,0 +1,165 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_common.kshlib 1.6 09/06/22 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +# +# Create a simple zvol volume +# +# Where disk_device: is the name of the disk to be used +# volume_size: is the size of the volume, e.g. 2G +# +function default_zvol_setup # disk_device volume_size +{ + typeset disk=$1 + typeset size=$2 + typeset savedumpdev + typeset -i output + + create_pool $TESTPOOL "$disk" + + log_must $ZFS create -V $size $TESTPOOL/$TESTVOL + + if [[ -n $DUMPADM ]]; then + if is_dumpswap_supported $TESTPOOL ; then + set_dumpsize $TESTPOOL/$TESTVOL + fi + fi +} + +# +# Destroy the default zvol which was setup using +# default_zvol_setup(). +# +function default_zvol_cleanup +{ + if datasetexists $TESTPOOL/$TESTVOL ; then + log_must $ZFS destroy $TESTPOOL/$TESTVOL + fi + + destroy_pool $TESTPOOL +} + +# +# Check if the given pool support "Swap and crash dumps" +# +function is_dumpswap_supported #pool +{ + typeset pool=$1 + + if [[ -z $pool ]] ; then + log_fail "No pool given." + fi + + typeset -i SPA_VER_DUMPSWAP=10 + typeset -i vp=$(get_pool_prop version $pool) + + if (( vp >= SPA_VER_DUMPSWAP )) ; then + return 0 + fi + + return 1 +} + +function get_dumpdevice +{ + typeset ret=$($DUMPADM | $GREP "Dump device:" | $AWK '{print $3}') + print $ret +} + +function set_dumpsize +{ + typeset volume=$1 + + if [[ -z $volume ]] ; then + log_note "No volume specified." + return 1 + fi + + log_must $ZFS set volsize=64m $volume + + output=$($DUMPADM -d /dev/zvol/dsk/$volume 2>&1 | \ + $TAIL -1 | $AWK '{print $3}') + + if [[ -n $output ]]; then + (( output = output / 1024 / 1024 )) + (( output = output + output / 5 )) + log_must $ZFS set volsize=${output}m $volume + fi + return 0 +} + +function safe_dumpadm +{ + typeset device=$1 + + if [[ -z $device || $device == "none" ]] ; then + log_note "No dump device volume specified." + return 1 + fi + if [[ $device == "/dev/zvol/dsk/"* ]] ; then + typeset volume=${device#/dev/zvol/dsk/} + set_dumpsize $volume + log_must $DUMPADM -d $device + else + log_must $SWAPADD + if ! is_swap_inuse $device ; then + log_must $SWAP -a $device + fi + log_must $DUMPADM -d swap + fi +} + +function is_zvol_dumpified +{ + typeset volume=$1 + + if [[ -z $volume ]] ; then + log_note "No volume specified." + return 1 + fi + + $ZDB -dddd $volume 2 | $GREP "dumpsize" > /dev/null 2>&1 + return $? +} + +function is_swap_inuse +{ + typeset device=$1 + + if [[ -z $device ]] ; then + log_note "No device specified." + return 1 + fi + + $SWAP -l | $GREP -w $device > /dev/null 2>&1 + return $? +} diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/Makefile b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/Makefile new file mode 100644 index 00000000000..43158e22d01 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/Makefile @@ -0,0 +1,26 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zvol/zvol_misc +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zvol_misc_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zvol_misc.cfg +${PACKAGE}FILES+= zvol_misc_006_pos.ksh +${PACKAGE}FILES+= zvol_misc_002_pos.ksh +${PACKAGE}FILES+= zvol_misc_003_neg.ksh +${PACKAGE}FILES+= zvol_misc_007_pos.ksh +${PACKAGE}FILES+= zvol_misc_009_pos.ksh +${PACKAGE}FILES+= zvol_misc_004_pos.ksh +${PACKAGE}FILES+= zvol_misc_008_pos.ksh +${PACKAGE}FILES+= zvol_misc_001_neg.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zvol_misc_005_neg.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/cleanup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/cleanup.ksh new file mode 100644 index 00000000000..1ed5386ed70 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/cleanup.ksh @@ -0,0 +1,39 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +default_zvol_cleanup + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/setup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/setup.ksh new file mode 100644 index 00000000000..8212eb70d08 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/setup.ksh @@ -0,0 +1,39 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +default_zvol_setup $DISK $VOLSIZE + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc.cfg b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc.cfg new file mode 100644 index 00000000000..ffa01d6760e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc.cfg @@ -0,0 +1,36 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc.cfg 1.3 08/05/14 SMI" +# + +. $STF_SUITE/tests/zvol/zvol.cfg + +export BLOCKSZ=$(( 1024 * 1024 )) +export NUM_WRITES=40 +export RESERVESNAP=%dumpdev diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_001_neg.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_001_neg.ksh new file mode 100644 index 00000000000..431f67c3271 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_001_neg.ksh @@ -0,0 +1,85 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_001_neg.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_001_neg +# +# DESCRIPTION: +# Verify that using ZFS volume as a dump device fails until +# dumpswap supported. +# +# STRATEGY: +# 1. Create a ZFS volume +# 2. Use dumpadm add the volume as dump device +# 3. Verify the return code as expected. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dumpdev=$(get_dumpdevice) + + if [[ $dumpdev != $savedumpdev ]] ; then + safe_dumpadm $savedumpdev + fi +} + +log_assert "Verify that ZFS volume cannot act as dump device until dumpswap supported." +log_onexit cleanup + +test_requires DUMPADM + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +savedumpdev=$(get_dumpdevice) + +if ! is_dumpswap_supported $TESTPOOL ; then + log_mustnot $DUMPADM -d $voldev +else + safe_dumpadm $voldev +fi + +log_pass "ZFS volume cannot act as dump device until dumpswap supported as expected." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_002_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_002_pos.ksh new file mode 100644 index 00000000000..3ac28a79b73 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_002_pos.ksh @@ -0,0 +1,89 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_002_pos.ksh 1.4 08/02/27 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_002_pos +# +# DESCRIPTION: +# Verify that ZFS volume snapshot could be fscked +# +# STRATEGY: +# 1. Create a ZFS volume +# 2. Copy some files and create snapshot +# 3. Verify fsck on the snapshot is OK +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-10-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + snapexists $TESTPOOL/$TESTVOL@snap && \ + $ZFS destroy $TESTPOOL/$TESTVOL@snap + + ismounted $TESTDIR ufs && log_must $UMOUNT $TESTDIR + [[ -e $TESTDIR ]] && $RM -rf $TESTDIR +} + +log_assert "Verify that ZFS volume snapshot could be fscked" +log_onexit cleanup + +$NEWFS /dev/zvol/$TESTPOOL/$TESTVOL >/dev/null 2>&1 +(( $? != 0 )) && log_fail "Unable to newfs(1M) $TESTPOOL/$TESTVOL" + +log_must $MKDIR $TESTDIR +log_must $MOUNT /dev/zvol/$TESTPOOL/$TESTVOL $TESTDIR + +typeset -i fn=0 +typeset -i retval=0 + +# Write about 200MB of data. +populate_dir $TESTDIR/testfile 5 $NUM_WRITES $BLOCKSZ 0 + +log_must sync +log_must $MOUNT -o rw -u $TESTDIR +log_must $ZFS snapshot $TESTPOOL/$TESTVOL@snap +log_must $FSCK -t ufs -n /dev/zvol/$TESTPOOL/$TESTVOL@snap >/dev/null 2>&1 + +log_pass "Verify that ZFS volume snapshot could be fscked" diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_003_neg.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_003_neg.ksh new file mode 100644 index 00000000000..c02d786afc2 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_003_neg.ksh @@ -0,0 +1,93 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_003_neg.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_003_neg +# +# DESCRIPTION: +# Verify create storage pool or newfs over volume as dump device is denied. +# +# STRATEGY: +# 1. Create a ZFS volume +# 2. Use dumpadm set the volume as dump device +# 3. Verify create pool & newfs over the volume return an error. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-01-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dumpdev=$(get_dumpdevice) + if [[ $dumpdev != $savedumpdev ]] ; then + safe_dumpadm $savedumpdev + fi + + if poolexists $TESTPOOL1 ; then + destroy_pool $TESTPOOL1 + fi +} + +log_assert "Verify create storage pool or newfs over dump volume is denied." +if ! is_dumpswap_supported $TESTPOOL ; then + log_unsupported "dumpswap not currently supported." +fi +log_onexit cleanup + +test_requires DUMPADM + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +savedumpdev=$(get_dumpdevice) + +safe_dumpadm $voldev + +$ECHO "y" | $NEWFS $voldev > /dev/null 2>&1 +if (( $? == 0 )) ; then + log_fail "newfs over dump volume succeed unexpected" +fi + +log_mustnot $ZPOOL create $TESTPOOL1 $voldev + +log_pass "Verify create storage pool or newfs over dump volume is denied." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_004_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_004_pos.ksh new file mode 100644 index 00000000000..181bace966e --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_004_pos.ksh @@ -0,0 +1,129 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_004_pos.ksh 1.1 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_004_pos +# +# DESCRIPTION: +# Verify permit to create snapshot over active dumpswap zvol. +# +# STRATEGY: +# 1. Create a ZFS volume +# 2. Set the volume as dump or swap +# 3. Verify create snapshot over the zvol succeed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-01-07) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dumpdev=$(get_dumpdevice) + if [[ $dumpdev != $savedumpdev ]] ; then + safe_dumpadm $savedumpdev + fi + + $SWAP -l | $GREP -w $voldev > /dev/null 2>&1 + if (( $? == 0 )); then + log_must $SWAP -d $voldev + fi + + typeset snap + for snap in snap0 snap1 ; do + if datasetexists $TESTPOOL/$TESTVOL@$snap ; then + log_must $ZFS destroy $TESTPOOL/$TESTVOL@$snap + fi + done +} + +function verify_snapshot +{ + typeset volume=$1 + + log_must $ZFS snapshot $volume@snap0 + log_must $ZFS snapshot $volume@snap1 + log_must datasetexists $volume@snap0 $volume@snap1 + + log_must $ZFS destroy $volume@snap1 + log_must $ZFS snapshot $volume@snap1 + + log_mustnot $ZFS rollback -r $volume@snap0 + log_must datasetexists $volume@snap0 + log_must datasetexists $volume@snap1 + + log_must $ZFS destroy -r $volume@snap0 +} + +log_assert "Verify permit to create snapshot over dumpswap." +if ! is_dumpswap_supported $TESTPOOL ; then + log_unsupported "dumpswap not currently supported." +fi +log_onexit cleanup + +test_requires DUMPADM + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +savedumpdev=$(get_dumpdevice) + +# create snapshot over dump zvol +safe_dumpadm $voldev +log_must is_zvol_dumpified $TESTPOOL/$TESTVOL + +verify_snapshot $TESTPOOL/$TESTVOL + +safe_dumpadm $savedumpdev +log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL + +# create snapshot over swap zvol + +log_must $SWAP -a $voldev +log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL + +verify_snapshot $TESTPOOL/$TESTVOL + +log_must $SWAP -d $voldev +log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL + +log_pass "Create snapshot over dumpswap zvol succeed." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_005_neg.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_005_neg.ksh new file mode 100644 index 00000000000..f1e794b603d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_005_neg.ksh @@ -0,0 +1,94 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_005_neg.ksh 1.1 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_005_neg +# +# DESCRIPTION: +# Verify a device cannot be dump and swap at the same time. +# +# STRATEGY: +# 1. Create a ZFS volume +# 2. Set it as swap device. +# 3. Verify dumpadm with this zvol will fail. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-10) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + $SWAP -l | $GREP $voldev > /dev/null 2>&1 + if (( $? == 0 )) ; then + log_must $SWAP -d $voldev + fi + + typeset dumpdev=$(get_dumpdevice) + if [[ $dumpdev != $savedumpdev ]] ; then + safe_dumpadm $savedumpdev + fi +} + +log_assert "Verify a device cannot be dump and swap at the same time." +if ! is_dumpswap_supported $TESTPOOL ; then + log_unsupported "dumpswap not currently supported." +fi +log_onexit cleanup + +test_requires DUMPADM + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +savedumpdev=$(get_dumpdevice) + +# If device in swap list, it cannot be dump device +log_must $SWAP -a $voldev +log_mustnot $DUMPADM -d $voldev +log_must $SWAP -d $voldev + +# If device has dedicated as dump device, it cannot add into swap list +safe_dumpadm $voldev +log_mustnot $SWAP -a $voldev + +log_pass "A device cannot be dump and swap at the same time." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_006_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_006_pos.ksh new file mode 100644 index 00000000000..4c4c13712dd --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_006_pos.ksh @@ -0,0 +1,92 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_006_pos.ksh 1.1 09/01/12 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_006_pos +# +# DESCRIPTION: +# ZFS volume as dump device, it should always have 128k volblocksize +# +# STRATEGY: +# 1. Create a ZFS volume +# 2. Use dumpadm set the volume as dump device +# 3. Verify the volume's volblocksize=128k +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-12-01) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset dumpdev=$(get_dumpdevice) + if [[ $dumpdev != $savedumpdev ]] ; then + safe_dumpadm $savedumpdev + fi +} + +log_assert "zfs volume as dumpdevice should have 128k volblocksize" + +if ! is_dumpswap_supported $TESTPOOL ; then + log_unsupported "dumpswap not currently supported." +fi +log_onexit cleanup + +test_requires DUMPADM + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +savedumpdev=$(get_dumpdevice) + +typeset oblksize=$($ZFS get -H -o value volblocksize $TESTPOOL/$TESTVOL) +log_note "original $TESTPOOL/$TESTVOL volblocksize=$oblksize" + +safe_dumpadm $voldev + +typeset blksize=$($ZFS get -H -o value volblocksize $TESTPOOL/$TESTVOL) + +if [[ $blksize != "128K" ]]; then + log_fail "ZFS volume $TESTPOOL/$TESTVOL volblocksize=$blksize" +fi + +log_pass "zfs volume as dumpdevice should have 128k volblocksize" diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_007_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_007_pos.ksh new file mode 100644 index 00000000000..c8bca20ea8a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_007_pos.ksh @@ -0,0 +1,133 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_007_pos.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_007_pos +# +# DESCRIPTION: +# Verify that device nodes are modified appropriately during zfs command +# operations on volumes. +# +# STRATEGY: +# For a certain number of iterations, with root setup for each test set: +# - Recursively snapshot the root. +# - Recursively rename the snapshot 3 times. +# - Destroy the root. +# +# - Recursively snapshot the root. +# - Clone the volume to another name in the root. +# - Rename the root. +# - Destroy the renamed root. +# +# - Recursively snapshot the root. +# - Send|Receive the root to another root. +# - Destroy the original and received roots. +# +# At each stage, the device nodes are checked to match the expectations. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify that ZFS volume device nodes are handled properly (part 1)." + +ROOTPREFIX=$TESTPOOL/007 +DIRS="dir0 dir1" +VOLS="vol0 dir0/dvol0 dir1/dvol1" + +typeset -i NUM_RENAMES=5 +typeset -i NUM_ITERATIONS=10 + +function onexit_callback +{ + log_must $ZFS list -t all + log_note "Char devices in /dev/zvol:" + find /dev/zvol -type c +} +log_onexit onexit_callback + +function root_setup +{ + rootds=$1 + + log_must $ZFS create $rootds + for dir in $DIRS; do + log_must $ZFS create $rootds/$dir + done + for vol in $VOLS; do + log_must $ZFS create -V 100M $rootds/$vol + log_must test -c /dev/zvol/$rootds/$vol + done +} + +typeset -i i=0 +root="" +while (( i != NUM_ITERATIONS )); do + root=${ROOTPREFIX}_iter${i} + # Test set 1: Recursive snapshot, recursive rename, and destroy + typeset -i cur=0 + log_mustnot test -e /dev/zvol/$root/vol0 + root_setup $root + log_must $ZFS snapshot -r $root@$cur + for vol in $VOLS; do + log_must test -c /dev/zvol/$root/$vol@$cur + done + while ((cur < $NUM_RENAMES)); do + ((next = cur + 1)) + log_must $ZFS rename -r $root@$cur $root@$next + for vol in $VOLS; do + v=$root/$vol + log_mustnot test -e /dev/zvol/$v@$cur + log_must test -c /dev/zvol/$v@$next + done + cur=$next + done + log_must $ZFS destroy -r $root + log_mustnot test -e /dev/zvol/$root/vol0 + + (( i += 1 )) +done + +log_pass "ZFS volume device nodes are handled properly." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_008_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_008_pos.ksh new file mode 100644 index 00000000000..f1bdfaf6392 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_008_pos.ksh @@ -0,0 +1,159 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_008_pos.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_008_pos +# +# DESCRIPTION: +# Verify that device nodes are modified appropriately during zfs command +# operations on volumes. +# +# STRATEGY: +# For a certain number of iterations, with root setup for each test set: +# - Recursively snapshot the root. +# - Clone the volume to another name in the root. +# - Promote the clone. +# - Demote the original clone. +# - Snapshot & clone the clone. +# - Rename the root. +# - Destroy the renamed root. +# +# At each stage, the device nodes are checked to match the expectations. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify that ZFS volume device nodes are handled properly (part 2)." + +ROOTPREFIX=$TESTPOOL/008 +DIRS="dir0 dir1" +VOLS="vol0 dir0/dvol0 dir1/dvol1" + +typeset -i NUM_ITERATIONS=10 + +function onexit_callback +{ + log_must $ZFS list -t all + log_note "Char devices in /dev/zvol:" + find /dev/zvol -type c +} +log_onexit onexit_callback + +function root_setup +{ + rootds=$1 + + log_must $ZFS create $rootds + for dir in $DIRS; do + log_must $ZFS create $rootds/$dir + done + for vol in $VOLS; do + log_must $ZFS create -V 100M $rootds/$vol + log_must test -c /dev/zvol/$rootds/$vol + done +} + +function test_exists +{ + for zvolds in $*; do + log_must test -c /dev/zvol/${zvolds} + done +} + +function test_notexists +{ + for zvolds in $*; do + log_mustnot test -e /dev/zvol/${zvolds} + done +} + +typeset -i i=0 +while (( i != NUM_ITERATIONS )); do + root=${ROOTPREFIX}_iter${i} + # Test set 2: Recursive snapshot, cloning/promoting, and root-rename + root_setup $root + log_must $ZFS snapshot -r $root@snap + log_must $ZFS clone $root/vol0@snap $root/vol1 + test_exists $root/vol1 + test_notexists $root/vol1@snap + + log_must $ZFS promote $root/vol1 + test_exists $root/vol0 $root/vol1 $root/vol1@snap + test_notexists $root/vol0@snap + + # Re-promote the original volume. + log_must $ZFS promote $root/vol0 + test_exists $root/vol0 $root/vol1 $root/vol0@snap + test_notexists $root/vol1@snap + + # Clone a clone's snapshot. + log_must $ZFS snapshot $root/vol1@newsnap + log_must $ZFS clone $root/vol1@newsnap $root/vol2 + test_exists $root/vol2 + test_notexists $root/vol2@snap + + # Now promote *that* clone. + log_must $ZFS promote $root/vol2 + test_exists $root/vol0 $root/vol0@snap \ + $root/vol1 $root/vol2 $root/vol2@newsnap + test_notexists $root/vol1@snap $root/vol1@newsnap + + renamed=${root}_renamed + log_must $ZFS rename $root $renamed + # Ensure that the root rename applies to clones and promoted clones. + test_exists $renamed/vol1 $renamed/vol2 $renamed/vol2@newsnap + test_notexists $root/vol1 $renamed/vol1@snap $renamed/vol1@newsnap + for vol in $VOLS; do + test_notexists $root/$vol $root/$vol@snap + test_exists $renamed/$vol $renamed/$vol@snap + done + + log_must $ZFS destroy -r $renamed + test_notexists $renamed/vol0 $renamed/vol1 $renamed/vol2 + + (( i += 1 )) +done +log_pass "ZFS volume device nodes are handled properly (part 2)." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_009_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_009_pos.ksh new file mode 100644 index 00000000000..cbc588cc207 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_009_pos.ksh @@ -0,0 +1,126 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_misc_009_pos.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_misc_009_pos +# +# DESCRIPTION: +# Verify that device nodes are modified appropriately during zfs command +# operations on volumes. +# +# STRATEGY: +# For a certain number of iterations, with root setup for each test set: +# - Recursively snapshot the root. +# - Send|Receive the root to another root. +# - Destroy the original and received roots. +# +# At each stage, the device nodes are checked to match the expectations. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2008-03-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "Verify that ZFS volume device nodes are handled properly (part 3)." + +ROOTPREFIX=$TESTPOOL/009 +DIRS="dir0 dir1" +VOLS="vol0 dir0/dvol0 dir1/dvol1" + +typeset -i NUM_ITERATIONS=5 + +function onexit_callback +{ + log_must $ZFS list -t all + log_note "Char devices in /dev/zvol:" + find /dev/zvol -type c +} +log_onexit onexit_callback + +function root_setup +{ + rootds=$1 + + log_must $ZFS create $rootds + for dir in $DIRS; do + log_must $ZFS create $rootds/$dir + done + for vol in $VOLS; do + log_must $ZFS create -V 100M $rootds/$vol + log_must test -c /dev/zvol/$rootds/$vol + done +} + +typeset -i i=0 +while (( i != NUM_ITERATIONS )); do + root=${ROOTPREFIX}_iter${i} + # Test set 3: send|receive & receive with forced rollback + root_setup $root + log_must $ZFS snapshot -r $root@snap + received=${root}_recv + log_must eval "$ZFS send -R $root@snap | $ZFS receive -F ${received}" + for vol in $VOLS; do + log_must test -c /dev/zvol/${received}/${vol} + log_must test -c /dev/zvol/${received}/${vol}@snap + done + # Re-send with -F, to ensure that actual receive rollback also works. + # For good measure, pre-destroy one of the volumes. Also, destroy + # the snapshot we received earlier for this to work. + log_must $ZFS destroy -r $received/vol0 + log_must $ZFS destroy -r $received@snap + log_must eval "$ZFS send -R $root@snap | $ZFS receive -F ${received}" + for vol in $VOLS; do + log_must test -c /dev/zvol/${received}/${vol} + log_must test -c /dev/zvol/${received}/${vol}@snap + done + log_must $ZFS destroy -r ${root} + log_mustnot test -e /dev/zvol/${root}/vol0 + log_mustnot test -e /dev/zvol/${root}/vol0@snap + log_must $ZFS destroy -r ${received} + log_mustnot test -e /dev/zvol/${received}/vol0 + log_mustnot test -e /dev/zvol/${received}/vol0@snap + + (( i += 1 )) +done +log_pass "ZFS volume device nodes are handled properly (part 3)." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_test.sh b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_test.sh new file mode 100755 index 00000000000..8c740f9fac0 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_misc/zvol_misc_test.sh @@ -0,0 +1,262 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zvol_misc_001_neg cleanup +zvol_misc_001_neg_head() +{ + atf_set "descr" "Verify that ZFS volume cannot act as dump device until dumpswap supported." + atf_set "require.progs" dumpadm +} +zvol_misc_001_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_001_neg.ksh || atf_fail "Testcase failed" +} +zvol_misc_001_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_002_pos cleanup +zvol_misc_002_pos_head() +{ + atf_set "descr" "Verify that ZFS volume snapshot could be fscked" + atf_set "require.progs" zfs +} +zvol_misc_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_002_pos.ksh || atf_fail "Testcase failed" +} +zvol_misc_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_003_neg cleanup +zvol_misc_003_neg_head() +{ + atf_set "descr" "Verify create storage pool or newfs over dump volume is denied." + atf_set "require.progs" dumpadm zpool +} +zvol_misc_003_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_003_neg.ksh || atf_fail "Testcase failed" +} +zvol_misc_003_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_004_pos cleanup +zvol_misc_004_pos_head() +{ + atf_set "descr" "Verify permit to create snapshot over dumpswap." + atf_set "require.progs" zfs swap +} +zvol_misc_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_004_pos.ksh || atf_fail "Testcase failed" +} +zvol_misc_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_005_neg cleanup +zvol_misc_005_neg_head() +{ + atf_set "descr" "Verify a device cannot be dump and swap at the same time." + atf_set "require.progs" dumpadm swap +} +zvol_misc_005_neg_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_005_neg.ksh || atf_fail "Testcase failed" +} +zvol_misc_005_neg_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_006_pos cleanup +zvol_misc_006_pos_head() +{ + atf_set "descr" "zfs volume as dumpdevice should have 128k volblocksize" + atf_set "require.progs" dumpadm zfs +} +zvol_misc_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_006_pos.ksh || atf_fail "Testcase failed" +} +zvol_misc_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_007_pos cleanup +zvol_misc_007_pos_head() +{ + atf_set "descr" "zfs volume device nodes are modified appropriately" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +zvol_misc_007_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + atf_expect_fail "PR 225223 zfs rename -r of a snapshot doesn't rename zvol snapshots' device nodes" + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_007_pos.ksh || atf_fail "Testcase failed" +} +zvol_misc_007_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_008_pos cleanup +zvol_misc_008_pos_head() +{ + atf_set "descr" "zfs volume device nodes are modified appropriately" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +zvol_misc_008_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + atf_expect_fail "PR 225200 zfs promote of a zvol doesn't rename device nodes for snapshots" + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_008_pos.ksh || atf_fail "Testcase failed" +} +zvol_misc_008_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_misc_009_pos cleanup +zvol_misc_009_pos_head() +{ + atf_set "descr" "zfs volume device nodes are modified appropriately" + atf_set "require.progs" zfs + atf_set "timeout" 1200 +} +zvol_misc_009_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + verify_disk_count "$DISKS" 1 + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_misc_009_pos.ksh || atf_fail "Testcase failed" +} +zvol_misc_009_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_misc.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zvol_misc_001_neg + atf_add_test_case zvol_misc_002_pos + atf_add_test_case zvol_misc_003_neg + atf_add_test_case zvol_misc_004_pos + atf_add_test_case zvol_misc_005_neg + atf_add_test_case zvol_misc_006_pos + atf_add_test_case zvol_misc_007_pos + atf_add_test_case zvol_misc_008_pos + atf_add_test_case zvol_misc_009_pos +} diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/Makefile b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/Makefile new file mode 100644 index 00000000000..613c2091270 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/Makefile @@ -0,0 +1,23 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zvol/zvol_swap +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zvol_swap_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= zvol_swap_004_pos.ksh +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= zvol_swap_005_pos.ksh +${PACKAGE}FILES+= zvol_swap_001_pos.ksh +${PACKAGE}FILES+= zvol_swap.cfg +${PACKAGE}FILES+= zvol_swap_003_pos.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zvol_swap_006_pos.ksh +${PACKAGE}FILES+= zvol_swap_002_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/cleanup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/cleanup.ksh new file mode 100644 index 00000000000..406915344f5 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/cleanup.ksh @@ -0,0 +1,52 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)cleanup.ksh 1.3 08/05/14 SMI" +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +log_must $SWAPADD +for swapdev in $SAVESWAPDEVS +do + if ! is_swap_inuse $swapdev ; then + log_must $SWAP -a $swapdev >/dev/null 2>&1 + fi +done + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +if is_swap_inuse $voldev ; then + log_must $SWAP -d $voldev +fi + +default_zvol_cleanup + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/setup.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/setup.ksh new file mode 100644 index 00000000000..c4b2b294593 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/setup.ksh @@ -0,0 +1,43 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)setup.ksh 1.2 07/01/09 SMI" +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +verify_runnable "global" + +for i in $SAVESWAPDEVS ; do + log_must eval "$SWAP -d $i >/dev/null 2>&1" +done + +default_zvol_setup $DISK $VOLSIZE + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap.cfg b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap.cfg new file mode 100644 index 00000000000..64f654f8492 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap.cfg @@ -0,0 +1,41 @@ +# vim: filetype=sh +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_swap.cfg 1.2 07/01/09 SMI" +# + +. $STF_SUITE/tests/zvol/zvol.cfg + +# +# Remember swap devices +# +SAVESWAPDEVS=$($SWAP -l | $NAWK '(NR != 1) {print $1}') + +export BLOCKSZ=$(( 1024 * 1024 )) +export NUM_WRITES=40 +export SAVESWAPDEVS diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_001_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_001_pos.ksh new file mode 100644 index 00000000000..f80f405b31a --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_001_pos.ksh @@ -0,0 +1,93 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)zvol_swap_001_pos.ksh 1.3 08/05/14 SMI" +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_swap_001_pos +# +# DESCRIPTION: +# Verify that a zvol can be used as a swap device +# +# STRATEGY: +# 1. Create a pool +# 2. Create a zvol volume +# 3. Use zvol as swap space +# 4. Create a file under $TMPDIR +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + $RM -rf $TMPDIR/$TESTFILE + + if is_swap_inuse $voldev ; then + log_must $SWAP -d $voldev + fi +} + +log_assert "Verify that a zvol can be used as a swap device" + +log_onexit cleanup + +test_requires SWAP + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +log_note "Add zvol volume as swap space" +log_must $SWAP -a $voldev + +log_note "Create a file under $TMPDIR" +log_must $FILE_WRITE -o create -f $TMPDIR/$TESTFILE \ + -b $BLOCKSZ -c $NUM_WRITES -d $DATA + +[[ ! -f $TMPDIR/$TESTFILE ]] && + log_fail "Unable to create file under $TMPDIR" + +filesize=`$LS -l $TMPDIR/$TESTFILE | $AWK '{print $5}'` +tf_size=$(( BLOCKSZ * NUM_WRITES )) +(( $tf_size != $filesize )) && + log_fail "testfile is ($filesize bytes), expected ($tf_size bytes)" + +log_pass "Successfully added a zvol to swap area." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_002_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_002_pos.ksh new file mode 100644 index 00000000000..0d292bb6a90 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_002_pos.ksh @@ -0,0 +1,100 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# ident "@(#)zvol_swap_002_pos.ksh 1.4 09/05/19 SMI" +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +############################################################################### +# +# __stc_assertion_start +# +# ID: zvol_swap_002_pos +# +# DESCRIPTION: +# Using a zvol as swap space, fill with files until ENOSPC returned. +# +# STRATEGY: +# 1. Create a pool +# 2. Create a zvol volume +# 3. Add zvol to swap space +# 4. Fill swap space until ENOSPC is returned +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +log_unsupported "Fill swap will cause system hang, hide this case temporarily." + +verify_runnable "global" + +function cleanup +{ + $RM -rf $TMPDIR/$TESTDIR + + if is_swap_inuse $voldev ; then + log_must $SWAP -d $voldev + fi +} + +log_assert "Using a zvol as swap space, fill with files until ENOSPC returned." + +if ! is_dumpswap_supported $TESTPOOL ; then + log_unsupported "ZVOLs as swap devices are not currently supported." +fi + +log_onexit cleanup + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL + +$SWAP -l | $GREP zvol +if (( $? != 0 )) ; then + log_note "Add zvol volume as swap space" + log_must $SWAP -a $voldev +fi + +typeset -i filenum=0 +typeset -i retval=0 +typeset testdir=$TMPDIR/$TESTDIR + +log_note "Attempt to fill $TMPDIR until ENOSPC is hit" +fill_fs $testdir -1 100 $BLOCKSZ $NUM_WRITES +retval=$? + +(( $retval != $ENOSPC )) && \ + log_fail "ENOSPC was not returned, $retval was returned instead" + +log_pass "ENOSPC was returned as expected" diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_003_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_003_pos.ksh new file mode 100644 index 00000000000..54b1bd35bd4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_003_pos.ksh @@ -0,0 +1,163 @@ +#! /usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_swap_003_pos.ksh 1.3 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +################################################################## +# +# __stc_assertion_start +# +# ID: zvol_swap_003_pos +# +# DESCRIPTION: +# Verify that a zvol device can be used as a swap device +# through /etc/vfstab configuration. +# +# STRATEGY: +# 1. Create a pool +# 2. Create a zvol volume +# 3. Save current swaps info and delete current swaps +# 4. Modify /etc/vfstab to add entry for zvol as swap device +# 5. Use /sbin/swapadd to zvol as swap device throuth /etc/vfstab +# 6. Create a file under $TMPDIR +# 7. Verify the file +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2005-07-04) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + if [[ -f $TMPDIR/$TESTFILE ]]; then + log_must $RM -rf $TMPDIR/$TESTFILE + fi + + if [[ -f $TMP_VFSTAB_FILE ]]; then + log_must $RM -rf $TMP_VFSTAB_FILE + fi + + if [[ -f $NEW_VFSTAB_FILE ]]; then + log_must $RM -f $NEW_VFSTAB_FILE + fi + + if [[ -f $PREV_VFSTAB_FILE ]]; then + log_must $MV $PREV_VFSTAB_FILE $VFSTAB_FILE + fi + + log_must $SWAPADD $VFSTAB_FILE + + if is_swap_inuse $voldev ; then + log_must $SWAP -d $voldev + fi + +} + + +log_assert "Verify that a zvol device can be used as a swap device"\ + "through /etc/vfstab configuration." + +log_onexit cleanup + +test_requires SWAPADD + +voldev=/dev/zvol/dsk/$TESTPOOL/$TESTVOL +VFSTAB_FILE=/etc/vfstab +NEW_VFSTAB_FILE=$TMPDIR/zvol_vfstab.${TESTCASE_ID} +PREV_VFSTAB_FILE=$TMPDIR/zvol_vfstab.PREV.${TESTCASE_ID} +TMP_VFSTAB_FILE=$TMPDIR/zvol_vfstab.tmp.${TESTCASE_ID} + +if [[ -f $NEW_VFSTAB_FILE ]]; then + $RM -f $NEW_VFSTAB_FILE +fi +$TOUCH $NEW_VFSTAB_FILE +$CHMOD 777 $NEW_VFSTAB_FILE + +# +# Go through each line of /etc/vfstab and +# exclude the comment line and formulate +# a new file with an entry of zvol device +# swap device. +# + +$GREP -v "^#" $VFSTAB_FILE > $TMP_VFSTAB_FILE + +typeset -i fndswapline=0 +while read -r i +do + line=`$ECHO "$i" | $AWK '{print $4}'` + if [[ $line == "swap" ]]; then + if [[ $fndswapline -eq 0 ]]; then + $ECHO "$voldev"\ + "\t-\t-\tswap\t-"\ + "\tno\t-" \ + >> $NEW_VFSTAB_FILE + fndswapline=1 + $ECHO "Add an entry of zvol device as"\ + "swap device in $VFSTAB_FILE." + fi + else + $ECHO "$i" >> $NEW_VFSTAB_FILE + fi + +done < $TMP_VFSTAB_FILE + +if [[ $fndswapline -eq 1 ]]; then + log_must $CP $VFSTAB_FILE $PREV_VFSTAB_FILE + log_must $CP $NEW_VFSTAB_FILE $VFSTAB_FILE +else + log_fail "The system has no swap device configuration in /etc/vfstab" +fi + +log_note "Add zvol volume as swap space" +log_must $SWAPADD $VFSTAB_FILE + +log_note "Create a file under $TMPDIR" +log_must $FILE_WRITE -o create -f $TMPDIR/$TESTFILE \ + -b $BLOCKSZ -c $NUM_WRITES -d $DATA + +[[ ! -f $TMPDIR/$TESTFILE ]] && + log_fail "Unable to create file under $TMPDIR" + +filesize=`$LS -l $TMPDIR/$TESTFILE | $AWK '{print $5}'` +tf_size=$(( BLOCKSZ * NUM_WRITES )) +(( $tf_size != $filesize )) && \ + log_fail "testfile is ($filesize bytes), expected ($tf_size bytes)" + +log_pass "Successfully added a zvol to swap area through /etc/vfstab." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_004_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_004_pos.ksh new file mode 100644 index 00000000000..2ef0533f3b6 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_004_pos.ksh @@ -0,0 +1,108 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_swap_004_pos.ksh 1.1 07/01/09 SMI" +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zvol_swap_004_pos +# +# DESCRIPTION: +# The minimum volume size for swap should be a multiple of 2 pagesize +# bytes. +# +# STRATEGY: +# 1. Get test system page size. +# 2. Create different size volumes. +# 3. Verify 'swap -a' has correct behaviour. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset tmp + for tmp in $swaplist ; do + log_must $SWAP -d $tmp + done + for tmp in $vollist ; do + log_must $ZFS destroy $tmp + done +} + +log_assert "The minimum volume size should be a multiple of 2 pagesize bytes." +log_onexit cleanup + +test_requires SWAP + +typeset -i volblksize pagesize=$($PAGESIZE) +((volblksize = pagesize / 2)) +# +# volume size for swap Expected results +# +set -A array \ + $((volblksize)) "fail" \ + $((2 * volblksize)) "fail" \ + $((3 * volblksize)) "fail" \ + $((4 * volblksize)) "pass" \ + $((5 * volblksize)) "pass" \ + $((6 * volblksize)) "pass" + +typeset -i i=0 +while ((i < ${#array[@]})); do + vol="$TESTPOOL/vol_${array[$i]}" + vollist="$vollist $vol" + + log_must $ZFS create -b $volblksize -V ${array[$i]} $vol + + swapname="/dev/zvol/dsk/$vol" + if [[ ${array[((i+1))]} == "fail" ]]; then + log_mustnot $SWAP -a $swapname + else + log_must $SWAP -a $swapname + swaplist="$swaplist $swapname" + fi + + ((i += 2)) +done + +log_pass "Verify the minimum volume size pass." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_005_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_005_pos.ksh new file mode 100644 index 00000000000..03e7e07d066 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_005_pos.ksh @@ -0,0 +1,109 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_swap_005_pos.ksh 1.2 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zvol_swap_005_pos +# +# DESCRIPTION: +# swaplow + swaplen must be less than or equal to the volume size. +# +# STRATEGY: +# 1. Get test system page size and test volume size. +# 2. Random get swaplow and swaplen. +# 3. Verify swap -a should succeed when swaplow + swaplen <= volume size. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-12) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +log_assert "swaplow + swaplen must be less than or equal to the volume size." + +test_requires SWAP + +typeset vol=$TESTPOOL/$TESTVOL +typeset -i pageblocks volblocks +# +# Both swaplow and swaplen are the desired length of +# the swap area in 512-byte blocks. +# +((pageblocks = $($PAGESIZE) / 512)) +((volblocks = $(get_prop volsize $vol) / 512)) + +typeset -i i=0 +while ((i < 10)) ; do + while true; do + ((swaplow = RANDOM % volblocks)) + # Upwards increment + ((swaplow += pageblocks)) + ((swaplow -= (swaplow % pageblocks))) + + # At lease one page size was left for swap area + ((swaplow != volblocks)) && break + done + + while true; do + ((swaplen = RANDOM % (volblocks - swaplow))) + # Downward increment + ((swaplen -= (swaplen % pageblocks))) + + # At lease one page size was left for swap area + ((swaplen != 0)) && break + done + + # The minimum swap size should be 2 pagesize. + ((swaplow + swaplen < pageblocks * 2)) && continue + + swapname="/dev/zvol/dsk/$vol" + if is_swap_inuse $swapname ; then + log_must $SWAP -d $swapname + fi + + log_must $SWAP -a $swapname $swaplow $swaplen + log_must $SWAP -d $swapname $swaplow + + ((i += 1)) +done + +log_pass "Verify swaplow + swaplen must be less than or equal to volsize passed." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_006_pos.ksh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_006_pos.ksh new file mode 100644 index 00000000000..794a7174419 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_006_pos.ksh @@ -0,0 +1,120 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2008 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)zvol_swap_006_pos.ksh 1.4 08/05/14 SMI" +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/tests/zvol/zvol_common.kshlib + +################################################################################# +# +# __stc_assertion_start +# +# ID: zvol_swap_006_pos +# +# DESCRIPTION: +# A volume can be add as several segments, but overlapping are not +# allowed. +# +# STRATEGY: +# 1. Figure out three groups swaplow and swaplen. +# 2. Verify different volume segments can be added correctly. +# 3. Verify overlapping swap volume are not allowed. +# +# TESTABILITY: explicit +# +# TEST_AUTOMATION_LEVEL: automated +# +# CODING_STATUS: COMPLETED (2006-12-13) +# +# __stc_assertion_end +# +################################################################################ + +verify_runnable "global" + +function cleanup +{ + typeset -i i=0 + + while ((count > 0)); do + log_must $SWAP -d $swapname ${swap_opt[$i]} + + ((i += 2)) + ((count -= 1)) + done +} + +log_assert "Verify volume can be add as several segments, but overlapping " \ + "are not allowed." +log_onexit cleanup + +test_requires SWAP + +typeset vol=$TESTPOOL/$TESTVOL +typeset -i pageblocks volblocks +((pageblocks = $($PAGESIZE) / 512)) +((volblocks = $(get_prop volsize $vol) / 512)) + +log_note "Verify volume can be add as several segments." + +# +# swaplow swaplen +set -A swap_opt $((pageblocks)) \ + $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \ + $((volblocks / 3)) \ + $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \ + $((volblocks / 2)) \ + $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) \ + $(((volblocks*2) / 3)) \ + $((pageblocks * ((RANDOM % 50) + 1) + (RANDOM % pageblocks) )) + +swapname=/dev/zvol/dsk/$vol +typeset -i i=0 count=0 + +if is_swap_inuse $swapname ; then + log_must $SWAP -d $swapname +fi + +while ((i < ${#swap_opt[@]})); do + log_must $SWAP -a $swapname ${swap_opt[$i]} ${swap_opt[((i+1))]} + + ((i += 2)) + ((count += 1)) +done + +log_note "Verify overlapping swap volume are not allowed" +i=0 +while ((i < ${#swap_opt[@]})); do + log_mustnot $SWAP -a $swapname ${swap_opt[$i]} + + ((i += 2)) +done + +log_pass "Verify volume can be added as several segments passed." diff --git a/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_test.sh b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_test.sh new file mode 100755 index 00000000000..92b567e0dc4 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol/zvol_swap/zvol_swap_test.sh @@ -0,0 +1,176 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zvol_swap_001_pos cleanup +zvol_swap_001_pos_head() +{ + atf_set "descr" "Verify that a zvol can be used as a swap device" + atf_set "require.progs" swap swapadd +} +zvol_swap_001_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_swap_001_pos.ksh || atf_fail "Testcase failed" +} +zvol_swap_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_swap_002_pos cleanup +zvol_swap_002_pos_head() +{ + atf_set "descr" "Using a zvol as swap space, fill with files until ENOSPC returned." + atf_set "require.progs" swap swapadd +} +zvol_swap_002_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_swap_002_pos.ksh || atf_fail "Testcase failed" +} +zvol_swap_002_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_swap_003_pos cleanup +zvol_swap_003_pos_head() +{ + atf_set "descr" "Verify that a zvol device can be used as a swap devicethrough /etc/vfstab configuration." + atf_set "require.progs" swapadd swap +} +zvol_swap_003_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_swap_003_pos.ksh || atf_fail "Testcase failed" +} +zvol_swap_003_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_swap_004_pos cleanup +zvol_swap_004_pos_head() +{ + atf_set "descr" "The minimum volume size should be a multiple of 2 pagesize bytes." + atf_set "require.progs" zfs swap pagesize swapadd +} +zvol_swap_004_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_swap_004_pos.ksh || atf_fail "Testcase failed" +} +zvol_swap_004_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_swap_005_pos cleanup +zvol_swap_005_pos_head() +{ + atf_set "descr" "swaplow + swaplen must be less than or equal to the volume size." + atf_set "require.progs" swap pagesize swapadd +} +zvol_swap_005_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_swap_005_pos.ksh || atf_fail "Testcase failed" +} +zvol_swap_005_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_test_case zvol_swap_006_pos cleanup +zvol_swap_006_pos_head() +{ + atf_set "descr" "Verify volume can be add as several segments, but overlappingare not allowed." + atf_set "require.progs" swap pagesize swapadd +} +zvol_swap_006_pos_body() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_swap_006_pos.ksh || atf_fail "Testcase failed" +} +zvol_swap_006_pos_cleanup() +{ + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zvol_swap.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zvol_swap_001_pos + atf_add_test_case zvol_swap_002_pos + atf_add_test_case zvol_swap_003_pos + atf_add_test_case zvol_swap_004_pos + atf_add_test_case zvol_swap_005_pos + atf_add_test_case zvol_swap_006_pos +} diff --git a/tests/sys/cddl/zfs/tests/zvol_thrash/Makefile b/tests/sys/cddl/zfs/tests/zvol_thrash/Makefile new file mode 100644 index 00000000000..80a89e0868d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol_thrash/Makefile @@ -0,0 +1,18 @@ +# $FreeBSD$ + +.include + +PACKAGE=tests +TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/zvol_thrash +FILESDIR=${TESTSDIR} + +ATF_TESTS_KSH93+= zvol_thrash_test +TEST_METADATA+= required_user="root" +TEST_METADATA+= is_exclusive=true + +${PACKAGE}FILES+= setup.ksh +${PACKAGE}FILES+= cleanup.ksh +${PACKAGE}FILES+= zvol_thrash.cfg +${PACKAGE}FILES+= zvol_thrash_001_pos.ksh + +.include diff --git a/tests/sys/cddl/zfs/tests/zvol_thrash/cleanup.ksh b/tests/sys/cddl/zfs/tests/zvol_thrash/cleanup.ksh new file mode 100644 index 00000000000..b60eb1ebf1d --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol_thrash/cleanup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2007 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)cleanup.ksh 1.2 07/01/09 SMI" +# +# $FreeBSD$ + +. ${STF_SUITE}/include/libtest.kshlib +. ${STF_SUITE}/include/libgnop.kshlib + +# Rotate logs now, because this test can generate a great volume of log entries +newsyslog + +default_cleanup_noexit +destroy_gnops ${DISKS} +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol_thrash/setup.ksh b/tests/sys/cddl/zfs/tests/zvol_thrash/setup.ksh new file mode 100644 index 00000000000..3eddbfb5516 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol_thrash/setup.ksh @@ -0,0 +1,39 @@ +#!/usr/local/bin/ksh93 -p +# +# 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 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. +# +# ident "@(#)setup.ksh 1.3 09/05/19 SMI" +# +# $FreeBSD$ + +. ${STF_SUITE}/include/libtest.kshlib +. $STF_SUITE/include/libgnop.kshlib + +log_must create_gnops ${DISKS} + +# Rotate logs now, because this test can generate a great volume of log entries +newsyslog + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash.cfg b/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash.cfg new file mode 100644 index 00000000000..df5370a0a20 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash.cfg @@ -0,0 +1,33 @@ +# vim: filetype=sh +# +# Copyright (c) 2010 Spectra Logic Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions, and the following disclaimer, +# without modification. +# 2. Redistributions in binary form must reproduce at minimum a disclaimer +# substantially similar to the "NO WARRANTY" disclaimer below +# ("Disclaimer") and any redistribution must be conditioned upon +# including a substantially similar Disclaimer requirement for further +# binary redistribution. +# +# NO WARRANTY +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGES. +# +# $FreeBSD$ +# +export RUNTIME=180 diff --git a/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash_001_pos.ksh b/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash_001_pos.ksh new file mode 100644 index 00000000000..8aac16b5a97 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash_001_pos.ksh @@ -0,0 +1,112 @@ +#!/usr/local/bin/ksh93 +# +# Copyright (c) 2010 Spectra Logic Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions, and the following disclaimer, +# without modification. +# 2. Redistributions in binary form must reproduce at minimum a disclaimer +# substantially similar to the "NO WARRANTY" disclaimer below +# ("Disclaimer") and any redistribution must be conditioned upon +# including a substantially similar Disclaimer requirement for further +# binary redistribution. +# +# NO WARRANTY +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGES. +# +# $FreeBSD$ +# + +. $STF_SUITE/include/libtest.kshlib +. $STF_SUITE/include/libgnop.kshlib + +# Cleanup function. Kill each of the children. +function docleanup +{ + for CPID in $CHILDREN + do + echo "Killing $CPID" + kill $CPID + done + for CPID in $CHILDREN + do + wait $CPID + done +} + +function childcleanup +{ + exit 0 +} + +# Wait for the timeout, and then kill the child processes. +function childrentimeout +{ + log_note "childrentimeout process waiting $1 seconds" + sleep $1 + docleanup +} + +function mk_vols +{ + ADISKS=($DISKS) #Create an array for convenience + N_DISKS=${#ADISKS[@]} + N_MIRRORS=$(($N_DISKS / 2 )) + # Use a special ksh93 expansion to generate the list of gnop devices + GNOPS=${DISKS//~(E)([[:space:]]+|$)/.nop\1} + setup_mirrors $N_MIRRORS $GNOPS + for pool in `all_pools`; do + # Create 4 ZVols per pool. Write a geom label to each, just so + # that we have another geom class between zvol and the vdev + # taster. That thwarts detection of zvols based on a geom + # producer's class name, as was attempted by Perforce change + # 538882 + for ((j=0; $j<4; j=$j+1)); do + $ZFS create -V 10G $pool/testvol.$j + glabel label testlabel$j /dev/zvol/$pool/testvol.$j + done + done +} + +export CHILDREN="" + +log_onexit docleanup + +log_assert "Cause frequent device removal and arrival in the prescence of zvols. ZFS should not crash or hang while tasting them for VDev GUIDs." +mk_vols +for p in `all_pools` +do + #Take the first gnop in the pool + typeset gnop + typeset disk + gnop=`get_disklist $p | cut -d " " -f 1` + disk=${gnop%.nop} + + log_note "thrashing $gnop" + trap childcleanup INT TERM && while `true`; do + log_must destroy_gnop $disk + $SLEEP 5 + log_must create_gnop $disk + $SLEEP 5 + done & + CHILDREN="$CHILDREN $!" +done + +log_note "Waiting $RUNTIME seconds for potential ZFS failure" +childrentimeout $RUNTIME + +log_pass diff --git a/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash_test.sh b/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash_test.sh new file mode 100755 index 00000000000..a56a55f2765 --- /dev/null +++ b/tests/sys/cddl/zfs/tests/zvol_thrash/zvol_thrash_test.sh @@ -0,0 +1,57 @@ +# 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 +# + +# $FreeBSD$ + +# +# Copyright 2012 Spectra Logic. All rights reserved. +# Use is subject to license terms. +# + + +atf_test_case zvol_thrash_001_pos cleanup +zvol_thrash_001_pos_head() +{ + atf_set "descr" "Cause frequent device removal and arrival in the prescence of zvols. ZFS should not misbehave while tasting them for VDev GUIDs." + atf_set "require.progs" zfs zpool gnop + atf_set "timeout" 900 +} +zvol_thrash_001_pos_body() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zvol_thrash.cfg + + ksh93 $(atf_get_srcdir)/setup.ksh || atf_fail "Setup failed" + ksh93 $(atf_get_srcdir)/zvol_thrash_001_pos.ksh || atf_fail "Testcase failed" +} +zvol_thrash_001_pos_cleanup() +{ + . $(atf_get_srcdir)/../../include/default.cfg + . $(atf_get_srcdir)/zvol_thrash.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + +atf_init_test_cases() +{ + + atf_add_test_case zvol_thrash_001_pos +}