diff options
Diffstat (limited to 'tests/sys/cddl/zfs/bin')
43 files changed, 2675 insertions, 0 deletions
diff --git a/tests/sys/cddl/zfs/bin/Makefile b/tests/sys/cddl/zfs/bin/Makefile new file mode 100644 index 000000000000..98db25e396d3 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/Makefile @@ -0,0 +1,61 @@ +.include <src.opts.mk> + +PACKAGE= tests +MAN= +BINDIR= ${TESTSBASE}/sys/cddl/zfs/bin +SCRIPTSDIR= ${TESTSBASE}/sys/cddl/zfs/bin + +WARNS?= 0 + +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 <bsd.progs.mk> diff --git a/tests/sys/cddl/zfs/bin/bsddisks.ksh b/tests/sys/cddl/zfs/bin/bsddisks.ksh new file mode 100644 index 000000000000..102b65597c11 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/bsddisks.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..cf491e6f23cf --- /dev/null +++ b/tests/sys/cddl/zfs/bin/chg_usr_exec.c @@ -0,0 +1,76 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <pwd.h> + +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 <login> <commands> ...\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 000000000000..dd67032e97cd --- /dev/null +++ b/tests/sys/cddl/zfs/bin/devname2devid.c @@ -0,0 +1,121 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +#include <sys/types.h> +#include <sys/stat.h> +#include <devid.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> + +/* + * Usage: devname2devid <devicepath> + * + * Examples: + * # ./devname2devid /dev/c1t4d0s0 + * devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/a + * # ./devname2devid /dev/c1t4d0 + * devid id1,sd@SSEAGATE_ST318404LSUN18G_3BT2G0Z300002146G4CR/wd + * # ./devname2devid /dev/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 <devicepath> [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/"; + } + + 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 000000000000..f48d74f710a5 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/dir_rd_update.c @@ -0,0 +1,120 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +/* + * 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 <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#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 <mount point>\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 000000000000..8780a5122d42 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/dircmp.ksh @@ -0,0 +1,3 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..0c0c0d509009 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/dumpadm.ksh @@ -0,0 +1,8 @@ +#! /usr/local/bin/ksh93 -p + +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 000000000000..9ac3e43306ca --- /dev/null +++ b/tests/sys/cddl/zfs/bin/ff.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..ee741412119d --- /dev/null +++ b/tests/sys/cddl/zfs/bin/file_check.c @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +#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 000000000000..f2fd40d31969 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/file_common.h @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + +#ifndef FILE_COMMON_H +#define FILE_COMMON_H + + +/* + * 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 <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> + +#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 000000000000..d4d23b6f8073 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/file_trunc.c @@ -0,0 +1,238 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <limits.h> +#include <errno.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/stat.h> +#include <sys/statvfs.h> +#include <sys/errno.h> +#include <sys/time.h> +#include <sys/ioctl.h> +#include <sys/wait.h> +#include <sys/param.h> +#include <string.h> + +#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 000000000000..597bdd03b65d --- /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 + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include "file_common.h" +#include <inttypes.h> +#include <libgen.h> + +static unsigned char bigbuffer[BIGBUFFERSIZE]; + +/* + * Writes (or appends) a given value to a file repeatedly. + * See header file for defaults. + */ + +static void usage(void) __dead2; +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 <file>)\n"); + err++; + } + + if (!operation) { + (void) printf("Operation not specified (-o <operation>).\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 <create|append> 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 (%"PRId64"/%"PRId64") " + "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 = %"PRId64", 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 = %"PRId64", " + "error: %s[%d]\n", (long)n, good_writes, + strerror(errno), errno); + exit(errno); + } + good_writes++; + } + + if (verbose) { + (void) printf("Success: good_writes = %"PRId64" (%"PRId64")\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 000000000000..9ac3e43306ca --- /dev/null +++ b/tests/sys/cddl/zfs/bin/fmadm.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..9ac3e43306ca --- /dev/null +++ b/tests/sys/cddl/zfs/bin/fmdump.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..9ac3e43306ca --- /dev/null +++ b/tests/sys/cddl/zfs/bin/format.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..fae75b6b5f9c --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupadd.ksh @@ -0,0 +1,11 @@ +#! /usr/local/bin/ksh93 -p + +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 000000000000..923913aaf07f --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupdel.ksh @@ -0,0 +1,11 @@ +#! /usr/local/bin/ksh93 -p + +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 000000000000..60b5401f9a34 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupmod.ksh @@ -0,0 +1,11 @@ +#! /usr/local/bin/ksh93 -p + +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 000000000000..dced36dc56e3 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/groupshow.ksh @@ -0,0 +1,3 @@ +#! /usr/local/bin/ksh93 -p + +/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 000000000000..b732a2207c8b --- /dev/null +++ b/tests/sys/cddl/zfs/bin/largest_file.c @@ -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 + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include "file_common.h" +#include <sys/param.h> +#include <signal.h> +#include <stdio.h> + +/* + * -------------------------------------------------------------- + * + * 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 <testfile>\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 000000000000..0b7f43c8f42f --- /dev/null +++ b/tests/sys/cddl/zfs/bin/mkfile.c @@ -0,0 +1,209 @@ +/*- + * 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. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <fcntl.h> +#include <limits.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/uio.h> +#include <unistd.h> +#include <ctype.h> +#include <errno.h> + +#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] <size>[e|p|t|g|m|k|b] <filename> ...\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; + int 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 000000000000..5cfad210de91 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/mktree.c @@ -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 + */ + +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/errno.h> +#include <sys/param.h> + +#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 <base_dir> -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 000000000000..75b36a75a33a --- /dev/null +++ b/tests/sys/cddl/zfs/bin/mmapwrite.c @@ -0,0 +1,97 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +#include <unistd.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mman.h> +#include <pthread.h> + +/* + * -------------------------------------------------------------------- + * 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 <file name>\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 000000000000..a32e3cef2af8 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/randfree_file.c @@ -0,0 +1,102 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +#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 000000000000..1d8eb403cb33 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/readmmap.c @@ -0,0 +1,139 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +/* + * -------------------------------------------------------------- + * BugId 5047993 : Getting bad read data. + * + * Usage: readmmap <filename> + * + * where: + * filename is an absolute path to the file name. + * + * Return values: + * 1 : error + * 0 : no errors + * -------------------------------------------------------------- + */ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/mman.h> + +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 <file name>\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 != %zu\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 != %zu\n", bytes, size); + retval = 1; + goto end; + } + + if (buf[idx] != 1) { + (void) printf( + "bad data from read! got buf[%zu]=%d, expected 1\n", + idx, buf[idx]); + retval = 1; + goto end; + } + + (void) printf("good data from read: buf[%zu]=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 000000000000..58a7cf51a4fd --- /dev/null +++ b/tests/sys/cddl/zfs/bin/rename_dir.c @@ -0,0 +1,90 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +/* + * 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 <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <string.h> + +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 000000000000..0c00e62fdc9a --- /dev/null +++ b/tests/sys/cddl/zfs/bin/rm_lnkcnt_zero_file.c @@ -0,0 +1,146 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this 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. + */ + + +/* + * -------------------------------------------------------------------- + * 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 <stdio.h> +#include <fcntl.h> +#include <pthread.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <stdlib.h> +#include <unistd.h> + +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 <filebase>\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 000000000000..9ac3e43306ca --- /dev/null +++ b/tests/sys/cddl/zfs/bin/svcs.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..fa25bcc16239 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/swap.ksh @@ -0,0 +1,3 @@ +#! /usr/local/bin/ksh93 -p + +swapinfo diff --git a/tests/sys/cddl/zfs/bin/testenv.ksh b/tests/sys/cddl/zfs/bin/testenv.ksh new file mode 100644 index 000000000000..667ac756fc78 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/testenv.ksh @@ -0,0 +1,6 @@ +#!/usr/bin/env ksh93 +script=$(realpath $0) +export STF_BIN=$(dirname ${script}) +export STF_SUITE=$(dirname ${STF_BIN}) + +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 000000000000..82f3b66d0218 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/useradd.ksh @@ -0,0 +1,11 @@ +#! /usr/local/bin/ksh93 -p + +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 000000000000..5aa031932288 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/userdel.ksh @@ -0,0 +1,11 @@ +#! /usr/local/bin/ksh93 -p + +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 000000000000..a3140304e1c4 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/usermod.ksh @@ -0,0 +1,11 @@ +#! /usr/local/bin/ksh93 -p + +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 000000000000..df33a22dcbed --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zfs.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. + +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 000000000000..73117bcdcdf8 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zfs_crypto.ksh @@ -0,0 +1,54 @@ +#! /usr/local/bin/ksh93 -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this 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. + +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 000000000000..bbd1b013c808 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zfs_version.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 +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. + +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 000000000000..9ac3e43306ca --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zlogin.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..82c9c7677250 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zoneadm.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..9ac3e43306ca --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zonecfg.ksh @@ -0,0 +1,4 @@ +#!/usr/local/bin/ksh93 + +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 000000000000..63731aeada54 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool.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 +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. + +. ${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 000000000000..24811d7274a1 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool_bsd.ksh @@ -0,0 +1,40 @@ +#!/usr/local/bin/ksh93 -p +# + +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/"* ]]; then + arg=${arg#/dev/} + 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 000000000000..1b9d73eeb143 --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool_smi.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 +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. + +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/${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/${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/"* ]]; then + arg=${arg#/dev/} + 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 000000000000..f8a0283b8a4c --- /dev/null +++ b/tests/sys/cddl/zfs/bin/zpool_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 +# + +# +# Copyright 2009 Sun Microsystems, Inc. All rights reserved. +# Use is subject to license terms. + +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" |
