diff --git a/tests/zfs-tests/cmd/largest_file/largest_file.c b/tests/zfs-tests/cmd/largest_file/largest_file.c index 1cf7529f13ec..286232da5b19 100644 --- a/tests/zfs-tests/cmd/largest_file/largest_file.c +++ b/tests/zfs-tests/cmd/largest_file/largest_file.c @@ -1,140 +1,142 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this 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. */ /* * Copyright (c) 2012 by Delphix. All rights reserved. */ #include "../file_common.h" #include #include #include #include #include #include typedef long long offset_t; #define MAXOFFSET_T LLONG_MAX /* * -------------------------------------------------------------- * * 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; offset_t offset = (MAXOFFSET_T - 1); offset_t llseek_ret = 0; int write_ret = 0; int err = 0; - char mybuf[5]; + char mybuf[5] = "aaaa\0"; char *testfile; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; if (argc != 2) { usage(argv[0]); } (void) sigset(SIGXFSZ, sigxfsz); testfile = strdup(argv[1]); fd = open(testfile, O_CREAT | O_RDWR, mode); if (fd < 0) { - perror("Failed to create testfile"); err = errno; - goto out; + perror("Failed to create testfile"); + free(testfile); + return (err); } llseek_ret = lseek64(fd, offset, SEEK_SET); if (llseek_ret < 0) { - perror("Failed to seek to end of testfile"); err = errno; + perror("Failed to seek to end of testfile"); goto out; } write_ret = write(fd, mybuf, 1); if (write_ret < 0) { - perror("Failed to write to end of file"); err = errno; + perror("Failed to write to end of file"); goto out; } offset = 0; llseek_ret = lseek64(fd, offset, SEEK_CUR); if (llseek_ret < 0) { - perror("Failed to seek to end of file"); err = errno; + perror("Failed to seek to end of file"); 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; + perror("Did not receive EFBIG"); } } else { (void) printf("write completed successfully, test failed\n"); err = 1; } out: (void) unlink(testfile); free(testfile); + close(fd); 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/zfs-tests/cmd/mmapwrite/mmapwrite.c b/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c index 2eca124696e0..190d31af3aaa 100644 --- a/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c +++ b/tests/zfs-tests/cmd/mmapwrite/mmapwrite.c @@ -1,97 +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 */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #include #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]; + char buf[1024]; pthread_t tid; + memset(buf, 'a', sizeof (buf)); + 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); } (void) pthread_setconcurrency(2); if (pthread_create(&tid, NULL, mapper, &fd) != 0) { perror("pthread_create"); + close(fd); exit(1); } for (;;) { if (write(fd, buf, sizeof (buf)) == -1) { perror("write"); + close(fd); exit(1); } } + close(fd); + /* NOTREACHED */ return (0); } diff --git a/tests/zfs-tests/cmd/randfree_file/randfree_file.c b/tests/zfs-tests/cmd/randfree_file/randfree_file.c index 05797448c90a..c708d647e8b9 100644 --- a/tests/zfs-tests/cmd/randfree_file/randfree_file.c +++ b/tests/zfs-tests/cmd/randfree_file/randfree_file.c @@ -1,115 +1,125 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this 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. */ /* * Copyright (c) 2012 by Delphix. All rights reserved. */ #include "../file_common.h" #include #include #include +#include #include /* * 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 = NULL; - char *buf; + char *buf = NULL; size_t filesize = 0; off_t start_off = 0; off_t off_len = 0; int fd, ch; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; 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]); if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) { perror("open"); return (1); } - buf = (char *)malloc(filesize); + buf = (char *)calloc(1, filesize); + if (buf == NULL) { + perror("write"); + close(fd); + return (1); + } + memset(buf, 'c', filesize); if (write(fd, buf, filesize) < filesize) { free(buf); perror("write"); + close(fd); return (1); } free(buf); #if defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, start_off, off_len) < 0) { perror("fallocate"); + close(fd); return (1); } #else /* !(defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE)) */ { perror("FALLOC_FL_PUNCH_HOLE unsupported"); + close(fd); return (1); } #endif /* defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) */ - + close(fd); return (0); }