usr/src/cmd/ztest/ztest.c
author timh
Sun, 27 Apr 2008 10:20:38 -0700
changeset 6492 903545192033
parent 5994 bedab011a2e5
child 6643 3a34b0dbb107
permissions -rw-r--r--
6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data 6666748 System panic occurred when attempting to view .zfs snapshot directory from CIFS client. 6693201 libzpool needlessly defines u8_textprep_str() 6694236 case-insensitive zfs file system doesn't work when created on sparc and then imported on x86
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 797
diff changeset
     5
 * Common Development and Distribution License (the "License").
e971e58d18f6 6322005 support for persistent offline
lling
parents: 797
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
5994
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5530
diff changeset
    22
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
 * The objective of this program is to provide a DMU/ZAP/SPA stress test
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
 * that runs entirely in userland, is easy to use, and easy to extend.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
 * The overall design of the ztest program is as follows:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
 * (1) For each major functional area (e.g. adding vdevs to a pool,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
 *     creating and destroying datasets, reading and writing objects, etc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 *     we have a simple routine to test that functionality.  These
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 *     individual routines do not have to do anything "stressful".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
 * (2) We turn these simple functionality tests into a stress test by
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 *     running them all in parallel, with as many threads as desired,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
 *     and spread across as many datasets, objects, and vdevs as desired.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 * (3) While all this is happening, we inject faults into the pool to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 *     verify that self-healing data really works.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
 * (4) Every time we open a dataset, we change its checksum and compression
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
 *     functions.  Thus even individual objects vary from block to block
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
 *     in which checksum they use and whether they're compressed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
 * (5) To verify that we never lose on-disk consistency after a crash,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 *     we run the entire test in a child of the main process.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 *     At random times, the child self-immolates with a SIGKILL.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 *     This is the software equivalent of pulling the power cord.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
 *     The parent then runs the test again, using the existing
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
 *     storage pool, as many times as desired.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
 * (6) To verify that we don't have future leaks or temporal incursions,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 *     many of the functional tests record the transaction group number
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 *     as part of their data.  When reading old data, they verify that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 *     the transaction group number is less than the current, open txg.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 *     If you add a new test, please do this if applicable.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 * When run with no arguments, ztest runs for about five minutes and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
 * produces no output if successful.  To get a little bit of information,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
 * specify -V.  To get more information, specify -VV, and so on.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
 * To turn this into an overnight stress test, use -T to specify run time.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
 * You can ask more more vdevs [-v], datasets [-d], or threads [-t]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
 * to increase the pool capacity, fanout, and overall stress level.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
 * The -N(okill) option will suppress kills, so each child runs to completion.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
 * This can be useful when you're trying to distinguish temporal incursions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
 * from plain old race conditions.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
#include <sys/dmu_traverse.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
#include <sys/dmu_objset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
#include <sys/poll.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
#include <sys/time.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
#include <sys/wait.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
#include <sys/mman.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
#include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
#include <sys/zio_compress.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
#include <sys/zil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
#include <sys/vdev_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
#include <sys/spa_impl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
#include <sys/dsl_prop.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
#include <sys/refcount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
#include <stdio.h>
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1807
diff changeset
    99
#include <stdio_ext.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
#include <stdlib.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
#include <unistd.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
#include <signal.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
#include <umem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
#include <dlfcn.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
#include <ctype.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
#include <math.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
static char cmdname[] = "ztest";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
static char *zopt_pool = cmdname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
static uint64_t zopt_vdevs = 5;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
static uint64_t zopt_vdevtime;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   114
static int zopt_ashift = SPA_MINBLOCKSHIFT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
static int zopt_mirrors = 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
static int zopt_raidz = 4;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   117
static int zopt_raidz_parity = 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
static size_t zopt_vdev_size = SPA_MINDEVSIZE;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   119
static int zopt_datasets = 7;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
static int zopt_threads = 23;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
static uint64_t zopt_passtime = 60;	/* 60 seconds */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
static uint64_t zopt_killrate = 70;	/* 70% kill rate */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
static int zopt_verbose = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
static int zopt_init = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
static char *zopt_dir = "/tmp";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
static uint64_t zopt_time = 300;	/* 5 minutes */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
static int zopt_maxfaults;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   128
static uint16_t zopt_write_fail_shift = 5;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   130
typedef struct ztest_block_tag {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   131
	uint64_t	bt_objset;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   132
	uint64_t	bt_object;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   133
	uint64_t	bt_offset;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   134
	uint64_t	bt_txg;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   135
	uint64_t	bt_thread;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   136
	uint64_t	bt_seq;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   137
} ztest_block_tag_t;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   138
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
typedef struct ztest_args {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   140
	char		za_pool[MAXNAMELEN];
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   141
	spa_t		*za_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
	objset_t	*za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	zilog_t		*za_zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	thread_t	za_thread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	uint64_t	za_instance;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
	uint64_t	za_random;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
	uint64_t	za_diroff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
	uint64_t	za_diroff_shared;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   149
	uint64_t	za_zil_seq;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	hrtime_t	za_start;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
	hrtime_t	za_stop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
	hrtime_t	za_kill;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
	traverse_handle_t *za_th;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   154
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   155
	 * Thread-local variables can go here to aid debugging.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   156
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   157
	ztest_block_tag_t za_rbt;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   158
	ztest_block_tag_t za_wbt;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   159
	dmu_object_info_t za_doi;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   160
	dmu_buf_t	*za_dbuf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
} ztest_args_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
typedef void ztest_func_t(ztest_args_t *);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
 * Note: these aren't static because we want dladdr() to work.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
ztest_func_t ztest_dmu_read_write;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
ztest_func_t ztest_dmu_write_parallel;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
ztest_func_t ztest_dmu_object_alloc_free;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
ztest_func_t ztest_zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
ztest_func_t ztest_zap_parallel;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
ztest_func_t ztest_traverse;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
ztest_func_t ztest_dsl_prop_get_set;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
ztest_func_t ztest_dmu_objset_create_destroy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
ztest_func_t ztest_dmu_snapshot_create_destroy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
ztest_func_t ztest_spa_create_destroy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
ztest_func_t ztest_fault_inject;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
ztest_func_t ztest_vdev_attach_detach;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
ztest_func_t ztest_vdev_LUN_growth;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
ztest_func_t ztest_vdev_add_remove;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
ztest_func_t ztest_scrub;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
ztest_func_t ztest_spa_rename;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
typedef struct ztest_info {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
	ztest_func_t	*zi_func;	/* test function */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   187
	uint64_t	zi_iters;	/* iterations per execution */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	uint64_t	*zi_interval;	/* execute every <interval> seconds */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	uint64_t	zi_calls;	/* per-pass count */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	uint64_t	zi_call_time;	/* per-pass time */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	uint64_t	zi_call_total;	/* cumulative total */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	uint64_t	zi_call_target;	/* target cumulative total */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
} ztest_info_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
uint64_t zopt_always = 0;		/* all the time */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
uint64_t zopt_often = 1;		/* every second */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
uint64_t zopt_sometimes = 10;		/* every 10 seconds */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
uint64_t zopt_rarely = 60;		/* every 60 seconds */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
ztest_info_t ztest_info[] = {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   201
	{ ztest_dmu_read_write,			1,	&zopt_always	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   202
	{ ztest_dmu_write_parallel,		30,	&zopt_always	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   203
	{ ztest_dmu_object_alloc_free,		1,	&zopt_always	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   204
	{ ztest_zap,				30,	&zopt_always	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   205
	{ ztest_zap_parallel,			100,	&zopt_always	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   206
	{ ztest_traverse,			1,	&zopt_often	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   207
	{ ztest_dsl_prop_get_set,		1,	&zopt_sometimes	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   208
	{ ztest_dmu_objset_create_destroy,	1,	&zopt_sometimes	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   209
	{ ztest_dmu_snapshot_create_destroy,	1,	&zopt_rarely	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   210
	{ ztest_spa_create_destroy,		1,	&zopt_sometimes	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   211
	{ ztest_fault_inject,			1,	&zopt_sometimes	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   212
	{ ztest_spa_rename,			1,	&zopt_rarely	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   213
	{ ztest_vdev_attach_detach,		1,	&zopt_rarely	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   214
	{ ztest_vdev_LUN_growth,		1,	&zopt_rarely	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   215
	{ ztest_vdev_add_remove,		1,	&zopt_vdevtime	},
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   216
	{ ztest_scrub,				1,	&zopt_vdevtime	},
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
#define	ZTEST_FUNCS	(sizeof (ztest_info) / sizeof (ztest_info_t))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
#define	ZTEST_SYNC_LOCKS	16
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
 * Stuff we need to share writably between parent and child.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
typedef struct ztest_shared {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	mutex_t		zs_vdev_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	rwlock_t	zs_name_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	uint64_t	zs_vdev_primaries;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
	uint64_t	zs_enospc_count;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
	hrtime_t	zs_start_time;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
	hrtime_t	zs_stop_time;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	uint64_t	zs_alloc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
	uint64_t	zs_space;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
	ztest_info_t	zs_info[ZTEST_FUNCS];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
	mutex_t		zs_sync_lock[ZTEST_SYNC_LOCKS];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
	uint64_t	zs_seq[ZTEST_SYNC_LOCKS];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
} ztest_shared_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
static char ztest_dev_template[] = "%s/%s.%llua";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
static ztest_shared_t *ztest_shared;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
static int ztest_random_fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
static int ztest_dump_core = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   246
static boolean_t ztest_exiting = B_FALSE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   247
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   248
extern uint64_t metaslab_gang_bang;
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   249
extern uint16_t zio_zil_fail_shift;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   250
extern uint16_t zio_io_fail_shift;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
#define	ZTEST_DIROBJ		1
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
#define	ZTEST_MICROZAP_OBJ	2
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
#define	ZTEST_FATZAP_OBJ	3
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
#define	ZTEST_DIROBJ_BLOCKSIZE	(1 << 10)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
#define	ZTEST_DIRSIZE		256
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
4008
a95c00c4179a 6543732 fix for 6524407 broke the nightly build with gcc
raf
parents: 3972
diff changeset
   259
static void usage(boolean_t) __NORETURN;
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   260
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
 * These libumem hooks provide a reasonable set of defaults for the allocator's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
 * debugging facilities.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
_umem_debug_init()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
	return ("default,verbose"); /* $UMEM_DEBUG setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
_umem_logging_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	return ("fail,contents"); /* $UMEM_LOGGING setting */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
#define	FATAL_MSG_SZ	1024
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
char *fatal_msg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
fatal(int do_perror, char *message, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
	va_list args;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	int save_errno = errno;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
	char buf[FATAL_MSG_SZ];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	(void) fflush(stdout);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
	va_start(args, message);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
	(void) sprintf(buf, "ztest: ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	/* LINTED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
	(void) vsprintf(buf + strlen(buf), message, args);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
	va_end(args);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	if (do_perror) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
		(void) snprintf(buf + strlen(buf), FATAL_MSG_SZ - strlen(buf),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
		    ": %s", strerror(save_errno));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
	(void) fprintf(stderr, "%s\n", buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	fatal_msg = buf;			/* to ease debugging */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	if (ztest_dump_core)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
		abort();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
	exit(3);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
str2shift(const char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
	const char *ends = "BKMGTPEZ";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
	if (buf[0] == '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	for (i = 0; i < strlen(ends); i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
		if (toupper(buf[0]) == ends[i])
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
	}
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   318
	if (i == strlen(ends)) {
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   319
		(void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n",
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   320
		    buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   321
		usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   322
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
	if (buf[1] == '\0' || (toupper(buf[1]) == 'B' && buf[2] == '\0')) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
		return (10*i);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	}
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   326
	(void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n", buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   327
	usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   328
	/* NOTREACHED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
static uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
nicenumtoull(const char *buf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
	char *end;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	uint64_t val;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
	val = strtoull(buf, &end, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	if (end == buf) {
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   339
		(void) fprintf(stderr, "ztest: bad numeric value: %s\n", buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   340
		usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
	} else if (end[0] == '.') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
		double fval = strtod(buf, &end);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
		fval *= pow(2, str2shift(end));
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   344
		if (fval > UINT64_MAX) {
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   345
			(void) fprintf(stderr, "ztest: value too large: %s\n",
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   346
			    buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   347
			usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   348
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
		val = (uint64_t)fval;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
		int shift = str2shift(end);
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   352
		if (shift >= 64 || (val << shift) >> shift != val) {
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   353
			(void) fprintf(stderr, "ztest: value too large: %s\n",
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   354
			    buf);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   355
			usage(B_FALSE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   356
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
		val <<= shift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
	return (val);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
static void
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   363
usage(boolean_t requested)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
	char nice_vdev_size[10];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
	char nice_gang_bang[10];
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   367
	FILE *fp = requested ? stdout : stderr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
	nicenum(zopt_vdev_size, nice_vdev_size);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   370
	nicenum(metaslab_gang_bang, nice_gang_bang);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   372
	(void) fprintf(fp, "Usage: %s\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
	    "\t[-v vdevs (default: %llu)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
	    "\t[-s size_of_each_vdev (default: %s)]\n"
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   375
	    "\t[-a alignment_shift (default: %d) (use 0 for random)]\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
	    "\t[-m mirror_copies (default: %d)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
	    "\t[-r raidz_disks (default: %d)]\n"
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   378
	    "\t[-R raidz_parity (default: %d)]\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
	    "\t[-d datasets (default: %d)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
	    "\t[-t threads (default: %d)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
	    "\t[-g gang_block_threshold (default: %s)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
	    "\t[-i initialize pool i times (default: %d)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	    "\t[-k kill percentage (default: %llu%%)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
	    "\t[-p pool_name (default: %s)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
	    "\t[-f file directory for vdev files (default: %s)]\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
	    "\t[-V(erbose)] (use multiple times for ever more blather)\n"
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   387
	    "\t[-E(xisting)] (use existing pool instead of creating new one)\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
	    "\t[-T time] total run time (default: %llu sec)\n"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
	    "\t[-P passtime] time per pass (default: %llu sec)\n"
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   390
	    "\t[-z zil failure rate (default: fail every 2^%llu allocs)]\n"
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   391
	    "\t[-w write failure rate (default: fail every 2^%llu allocs)]\n"
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   392
	    "\t[-h] (print help)\n"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
	    "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
	    cmdname,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   395
	    (u_longlong_t)zopt_vdevs,			/* -v */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   396
	    nice_vdev_size,				/* -s */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   397
	    zopt_ashift,				/* -a */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   398
	    zopt_mirrors,				/* -m */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   399
	    zopt_raidz,					/* -r */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   400
	    zopt_raidz_parity,				/* -R */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   401
	    zopt_datasets,				/* -d */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   402
	    zopt_threads,				/* -t */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   403
	    nice_gang_bang,				/* -g */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   404
	    zopt_init,					/* -i */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   405
	    (u_longlong_t)zopt_killrate,		/* -k */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   406
	    zopt_pool,					/* -p */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   407
	    zopt_dir,					/* -f */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   408
	    (u_longlong_t)zopt_time,			/* -T */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   409
	    (u_longlong_t)zopt_passtime,		/* -P */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   410
	    (u_longlong_t)zio_zil_fail_shift,		/* -z */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   411
	    (u_longlong_t)zopt_write_fail_shift);	/* -w */
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   412
	exit(requested ? 0 : 1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
static uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
ztest_random(uint64_t range)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
	uint64_t r;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
	if (range == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	if (read(ztest_random_fd, &r, sizeof (r)) != sizeof (r))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
		fatal(1, "short read from /dev/urandom");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
	return (r % range);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
ztest_record_enospc(char *s)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
	dprintf("ENOSPC doing: %s\n", s ? s : "<unknown>");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
	ztest_shared->zs_enospc_count++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
process_options(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
	int opt;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
	uint64_t value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
	/* By default, test gang blocks for blocks 32K and greater */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   443
	metaslab_gang_bang = 32 << 10;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   445
	/* Default value, fail every 32nd allocation */
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   446
	zio_zil_fail_shift = 5;
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   447
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
	while ((opt = getopt(argc, argv,
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   449
	    "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:z:w:h")) != EOF) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
		value = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
		switch (opt) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   452
		case 'v':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   453
		case 's':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   454
		case 'a':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   455
		case 'm':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   456
		case 'r':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   457
		case 'R':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   458
		case 'd':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   459
		case 't':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   460
		case 'g':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   461
		case 'i':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   462
		case 'k':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   463
		case 'T':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   464
		case 'P':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   465
		case 'z':
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   466
		case 'w':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
			value = nicenumtoull(optarg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
		switch (opt) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   470
		case 'v':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
			zopt_vdevs = value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   473
		case 's':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
			zopt_vdev_size = MAX(SPA_MINDEVSIZE, value);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   476
		case 'a':
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   477
			zopt_ashift = value;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   478
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   479
		case 'm':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
			zopt_mirrors = value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   482
		case 'r':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
			zopt_raidz = MAX(1, value);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   485
		case 'R':
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   486
			zopt_raidz_parity = MIN(MAX(value, 1), 2);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   487
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   488
		case 'd':
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   489
			zopt_datasets = MAX(1, value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   491
		case 't':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
			zopt_threads = MAX(1, value);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   494
		case 'g':
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   495
			metaslab_gang_bang = MAX(SPA_MINBLOCKSIZE << 1, value);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   497
		case 'i':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
			zopt_init = value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   500
		case 'k':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
			zopt_killrate = value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   503
		case 'p':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
			zopt_pool = strdup(optarg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   506
		case 'f':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
			zopt_dir = strdup(optarg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   509
		case 'V':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
			zopt_verbose++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   512
		case 'E':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
			zopt_init = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   515
		case 'T':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
			zopt_time = value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   518
		case 'P':
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
			zopt_passtime = MAX(1, value);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   521
		case 'z':
3668
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   522
			zio_zil_fail_shift = MIN(value, 16);
dc5b9a9208ca 6513020 zio pipeline went out to lunch
gw25295
parents: 3461
diff changeset
   523
			break;
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   524
		case 'w':
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   525
			zopt_write_fail_shift = MIN(value, 16);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
   526
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   527
		case 'h':
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   528
			usage(B_TRUE);
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   529
			break;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   530
		case '?':
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
   531
		default:
3972
cf5de7ce56fd 6524407 ztest's nicenumtoull() is not so nice
vb160487
parents: 3711
diff changeset
   532
			usage(B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   537
	zopt_raidz_parity = MIN(zopt_raidz_parity, zopt_raidz - 1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   538
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	zopt_vdevtime = (zopt_vdevs > 0 ? zopt_time / zopt_vdevs : UINT64_MAX);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   540
	zopt_maxfaults = MAX(zopt_mirrors, 1) * (zopt_raidz_parity + 1) - 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   543
static uint64_t
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   544
ztest_get_ashift(void)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   545
{
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   546
	if (zopt_ashift == 0)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   547
		return (SPA_MINBLOCKSHIFT + ztest_random(3));
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   548
	return (zopt_ashift);
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   549
}
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   550
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
static nvlist_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
make_vdev_file(size_t size)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
	char dev_name[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
	uint64_t vdev;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   556
	uint64_t ashift = ztest_get_ashift();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
	nvlist_t *file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
	if (size == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
		(void) snprintf(dev_name, sizeof (dev_name), "%s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
		    "/dev/bogus");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
		vdev = ztest_shared->zs_vdev_primaries++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
		(void) sprintf(dev_name, ztest_dev_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
		    zopt_dir, zopt_pool, vdev);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
		fd = open(dev_name, O_RDWR | O_CREAT | O_TRUNC, 0666);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
		if (fd == -1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
			fatal(1, "can't open %s", dev_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
		if (ftruncate(fd, size) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
			fatal(1, "can't ftruncate %s", dev_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
		(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
	VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, dev_name) == 0);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   579
	VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
	return (file);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
static nvlist_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
make_vdev_raidz(size_t size, int r)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
	nvlist_t *raidz, **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
	if (r < 2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
		return (make_vdev_file(size));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
	for (c = 0; c < r; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
		child[c] = make_vdev_file(size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
	VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
	VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
	    VDEV_TYPE_RAIDZ) == 0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   601
	VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   602
	    zopt_raidz_parity) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
	VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
	    child, r) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	for (c = 0; c < r; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
		nvlist_free(child[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
	umem_free(child, r * sizeof (nvlist_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
	return (raidz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
static nvlist_t *
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   615
make_vdev_mirror(size_t size, int log, int r, int m)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
	nvlist_t *mirror, **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
	if (m < 1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
		return (make_vdev_raidz(size, r));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
	child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
	for (c = 0; c < m; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
		child[c] = make_vdev_raidz(size, r);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
	VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
	VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
	    VDEV_TYPE_MIRROR) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
	VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
	    child, m) == 0);
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   633
	VERIFY(nvlist_add_uint64(mirror, ZPOOL_CONFIG_IS_LOG, log) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
	for (c = 0; c < m; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
		nvlist_free(child[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
	umem_free(child, m * sizeof (nvlist_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
	return (mirror);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
static nvlist_t *
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   644
make_vdev_root(size_t size, int log, int r, int m, int t)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
	nvlist_t *root, **child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
	int c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
	ASSERT(t > 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
	child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
	for (c = 0; c < t; c++)
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   654
		child[c] = make_vdev_mirror(size, log, r, m);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
	VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
	VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
	VERIFY(nvlist_add_nvlist_array(root, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
	    child, t) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
	for (c = 0; c < t; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
		nvlist_free(child[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	umem_free(child, t * sizeof (nvlist_t *));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
	return (root);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   670
ztest_set_random_blocksize(objset_t *os, uint64_t object, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   671
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   672
	int bs = SPA_MINBLOCKSHIFT +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
	    ztest_random(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
	int ibs = DN_MIN_INDBLKSHIFT +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
	    ztest_random(DN_MAX_INDBLKSHIFT - DN_MIN_INDBLKSHIFT + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
	error = dmu_object_set_blocksize(os, object, 1ULL << bs, ibs, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
		char osname[300];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
		dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   682
		fatal(0, "dmu_object_set_blocksize('%s', %llu, %d, %d) = %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
		    osname, object, 1 << bs, ibs, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   685
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
static uint8_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
ztest_random_checksum(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   689
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
	uint8_t checksum;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
	do {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
		checksum = ztest_random(ZIO_CHECKSUM_FUNCTIONS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	} while (zio_checksum_table[checksum].ci_zbt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
	if (checksum == ZIO_CHECKSUM_OFF)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
		checksum = ZIO_CHECKSUM_ON;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
	return (checksum);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
static uint8_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
ztest_random_compress(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
	return ((uint8_t)ztest_random(ZIO_COMPRESS_FUNCTIONS));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
typedef struct ztest_replay {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	objset_t	*zr_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
	uint64_t	zr_assign;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
} ztest_replay_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
ztest_replay_create(ztest_replay_t *zr, lr_create_t *lr, boolean_t byteswap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
	objset_t *os = zr->zr_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
	if (byteswap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
		byteswap_uint64_array(lr, sizeof (*lr));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
	tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
	dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
	error = dmu_tx_assign(tx, zr->zr_assign);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
		dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
	error = dmu_object_claim(os, lr->lr_doid, lr->lr_mode, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
	    DMU_OT_NONE, 0, tx);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1914
diff changeset
   733
	ASSERT3U(error, ==, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	if (zopt_verbose >= 5) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
		char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
		dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
		(void) printf("replay create of %s object %llu"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   740
		    " in txg %llu = %d\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
		    osname, (u_longlong_t)lr->lr_doid,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
		    (u_longlong_t)zr->zr_assign, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
ztest_replay_remove(ztest_replay_t *zr, lr_remove_t *lr, boolean_t byteswap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
	objset_t *os = zr->zr_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
	if (byteswap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
		byteswap_uint64_array(lr, sizeof (*lr));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
	tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
	dmu_tx_hold_free(tx, lr->lr_doid, 0, DMU_OBJECT_END);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
	error = dmu_tx_assign(tx, zr->zr_assign);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
		dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
	error = dmu_object_free(os, lr->lr_doid, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
zil_replay_func_t *ztest_replay_vector[TX_MAX_TYPE] = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	NULL,			/* 0 no such transaction type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
	ztest_replay_create,	/* TX_CREATE */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
	NULL,			/* TX_MKDIR */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
	NULL,			/* TX_MKXATTR */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
	NULL,			/* TX_SYMLINK */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
	ztest_replay_remove,	/* TX_REMOVE */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
	NULL,			/* TX_RMDIR */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
	NULL,			/* TX_LINK */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
	NULL,			/* TX_RENAME */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	NULL,			/* TX_WRITE */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	NULL,			/* TX_TRUNCATE */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
	NULL,			/* TX_SETATTR */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	NULL,			/* TX_ACL */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
 * Verify that we can't destroy an active pool, create an existing pool,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
 * or create a pool with a bad vdev spec.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
ztest_spa_create_destroy(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
	 * Attempt to create using a bad file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
	 */
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   802
	nvroot = make_vdev_root(0, 0, 0, 0, 1);
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4543
diff changeset
   803
	error = spa_create("ztest_bad_file", nvroot, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
	if (error != ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
		fatal(0, "spa_create(bad_file) = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
	 * Attempt to create using a bad mirror.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
	 */
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   811
	nvroot = make_vdev_root(0, 0, 0, 2, 1);
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4543
diff changeset
   812
	error = spa_create("ztest_bad_mirror", nvroot, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
	if (error != ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
		fatal(0, "spa_create(bad_mirror) = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
	 * Attempt to create an existing pool.  It shouldn't matter
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
	 * what's in the nvroot; we should fail with EEXIST.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
	(void) rw_rdlock(&ztest_shared->zs_name_lock);
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   822
	nvroot = make_vdev_root(0, 0, 0, 0, 1);
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4543
diff changeset
   823
	error = spa_create(za->za_pool, nvroot, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
	if (error != EEXIST)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
		fatal(0, "spa_create(whatever) = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
	error = spa_open(za->za_pool, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
		fatal(0, "spa_open() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
	error = spa_destroy(za->za_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
	if (error != EBUSY)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
		fatal(0, "spa_destroy() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   835
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   836
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   837
	(void) rw_unlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
 * Verify that vdev_add() works as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
ztest_vdev_add_remove(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   846
	spa_t *spa = za->za_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
	uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
	if (zopt_verbose >= 6)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
		(void) printf("adding vdev\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
	(void) mutex_lock(&ztest_shared->zs_vdev_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   856
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   858
	ztest_shared->zs_vdev_primaries =
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
	    spa->spa_root_vdev->vdev_children * leaves;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   861
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   863
	/*
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   864
	 * Make 1/4 of the devices be log devices.
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   865
	 */
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   866
	nvroot = make_vdev_root(zopt_vdev_size,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   867
	    ztest_random(4) == 0, zopt_raidz, zopt_mirrors, 1);
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
   868
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	error = spa_vdev_add(spa, nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	(void) mutex_unlock(&ztest_shared->zs_vdev_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
	if (error == ENOSPC)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
		ztest_record_enospc("spa_vdev_add");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
	else if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
		fatal(0, "spa_vdev_add() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
	if (zopt_verbose >= 6)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
		(void) printf("spa_vdev_add = %d, as expected\n", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   883
static vdev_t *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   884
vdev_lookup_by_path(vdev_t *vd, const char *path)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   885
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   886
	int c;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   887
	vdev_t *mvd;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   888
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   889
	if (vd->vdev_path != NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   890
		if (vd->vdev_wholedisk == 1) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   891
			/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   892
			 * For whole disks, the internal path has 's0', but the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   893
			 * path passed in by the user doesn't.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   894
			 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   895
			if (strlen(path) == strlen(vd->vdev_path) - 2 &&
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   896
			    strncmp(path, vd->vdev_path, strlen(path)) == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   897
				return (vd);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   898
		} else if (strcmp(path, vd->vdev_path) == 0) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   899
			return (vd);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   900
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   901
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   902
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   903
	for (c = 0; c < vd->vdev_children; c++)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   904
		if ((mvd = vdev_lookup_by_path(vd->vdev_child[c], path)) !=
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   905
		    NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   906
			return (mvd);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   907
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   908
	return (NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   909
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   910
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
 * Verify that we can attach and detach devices.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   913
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
ztest_vdev_attach_detach(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
   917
	spa_t *spa = za->za_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
	vdev_t *rvd = spa->spa_root_vdev;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   919
	vdev_t *oldvd, *newvd, *pvd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
	nvlist_t *root, *file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
	uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
	uint64_t leaf, top;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
   923
	uint64_t ashift = ztest_get_ashift();
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   924
	size_t oldsize, newsize;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   925
	char oldpath[MAXPATHLEN], newpath[MAXPATHLEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
	int replacing;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
	int error, expected_error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
	(void) mutex_lock(&ztest_shared->zs_vdev_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   932
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
	 * Decide whether to do an attach or a replace.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
	replacing = ztest_random(2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	 * Pick a random top-level vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
	top = ztest_random(rvd->vdev_children);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
	 * Pick a random leaf within it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
	leaf = ztest_random(leaves);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
	 * Generate the path to this leaf.  The filename will end with 'a'.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
	 * We'll alternate replacements with a filename that ends with 'b'.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   953
	(void) snprintf(oldpath, sizeof (oldpath),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
	    ztest_dev_template, zopt_dir, zopt_pool, top * leaves + leaf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   956
	bcopy(oldpath, newpath, MAXPATHLEN);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
	 * If the 'a' file isn't part of the pool, the 'b' file must be.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   961
	if (vdev_lookup_by_path(rvd, oldpath) == NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   962
		oldpath[strlen(oldpath) - 1] = 'b';
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
	else
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   964
		newpath[strlen(newpath) - 1] = 'b';
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   967
	 * Now oldpath represents something that's already in the pool,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   968
	 * and newpath is the thing we'll try to attach.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   970
	oldvd = vdev_lookup_by_path(rvd, oldpath);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   971
	newvd = vdev_lookup_by_path(rvd, newpath);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   972
	ASSERT(oldvd != NULL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   973
	pvd = oldvd->vdev_parent;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   976
	 * Make newsize a little bigger or smaller than oldsize.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
	 * If it's smaller, the attach should fail.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
	 * If it's larger, and we're doing a replace,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
	 * we should get dynamic LUN growth when we're done.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   981
	oldsize = vdev_get_rsize(oldvd);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   982
	newsize = 10 * oldsize / (9 + ztest_random(3));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
	 * If pvd is not a mirror or root, the attach should fail with ENOTSUP,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
	 * unless it's a replace; in that case any non-replacing parent is OK.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
	 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   988
	 * If newvd is already part of the pool, it should fail with EBUSY.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
	 *
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   990
	 * If newvd is too small, it should fail with EOVERFLOW.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
	 */
2174
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2113
diff changeset
   992
	if (newvd != NULL)
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2113
diff changeset
   993
		expected_error = EBUSY;
73de7a781492 6433717 offline devices should not be marked persistently unavailble
eschrock
parents: 2113
diff changeset
   994
	else if (pvd->vdev_ops != &vdev_mirror_ops &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
	    pvd->vdev_ops != &vdev_root_ops &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	    (!replacing || pvd->vdev_ops == &vdev_replacing_ops))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
		expected_error = ENOTSUP;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   998
	else if (newsize < oldsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
		expected_error = EOVERFLOW;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  1000
	else if (ashift > oldvd->vdev_top->vdev_ashift)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  1001
		expected_error = EDOM;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
		expected_error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1006
	 * If newvd isn't already part of the pool, create it.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1008
	if (newvd == NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1009
		fd = open(newpath, O_RDWR | O_CREAT | O_TRUNC, 0666);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
		if (fd == -1)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1011
			fatal(1, "can't open %s", newpath);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1012
		if (ftruncate(fd, newsize) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1013
			fatal(1, "can't ftruncate %s", newpath);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
		(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1017
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1020
	 * Build the nvlist describing newpath.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
	VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1024
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, newpath) == 0);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  1025
	VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
	VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
	VERIFY(nvlist_add_nvlist_array(root, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
	    &file, 1) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1032
	error = spa_vdev_attach(spa, oldvd->vdev_guid, root, replacing);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
	nvlist_free(file);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
	nvlist_free(root);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
	 * If our parent was the replacing vdev, but the replace completed,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
	 * then instead of failing with ENOTSUP we may either succeed,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
	 * fail with ENODEV, or fail with EOVERFLOW.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
	if (expected_error == ENOTSUP &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
	    (error == 0 || error == ENODEV || error == EOVERFLOW))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
		expected_error = error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
797
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  1046
	/*
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  1047
	 * If someone grew the LUN, the replacement may be too small.
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  1048
	 */
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  1049
	if (error == EOVERFLOW)
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  1050
		expected_error = error;
af56ba8b7e41 6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents: 789
diff changeset
  1051
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
	if (error != expected_error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
		fatal(0, "attach (%s, %s, %d) returned %d, expected %d",
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1054
		    oldpath, newpath, replacing, error, expected_error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
	(void) mutex_unlock(&ztest_shared->zs_vdev_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1060
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
 * Verify that dynamic LUN growth works as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
ztest_vdev_LUN_growth(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1067
	spa_t *spa = za->za_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
	char dev_name[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
	uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
	uint64_t vdev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
	size_t fsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
	(void) mutex_lock(&ztest_shared->zs_vdev_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
	 * Pick a random leaf vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1079
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	vdev = ztest_random(spa->spa_root_vdev->vdev_children * leaves);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1081
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
	(void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
	if ((fd = open(dev_name, O_RDWR)) != -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
		 * Determine the size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
		fsize = lseek(fd, 0, SEEK_END);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
		 * If it's less than 2x the original size, grow by around 3%.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
		if (fsize < 2 * zopt_vdev_size) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
			size_t newsize = fsize + ztest_random(fsize / 32);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
			(void) ftruncate(fd, newsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
			if (zopt_verbose >= 6) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
				(void) printf("%s grew from %lu to %lu bytes\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
				    dev_name, (ulong_t)fsize, (ulong_t)newsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
		(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
	(void) mutex_unlock(&ztest_shared->zs_vdev_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4527
diff changeset
  1110
ztest_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
	 * Create the directory object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
	VERIFY(dmu_object_claim(os, ZTEST_DIROBJ,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
	    DMU_OT_UINT64_OTHER, ZTEST_DIROBJ_BLOCKSIZE,
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1117
	    DMU_OT_UINT64_OTHER, 5 * sizeof (ztest_block_tag_t), tx) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
	VERIFY(zap_create_claim(os, ZTEST_MICROZAP_OBJ,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
	    DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
	VERIFY(zap_create_claim(os, ZTEST_FATZAP_OBJ,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
	    DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1125
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2174
diff changeset
  1126
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1127
ztest_destroy_cb(char *name, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1128
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1129
	ztest_args_t *za = arg;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
	objset_t *os;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1131
	dmu_object_info_t *doi = &za->za_doi;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
	 * Verify that the dataset contains a directory object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
	error = dmu_objset_open(name, DMU_OST_OTHER,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
	    DS_MODE_STANDARD | DS_MODE_READONLY, &os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
	ASSERT3U(error, ==, 0);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1140
	error = dmu_object_info(os, ZTEST_DIROBJ, doi);
1731
1efa8b3d1296 6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents: 1646
diff changeset
  1141
	if (error != ENOENT) {
1efa8b3d1296 6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents: 1646
diff changeset
  1142
		/* We could have crashed in the middle of destroying it */
1efa8b3d1296 6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents: 1646
diff changeset
  1143
		ASSERT3U(error, ==, 0);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1144
		ASSERT3U(doi->doi_type, ==, DMU_OT_UINT64_OTHER);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1145
		ASSERT3S(doi->doi_physical_blks, >=, 0);
1731
1efa8b3d1296 6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents: 1646
diff changeset
  1146
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
	dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
	 * Destroy the dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
	error = dmu_objset_destroy(name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
	ASSERT3U(error, ==, 0);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2174
diff changeset
  1154
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
 * Verify that dmu_objset_{create,destroy,open,close} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
static uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
ztest_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t object, int mode)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
	itx_t *itx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
	lr_create_t *lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
	size_t namesize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
	char name[24];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
	(void) sprintf(name, "ZOBJ_%llu", (u_longlong_t)object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
	namesize = strlen(name) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
	itx = zil_itx_create(TX_CREATE, sizeof (*lr) + namesize +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
	    ztest_random(ZIL_MAX_BLKSZ));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
	lr = (lr_create_t *)&itx->itx_lr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
	bzero(lr + 1, lr->lr_common.lrc_reclen - sizeof (*lr));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
	lr->lr_doid = object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
	lr->lr_foid = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
	lr->lr_mode = mode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
	lr->lr_uid = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
	lr->lr_gid = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
	lr->lr_gen = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
	lr->lr_crtime[0] = time(NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
	lr->lr_crtime[1] = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
	lr->lr_rdev = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
	bcopy(name, (char *)(lr + 1), namesize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
	return (zil_itx_assign(zilog, itx, tx));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
ztest_dmu_objset_create_destroy(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
	objset_t *os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
	char name[100];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
	int mode, basemode, expected_error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
	zilog_t *zilog;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
	uint64_t seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
	uint64_t objects;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
	ztest_replay_t zr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
	(void) rw_rdlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	(void) snprintf(name, 100, "%s/%s_temp_%llu", za->za_pool, za->za_pool,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
	    (u_longlong_t)za->za_instance);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	basemode = DS_MODE_LEVEL(za->za_instance);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
	if (basemode == DS_MODE_NONE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
		basemode++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
	 * If this dataset exists from a previous run, process its replay log
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
	 * half of the time.  If we don't replay it, then dmu_objset_destroy()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
	 * (invoked from ztest_destroy_cb() below) should just throw it away.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	if (ztest_random(2) == 0 &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
	    dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_PRIMARY, &os) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
		zr.zr_os = os;
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 2856
diff changeset
  1217
		zil_replay(os, &zr, &zr.zr_assign, ztest_replay_vector);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
		dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1221
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
	 * There may be an old instance of the dataset we're about to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
	 * create lying around from a previous run.  If so, destroy it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
	 * and all of its snapshots.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
	 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1226
	(void) dmu_objset_find(name, ztest_destroy_cb, za,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2237
diff changeset
  1227
	    DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
	 * Verify that the destroyed dataset is no longer in the namespace.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
	error = dmu_objset_open(name, DMU_OST_OTHER, basemode, &os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
	if (error != ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
		fatal(1, "dmu_objset_open(%s) found destroyed dataset %p",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
		    name, os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
	 * Verify that we can create a new dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
	 */
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 5994
diff changeset
  1240
	error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0,
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 5994
diff changeset
  1241
	    ztest_create_cb, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1243
		if (error == ENOSPC) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1244
			ztest_record_enospc("dmu_objset_create");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1245
			(void) rw_unlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1246
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1247
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
		fatal(0, "dmu_objset_create(%s) = %d", name, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
	error = dmu_objset_open(name, DMU_OST_OTHER, basemode, &os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1252
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
		fatal(0, "dmu_objset_open(%s) = %d", name, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1256
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1257
	 * Open the intent log for it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1258
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1259
	zilog = zil_open(os, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1261
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
	 * Put a random number of objects in there.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
	 */
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  1264
	objects = ztest_random(20);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1265
	seq = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
	while (objects-- != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
		uint64_t object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
		dmu_tx_t *tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
		dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, sizeof (name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1273
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
			object = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
			    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1276
			ztest_set_random_blocksize(os, object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
			seq = ztest_log_create(zilog, tx, object,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1278
			    DMU_OT_UINT64_OTHER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1279
			dmu_write(os, object, 0, sizeof (name), name, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1280
			dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1281
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1282
		if (ztest_random(5) == 0) {
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2417
diff changeset
  1283
			zil_commit(zilog, seq, object);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1284
		}
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  1285
		if (ztest_random(100) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1286
			error = zil_suspend(zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1287
			if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1288
				zil_resume(zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1289
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1290
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1293
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1294
	 * Verify that we cannot create an existing dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1295
	 */
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 5994
diff changeset
  1296
	error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1297
	if (error != EEXIST)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1298
		fatal(0, "created existing dataset, error = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1299
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1300
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1301
	 * Verify that multiple dataset opens are allowed, but only when
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1302
	 * the new access mode is compatible with the base mode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1303
	 * We use a mixture of typed and typeless opens, and when the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1304
	 * open succeeds, verify that the discovered type is correct.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1305
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
	for (mode = DS_MODE_STANDARD; mode < DS_MODE_LEVELS; mode++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1307
		objset_t *os2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
		error = dmu_objset_open(name, DMU_OST_OTHER, mode, &os2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1309
		expected_error = (basemode + mode < DS_MODE_LEVELS) ? 0 : EBUSY;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
		if (error != expected_error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
			fatal(0, "dmu_objset_open('%s') = %d, expected %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
			    name, error, expected_error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1313
		if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1314
			dmu_objset_close(os2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1315
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1317
	zil_close(zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
	dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
	error = dmu_objset_destroy(name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1321
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
		fatal(0, "dmu_objset_destroy(%s) = %d", name, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
	(void) rw_unlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1327
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1328
 * Verify that dmu_snapshot_{create,destroy,open,close} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1331
ztest_dmu_snapshot_create_destroy(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1333
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1334
	objset_t *os = za->za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1335
	char snapname[100];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
	char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
	(void) rw_rdlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
	dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1340
	(void) snprintf(snapname, 100, "%s@%llu", osname,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1341
	    (u_longlong_t)za->za_instance);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1342
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
	error = dmu_objset_destroy(snapname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1344
	if (error != 0 && error != ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
		fatal(0, "dmu_objset_destroy() = %d", error);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2174
diff changeset
  1346
	error = dmu_objset_snapshot(osname, strchr(snapname, '@')+1, FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1347
	if (error == ENOSPC)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1348
		ztest_record_enospc("dmu_take_snapshot");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
	else if (error != 0 && error != EEXIST)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1350
		fatal(0, "dmu_take_snapshot() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1351
	(void) rw_unlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1352
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1353
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1354
#define	ZTEST_TRAVERSE_BLOCKS	1000
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1355
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1356
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1357
ztest_blk_cb(traverse_blk_cache_t *bc, spa_t *spa, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1358
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
	ztest_args_t *za = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
	zbookmark_t *zb = &bc->bc_bookmark;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
	blkptr_t *bp = &bc->bc_blkptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
	dnode_phys_t *dnp = bc->bc_dnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
	traverse_handle_t *th = za->za_th;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
	uint64_t size = BP_GET_LSIZE(bp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1365
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1366
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1367
	 * Level -1 indicates the objset_phys_t or something in its intent log.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1368
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1369
	if (zb->zb_level == -1) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1370
		if (BP_GET_TYPE(bp) == DMU_OT_OBJSET) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1371
			ASSERT3U(zb->zb_object, ==, 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1372
			ASSERT3U(zb->zb_blkid, ==, 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1373
			ASSERT3U(size, ==, sizeof (objset_phys_t));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1374
			za->za_zil_seq = 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1375
		} else if (BP_GET_TYPE(bp) == DMU_OT_INTENT_LOG) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1376
			ASSERT3U(zb->zb_object, ==, 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1377
			ASSERT3U(zb->zb_blkid, >, za->za_zil_seq);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1378
			za->za_zil_seq = zb->zb_blkid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1379
		} else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1380
			ASSERT3U(zb->zb_object, !=, 0);	/* lr_write_t */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1381
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1382
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1383
		return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1384
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1385
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1386
	ASSERT(dnp != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
	if (bc->bc_errno)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
		return (ERESTART);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1392
	 * Once in a while, abort the traverse.   We only do this to odd
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
	 * instance numbers to ensure that even ones can run to completion.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1395
	if ((za->za_instance & 1) && ztest_random(10000) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1396
		return (EINTR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
	if (bp->blk_birth == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
		ASSERT(th->th_advance & ADVANCE_HOLES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1400
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1401
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1402
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
	if (zb->zb_level == 0 && !(th->th_advance & ADVANCE_DATA) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
	    bc == &th->th_cache[ZB_DN_CACHE][0]) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
		ASSERT(bc->bc_data == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
	ASSERT(bc->bc_data != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
	 * This is an expensive question, so don't ask it too often.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
	if (((za->za_random ^ th->th_callbacks) & 0xff) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1415
		void *xbuf = umem_alloc(size, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1416
		if (arc_tryread(spa, bp, xbuf) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
			ASSERT(bcmp(bc->bc_data, xbuf, size) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1419
		umem_free(xbuf, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
	if (zb->zb_level > 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
		ASSERT3U(size, ==, 1ULL << dnp->dn_indblkshift);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
	ASSERT(zb->zb_level == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
	ASSERT3U(size, ==, dnp->dn_datablkszsec << DEV_BSHIFT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1431
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
 * Verify that live pool traversal works.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
ztest_traverse(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1438
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1439
	spa_t *spa = za->za_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
	traverse_handle_t *th = za->za_th;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1441
	int rc, advance;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
	uint64_t cbstart, cblimit;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
	if (th == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1445
		advance = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1447
		if (ztest_random(2) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1448
			advance |= ADVANCE_PRE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1449
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1450
		if (ztest_random(2) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
			advance |= ADVANCE_PRUNE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
		if (ztest_random(2) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
			advance |= ADVANCE_DATA;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
		if (ztest_random(2) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1457
			advance |= ADVANCE_HOLES;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1458
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1459
		if (ztest_random(2) == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1460
			advance |= ADVANCE_ZIL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1461
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1462
		th = za->za_th = traverse_init(spa, ztest_blk_cb, za, advance,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1463
		    ZIO_FLAG_CANFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
		traverse_add_pool(th, 0, -1ULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1467
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1468
	advance = th->th_advance;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
	cbstart = th->th_callbacks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1470
	cblimit = cbstart + ((advance & ADVANCE_DATA) ? 100 : 1000);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1471
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
	while ((rc = traverse_more(th)) == EAGAIN && th->th_callbacks < cblimit)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1473
		continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1474
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1475
	if (zopt_verbose >= 5)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1476
		(void) printf("traverse %s%s%s%s %llu blocks to "
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1477
		    "<%llu, %llu, %lld, %llx>%s\n",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
		    (advance & ADVANCE_PRE) ? "pre" : "post",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
		    (advance & ADVANCE_PRUNE) ? "|prune" : "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1480
		    (advance & ADVANCE_DATA) ? "|data" : "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1481
		    (advance & ADVANCE_HOLES) ? "|holes" : "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1482
		    (u_longlong_t)(th->th_callbacks - cbstart),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
		    (u_longlong_t)th->th_lastcb.zb_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
		    (u_longlong_t)th->th_lastcb.zb_object,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1485
		    (u_longlong_t)th->th_lastcb.zb_level,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
		    (u_longlong_t)th->th_lastcb.zb_blkid,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
		    rc == 0 ? " [done]" :
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
		    rc == EINTR ? " [aborted]" :
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
		    rc == EAGAIN ? "" :
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
		    strerror(rc));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
	if (rc != EAGAIN) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
		if (rc != 0 && rc != EINTR)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
			fatal(0, "traverse_more(%p) = %d", th, rc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
		traverse_fini(th);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
		za->za_th = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
 * Verify that dmu_object_{alloc,free} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
ztest_dmu_object_alloc_free(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
	objset_t *os = za->za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
	dmu_buf_t *db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
	uint64_t batchobj, object, batchsize, endoff, temp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
	int b, c, error, bonuslen;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1511
	dmu_object_info_t *doi = &za->za_doi;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1512
	char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
	dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
	endoff = -8ULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
	batchsize = 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1520
	 * Create a batch object if necessary, and record it in the directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1521
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1522
	VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1523
	    sizeof (uint64_t), &batchobj));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1524
	if (batchobj == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1525
		tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1526
		dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1527
		    sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1528
		dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1529
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1530
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1531
			ztest_record_enospc("create a batch object");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1532
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1533
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1534
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1535
		batchobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
		    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1537
		ztest_set_random_blocksize(os, batchobj, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1538
		dmu_write(os, ZTEST_DIROBJ, za->za_diroff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1539
		    sizeof (uint64_t), &batchobj, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1540
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1541
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1542
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1544
	 * Destroy the previous batch of objects.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1545
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1546
	for (b = 0; b < batchsize; b++) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1547
		VERIFY(0 == dmu_read(os, batchobj, b * sizeof (uint64_t),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1548
		    sizeof (uint64_t), &object));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
		if (object == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1550
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1551
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1552
		 * Read and validate contents.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1553
		 * We expect the nth byte of the bonus buffer to be n.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1554
		 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1555
		VERIFY(0 == dmu_bonus_hold(os, object, FTAG, &db));
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1556
		za->za_dbuf = db;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1557
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1558
		dmu_object_info_from_db(db, doi);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1559
		ASSERT(doi->doi_type == DMU_OT_UINT64_OTHER);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1560
		ASSERT(doi->doi_bonus_type == DMU_OT_PLAIN_OTHER);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1561
		ASSERT3S(doi->doi_physical_blks, >=, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1562
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1563
		bonuslen = doi->doi_bonus_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
		for (c = 0; c < bonuslen; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
			if (((uint8_t *)db->db_data)[c] !=
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
			    (uint8_t)(c + bonuslen)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
				fatal(0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
				    "bad bonus: %s, obj %llu, off %d: %u != %u",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
				    osname, object, c,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
				    ((uint8_t *)db->db_data)[c],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
				    (uint8_t)(c + bonuslen));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1576
		dmu_buf_rele(db, FTAG);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1577
		za->za_dbuf = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
		 * We expect the word at endoff to be our object number.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
		 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1582
		VERIFY(0 == dmu_read(os, object, endoff,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1583
		    sizeof (uint64_t), &temp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
		if (temp != object) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
			fatal(0, "bad data in %s, got %llu, expected %llu",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
			    osname, temp, object);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
		 * Destroy old object and clear batch entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
		tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1594
		dmu_tx_hold_write(tx, batchobj,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
		    b * sizeof (uint64_t), sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
		dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
			ztest_record_enospc("free object");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1603
		error = dmu_object_free(os, object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1604
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1605
			fatal(0, "dmu_object_free('%s', %llu) = %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1606
			    osname, object, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1608
		object = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1609
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1610
		dmu_object_set_checksum(os, batchobj,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
		    ztest_random_checksum(), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
		dmu_object_set_compress(os, batchobj,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
		    ztest_random_compress(), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
		dmu_write(os, batchobj, b * sizeof (uint64_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
		    sizeof (uint64_t), &object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
	 * Before creating the new batch of objects, generate a bunch of churn.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
	for (b = ztest_random(100); b > 0; b--) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1625
		tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1626
		dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1628
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
			ztest_record_enospc("churn objects");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
		object = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1634
		    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1635
		ztest_set_random_blocksize(os, object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1636
		error = dmu_object_free(os, object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
			fatal(0, "dmu_object_free('%s', %llu) = %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
			    osname, object, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	 * Create a new batch of objects with randomly chosen
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
	 * blocksizes and record them in the batch directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
	for (b = 0; b < batchsize; b++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1649
		uint32_t va_blksize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
		u_longlong_t va_nblocks;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1651
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
		tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1653
		dmu_tx_hold_write(tx, batchobj, b * sizeof (uint64_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
		    sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1655
		dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1656
		dmu_tx_hold_write(tx, DMU_NEW_OBJECT, endoff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1657
		    sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1658
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1660
			ztest_record_enospc("create batchobj");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1661
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1662
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1663
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1664
		bonuslen = (int)ztest_random(dmu_bonus_max()) + 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1665
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1666
		object = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
		    DMU_OT_PLAIN_OTHER, bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1669
		ztest_set_random_blocksize(os, object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1670
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1671
		dmu_object_set_checksum(os, object,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1672
		    ztest_random_checksum(), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1673
		dmu_object_set_compress(os, object,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1674
		    ztest_random_compress(), tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1675
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1676
		dmu_write(os, batchobj, b * sizeof (uint64_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
		    sizeof (uint64_t), &object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1678
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1680
		 * Write to both the bonus buffer and the regular data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1681
		 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1682
		VERIFY(dmu_bonus_hold(os, object, FTAG, &db) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1683
		za->za_dbuf = db;
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4808
diff changeset
  1684
		ASSERT3U(bonuslen, <=, db->db_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1685
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1686
		dmu_object_size_from_db(db, &va_blksize, &va_nblocks);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1687
		ASSERT3S(va_nblocks, >=, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1689
		dmu_buf_will_dirty(db, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
		 * See comments above regarding the contents of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
		 * the bonus buffer and the word at endoff.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
		 */
4944
96d96f8de974 6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents: 4808
diff changeset
  1695
		for (c = 0; c < bonuslen; c++)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1696
			((uint8_t *)db->db_data)[c] = (uint8_t)(c + bonuslen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1697
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1698
		dmu_buf_rele(db, FTAG);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1699
		za->za_dbuf = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1700
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1701
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1702
		 * Write to a large offset to increase indirection.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1703
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
		dmu_write(os, object, endoff, sizeof (uint64_t), &object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1705
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1706
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1708
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1711
 * Verify that dmu_{read,write} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1712
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1713
typedef struct bufwad {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1714
	uint64_t	bw_index;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1715
	uint64_t	bw_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
	uint64_t	bw_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1717
} bufwad_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
typedef struct dmu_read_write_dir {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
	uint64_t	dd_packobj;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
	uint64_t	dd_bigobj;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
	uint64_t	dd_chunk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
} dmu_read_write_dir_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
ztest_dmu_read_write(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1728
	objset_t *os = za->za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
	dmu_read_write_dir_t dd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1730
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1731
	int i, freeit, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1732
	uint64_t n, s, txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
	bufwad_t *packbuf, *bigbuf, *pack, *bigH, *bigT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1734
	uint64_t packoff, packsize, bigoff, bigsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
	uint64_t regions = 997;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
	uint64_t stride = 123456789ULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
	uint64_t width = 40;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1738
	int free_percent = 5;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1739
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1740
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
	 * This test uses two objects, packobj and bigobj, that are always
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
	 * updated together (i.e. in the same tx) so that their contents are
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
	 * in sync and can be compared.  Their contents relate to each other
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1744
	 * in a simple way: packobj is a dense array of 'bufwad' structures,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1745
	 * while bigobj is a sparse array of the same bufwads.  Specifically,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1746
	 * for any index n, there are three bufwads that should be identical:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1747
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1748
	 *	packobj, at offset n * sizeof (bufwad_t)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1749
	 *	bigobj, at the head of the nth chunk
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1750
	 *	bigobj, at the tail of the nth chunk
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1751
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1752
	 * The chunk size is arbitrary. It doesn't have to be a power of two,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1753
	 * and it doesn't have any relation to the object blocksize.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1754
	 * The only requirement is that it can hold at least two bufwads.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1755
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1756
	 * Normally, we write the bufwad to each of these locations.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1757
	 * However, free_percent of the time we instead write zeroes to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1758
	 * packobj and perform a dmu_free_range() on bigobj.  By comparing
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1759
	 * bigobj to packobj, we can verify that the DMU is correctly
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1760
	 * tracking which parts of an object are allocated and free,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1761
	 * and that the contents of the allocated blocks are correct.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1762
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1764
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1765
	 * Read the directory info.  If it's the first time, set things up.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1766
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1767
	VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1768
	    sizeof (dd), &dd));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1769
	if (dd.dd_chunk == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1770
		ASSERT(dd.dd_packobj == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1771
		ASSERT(dd.dd_bigobj == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1772
		tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1773
		dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (dd));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1774
		dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1775
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1776
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1777
			ztest_record_enospc("create r/w directory");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1779
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1780
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1781
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
		dd.dd_packobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1783
		    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1784
		dd.dd_bigobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1785
		    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1786
		dd.dd_chunk = (1000 + ztest_random(1000)) * sizeof (uint64_t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1787
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1788
		ztest_set_random_blocksize(os, dd.dd_packobj, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1789
		ztest_set_random_blocksize(os, dd.dd_bigobj, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1790
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
		dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (dd), &dd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1792
		    tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1793
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1794
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1797
	 * Prefetch a random chunk of the big object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1798
	 * Our aim here is to get some async reads in flight
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1799
	 * for blocks that we may free below; the DMU should
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
	 * handle this race correctly.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1801
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1802
	n = ztest_random(regions) * stride + ztest_random(width);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1803
	s = 1 + ztest_random(2 * width - 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1804
	dmu_prefetch(os, dd.dd_bigobj, n * dd.dd_chunk, s * dd.dd_chunk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1805
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1806
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1807
	 * Pick a random index and compute the offsets into packobj and bigobj.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1808
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1809
	n = ztest_random(regions) * stride + ztest_random(width);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1810
	s = 1 + ztest_random(width - 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1811
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1812
	packoff = n * sizeof (bufwad_t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1813
	packsize = s * sizeof (bufwad_t);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1814
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
	bigoff = n * dd.dd_chunk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1816
	bigsize = s * dd.dd_chunk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1817
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1818
	packbuf = umem_alloc(packsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1819
	bigbuf = umem_alloc(bigsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1820
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	 * free_percent of the time, free a range of bigobj rather than
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
	 * overwriting it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
	freeit = (ztest_random(100) < free_percent);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
	 * Read the current contents of our objects.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1830
	error = dmu_read(os, dd.dd_packobj, packoff, packsize, packbuf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1831
	ASSERT3U(error, ==, 0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1832
	error = dmu_read(os, dd.dd_bigobj, bigoff, bigsize, bigbuf);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1833
	ASSERT3U(error, ==, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1834
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1835
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1836
	 * Get a tx for the mods to both packobj and bigobj.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1837
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1838
	tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1839
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
	dmu_tx_hold_write(tx, dd.dd_packobj, packoff, packsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
	if (freeit)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1843
		dmu_tx_hold_free(tx, dd.dd_bigobj, bigoff, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1844
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1845
		dmu_tx_hold_write(tx, dd.dd_bigobj, bigoff, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1846
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1847
	error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1848
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1849
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
		ztest_record_enospc("dmu r/w range");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1851
		dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1852
		umem_free(packbuf, packsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1853
		umem_free(bigbuf, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1854
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1855
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1857
	txg = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1859
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1860
	 * For each index from n to n + s, verify that the existing bufwad
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
	 * in packobj matches the bufwads at the head and tail of the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
	 * corresponding chunk in bigobj.  Then update all three bufwads
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
	 * with the new values we want to write out.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1864
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1865
	for (i = 0; i < s; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
		/* LINTED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1867
		pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
		/* LINTED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1869
		bigH = (bufwad_t *)((char *)bigbuf + i * dd.dd_chunk);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1870
		/* LINTED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1871
		bigT = (bufwad_t *)((char *)bigH + dd.dd_chunk) - 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1872
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1873
		ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1874
		ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1875
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1876
		if (pack->bw_txg > txg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1877
			fatal(0, "future leak: got %llx, open txg is %llx",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1878
			    pack->bw_txg, txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1879
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1880
		if (pack->bw_data != 0 && pack->bw_index != n + i)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1881
			fatal(0, "wrong index: got %llx, wanted %llx+%llx",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1882
			    pack->bw_index, n, i);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1883
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1884
		if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1885
			fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1886
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1887
		if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
			fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1889
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1890
		if (freeit) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1891
			bzero(pack, sizeof (bufwad_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1892
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1893
			pack->bw_index = n + i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1894
			pack->bw_txg = txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1895
			pack->bw_data = 1 + ztest_random(-2ULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1896
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1897
		*bigH = *pack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1898
		*bigT = *pack;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1899
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1900
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1901
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1902
	 * We've verified all the old bufwads, and made new ones.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1903
	 * Now write them out.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1904
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1905
	dmu_write(os, dd.dd_packobj, packoff, packsize, packbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1906
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1907
	if (freeit) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1908
		if (zopt_verbose >= 6) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1909
			(void) printf("freeing offset %llx size %llx"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1910
			    " txg %llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1911
			    (u_longlong_t)bigoff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1912
			    (u_longlong_t)bigsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1913
			    (u_longlong_t)txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1914
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1915
		VERIFY(0 == dmu_free_range(os, dd.dd_bigobj, bigoff,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1916
		    bigsize, tx));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1917
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1918
		if (zopt_verbose >= 6) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1919
			(void) printf("writing offset %llx size %llx"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1920
			    " txg %llx\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1921
			    (u_longlong_t)bigoff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1922
			    (u_longlong_t)bigsize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1923
			    (u_longlong_t)txg);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1924
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1925
		dmu_write(os, dd.dd_bigobj, bigoff, bigsize, bigbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1926
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1927
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1928
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1929
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1930
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1931
	 * Sanity check the stuff we just wrote.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1932
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1933
	{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1934
		void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1935
		void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1936
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1937
		VERIFY(0 == dmu_read(os, dd.dd_packobj, packoff,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1938
		    packsize, packcheck));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1939
		VERIFY(0 == dmu_read(os, dd.dd_bigobj, bigoff,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1940
		    bigsize, bigcheck));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1941
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1942
		ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1943
		ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1944
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1945
		umem_free(packcheck, packsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1946
		umem_free(bigcheck, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1947
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1948
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1949
	umem_free(packbuf, packsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1950
	umem_free(bigbuf, bigsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1951
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1952
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1953
void
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1954
ztest_dmu_check_future_leak(ztest_args_t *za)
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1955
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1956
	objset_t *os = za->za_os;
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1957
	dmu_buf_t *db;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1958
	ztest_block_tag_t *bt;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1959
	dmu_object_info_t *doi = &za->za_doi;
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1960
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1961
	/*
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1962
	 * Make sure that, if there is a write record in the bonus buffer
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1963
	 * of the ZTEST_DIROBJ, that the txg for this record is <= the
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1964
	 * last synced txg of the pool.
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1965
	 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1966
	VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &db) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1967
	za->za_dbuf = db;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1968
	VERIFY(dmu_object_info(os, ZTEST_DIROBJ, doi) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1969
	ASSERT3U(doi->doi_bonus_size, >=, sizeof (*bt));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1970
	ASSERT3U(doi->doi_bonus_size, <=, db->db_size);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1971
	ASSERT3U(doi->doi_bonus_size % sizeof (*bt), ==, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1972
	bt = (void *)((char *)db->db_data + doi->doi_bonus_size - sizeof (*bt));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1973
	if (bt->bt_objset != 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1974
		ASSERT3U(bt->bt_objset, ==, dmu_objset_id(os));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1975
		ASSERT3U(bt->bt_object, ==, ZTEST_DIROBJ);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1976
		ASSERT3U(bt->bt_offset, ==, -1ULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1977
		ASSERT3U(bt->bt_txg, <, spa_first_txg(za->za_spa));
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1978
	}
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1979
	dmu_buf_rele(db, FTAG);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1980
	za->za_dbuf = NULL;
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1981
}
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1982
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  1983
void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1984
ztest_dmu_write_parallel(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1985
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1986
	objset_t *os = za->za_os;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1987
	ztest_block_tag_t *rbt = &za->za_rbt;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1988
	ztest_block_tag_t *wbt = &za->za_wbt;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1989
	const size_t btsize = sizeof (ztest_block_tag_t);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1990
	dmu_buf_t *db;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1991
	int b, error;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1992
	int bs = ZTEST_DIROBJ_BLOCKSIZE;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1993
	int do_free = 0;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1994
	uint64_t off, txg_how;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1995
	mutex_t *lp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1996
	char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1997
	char iobuf[SPA_MAXBLOCKSIZE];
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1998
	blkptr_t blk = { 0 };
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1999
	uint64_t blkoff;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2000
	zbookmark_t zb;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2001
	dmu_tx_t *tx = dmu_tx_create(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2002
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2003
	dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2004
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2005
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2006
	 * Have multiple threads write to large offsets in ZTEST_DIROBJ
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2007
	 * to verify that having multiple threads writing to the same object
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2008
	 * in parallel doesn't cause any trouble.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2009
	 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2010
	if (ztest_random(4) == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2011
		/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2012
		 * Do the bonus buffer instead of a regular block.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2013
		 * We need a lock to serialize resize vs. others,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2014
		 * so we hash on the objset ID.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2015
		 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2016
		b = dmu_objset_id(os) % ZTEST_SYNC_LOCKS;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2017
		off = -1ULL;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2018
		dmu_tx_hold_bonus(tx, ZTEST_DIROBJ);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2019
	} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2020
		b = ztest_random(ZTEST_SYNC_LOCKS);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2021
		off = za->za_diroff_shared + (b << SPA_MAXBLOCKSHIFT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
		if (ztest_random(4) == 0) {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2023
			do_free = 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
			dmu_tx_hold_free(tx, ZTEST_DIROBJ, off, bs);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2025
		} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
			dmu_tx_hold_write(tx, ZTEST_DIROBJ, off, bs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2028
	}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2029
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2030
	txg_how = ztest_random(2) == 0 ? TXG_WAIT : TXG_NOWAIT;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2031
	error = dmu_tx_assign(tx, txg_how);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2032
	if (error) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2033
		if (error == ERESTART) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2034
			ASSERT(txg_how == TXG_NOWAIT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2035
			dmu_tx_wait(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2036
		} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2037
			ztest_record_enospc("dmu write parallel");
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2038
		}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2039
		dmu_tx_abort(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2040
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2041
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2042
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2043
	lp = &ztest_shared->zs_sync_lock[b];
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2044
	(void) mutex_lock(lp);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2045
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2046
	wbt->bt_objset = dmu_objset_id(os);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2047
	wbt->bt_object = ZTEST_DIROBJ;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2048
	wbt->bt_offset = off;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2049
	wbt->bt_txg = dmu_tx_get_txg(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2050
	wbt->bt_thread = za->za_instance;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2051
	wbt->bt_seq = ztest_shared->zs_seq[b]++;	/* protected by lp */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2052
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2053
	if (off == -1ULL) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2054
		dmu_object_info_t *doi = &za->za_doi;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2055
		char *dboff;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2056
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2057
		VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &db) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2058
		za->za_dbuf = db;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2059
		dmu_object_info_from_db(db, doi);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2060
		ASSERT3U(doi->doi_bonus_size, <=, db->db_size);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2061
		ASSERT3U(doi->doi_bonus_size, >=, btsize);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2062
		ASSERT3U(doi->doi_bonus_size % btsize, ==, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2063
		dboff = (char *)db->db_data + doi->doi_bonus_size - btsize;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2064
		bcopy(dboff, rbt, btsize);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2065
		if (rbt->bt_objset != 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2066
			ASSERT3U(rbt->bt_objset, ==, wbt->bt_objset);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2067
			ASSERT3U(rbt->bt_object, ==, wbt->bt_object);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2068
			ASSERT3U(rbt->bt_offset, ==, wbt->bt_offset);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2069
			ASSERT3U(rbt->bt_txg, <=, wbt->bt_txg);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2070
		}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2071
		if (ztest_random(10) == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2072
			int newsize = (ztest_random(db->db_size /
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2073
			    btsize) + 1) * btsize;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2074
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2075
			ASSERT3U(newsize, >=, btsize);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2076
			ASSERT3U(newsize, <=, db->db_size);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2077
			VERIFY3U(dmu_set_bonus(db, newsize, tx), ==, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2078
			dboff = (char *)db->db_data + newsize - btsize;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2079
		}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2080
		dmu_buf_will_dirty(db, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2081
		bcopy(wbt, dboff, btsize);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2082
		dmu_buf_rele(db, FTAG);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2083
		za->za_dbuf = NULL;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2084
	} else if (do_free) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2085
		VERIFY(dmu_free_range(os, ZTEST_DIROBJ, off, bs, tx) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2086
	} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2087
		dmu_write(os, ZTEST_DIROBJ, off, btsize, wbt, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2088
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2089
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2090
	(void) mutex_unlock(lp);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2091
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2092
	if (ztest_random(1000) == 0)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2093
		(void) poll(NULL, 0, 1); /* open dn_notxholds window */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2094
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2095
	dmu_tx_commit(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2096
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2097
	if (ztest_random(10000) == 0)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2098
		txg_wait_synced(dmu_objset_pool(os), wbt->bt_txg);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2099
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2100
	if (off == -1 || do_free)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2101
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2102
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2103
	if (ztest_random(2) != 0)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2104
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2105
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2106
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2107
	 * dmu_sync() the block we just wrote.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2108
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2109
	(void) mutex_lock(lp);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2110
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2111
	blkoff = P2ALIGN_TYPED(off, bs, uint64_t);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2112
	error = dmu_buf_hold(os, ZTEST_DIROBJ, blkoff, FTAG, &db);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2113
	za->za_dbuf = db;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2114
	if (error) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2115
		dprintf("dmu_buf_hold(%s, %d, %llx) = %d\n",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2116
		    osname, ZTEST_DIROBJ, blkoff, error);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2117
		(void) mutex_unlock(lp);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2118
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2119
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2120
	blkoff = off - blkoff;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2121
	error = dmu_sync(NULL, db, &blk, wbt->bt_txg, NULL, NULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2122
	dmu_buf_rele(db, FTAG);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2123
	za->za_dbuf = NULL;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2124
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2125
	(void) mutex_unlock(lp);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2126
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2127
	if (error) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2128
		dprintf("dmu_sync(%s, %d, %llx) = %d\n",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2129
		    osname, ZTEST_DIROBJ, off, error);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2130
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2131
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2132
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2133
	if (blk.blk_birth == 0)		/* concurrent free */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2134
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2135
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2136
	txg_suspend(dmu_objset_pool(os));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2137
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2138
	ASSERT(blk.blk_fill == 1);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2139
	ASSERT3U(BP_GET_TYPE(&blk), ==, DMU_OT_UINT64_OTHER);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2140
	ASSERT3U(BP_GET_LEVEL(&blk), ==, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2141
	ASSERT3U(BP_GET_LSIZE(&blk), ==, bs);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2142
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2143
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2144
	 * Read the block that dmu_sync() returned to make sure its contents
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2145
	 * match what we wrote.  We do this while still txg_suspend()ed
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2146
	 * to ensure that the block can't be reused before we read it.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2147
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2148
	zb.zb_objset = dmu_objset_id(os);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2149
	zb.zb_object = ZTEST_DIROBJ;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2150
	zb.zb_level = 0;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2151
	zb.zb_blkid = off / bs;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2152
	error = zio_wait(zio_read(NULL, za->za_spa, &blk, iobuf, bs,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2153
	    NULL, NULL, ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_MUSTSUCCEED, &zb));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2154
	ASSERT3U(error, ==, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2155
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2156
	txg_resume(dmu_objset_pool(os));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2157
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2158
	bcopy(&iobuf[blkoff], rbt, btsize);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2159
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2160
	if (rbt->bt_objset == 0)		/* concurrent free */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2161
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2162
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2163
	ASSERT3U(rbt->bt_objset, ==, wbt->bt_objset);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2164
	ASSERT3U(rbt->bt_object, ==, wbt->bt_object);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2165
	ASSERT3U(rbt->bt_offset, ==, wbt->bt_offset);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2166
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2167
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2168
	 * The semantic of dmu_sync() is that we always push the most recent
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2169
	 * version of the data, so in the face of concurrent updates we may
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2170
	 * see a newer version of the block.  That's OK.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2171
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2172
	ASSERT3U(rbt->bt_txg, >=, wbt->bt_txg);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2173
	if (rbt->bt_thread == wbt->bt_thread)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2174
		ASSERT3U(rbt->bt_seq, ==, wbt->bt_seq);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2175
	else
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2176
		ASSERT3U(rbt->bt_seq, >, wbt->bt_seq);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2178
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2179
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
 * Verify that zap_{create,destroy,add,remove,update} work as expected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2182
#define	ZTEST_ZAP_MIN_INTS	1
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
#define	ZTEST_ZAP_MAX_INTS	4
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2184
#define	ZTEST_ZAP_MAX_PROPS	1000
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2185
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2186
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2187
ztest_zap(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2188
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2189
	objset_t *os = za->za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
	uint64_t object;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2191
	uint64_t txg, last_txg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2192
	uint64_t value[ZTEST_ZAP_MAX_INTS];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2193
	uint64_t zl_ints, zl_intsize, prop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2194
	int i, ints;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2195
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2196
	char propname[100], txgname[100];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2197
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2198
	char osname[MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2199
	char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2200
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2201
	dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2202
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2203
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2204
	 * Create a new object if necessary, and record it in the directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2205
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2206
	VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2207
	    sizeof (uint64_t), &object));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2209
	if (object == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2210
		tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
		dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2212
		    sizeof (uint64_t));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2213
		dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
			ztest_record_enospc("create zap test obj");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2218
			return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2219
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2220
		object = zap_create(os, DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2221
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2222
			fatal(0, "zap_create('%s', %llu) = %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2223
			    osname, object, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2224
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2225
		ASSERT(object != 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2226
		dmu_write(os, ZTEST_DIROBJ, za->za_diroff,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2227
		    sizeof (uint64_t), &object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2228
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2229
		 * Generate a known hash collision, and verify that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2230
		 * we can lookup and remove both entries.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2231
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2232
		for (i = 0; i < 2; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2233
			value[i] = i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2234
			error = zap_add(os, object, hc[i], sizeof (uint64_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2235
			    1, &value[i], tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
			ASSERT3U(error, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2237
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
		for (i = 0; i < 2; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2239
			error = zap_add(os, object, hc[i], sizeof (uint64_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2240
			    1, &value[i], tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2241
			ASSERT3U(error, ==, EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2242
			error = zap_length(os, object, hc[i],
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2243
			    &zl_intsize, &zl_ints);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2244
			ASSERT3U(error, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2245
			ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
			ASSERT3U(zl_ints, ==, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
		for (i = 0; i < 2; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
			error = zap_remove(os, object, hc[i], tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2250
			ASSERT3U(error, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2251
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2253
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2254
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2256
	ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2257
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2258
	prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2259
	(void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2260
	(void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2261
	bzero(value, sizeof (value));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2262
	last_txg = 0;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2263
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2264
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2265
	 * If these zap entries already exist, validate their contents.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2266
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2267
	error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2268
	if (error == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2269
		ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2270
		ASSERT3U(zl_ints, ==, 1);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2271
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2272
		VERIFY(zap_lookup(os, object, txgname, zl_intsize,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2273
		    zl_ints, &last_txg) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2274
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2275
		VERIFY(zap_length(os, object, propname, &zl_intsize,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2276
		    &zl_ints) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2277
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2278
		ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2279
		ASSERT3U(zl_ints, ==, ints);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2280
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2281
		VERIFY(zap_lookup(os, object, propname, zl_intsize,
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2282
		    zl_ints, value) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2283
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2284
		for (i = 0; i < ints; i++) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2285
			ASSERT3U(value[i], ==, last_txg + object + i);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2286
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2287
	} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2288
		ASSERT3U(error, ==, ENOENT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2289
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2290
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2291
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2292
	 * Atomically update two entries in our zap object.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2293
	 * The first is named txg_%llu, and contains the txg
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2294
	 * in which the property was last updated.  The second
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2295
	 * is named prop_%llu, and the nth element of its value
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2296
	 * should be txg + object + n.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2297
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2298
	tx = dmu_tx_create(os);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2299
	dmu_tx_hold_zap(tx, object, TRUE, NULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2300
	error = dmu_tx_assign(tx, TXG_WAIT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2301
	if (error) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2302
		ztest_record_enospc("create zap entry");
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2303
		dmu_tx_abort(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2304
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2305
	}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2306
	txg = dmu_tx_get_txg(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2307
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2308
	if (last_txg > txg)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2309
		fatal(0, "zap future leak: old %llu new %llu", last_txg, txg);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2310
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2311
	for (i = 0; i < ints; i++)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2312
		value[i] = txg + object + i;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2313
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2314
	error = zap_update(os, object, txgname, sizeof (uint64_t), 1, &txg, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2315
	if (error)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2316
		fatal(0, "zap_update('%s', %llu, '%s') = %d",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2317
		    osname, object, txgname, error);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2318
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2319
	error = zap_update(os, object, propname, sizeof (uint64_t),
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2320
	    ints, value, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2321
	if (error)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2322
		fatal(0, "zap_update('%s', %llu, '%s') = %d",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2323
		    osname, object, propname, error);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2324
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2325
	dmu_tx_commit(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2326
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2327
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2328
	 * Remove a random pair of entries.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2329
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2330
	prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2331
	(void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2332
	(void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2333
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2334
	error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2335
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2336
	if (error == ENOENT)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2337
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2338
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2339
	ASSERT3U(error, ==, 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2340
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2341
	tx = dmu_tx_create(os);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2342
	dmu_tx_hold_zap(tx, object, TRUE, NULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2343
	error = dmu_tx_assign(tx, TXG_WAIT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2344
	if (error) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2345
		ztest_record_enospc("remove zap entry");
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2346
		dmu_tx_abort(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2347
		return;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2348
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2349
	error = zap_remove(os, object, txgname, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2350
	if (error)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2351
		fatal(0, "zap_remove('%s', %llu, '%s') = %d",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2352
		    osname, object, txgname, error);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2353
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2354
	error = zap_remove(os, object, propname, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2355
	if (error)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2356
		fatal(0, "zap_remove('%s', %llu, '%s') = %d",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2357
		    osname, object, propname, error);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2358
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2359
	dmu_tx_commit(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2360
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
	 * Once in a while, destroy the object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2363
	 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2364
	if (ztest_random(1000) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2365
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2366
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2367
	tx = dmu_tx_create(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2368
	dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2369
	dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2370
	error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2371
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
		ztest_record_enospc("destroy zap object");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
		dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2374
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2375
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2376
	error = zap_destroy(os, object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2377
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2378
		fatal(0, "zap_destroy('%s', %llu) = %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2379
		    osname, object, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2380
	object = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2381
	dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2382
	    &object, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2383
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2384
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2385
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2386
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2387
ztest_zap_parallel(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2388
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2389
	objset_t *os = za->za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2390
	uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2391
	dmu_tx_t *tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2392
	int i, namelen, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2393
	char name[20], string_value[20];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2394
	void *data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2395
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2396
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2397
	 * Generate a random name of the form 'xxx.....' where each
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2398
	 * x is a random printable character and the dots are dots.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2399
	 * There are 94 such characters, and the name length goes from
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2400
	 * 6 to 20, so there are 94^3 * 15 = 12,458,760 possible names.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2401
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2402
	namelen = ztest_random(sizeof (name) - 5) + 5 + 1;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2403
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2404
	for (i = 0; i < 3; i++)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2405
		name[i] = '!' + ztest_random('~' - '!' + 1);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2406
	for (; i < namelen - 1; i++)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2407
		name[i] = '.';
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2408
	name[i] = '\0';
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2409
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2410
	if (ztest_random(2) == 0)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2411
		object = ZTEST_MICROZAP_OBJ;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2412
	else
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2413
		object = ZTEST_FATZAP_OBJ;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2414
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2415
	if ((namelen & 1) || object == ZTEST_MICROZAP_OBJ) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2416
		wsize = sizeof (txg);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2417
		wc = 1;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2418
		data = &txg;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2419
	} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2420
		wsize = 1;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2421
		wc = namelen;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2422
		data = string_value;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2423
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2424
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2425
	count = -1ULL;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2426
	VERIFY(zap_count(os, object, &count) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2427
	ASSERT(count != -1ULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2428
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2429
	/*
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2430
	 * Select an operation: length, lookup, add, update, remove.
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2431
	 */
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2432
	i = ztest_random(5);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2433
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2434
	if (i >= 2) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2435
		tx = dmu_tx_create(os);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2436
		dmu_tx_hold_zap(tx, object, TRUE, NULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2437
		error = dmu_tx_assign(tx, TXG_WAIT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2438
		if (error) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2439
			ztest_record_enospc("zap parallel");
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2440
			dmu_tx_abort(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2441
			return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2442
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2443
		txg = dmu_tx_get_txg(tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2444
		bcopy(name, string_value, namelen);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2445
	} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2446
		tx = NULL;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2447
		txg = 0;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2448
		bzero(string_value, namelen);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2449
	}
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2450
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2451
	switch (i) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2452
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2453
	case 0:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2454
		error = zap_length(os, object, name, &zl_wsize, &zl_wc);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2455
		if (error == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2456
			ASSERT3U(wsize, ==, zl_wsize);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2457
			ASSERT3U(wc, ==, zl_wc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2458
		} else {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2459
			ASSERT3U(error, ==, ENOENT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2460
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2461
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2462
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2463
	case 1:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2464
		error = zap_lookup(os, object, name, wsize, wc, data);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2465
		if (error == 0) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2466
			if (data == string_value &&
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2467
			    bcmp(name, data, namelen) != 0)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2468
				fatal(0, "name '%s' != val '%s' len %d",
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2469
				    name, data, namelen);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2470
		} else {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2471
			ASSERT3U(error, ==, ENOENT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2472
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2473
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2474
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2475
	case 2:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2476
		error = zap_add(os, object, name, wsize, wc, data, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2477
		ASSERT(error == 0 || error == EEXIST);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2478
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2479
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2480
	case 3:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2481
		VERIFY(zap_update(os, object, name, wsize, wc, data, tx) == 0);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2482
		break;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2483
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2484
	case 4:
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2485
		error = zap_remove(os, object, name, tx);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2486
		ASSERT(error == 0 || error == ENOENT);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2487
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2488
	}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2489
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2490
	if (tx != NULL)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2491
		dmu_tx_commit(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2492
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2494
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2495
ztest_dsl_prop_get_set(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2496
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2497
	objset_t *os = za->za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2498
	int i, inherit;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2499
	uint64_t value;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2500
	const char *prop, *valname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2501
	char setpoint[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2502
	char osname[MAXNAMELEN];
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2503
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2504
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2505
	(void) rw_rdlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2506
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2507
	dmu_objset_name(os, osname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2508
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2509
	for (i = 0; i < 2; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2510
		if (i == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2511
			prop = "checksum";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2512
			value = ztest_random_checksum();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2513
			inherit = (value == ZIO_CHECKSUM_INHERIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2514
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2515
			prop = "compression";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2516
			value = ztest_random_compress();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2517
			inherit = (value == ZIO_COMPRESS_INHERIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2518
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2519
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2520
		error = dsl_prop_set(osname, prop, sizeof (value),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2521
		    !inherit, &value);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2522
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2523
		if (error == ENOSPC) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2524
			ztest_record_enospc("dsl_prop_set");
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2525
			break;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2526
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2527
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2528
		ASSERT3U(error, ==, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2529
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2530
		VERIFY3U(dsl_prop_get(osname, prop, sizeof (value),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2531
		    1, &value, setpoint), ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2532
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2533
		if (i == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2534
			valname = zio_checksum_table[value].ci_name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2535
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2536
			valname = zio_compress_table[value].ci_name;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2538
		if (zopt_verbose >= 6) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2539
			(void) printf("%s %s = %s for '%s'\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2540
			    osname, prop, valname, setpoint);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2541
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2542
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2544
	(void) rw_unlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2545
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2547
static void
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2548
ztest_error_setup(vdev_t *vd, int mode, int mask, uint64_t arg)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2549
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2550
	int c;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2551
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2552
	for (c = 0; c < vd->vdev_children; c++)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2553
		ztest_error_setup(vd->vdev_child[c], mode, mask, arg);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2554
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2555
	if (vd->vdev_path != NULL) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2556
		vd->vdev_fault_mode = mode;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2557
		vd->vdev_fault_mask = mask;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2558
		vd->vdev_fault_arg = arg;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2559
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2560
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2561
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2562
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2563
 * Inject random faults into the on-disk data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2564
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2565
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2566
ztest_fault_inject(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2567
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2569
	uint64_t offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2570
	uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2571
	uint64_t bad = 0x1990c0ffeedecade;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
	uint64_t top, leaf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2573
	char path0[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2574
	char pathrand[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2575
	size_t fsize;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2576
	spa_t *spa = za->za_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2577
	int bshift = SPA_MAXBLOCKSHIFT + 2;	/* don't scrog all labels */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2578
	int iters = 1000;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2579
	vdev_t *vd0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2580
	uint64_t guid0 = 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2581
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2582
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2583
	 * We can't inject faults when we have no fault tolerance.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2584
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2585
	if (zopt_maxfaults == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2586
		return;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2587
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2588
	ASSERT(leaves >= 2);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2591
	 * Pick a random top-level vdev.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2593
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2594
	top = ztest_random(spa->spa_root_vdev->vdev_children);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2595
	spa_config_exit(spa, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2596
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2597
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2598
	 * Pick a random leaf.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2599
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2600
	leaf = ztest_random(leaves);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2601
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2602
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2603
	 * Generate paths to the first two leaves in this top-level vdev,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2604
	 * and to the random leaf we selected.  We'll induce transient
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2605
	 * I/O errors and random online/offline activity on leaf 0,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2606
	 * and we'll write random garbage to the randomly chosen leaf.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2607
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2608
	(void) snprintf(path0, sizeof (path0),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2609
	    ztest_dev_template, zopt_dir, zopt_pool, top * leaves + 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2610
	(void) snprintf(pathrand, sizeof (pathrand),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2611
	    ztest_dev_template, zopt_dir, zopt_pool, top * leaves + leaf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2612
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2613
	dprintf("damaging %s and %s\n", path0, pathrand);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2614
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2615
	spa_config_enter(spa, RW_READER, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2616
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2617
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2618
	 * If we can tolerate two or more faults, make vd0 fail randomly.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2619
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2620
	vd0 = vdev_lookup_by_path(spa->spa_root_vdev, path0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2621
	if (vd0 != NULL && zopt_maxfaults >= 2) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2622
		guid0 = vd0->vdev_guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2623
		ztest_error_setup(vd0, VDEV_FAULT_COUNT,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2624
		    (1U << ZIO_TYPE_READ) | (1U << ZIO_TYPE_WRITE), 100);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2625
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2626
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2627
	spa_config_exit(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2628
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2629
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2630
	 * If we can tolerate two or more faults, randomly online/offline vd0.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2631
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2632
	if (zopt_maxfaults >= 2 && guid0 != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2633
		if (ztest_random(10) < 6)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2634
			(void) vdev_offline(spa, guid0, B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2635
		else
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4008
diff changeset
  2636
			(void) vdev_online(spa, guid0, B_FALSE, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2637
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2638
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2639
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2640
	 * We have at least single-fault tolerance, so inject data corruption.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2641
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2642
	fd = open(pathrand, O_RDWR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2643
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2644
	if (fd == -1)	/* we hit a gap in the device namespace */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2645
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2646
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2647
	fsize = lseek(fd, 0, SEEK_END);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2648
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2649
	while (--iters != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2650
		offset = ztest_random(fsize / (leaves << bshift)) *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2651
		    (leaves << bshift) + (leaf << bshift) +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2652
		    (ztest_random(1ULL << (bshift - 1)) & -8ULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2653
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2654
		if (offset >= fsize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2655
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2656
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2657
		if (zopt_verbose >= 6)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2658
			(void) printf("injecting bad word into %s,"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2659
			    " offset 0x%llx\n", pathrand, (u_longlong_t)offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2660
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2661
		if (pwrite(fd, &bad, sizeof (bad), offset) != sizeof (bad))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2662
			fatal(1, "can't inject bad word at 0x%llx in %s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2663
			    offset, pathrand);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2664
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2665
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2666
	(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2667
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2669
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2670
 * Scrub the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2671
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2672
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2673
ztest_scrub(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2674
{
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2675
	spa_t *spa = za->za_spa;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2676
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4715
diff changeset
  2677
	mutex_enter(&spa_namespace_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2678
	(void) spa_scrub(spa, POOL_SCRUB_EVERYTHING, B_FALSE);
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4715
diff changeset
  2679
	mutex_exit(&spa_namespace_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2680
	(void) poll(NULL, 0, 1000); /* wait a second, then force a restart */
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4715
diff changeset
  2681
	mutex_enter(&spa_namespace_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2682
	(void) spa_scrub(spa, POOL_SCRUB_EVERYTHING, B_FALSE);
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4715
diff changeset
  2683
	mutex_exit(&spa_namespace_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2684
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2685
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2686
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2687
 * Rename the pool to a different name and then rename it back.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2688
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2689
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2690
ztest_spa_rename(ztest_args_t *za)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2691
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2692
	char *oldname, *newname;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2693
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2694
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2696
	(void) rw_wrlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2697
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2698
	oldname = za->za_pool;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2699
	newname = umem_alloc(strlen(oldname) + 5, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2700
	(void) strcpy(newname, oldname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2701
	(void) strcat(newname, "_tmp");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2702
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2703
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2704
	 * Do the rename
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2705
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2706
	error = spa_rename(oldname, newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2707
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2708
		fatal(0, "spa_rename('%s', '%s') = %d", oldname,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2709
		    newname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2710
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2711
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2712
	 * Try to open it under the old name, which shouldn't exist
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2713
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2714
	error = spa_open(oldname, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2715
	if (error != ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2716
		fatal(0, "spa_open('%s') = %d", oldname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2717
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2718
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2719
	 * Open it under the new name and make sure it's still the same spa_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2720
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
	error = spa_open(newname, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2722
	if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2723
		fatal(0, "spa_open('%s') = %d", newname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2725
	ASSERT(spa == za->za_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2726
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2727
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2728
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
	 * Rename it back to the original
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2730
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2731
	error = spa_rename(newname, oldname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2732
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2733
		fatal(0, "spa_rename('%s', '%s') = %d", newname,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2734
		    oldname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2736
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2737
	 * Make sure it can still be opened
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2738
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2739
	error = spa_open(oldname, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2740
	if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2741
		fatal(0, "spa_open('%s') = %d", oldname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2742
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2743
	ASSERT(spa == za->za_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2744
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2745
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2746
	umem_free(newname, strlen(newname) + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2747
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2748
	(void) rw_unlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2749
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2750
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2751
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2752
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2753
 * Completely obliterate one disk.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2754
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2755
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2756
ztest_obliterate_one_disk(uint64_t vdev)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2757
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2758
	int fd;
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  2759
	char dev_name[MAXPATHLEN], copy_name[MAXPATHLEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2760
	size_t fsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2761
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2762
	if (zopt_maxfaults < 2)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2763
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2764
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2765
	(void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  2766
	(void) snprintf(copy_name, MAXPATHLEN, "%s.old", dev_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2767
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2768
	fd = open(dev_name, O_RDWR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2769
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2770
	if (fd == -1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2771
		fatal(1, "can't open %s", dev_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2772
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2773
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2774
	 * Determine the size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2775
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2776
	fsize = lseek(fd, 0, SEEK_END);
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  2777
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2778
	(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2779
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2780
	/*
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  2781
	 * Rename the old device to dev_name.old (useful for debugging).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2782
	 */
1807
35c8b566d7af 6410711 intent log blocks don't get invited to pool parties
bonwick
parents: 1775
diff changeset
  2783
	VERIFY(rename(dev_name, copy_name) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2784
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2785
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2786
	 * Create a new one.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2787
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2788
	VERIFY((fd = open(dev_name, O_RDWR | O_CREAT | O_TRUNC, 0666)) >= 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2789
	VERIFY(ftruncate(fd, fsize) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2790
	(void) close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2791
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2792
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2793
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2794
ztest_replace_one_disk(spa_t *spa, uint64_t vdev)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2795
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2796
	char dev_name[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2797
	nvlist_t *file, *root;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2798
	int error;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2799
	uint64_t guid;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2800
	uint64_t ashift = ztest_get_ashift();
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2801
	vdev_t *vd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2802
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2803
	(void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2804
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2805
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2806
	 * Build the nvlist describing dev_name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2807
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2808
	VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2809
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2810
	VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, dev_name) == 0);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2811
	VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2812
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2813
	VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2814
	VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2815
	VERIFY(nvlist_add_nvlist_array(root, ZPOOL_CONFIG_CHILDREN,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2816
	    &file, 1) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2817
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2818
	spa_config_enter(spa, RW_READER, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2819
	if ((vd = vdev_lookup_by_path(spa->spa_root_vdev, dev_name)) == NULL)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2820
		guid = 0;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2821
	else
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2822
		guid = vd->vdev_guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2823
	spa_config_exit(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2824
	error = spa_vdev_attach(spa, guid, root, B_TRUE);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2825
	if (error != 0 &&
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2826
	    error != EBUSY &&
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2827
	    error != ENOTSUP &&
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2828
	    error != ENODEV &&
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  2829
	    error != EDOM)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2830
		fatal(0, "spa_vdev_attach(in-place) = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2831
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2832
	nvlist_free(file);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2833
	nvlist_free(root);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2834
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2835
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2836
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2837
ztest_verify_blocks(char *pool)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2838
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2839
	int status;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2840
	char zdb[MAXPATHLEN + MAXNAMELEN + 20];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2841
	char zbuf[1024];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2842
	char *bin;
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2843
	char *ztest;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2844
	char *isa;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2845
	int isalen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2846
	FILE *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2847
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2848
	(void) realpath(getexecname(), zdb);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2849
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2850
	/* zdb lives in /usr/sbin, while ztest lives in /usr/bin */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2851
	bin = strstr(zdb, "/usr/bin/");
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2852
	ztest = strstr(bin, "/ztest");
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2853
	isa = bin + 8;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2854
	isalen = ztest - isa;
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2855
	isa = strdup(isa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2856
	/* LINTED */
5994
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5530
diff changeset
  2857
	(void) sprintf(bin,
bedab011a2e5 6580270 'zdb [-C|-L] <pool'> can't open alternate root pools
ck153898
parents: 5530
diff changeset
  2858
	    "/usr/sbin%.*s/zdb -bc%s%s -U /tmp/zpool.cache -O %s %s",
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2859
	    isalen,
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2860
	    isa,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2861
	    zopt_verbose >= 3 ? "s" : "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2862
	    zopt_verbose >= 4 ? "v" : "",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2863
	    ztest_random(2) == 0 ? "pre" : "post", pool);
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  2864
	free(isa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2865
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2866
	if (zopt_verbose >= 5)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2867
		(void) printf("Executing %s\n", strstr(zdb, "zdb "));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2868
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2869
	fp = popen(zdb, "r");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2870
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2871
	while (fgets(zbuf, sizeof (zbuf), fp) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2872
		if (zopt_verbose >= 3)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2873
			(void) printf("%s", zbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2874
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2875
	status = pclose(fp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2876
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2877
	if (status == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2878
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2879
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2880
	ztest_dump_core = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2881
	if (WIFEXITED(status))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2882
		fatal(0, "'%s' exit code %d", zdb, WEXITSTATUS(status));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2883
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2884
		fatal(0, "'%s' died with signal %d", zdb, WTERMSIG(status));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2885
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2886
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2887
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2888
ztest_walk_pool_directory(char *header)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2889
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2890
	spa_t *spa = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2891
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2892
	if (zopt_verbose >= 6)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2893
		(void) printf("%s\n", header);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2894
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2895
	mutex_enter(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2896
	while ((spa = spa_next(spa)) != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2897
		if (zopt_verbose >= 6)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2898
			(void) printf("\t%s\n", spa_name(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2899
	mutex_exit(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2900
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2901
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2902
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2903
ztest_spa_import_export(char *oldname, char *newname)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2904
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2905
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2906
	uint64_t pool_guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2907
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2908
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2909
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2910
	if (zopt_verbose >= 4) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2911
		(void) printf("import/export: old = %s, new = %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2912
		    oldname, newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2913
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2914
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2915
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2916
	 * Clean up from previous runs.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2917
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2918
	(void) spa_destroy(newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2919
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2920
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2921
	 * Get the pool's configuration and guid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2922
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2923
	error = spa_open(oldname, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2924
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2925
		fatal(0, "spa_open('%s') = %d", oldname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2927
	pool_guid = spa_guid(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2928
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2929
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2930
	ztest_walk_pool_directory("pools before export");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2931
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2932
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2933
	 * Export it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2934
	 */
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2935
	error = spa_export(oldname, &config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2936
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2937
		fatal(0, "spa_export('%s') = %d", oldname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2938
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2939
	ztest_walk_pool_directory("pools after export");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2940
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2941
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2942
	 * Import it under the new name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2943
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2944
	error = spa_import(newname, config, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2945
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2946
		fatal(0, "spa_import('%s') = %d", newname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2947
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2948
	ztest_walk_pool_directory("pools after import");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2949
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2950
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2951
	 * Try to import it again -- should fail with EEXIST.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2952
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2953
	error = spa_import(newname, config, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2954
	if (error != EEXIST)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2955
		fatal(0, "spa_import('%s') twice", newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2956
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2957
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2958
	 * Try to import it under a different name -- should fail with EEXIST.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2959
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2960
	error = spa_import(oldname, config, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2961
	if (error != EEXIST)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2962
		fatal(0, "spa_import('%s') under multiple names", newname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2963
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2964
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2965
	 * Verify that the pool is no longer visible under the old name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2966
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2967
	error = spa_open(oldname, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2968
	if (error != ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2969
		fatal(0, "spa_open('%s') = %d", newname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2970
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2971
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2972
	 * Verify that we can open and close the pool using the new name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2973
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2974
	error = spa_open(newname, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2975
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2976
		fatal(0, "spa_open('%s') = %d", newname, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2977
	ASSERT(pool_guid == spa_guid(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2978
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2979
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2980
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2981
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2982
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2983
/* ARGSUSED */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2984
static void *
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2985
ztest_suspend_monitor(void *arg)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2986
{
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2987
	spa_t *spa;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2988
	int error;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2989
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2990
	error = spa_open(zopt_pool, &spa, FTAG);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2991
	if (error) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2992
		(void) printf("Unable to monitor pool '%s'\n", zopt_pool);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2993
		return (NULL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2994
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2995
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2996
	while (!ztest_exiting) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2997
		mutex_enter(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2998
		while (!ztest_exiting && list_is_empty(&spa->spa_zio_list))
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  2999
			cv_wait(&spa->spa_zio_cv, &spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3000
		mutex_exit(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3001
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3002
		(void) sleep(3);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3003
		/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3004
		 * We don't hold the spa_config_lock since the pool is in
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3005
		 * complete failure mode and there is no way for us to
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3006
		 * change the vdev config when we're in this state.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3007
		 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3008
		while ((error = zio_vdev_resume_io(spa)) != 0) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3009
			(void) printf("I/O could not be resumed, %d\n", error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3010
			(void) sleep(1);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3011
		}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3012
		vdev_clear(spa, NULL, B_TRUE);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3013
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3014
	spa_close(spa, FTAG);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3015
	return (NULL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3016
}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3017
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3018
static void *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3019
ztest_thread(void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3020
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3021
	ztest_args_t *za = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3022
	ztest_shared_t *zs = ztest_shared;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3023
	hrtime_t now, functime;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3024
	ztest_info_t *zi;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3025
	int f, i;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3026
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3027
	while ((now = gethrtime()) < za->za_stop) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3028
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3029
		 * See if it's time to force a crash.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3030
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3031
		if (now > za->za_kill) {
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3032
			zs->zs_alloc = spa_get_alloc(za->za_spa);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3033
			zs->zs_space = spa_get_space(za->za_spa);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3034
			(void) kill(getpid(), SIGKILL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3035
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3036
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3037
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3038
		 * Pick a random function.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3039
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3040
		f = ztest_random(ZTEST_FUNCS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3041
		zi = &zs->zs_info[f];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3042
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3043
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3044
		 * Decide whether to call it, based on the requested frequency.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3045
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3046
		if (zi->zi_call_target == 0 ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3047
		    (double)zi->zi_call_total / zi->zi_call_target >
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3048
		    (double)(now - zs->zs_start_time) / (zopt_time * NANOSEC))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3049
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3050
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3051
		atomic_add_64(&zi->zi_calls, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3052
		atomic_add_64(&zi->zi_call_total, 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3053
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3054
		za->za_diroff = (za->za_instance * ZTEST_FUNCS + f) *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3055
		    ZTEST_DIRSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3056
		za->za_diroff_shared = (1ULL << 63);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3057
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3058
		for (i = 0; i < zi->zi_iters; i++)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3059
			zi->zi_func(za);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3060
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3061
		functime = gethrtime() - now;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3062
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3063
		atomic_add_64(&zi->zi_call_time, functime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3064
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3065
		if (zopt_verbose >= 4) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3066
			Dl_info dli;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3067
			(void) dladdr((void *)zi->zi_func, &dli);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3068
			(void) printf("%6.2f sec in %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3069
			    (double)functime / NANOSEC, dli.dli_sname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3070
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3071
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3072
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3073
		 * If we're getting ENOSPC with some regularity, stop.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3074
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3075
		if (zs->zs_enospc_count > 10)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3076
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3077
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3078
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3079
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3080
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3081
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3082
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3083
 * Kick off threads to run tests on all datasets in parallel.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3084
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3085
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3086
ztest_run(char *pool)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3087
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3088
	int t, d, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3089
	ztest_shared_t *zs = ztest_shared;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3090
	ztest_args_t *za;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3091
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3092
	char name[100];
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3093
	thread_t tid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3094
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3095
	(void) _mutex_init(&zs->zs_vdev_lock, USYNC_THREAD, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3096
	(void) rwlock_init(&zs->zs_name_lock, USYNC_THREAD, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3097
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3098
	for (t = 0; t < ZTEST_SYNC_LOCKS; t++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3099
		(void) _mutex_init(&zs->zs_sync_lock[t], USYNC_THREAD, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3100
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3101
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3102
	 * Destroy one disk before we even start.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3103
	 * It's mirrored, so everything should work just fine.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3104
	 * This makes us exercise fault handling very early in spa_load().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3105
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3106
	ztest_obliterate_one_disk(0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3108
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3109
	 * Verify that the sum of the sizes of all blocks in the pool
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3110
	 * equals the SPA's allocated space total.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3111
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3112
	ztest_verify_blocks(pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3113
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3114
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3115
	 * Kick off a replacement of the disk we just obliterated.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3116
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3117
	kernel_init(FREAD | FWRITE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3118
	error = spa_open(pool, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3119
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3120
		fatal(0, "spa_open(%s) = %d", pool, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3121
	ztest_replace_one_disk(spa, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3122
	if (zopt_verbose >= 5)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3123
		show_pool_stats(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3124
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3125
	kernel_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3126
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3127
	kernel_init(FREAD | FWRITE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3128
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3129
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3130
	 * Verify that we can export the pool and reimport it under a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3131
	 * different name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3132
	 */
1585
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
  3133
	if (ztest_random(2) == 0) {
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
  3134
		(void) snprintf(name, 100, "%s_import", pool);
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
  3135
		ztest_spa_import_export(pool, name);
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
  3136
		ztest_spa_import_export(name, pool);
4ad213e858a9 6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents: 1544
diff changeset
  3137
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3138
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3139
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3140
	 * Verify that we can loop over all pools.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3141
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3142
	mutex_enter(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3143
	for (spa = spa_next(NULL); spa != NULL; spa = spa_next(spa)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3144
		if (zopt_verbose > 3) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3145
			(void) printf("spa_next: found %s\n", spa_name(spa));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3146
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3147
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3148
	mutex_exit(&spa_namespace_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3149
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3150
	/*
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3151
	 * Create a thread to handling complete pool failures. This
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3152
	 * thread will kickstart the I/Os when they suspend. We must
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3153
	 * start the thread before setting the zio_io_fail_shift, which
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3154
	 * will indicate our failure rate.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3155
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3156
	error = thr_create(0, 0, ztest_suspend_monitor, NULL, THR_BOUND, &tid);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3157
	if (error) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3158
		fatal(0, "can't create suspend monitor thread: error %d",
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3159
		    t, error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3160
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3161
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3162
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3163
	 * Open our pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3164
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3165
	error = spa_open(pool, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3166
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3167
		fatal(0, "spa_open() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3168
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3169
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3170
	 * Verify that we can safely inquire about about any object,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3171
	 * whether it's allocated or not.  To make it interesting,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3172
	 * we probe a 5-wide window around each power of two.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3173
	 * This hits all edge cases, including zero and the max.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3174
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3175
	for (t = 0; t < 64; t++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3176
		for (d = -5; d <= 5; d++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3177
			error = dmu_object_info(spa->spa_meta_objset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3178
			    (1ULL << t) + d, NULL);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3179
			ASSERT(error == 0 || error == ENOENT ||
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3180
			    error == EINVAL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3181
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3182
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3183
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3184
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3185
	 * Now kick off all the tests that run in parallel.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3186
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3187
	zs->zs_enospc_count = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3189
	za = umem_zalloc(zopt_threads * sizeof (ztest_args_t), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3190
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3191
	if (zopt_verbose >= 4)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3192
		(void) printf("starting main threads...\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3193
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3194
	/* Let failures begin */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3195
	zio_io_fail_shift = zopt_write_fail_shift;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3196
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3197
	za[0].za_start = gethrtime();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3198
	za[0].za_stop = za[0].za_start + zopt_passtime * NANOSEC;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3199
	za[0].za_stop = MIN(za[0].za_stop, zs->zs_stop_time);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3200
	za[0].za_kill = za[0].za_stop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3201
	if (ztest_random(100) < zopt_killrate)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3202
		za[0].za_kill -= ztest_random(zopt_passtime * NANOSEC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3203
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3204
	for (t = 0; t < zopt_threads; t++) {
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  3205
		d = t % zopt_datasets;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3206
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3207
		(void) strcpy(za[t].za_pool, pool);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3208
		za[t].za_os = za[d].za_os;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3209
		za[t].za_spa = spa;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3210
		za[t].za_zilog = za[d].za_zilog;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3211
		za[t].za_instance = t;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3212
		za[t].za_random = ztest_random(-1ULL);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3213
		za[t].za_start = za[0].za_start;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3214
		za[t].za_stop = za[0].za_stop;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3215
		za[t].za_kill = za[0].za_kill;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3216
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  3217
		if (t < zopt_datasets) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3218
			ztest_replay_t zr;
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3219
			int test_future = FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3220
			(void) rw_rdlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3221
			(void) snprintf(name, 100, "%s/%s_%d", pool, pool, d);
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 5994
diff changeset
  3222
			error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3223
			    ztest_create_cb, NULL);
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3224
			if (error == EEXIST) {
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3225
				test_future = TRUE;
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3226
			} else if (error == ENOSPC) {
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3227
				zs->zs_enospc_count++;
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3228
				(void) rw_unlock(&ztest_shared->zs_name_lock);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3229
				break;
3711
2226ffbe7873 6526196 ZFS: assertion failed: zp->z_phys->zp_links > zp_is_dir
maybee
parents: 3668
diff changeset
  3230
			} else if (error != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3231
				fatal(0, "dmu_objset_create(%s) = %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3232
				    name, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3233
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3234
			error = dmu_objset_open(name, DMU_OST_OTHER,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3235
			    DS_MODE_STANDARD, &za[d].za_os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3236
			if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3237
				fatal(0, "dmu_objset_open('%s') = %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3238
				    name, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3239
			(void) rw_unlock(&ztest_shared->zs_name_lock);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3240
			if (test_future)
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3241
				ztest_dmu_check_future_leak(&za[t]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3242
			zr.zr_os = za[d].za_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3243
			zil_replay(zr.zr_os, &zr, &zr.zr_assign,
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 2856
diff changeset
  3244
			    ztest_replay_vector);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3245
			za[d].za_zilog = zil_open(za[d].za_os, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3246
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3247
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3248
		error = thr_create(0, 0, ztest_thread, &za[t], THR_BOUND,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3249
		    &za[t].za_thread);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3250
		if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3251
			fatal(0, "can't create thread %d: error %d",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3252
			    t, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3253
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3255
	while (--t >= 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3256
		error = thr_join(za[t].za_thread, NULL, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3257
		if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3258
			fatal(0, "thr_join(%d) = %d", t, error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3259
		if (za[t].za_th)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3260
			traverse_fini(za[t].za_th);
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  3261
		if (t < zopt_datasets) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3262
			zil_close(za[t].za_zilog);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3263
			dmu_objset_close(za[t].za_os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3264
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3265
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3266
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3267
	if (zopt_verbose >= 3)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3268
		show_pool_stats(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3270
	txg_wait_synced(spa_get_dsl(spa), 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3271
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3272
	zs->zs_alloc = spa_get_alloc(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3273
	zs->zs_space = spa_get_space(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3274
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3275
	/*
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3276
	 * If we had out-of-space errors, destroy a random objset.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3277
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3278
	if (zs->zs_enospc_count != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3279
		(void) rw_rdlock(&ztest_shared->zs_name_lock);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3280
		d = (int)ztest_random(zopt_datasets);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3281
		(void) snprintf(name, 100, "%s/%s_%d", pool, pool, d);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3282
		if (zopt_verbose >= 3)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3283
			(void) printf("Destroying %s to free up space\n", name);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3284
		(void) dmu_objset_find(name, ztest_destroy_cb, &za[d],
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2237
diff changeset
  3285
		    DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3286
		(void) rw_unlock(&ztest_shared->zs_name_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3287
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3288
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3289
	txg_wait_synced(spa_get_dsl(spa), 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3290
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3291
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3292
	 * Right before closing the pool, kick off a bunch of async I/O;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3293
	 * spa_close() should wait for it to complete.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3294
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3295
	for (t = 1; t < 50; t++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3296
		dmu_prefetch(spa->spa_meta_objset, t, 0, 1 << 15);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3297
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3298
	/* Shutdown the suspend monitor thread */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3299
	zio_io_fail_shift = 0;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3300
	ztest_exiting = B_TRUE;
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3301
	mutex_enter(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3302
	cv_broadcast(&spa->spa_zio_cv);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3303
	mutex_exit(&spa->spa_zio_lock);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3304
	error = thr_join(tid, NULL, NULL);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3305
	if (error)
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3306
		fatal(0, "thr_join(%d) = %d", tid, error);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4944
diff changeset
  3307
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3308
	umem_free(za, zopt_threads * sizeof (ztest_args_t));
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3309
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3310
	spa_close(spa, FTAG);
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  3311
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3312
	kernel_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3313
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3314
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3315
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3316
print_time(hrtime_t t, char *timebuf)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3317
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3318
	hrtime_t s = t / NANOSEC;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3319
	hrtime_t m = s / 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3320
	hrtime_t h = m / 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3321
	hrtime_t d = h / 24;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3322
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3323
	s -= m * 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3324
	m -= h * 60;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3325
	h -= d * 24;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3327
	timebuf[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3328
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3329
	if (d)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3330
		(void) sprintf(timebuf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3331
		    "%llud%02lluh%02llum%02llus", d, h, m, s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3332
	else if (h)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3333
		(void) sprintf(timebuf, "%lluh%02llum%02llus", h, m, s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3334
	else if (m)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3335
		(void) sprintf(timebuf, "%llum%02llus", m, s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3336
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3337
		(void) sprintf(timebuf, "%llus", s);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3338
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3339
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3340
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3341
 * Create a storage pool with the given name and initial vdev size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3342
 * Then create the specified number of datasets in the pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3343
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3344
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3345
ztest_init(char *pool)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3346
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3347
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3348
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3349
	nvlist_t *nvroot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3350
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3351
	kernel_init(FREAD | FWRITE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3352
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3353
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3354
	 * Create the storage pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3355
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3356
	(void) spa_destroy(pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3357
	ztest_shared->zs_vdev_primaries = 0;
4527
5d5b6ba91b17 PSARC 2007/171 ZFS Separate Intent Log
perrin
parents: 4451
diff changeset
  3358
	nvroot = make_vdev_root(zopt_vdev_size, 0, zopt_raidz, zopt_mirrors, 1);
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4543
diff changeset
  3359
	error = spa_create(pool, nvroot, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3360
	nvlist_free(nvroot);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3361
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3362
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3363
		fatal(0, "spa_create() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3364
	error = spa_open(pool, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3365
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3366
		fatal(0, "spa_open() = %d", error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3367
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3368
	if (zopt_verbose >= 3)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3369
		show_pool_stats(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3370
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3371
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3372
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3373
	kernel_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3374
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3375
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3376
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3377
main(int argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3378
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3379
	int kills = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3380
	int iters = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3381
	int i, f;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3382
	ztest_shared_t *zs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3383
	ztest_info_t *zi;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3384
	char timebuf[100];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3385
	char numbuf[6];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3386
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3387
	(void) setvbuf(stdout, NULL, _IOLBF, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3388
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3389
	/* Override location of zpool.cache */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3390
	spa_config_dir = "/tmp";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3391
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3392
	ztest_random_fd = open("/dev/urandom", O_RDONLY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3393
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3394
	process_options(argc, argv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3395
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3396
	argc -= optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3397
	argv += optind;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3398
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3399
	dprintf_setup(&argc, argv);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3400
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3401
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3402
	 * Blow away any existing copy of zpool.cache
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3403
	 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3404
	if (zopt_init != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3405
		(void) remove("/tmp/zpool.cache");
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3406
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3407
	zs = ztest_shared = (void *)mmap(0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3408
	    P2ROUNDUP(sizeof (ztest_shared_t), getpagesize()),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3409
	    PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3411
	if (zopt_verbose >= 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3412
		(void) printf("%llu vdevs, %d datasets, %d threads,"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3413
		    " %llu seconds...\n",
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1731
diff changeset
  3414
		    (u_longlong_t)zopt_vdevs, zopt_datasets, zopt_threads,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3415
		    (u_longlong_t)zopt_time);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3416
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3417
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3418
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3419
	 * Create and initialize our storage pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3420
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3421
	for (i = 1; i <= zopt_init; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3422
		bzero(zs, sizeof (ztest_shared_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3423
		if (zopt_verbose >= 3 && zopt_init != 1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3424
			(void) printf("ztest_init(), pass %d\n", i);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3425
		ztest_init(zopt_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3426
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3427
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3428
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3429
	 * Initialize the call targets for each function.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3430
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3431
	for (f = 0; f < ZTEST_FUNCS; f++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3432
		zi = &zs->zs_info[f];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3433
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3434
		*zi = ztest_info[f];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3436
		if (*zi->zi_interval == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3437
			zi->zi_call_target = UINT64_MAX;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3438
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3439
			zi->zi_call_target = zopt_time / *zi->zi_interval;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3440
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3441
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3442
	zs->zs_start_time = gethrtime();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3443
	zs->zs_stop_time = zs->zs_start_time + zopt_time * NANOSEC;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3444
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3445
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3446
	 * Run the tests in a loop.  These tests include fault injection
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3447
	 * to verify that self-healing data works, and forced crashes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3448
	 * to verify that we never lose on-disk consistency.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3449
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3450
	while (gethrtime() < zs->zs_stop_time) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3451
		int status;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3452
		pid_t pid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3453
		char *tmp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3454
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3455
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3456
		 * Initialize the workload counters for each function.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3457
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3458
		for (f = 0; f < ZTEST_FUNCS; f++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3459
			zi = &zs->zs_info[f];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3460
			zi->zi_calls = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3461
			zi->zi_call_time = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3462
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3463
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3464
		pid = fork();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3465
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3466
		if (pid == -1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3467
			fatal(1, "fork failed");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3468
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3469
		if (pid == 0) {	/* child */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3470
			struct rlimit rl = { 1024, 1024 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3471
			(void) setrlimit(RLIMIT_NOFILE, &rl);
1914
8a8c5f225b1b 4916205 libcmd should not use file operation routines from C library
casper
parents: 1807
diff changeset
  3472
			(void) enable_extended_FILE_stdio(-1, -1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3473
			ztest_run(zopt_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3474
			exit(0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3475
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3476
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  3477
		while (waitpid(pid, &status, 0) != pid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3478
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3479
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3480
		if (WIFEXITED(status)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3481
			if (WEXITSTATUS(status) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3482
				(void) fprintf(stderr,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3483
				    "child exited with code %d\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3484
				    WEXITSTATUS(status));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3485
				exit(2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3486
			}
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  3487
		} else if (WIFSIGNALED(status)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3488
			if (WTERMSIG(status) != SIGKILL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3489
				(void) fprintf(stderr,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3490
				    "child died with signal %d\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3491
				    WTERMSIG(status));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3492
				exit(3);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3493
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3494
			kills++;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  3495
		} else {
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  3496
			(void) fprintf(stderr, "something strange happened "
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  3497
			    "to child\n");
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2638
diff changeset
  3498
			exit(4);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3499
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3500
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3501
		iters++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3502
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3503
		if (zopt_verbose >= 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3504
			hrtime_t now = gethrtime();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3506
			now = MIN(now, zs->zs_stop_time);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3507
			print_time(zs->zs_stop_time - now, timebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3508
			nicenum(zs->zs_space, numbuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3509
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3510
			(void) printf("Pass %3d, %8s, %3llu ENOSPC, "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3511
			    "%4.1f%% of %5s used, %3.0f%% done, %8s to go\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3512
			    iters,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3513
			    WIFEXITED(status) ? "Complete" : "SIGKILL",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3514
			    (u_longlong_t)zs->zs_enospc_count,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3515
			    100.0 * zs->zs_alloc / zs->zs_space,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3516
			    numbuf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3517
			    100.0 * (now - zs->zs_start_time) /
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3518
			    (zopt_time * NANOSEC), timebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3519
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3520
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3521
		if (zopt_verbose >= 2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3522
			(void) printf("\nWorkload summary:\n\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3523
			(void) printf("%7s %9s   %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3524
			    "Calls", "Time", "Function");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3525
			(void) printf("%7s %9s   %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3526
			    "-----", "----", "--------");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3527
			for (f = 0; f < ZTEST_FUNCS; f++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3528
				Dl_info dli;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3529
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3530
				zi = &zs->zs_info[f];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3531
				print_time(zi->zi_call_time, timebuf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3532
				(void) dladdr((void *)zi->zi_func, &dli);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3533
				(void) printf("%7llu %9s   %s\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3534
				    (u_longlong_t)zi->zi_calls, timebuf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3535
				    dli.dli_sname);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3536
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3537
			(void) printf("\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3538
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3539
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3540
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3541
		 * It's possible that we killed a child during a rename test, in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3542
		 * which case we'll have a 'ztest_tmp' pool lying around instead
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3543
		 * of 'ztest'.  Do a blind rename in case this happened.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3544
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3545
		tmp = umem_alloc(strlen(zopt_pool) + 5, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3546
		(void) strcpy(tmp, zopt_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3547
		(void) strcat(tmp, "_tmp");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3548
		kernel_init(FREAD | FWRITE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3549
		(void) spa_rename(tmp, zopt_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3550
		kernel_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3551
		umem_free(tmp, strlen(tmp) + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3552
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3553
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3554
	ztest_verify_blocks(zopt_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3555
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3556
	if (zopt_verbose >= 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3557
		(void) printf("%d killed, %d completed, %.0f%% kill rate\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3558
		    kills, iters - kills, (100.0 * kills) / MAX(1, iters));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3559
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3560
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3561
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3562
}