Skip to content

Commit

Permalink
5767 fix several problems with zfs test suite
Browse files Browse the repository at this point in the history
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Approved by: Gordon Ross <gwr@nexenta.com>
  • Loading branch information
jwk404 authored and ahrens committed Apr 26, 2015
1 parent 8430278 commit 52244c0
Show file tree
Hide file tree
Showing 40 changed files with 1,003 additions and 586 deletions.
46 changes: 36 additions & 10 deletions usr/src/cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,9 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
uint_t c, children;
char *vname;
boolean_t scripted = cb->cb_scripted;
uint64_t islog = B_FALSE;
boolean_t haslog = B_FALSE;
char *dashes = "%-*s - - - - - -\n";

verify(nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
(uint64_t **)&vs, &c) == 0);
Expand Down Expand Up @@ -2842,24 +2845,47 @@ print_list_stats(zpool_handle_t *zhp, const char *name, nvlist_t *nv,
ZPOOL_CONFIG_IS_HOLE, &ishole) == 0 && ishole)
continue;

if (nvlist_lookup_uint64(child[c],
ZPOOL_CONFIG_IS_LOG, &islog) == 0 && islog) {
haslog = B_TRUE;
continue;
}

vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
print_list_stats(zhp, vname, child[c], cb, depth + 2);
free(vname);
}

/*
* Include level 2 ARC devices in iostat output
*/
if (haslog == B_TRUE) {
/* LINTED E_SEC_PRINTF_VAR_FMT */
(void) printf(dashes, cb->cb_namewidth, "log");
for (c = 0; c < children; c++) {
if (nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
&islog) != 0 || !islog)
continue;
vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
print_list_stats(zhp, vname, child[c], cb, depth + 2);
free(vname);
}
}

if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
&child, &children) != 0)
return;
&child, &children) == 0 && children > 0) {
/* LINTED E_SEC_PRINTF_VAR_FMT */
(void) printf(dashes, cb->cb_namewidth, "cache");
for (c = 0; c < children; c++) {
vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
print_list_stats(zhp, vname, child[c], cb, depth + 2);
free(vname);
}
}

if (children > 0) {
(void) printf("%-*s - - - - - "
"-\n", cb->cb_namewidth, "cache");
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES, &child,
&children) == 0 && children > 0) {
/* LINTED E_SEC_PRINTF_VAR_FMT */
(void) printf(dashes, cb->cb_namewidth, "spare");
for (c = 0; c < children; c++) {
vname = zpool_vdev_name(g_zfs, zhp, child[c],
B_FALSE);
vname = zpool_vdev_name(g_zfs, zhp, child[c], B_FALSE);
print_list_stats(zhp, vname, child[c], cb, depth + 2);
free(vname);
}
Expand Down
10 changes: 8 additions & 2 deletions usr/src/pkg/manifests/system-test-zfstest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dir path=opt/zfs-tests/tests/functional/features/async_destroy
dir path=opt/zfs-tests/tests/functional/grow_pool
dir path=opt/zfs-tests/tests/functional/grow_replicas
dir path=opt/zfs-tests/tests/functional/history
dir path=opt/zfs-tests/tests/functional/holes
dir path=opt/zfs-tests/tests/functional/inheritance
dir path=opt/zfs-tests/tests/functional/interop
dir path=opt/zfs-tests/tests/functional/inuse
Expand Down Expand Up @@ -147,8 +148,10 @@ file path=opt/zfs-tests/bin/dir_rd_update mode=0555
file path=opt/zfs-tests/bin/file_check mode=0555
file path=opt/zfs-tests/bin/file_trunc mode=0555
file path=opt/zfs-tests/bin/file_write mode=0555
file path=opt/zfs-tests/bin/getholes mode=0555
file path=opt/zfs-tests/bin/largest_file mode=0555
file path=opt/zfs-tests/bin/mkbusy mode=0555
file path=opt/zfs-tests/bin/mkholes mode=0555
file path=opt/zfs-tests/bin/mktree mode=0555
file path=opt/zfs-tests/bin/mmapwrite mode=0555
file path=opt/zfs-tests/bin/randfree_file mode=0555
Expand Down Expand Up @@ -1702,6 +1705,10 @@ file path=opt/zfs-tests/tests/functional/history/sparc.migratedpool.DAT.Z \
file path=opt/zfs-tests/tests/functional/history/sparc.orig_history.txt \
mode=0444
file path=opt/zfs-tests/tests/functional/history/zfs-pool-v4.dat.Z mode=0444
file path=opt/zfs-tests/tests/functional/holes/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/holes/holes.shlib mode=0555
file path=opt/zfs-tests/tests/functional/holes/holes_sanity mode=0555
file path=opt/zfs-tests/tests/functional/holes/setup mode=0555
file path=opt/zfs-tests/tests/functional/inheritance/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/inheritance/config001.cfg mode=0555
file path=opt/zfs-tests/tests/functional/inheritance/config002.cfg mode=0555
Expand Down Expand Up @@ -1836,8 +1843,6 @@ file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression \
file path=opt/zfs-tests/tests/functional/nopwrite/nopwrite_volume mode=0555
file path=opt/zfs-tests/tests/functional/nopwrite/setup mode=0555
file path=opt/zfs-tests/tests/functional/online_offline/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/online_offline/online_offline.cfg \
mode=0555
file path=opt/zfs-tests/tests/functional/online_offline/online_offline_001_pos \
mode=0555
file path=opt/zfs-tests/tests/functional/online_offline/online_offline_002_neg \
Expand Down Expand Up @@ -1973,6 +1978,7 @@ file path=opt/zfs-tests/tests/functional/rsend/rsend_010_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/rsend_011_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/rsend_012_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/rsend_013_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/rsend_014_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/setup mode=0555
file path=opt/zfs-tests/tests/functional/scrub_mirror/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/scrub_mirror/default.cfg mode=0555
Expand Down
4 changes: 3 additions & 1 deletion usr/src/test/zfs-tests/cmd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#

#
# Copyright (c) 2012 by Delphix. All rights reserved.
# Copyright (c) 2012, 2014 by Delphix. All rights reserved.
#

.PARALLEL: $(SUBDIRS)
Expand All @@ -21,8 +21,10 @@ SUBDIRS = chg_usr_exec \
file_check \
file_trunc \
file_write \
getholes \
largest_file \
mkbusy \
mkholes \
mktree \
mmapwrite \
randfree_file \
Expand Down
10 changes: 4 additions & 6 deletions usr/src/test/zfs-tests/cmd/file_trunc/file_trunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

/*
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright (c) 2012, 2014 by Delphix. All rights reserved.
*/

#include <stdio.h>
Expand Down Expand Up @@ -76,7 +76,7 @@ usage(char *execname)
int
main(int argc, char *argv[])
{
int i = 0;
int i;
int fd = -1;

parse_options(argc, argv);
Expand All @@ -87,11 +87,9 @@ main(int argc, char *argv[])
exit(3);
}

while (i < count) {
for (i = 0; count == 0 || i < count; i++) {
(void) do_write(fd);
(void) do_trunc(fd);

i++;
}

(void) close(fd);
Expand Down Expand Up @@ -188,7 +186,7 @@ do_write(int fd)
exit(5);
}

buf = "ZFS Test Suite Truncation Test";
(void) strcpy(buf, "ZFS Test Suite Truncation Test");
if (write(fd, buf, bsize) < bsize) {
perror("write");
exit(6);
Expand Down
22 changes: 22 additions & 0 deletions usr/src/test/zfs-tests/cmd/getholes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2014 by Delphix. All rights reserved.
#

PROG = getholes

include $(SRC)/cmd/Makefile.cmd

LDLIBS += -lcmdutils -lumem -lzfs

include ../Makefile.subdirs
194 changes: 194 additions & 0 deletions usr/src/test/zfs-tests/cmd/getholes/getholes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/

/*
* Copyright (c) 2014 by Delphix. All rights reserved.
*/

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <libzfs.h>
#include <umem.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/types.h>
#include <sys/list.h>
#include <sys/stat.h>
#include <sys/errno.h>

#define PRINT_HOLE 0x1
#define PRINT_DATA 0x2
#define PRINT_VERBOSE 0x4

extern int errno;

static void
usage(char *msg, int exit_value)
{
(void) fprintf(stderr, "getholes [-dhv] filename\n");
(void) fprintf(stderr, "%s\n", msg);
exit(exit_value);
}

typedef struct segment {
list_node_t seg_node;
int seg_type;
off_t seg_offset;
off_t seg_len;
} seg_t;

/*
* Return an appropriate whence value, depending on whether the file begins
* with a holes or data.
*/
static int
starts_with_hole(int fd)
{
off_t off;

if ((off = lseek(fd, 0, SEEK_HOLE)) == -1) {
/* ENXIO means no holes were found */
if (errno == ENXIO)
return (SEEK_DATA);
perror("lseek failed");
exit(1);
}

return (off == 0 ? SEEK_HOLE : SEEK_DATA);
}

static void
print_list(list_t *seg_list, char *fname, int options)
{
uint64_t lz_holes, bs = 0;
uint64_t hole_blks_seen = 0, data_blks_seen = 0;
seg_t *seg;

if (0 == bs)
if (zfs_get_hole_count(fname, &lz_holes, &bs) != 0) {
perror("zfs_get_hole_count");
exit(1);
}

while ((seg = list_remove_head(seg_list)) != NULL) {
if (options & PRINT_VERBOSE)
(void) fprintf(stdout, "%c %llu:%llu\n",
seg->seg_type == SEEK_HOLE ? 'h' : 'd',
seg->seg_offset, seg->seg_len);

if (seg->seg_type == SEEK_HOLE) {
hole_blks_seen += seg->seg_len / bs;
} else {
data_blks_seen += seg->seg_len / bs;
}
umem_free(seg, sizeof (seg_t));
}

/* Verify libzfs sees the same number of hole blocks found manually. */
if (lz_holes != hole_blks_seen) {
(void) fprintf(stderr, "Counted %llu holes, but libzfs found "
"%llu\n", hole_blks_seen, lz_holes);
exit(1);
}

if (options & PRINT_HOLE && options & PRINT_DATA) {
(void) fprintf(stdout, "datablks: %llu\n", data_blks_seen);
(void) fprintf(stdout, "holeblks: %llu\n", hole_blks_seen);
return;
}

if (options & PRINT_DATA)
(void) fprintf(stdout, "%llu\n", data_blks_seen);
if (options & PRINT_HOLE)
(void) fprintf(stdout, "%llu\n", hole_blks_seen);
}

int
main(int argc, char *argv[])
{
off_t len, off = 0;
int c, fd, options = 0, whence = SEEK_DATA;
struct stat statbuf;
char *fname;
list_t seg_list;
seg_t *seg = NULL;

list_create(&seg_list, sizeof (seg_t), offsetof(seg_t, seg_node));

while ((c = getopt(argc, argv, "dhv")) != -1) {
switch (c) {
case 'd':
options |= PRINT_DATA;
break;
case 'h':
options |= PRINT_HOLE;
break;
case 'v':
options |= PRINT_VERBOSE;
break;
}
}
argc -= optind;
argv += optind;

if (argc != 1)
usage("Incorrect number of arguments.", 1);

if ((fname = argv[0]) == NULL)
usage("No filename provided.", 1);

if ((fd = open(fname, O_LARGEFILE | O_RDONLY)) < 0) {
perror("open failed");
exit(1);
}

if (fstat(fd, &statbuf) != 0) {
perror("fstat failed");
exit(1);
}
len = statbuf.st_size;

whence = starts_with_hole(fd);
while ((off = lseek(fd, off, whence)) != -1) {
seg_t *s;

seg = umem_alloc(sizeof (seg_t), UMEM_DEFAULT);
seg->seg_type = whence;
seg->seg_offset = off;

list_insert_tail(&seg_list, seg);
if ((s = list_prev(&seg_list, seg)) != NULL)
s->seg_len = seg->seg_offset - s->seg_offset;

whence = whence == SEEK_HOLE ? SEEK_DATA : SEEK_HOLE;
}
if (errno != ENXIO) {
perror("lseek failed");
exit(1);
}
(void) close(fd);

/*
* If this file ends with a hole block, then populate the length of
* the last segment, otherwise this is the end of the file, so
* discard the remaining zero length segment.
*/
if (seg && seg->seg_offset != len) {
seg->seg_len = len - seg->seg_offset;
} else {
(void) list_remove_tail(&seg_list);
}

print_list(&seg_list, fname, options);
list_destroy(&seg_list);
return (0);
}
Loading

0 comments on commit 52244c0

Please sign in to comment.